1 | dnl $Id: ftest_util.m4,v 1.11 1997-11-13 08:37:43 schmidt Exp $ |
---|
2 | dnl |
---|
3 | dnl ftest_util.m4 - m4 macros used by the factory test environment. |
---|
4 | dnl |
---|
5 | dnl "External" macro start with prefix `ftest', "internal" macros |
---|
6 | dnl with prefix `_'. |
---|
7 | dnl |
---|
8 | dnl Note: mind the ';'! |
---|
9 | dnl |
---|
10 | dnl do not output anything of this library |
---|
11 | divert(-1) |
---|
12 | |
---|
13 | # |
---|
14 | # - internal macros. |
---|
15 | # |
---|
16 | |
---|
17 | # |
---|
18 | # _stripTWS() - strip trailing white space from $1. |
---|
19 | # |
---|
20 | define(`_stripTWS', `dnl |
---|
21 | patsubst(`$1', `[ ]*$')') |
---|
22 | |
---|
23 | # |
---|
24 | # _qstripTWS() - strip trailing white space from $1, return |
---|
25 | # quoted result. |
---|
26 | # |
---|
27 | define(`_qstripTWS', `dnl |
---|
28 | ifelse( |
---|
29 | translit(`$1', ` '), `', , |
---|
30 | `patsubst(`$1', `\(.*[^ ]\)[ ]*$', ``\1'')')') |
---|
31 | |
---|
32 | |
---|
33 | # |
---|
34 | # - external macros. |
---|
35 | # |
---|
36 | |
---|
37 | # |
---|
38 | # ftestSetNameOfGame() - set name of game. |
---|
39 | # |
---|
40 | # $1: name of algorithm |
---|
41 | # $2: usage of algorithm |
---|
42 | # |
---|
43 | # These are stored in the macros `ftestAlgorithm' and |
---|
44 | # `ftestUsage', resp. Leave notice on creator of this file. |
---|
45 | # |
---|
46 | define(`ftestSetNameOfGame', `dnl |
---|
47 | define(`ftestAlgorithm',``$1'')dnl |
---|
48 | define(`ftestUsage',``$2'')dnl |
---|
49 | `/* This file was automatically generated by m4 using the ftest_util.m4 library */'') |
---|
50 | |
---|
51 | # |
---|
52 | # ftestPreprocInit() - initial preprocessor directives. |
---|
53 | # |
---|
54 | # In addition, we change m4's comment character. |
---|
55 | # |
---|
56 | define(`ftestPreprocInit', `dnl |
---|
57 | changecom(`//')dnl |
---|
58 | `#include <unistd.h> |
---|
59 | |
---|
60 | #define TIMING |
---|
61 | #include <timing.h> |
---|
62 | |
---|
63 | #include <factory.h> |
---|
64 | |
---|
65 | #include "ftest_util.h" |
---|
66 | #include "ftest_io.h" |
---|
67 | '') |
---|
68 | |
---|
69 | # |
---|
70 | # ftestGlobalInit() - global initialization. |
---|
71 | # |
---|
72 | define(`ftestGlobalInit', `dnl |
---|
73 | `TIMING_DEFINE_PRINT( ftestTimer )'') |
---|
74 | |
---|
75 | # |
---|
76 | # ftestMainInit() - initialization in main(). |
---|
77 | # |
---|
78 | define(`ftestMainInit', `dnl |
---|
79 | `int optind = 0; |
---|
80 | ftestStatusT check = UndefinedResult; |
---|
81 | |
---|
82 | ftestSetName( argv[0], "'ftestAlgorithm`", 'ftestUsage`); |
---|
83 | |
---|
84 | ftestSignalCatch()'') |
---|
85 | |
---|
86 | # |
---|
87 | # ftestMainExit() - clean up in main(). |
---|
88 | # |
---|
89 | define(`ftestMainExit', `dnl |
---|
90 | `return check'') |
---|
91 | |
---|
92 | # |
---|
93 | # ftestOutVar() - declare output variable. |
---|
94 | # |
---|
95 | # $1: type of output variable |
---|
96 | # $2: name of output variable |
---|
97 | # |
---|
98 | # Stores type of variable in macro _ftestOutType_<name>. |
---|
99 | # |
---|
100 | define(`ftestOutVar', `dnl |
---|
101 | define(`_ftestOutType_'_qstripTWS(`$2'), `$1')dnl |
---|
102 | ifelse(`$1', `int', |
---|
103 | ``$1 '_qstripTWS(`$2')` = 0;'', |
---|
104 | ``$1 '_qstripTWS(`$2')`;'')') |
---|
105 | |
---|
106 | # |
---|
107 | # ftestInVar() - declare input variable. |
---|
108 | # |
---|
109 | # $1: type of input variable |
---|
110 | # $2: name of input variable |
---|
111 | # |
---|
112 | # Stores type of variable in macro _ftestInType_<name>. |
---|
113 | # |
---|
114 | define(`ftestInVar', `dnl |
---|
115 | define(`_ftestInType_'_qstripTWS(`$2'), `$1')dnl |
---|
116 | ifelse(`$1', `int', |
---|
117 | ``$1 '_qstripTWS(`$2')` = 0;'', |
---|
118 | ``$1 '_qstripTWS(`$2')`;'')` |
---|
119 | bool ftestArgGiven$2= false'') |
---|
120 | |
---|
121 | # |
---|
122 | # ftestGetOpts() - read options. |
---|
123 | # |
---|
124 | define(`ftestGetOpts', `dnl |
---|
125 | `ftestGetOpts( argc, argv, optind )'') |
---|
126 | |
---|
127 | # |
---|
128 | # ftestGetEnv() - read environment. |
---|
129 | # |
---|
130 | define(`ftestGetEnv', `dnl |
---|
131 | `ftestGetEnv( argc, argv, optind ); |
---|
132 | ftestPrintEnv()'') |
---|
133 | |
---|
134 | # |
---|
135 | # ftestGetInVar() - read variable from command line. |
---|
136 | # |
---|
137 | # $1: name of input variable |
---|
138 | # $2: default for optional command line arguments |
---|
139 | # |
---|
140 | define(`ftestGetInVar', `dnl |
---|
141 | ifelse(`$#', `1', |
---|
142 | ``if ( argv[ optind ] ) { |
---|
143 | ftestArgGiven$1= true; |
---|
144 | $1= ftestGet'_stripTWS(`_ftestInType_$1')`( argv[ optind++ ] ); |
---|
145 | } else |
---|
146 | ftestError( CommandlineError, |
---|
147 | "expected '_stripTWS(`_ftestInType_$1')` at position %d in commandline\n", |
---|
148 | optind )'', |
---|
149 | ``if ( argv[ optind ] ) { |
---|
150 | ftestArgGiven$1 = true; |
---|
151 | $1 = ftestGet'_stripTWS(`_ftestInType_$1')`( argv[ optind++ ] ); |
---|
152 | } else |
---|
153 | $1 = '_qstripTWS(`$2')')') |
---|
154 | |
---|
155 | # |
---|
156 | # ftestArgGiven() - check whether an argument was given. |
---|
157 | # |
---|
158 | # $1: name of input variable |
---|
159 | # |
---|
160 | define(`ftestArgGiven', `dnl |
---|
161 | `ftestArgGiven'_qstripTWS(`$1')') |
---|
162 | |
---|
163 | # |
---|
164 | # ftestSetEnv() - set factory environment. |
---|
165 | # |
---|
166 | define(`ftestSetEnv', `dnl |
---|
167 | `ftestSetEnv(); |
---|
168 | ftestPrintEnv()'') |
---|
169 | |
---|
170 | # |
---|
171 | # ftestRun() - run test. |
---|
172 | # |
---|
173 | # $1: code to execute |
---|
174 | # |
---|
175 | define(`ftestRun', `dnl |
---|
176 | `ftestWriteSeed(); // save random generator seed |
---|
177 | if ( ftestAlarm ) |
---|
178 | alarm( ftestAlarm ); // set alarm |
---|
179 | TIMING_START(ftestTimer); |
---|
180 | while ( ftestCircle > 0 ) { |
---|
181 | $1 |
---|
182 | ftestCircle--; |
---|
183 | }; |
---|
184 | TIMING_END(ftestTimer)'') |
---|
185 | |
---|
186 | # |
---|
187 | # ftestCheck() - run check. |
---|
188 | # |
---|
189 | # $1: check function (with parameters) to call |
---|
190 | # |
---|
191 | define(`ftestCheck', `dnl |
---|
192 | `check = '_qstripTWS(`$1')') |
---|
193 | |
---|
194 | # |
---|
195 | # ftestOuput() - print results. |
---|
196 | # |
---|
197 | # Expands to code to print timer and check. Then, for each |
---|
198 | # argument pair `resultName, result', expands to print this |
---|
199 | # pair. |
---|
200 | # |
---|
201 | |
---|
202 | # internal auxiliary function |
---|
203 | define(`_ftestOutput', `dnl |
---|
204 | ifelse(`$#', `0', , |
---|
205 | `$#', `1', , |
---|
206 | ``; |
---|
207 | ftestPrintResult( $1, '_qstripTWS(`$2')` )'_ftestOutput(shift(shift($@)))')') |
---|
208 | |
---|
209 | define(`ftestOutput', `dnl |
---|
210 | `ftestPrintTimer( timing_ftestTimer_time ); |
---|
211 | ftestPrintCheck( check )'_ftestOutput($@)') |
---|
212 | |
---|
213 | dnl switch on output again |
---|
214 | divert`'dnl |
---|