From: mdw Date: Sun, 14 Nov 1999 13:53:44 +0000 (+0000) Subject: New, more portable test vector generator written in AWK. X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/commitdiff_plain/50b059f06ae339df7403f80ea098055bc0245dad New, more portable test vector generator written in AWK. --- diff --git a/tests/mpx-gen b/tests/mpx-gen new file mode 100755 index 0000000..89cfdb3 --- /dev/null +++ b/tests/mpx-gen @@ -0,0 +1,96 @@ +#! /usr/bin/awk -f +# +# $Id: mpx-gen,v 1.1 1999/11/14 13:53:44 mdw Exp $ +# +# Generate test vectors for MPX testing + +# --- Generate an `l'-byte hex number --- + +function r(l, i, s, x) +{ + if (!l) l = len; + s = ""; + for (i = 0; i < l; i++) { + x = int(rand() * 256); + s = s sprintf("%02X", x); + } + return (s); +} + +# --- Main code --- + +BEGIN { + + # --- Initialization --- + + i = 1; + if (i in ARGV) len = ARGV[i++]; else len = 32; + if (i in ARGV) op = ARGV[i++]; else op = "+"; + if (i in ARGV) rep = ARGV[i++]; else rep = 1; + + # --- Output filters --- + + bc = "bc | sed 'y/ABCDEF/abcdef/; \ + s/^[0-9a-f]\\([0-9a-f][0-9a-f]\\)*$/0&/; \ + s/^/ /; \ + $ s/$/;/'"; + out = "sed 'y/ABCDEF/abcdef/; s/^/ /'" + + # --- Main code --- + + srand(); + + while (rep--) { + x = r(); + + print "obase = 16" | bc; + print "ibase = 16" | bc; + + # --- Shifting operations --- + + if (op == "<<" || op == ">>") { + y = int(rand() * len * 4) + int(rand() * len * 4); + rop = (op == "<<" ? "*" : "/"); + z = sprintf("%X", y); + print x, y | out; + print x, rop, "(2 ^ " z ")" | bc; + } + + # --- Division --- + + else if (op == "/") { + ylen = int(rand() * len) + 1; + y = r(ylen); + print x | out; + print y | out; + print x, "/", y | bc; + print x, "%", y | bc; + } + + # --- Squaring --- + + else if (op == "2") { + print x | out; + print x, "*", x | bc; + } + + # --- Other operations --- + + else { + y = r(); + if (op == "-" && x < y) { + t = x; x = y; y = t; + } + print x | out; + print y | out; + print x, op, y | bc; + } + + close(out); + close(bc); + if (rep) + print; + } + + exit 0; +}