configure.ac: Replace with a new version.
[u/mdw/catacomb] / tests / mpx-gen
1 #! /usr/bin/awk -f
2 #
3 # $Id: mpx-gen,v 1.2 1999/12/10 23:26:51 mdw Exp $
4 #
5 # Generate test vectors for MPX testing
6
7 # --- Generate an `l'-byte hex number ---
8
9 function r(l, i, s, x)
10 {
11 if (!l) l = len;
12 s = "";
13 for (i = 0; i < l; i++) {
14 x = int(rand() * 256);
15 s = s sprintf("%02X", x);
16 }
17 return (s);
18 }
19
20 # --- Main code ---
21
22 BEGIN {
23
24 # --- Initialization ---
25
26 i = 1;
27 if (i in ARGV) len = ARGV[i++]; else len = 32;
28 if (i in ARGV) op = ARGV[i++]; else op = "+";
29 if (i in ARGV) rep = ARGV[i++]; else rep = 1;
30
31 # --- Output filters ---
32 #
33 # This is complicated. `bc' emits numbers split over multiple lines with
34 # backslashes. It also doesn't pad to an even number of digits, which the
35 # test rig is expecting, or use lower-case, which looks nicer.
36 #
37 # The first bit matches a line ending with a backslash. If it finds one,
38 # it appends the next line, removes the backslash/newline pair, and loops
39 # around to the top.
40 #
41 # The next substitution translates the whole kaboodle into lower-case.
42 #
43 # The next one looks for an off number of hex digits and prepends a zero if
44 # it finds one.
45 #
46 # The one after that just indents by two spaces. The final one sticks a
47 # semicolon on the end.
48
49 bc = "bc | sed '\
50 :top\n\
51 /\\\\$/ {\n\
52 N\n\
53 s/\\\\\\\n\
54 //;\n\
55 b top;\n\
56 }\n\
57 y/ABCDEF/abcdef/\n\
58 s/^[0-9a-f]\\([0-9a-f][0-9a-f]\\)*$/0&/\n\
59 s/^/ /\n\
60 $ s/$/;/'";
61 out = "sed 'y/ABCDEF/abcdef/; s/^/ /'"
62
63 # --- Main code ---
64
65 srand();
66
67 while (rep--) {
68 x = r();
69
70 print "obase = 16" | bc;
71 print "ibase = 16" | bc;
72
73 # --- Shifting operations ---
74
75 if (op == "<<" || op == ">>") {
76 y = int(rand() * len * 4) + int(rand() * len * 4);
77 rop = (op == "<<" ? "*" : "/");
78 z = sprintf("%X", y);
79 print x, y | out;
80 print x, rop, "(2 ^ " z ")" | bc;
81 }
82
83 # --- Division ---
84
85 else if (op == "/") {
86 ylen = int(rand() * len) + 1;
87 y = r(ylen);
88 print x | out;
89 print y | out;
90 print x, "/", y | bc;
91 print x, "%", y | bc;
92 }
93
94 # --- Squaring ---
95
96 else if (op == "2") {
97 print x | out;
98 print x, "*", x | bc;
99 }
100
101 # --- Other operations ---
102
103 else {
104 y = r();
105 if (op == "-" && x < y) {
106 t = x; x = y; y = t;
107 }
108 print x | out;
109 print y | out;
110 print x, op, y | bc;
111 }
112
113 close(out);
114 close(bc);
115 if (rep)
116 print;
117 }
118
119 exit 0;
120 }