1 /* Test application (Mutatee) */
4 * $Log: test1.mutatee.c,v $
5 * Revision 1.2 1997/04/29 16:58:55 buck
6 * Added features to dyninstAPI library, including the ability to delete
7 * inserted snippets and the start of type checking.
9 * Revision 1.2 1997/04/09 17:20:54 buck
10 * Added test for deleting snippets.
12 * Revision 1.1.1.1 1997/04/01 20:25:16 buck
13 * Update Maryland repository with latest from Wisconsin.
15 * Revision 1.1 1997/03/18 19:45:22 buck
16 * first commit of dyninst library. Also includes:
17 * moving templates from paradynd to dyninstAPI
18 * converting showError into a function (in showerror.C)
19 * many ifdefs for BPATCH_LIBRARY in dyinstAPI/src.
24 #include <sys/types.h>
27 // control debug printf statements
28 #define dprintf if (debugPrint) printf
32 int globalVariable1_1 = 0;
33 int globalVariable3_1 = 31;
34 int globalVariable4_1 = 41;
35 int globalVariable5_1 = 51;
36 int globalVariable5_2 = 51;
38 int globalVariable6_1 = 0xdeadbeef;
39 int globalVariable6_2 = 0xdeadbeef;
40 int globalVariable6_3 = 0xdeadbeef;
41 int globalVariable6_4 = 0xdeadbeef;
42 int globalVariable6_5 = 0xdeadbeef;
43 int globalVariable6_6 = 0xdeadbeef;
45 int globalVariable7_1 = 71, globalVariable7_2 = 71,
46 globalVariable7_3 = 71, globalVariable7_4 = 71,
47 globalVariable7_5 = 71, globalVariable7_6 = 71,
48 globalVariable7_7 = 71, globalVariable7_8 = 71,
49 globalVariable7_9 = 71, globalVariable7_10 = 71,
50 globalVariable7_11 = 71, globalVariable7_12 = 71,
51 globalVariable7_13 = 71, globalVariable7_14 = 71,
52 globalVariable7_15 = 71, globalVariable7_16 = 71;
55 int globalVariable8_1 = 1;
57 int globalVariable10_1 = 0, globalVariable10_2 = 0,
58 globalVariable10_3 = 0, globalVariable10_4 = 0;
60 int globalVariable11_1 = 0, globalVariable11_2 = 0,
61 globalVariable11_3 = 0, globalVariable11_4 = 0, globalVariable11_5 = 0;
63 int globalVariable12_1 = 0;
65 int globalVariable13_1 = 0;
69 dprintf("call1() called - setting globalVariable1_1 = 11\n");
70 globalVariable1_1 = 11;
73 void call2_1(int arg1, int arg2, char *arg3)
75 if ((arg1 == 1) && (arg2 == 2) && (!strcmp(arg3, "testString2_1"))) {
76 printf("Passed test #2 (three parameter function)\n");
78 printf("**Failed** test #2 (three parameter function)\n");
80 printf(" arg1 = %d, should be 1\n", arg1);
82 printf(" arg2 = %d, should be 2\n", arg2);
83 if (strcmp(arg3, "testString2_1"))
84 printf(" arg3 = %s, should be \"testString2_1\"\n", arg3);
88 void call3_1(int arg1, int arg2)
90 if ((arg1 == 31) && (arg2 == 32)) {
91 printf("Passed test #3 (passing variables to functions)\n");
93 printf("**Failed** test #3 (passing variables to functions)\n");
94 printf(" arg1 = %d, should be 31\n", arg1);
95 printf(" arg2 = %d, should be 32\n", arg2);
99 int call9_1(int p1, int p2, int p3, int p4, int p5)
102 x = (((p1 + p2) + (p3 + p4) + (p5)));
103 if (x != (91 + 92 + 93 + 94 + 95 )) {
104 printf("**Failed** test case #9 (preserve registers - funcCall)\n");
105 if (p1 != 91) printf(" call9_1 parameter 1 is %d not 91\n", p1);
106 if (p2 != 92) printf(" call9_1 parameter 2 is %d not 92\n", p2);
107 if (p3 != 93) printf(" call9_1 parameter 2 is %d not 93\n", p3);
108 if (p4 != 94) printf(" call9_1 parameter 4 is %d not 94\n", p4);
109 if (p5 != 95) printf(" call9_1 parameter 5 is %d not 95\n", p5);
112 dprintf("inside call9_1\n");
118 if (globalVariable10_4 == 0) {
119 globalVariable10_4 = 1; // update marker of call order
120 globalVariable10_1 = 1; // flag that this was called first
127 if (globalVariable10_4 == 1) {
128 globalVariable10_4 = 2; // update marker of call order
129 globalVariable10_2 = 1; // flag that this was called first
135 if (globalVariable10_4 == 2) {
136 globalVariable10_4 = 3; // update marker of call order
137 globalVariable10_3 = 1; // flag that this was called first
143 if (globalVariable11_1 == 0) globalVariable11_2 = 1;
148 if (globalVariable11_1 == 1) globalVariable11_3 = 1;
153 if (globalVariable11_1 == 2) globalVariable11_4 = 1;
158 if (globalVariable11_1 == 3) globalVariable11_5 = 1;
160 if (globalVariable11_2 && globalVariable11_3 &&
161 globalVariable11_4 && globalVariable11_5) {
162 printf("Passed test #11 (snippets at entry,exit,call)\n");
164 printf("**Failed test #11 (snippets at entry,exit,call)\n");
165 if (!globalVariable11_2)
166 printf(" entry snippet not called at the correct time\n");
167 if (!globalVariable11_3)
168 printf(" pre call snippet not called at the correct time\n");
169 if (!globalVariable11_4)
170 printf(" post call snippet not called at the correct time\n");
171 if (!globalVariable11_5)
172 printf(" exit snippet not called at the correct time\n");
178 globalVariable12_1++;
181 void call13_1(int a1, int a2, int a3, int a4, int a5)
183 if (a1 == 131) globalVariable13_1 |= 1;
184 if (a2 == 132) globalVariable13_1 |= 2;
185 if (a3 == 133) globalVariable13_1 |= 4;
186 if (a4 == 134) globalVariable13_1 |= 8;
187 if (a5 == 135) globalVariable13_1 |= 16;
188 dprintf("a1 = %d\n", a1);
189 dprintf("a2 = %d\n", a2);
190 dprintf("a3 = %d\n", a3);
191 dprintf("a4 = %d\n", a4);
192 dprintf("a5 = %d\n", a5);
196 // This is a series of nearly empty functions to attach code to
198 void func1_1() { dprintf("func1_1 () called\n"); }
199 void func2_1() { dprintf("func2_1 () called\n"); }
200 void func3_1() { dprintf("func3_1 () called\n"); }
201 void func4_1() { dprintf("func4_1 () called\n"); }
202 void func5_1() { dprintf("func5_1 () called\n"); }
203 void func6_1() { dprintf("func7_1 () called\n"); }
204 void func7_1() { dprintf("func7_1 () called\n"); }
206 void func8_1(int p1, int p2, int p3, int p4, int p5, int p6, int p7,
207 int p8, int p9, int p10)
209 dprintf("func8_1 (...) called\n");
210 if ((p1 == 1) && (p2 == 2) && (p3 == 3) && (p4 == 4) && (p5 == 5) &&
211 (p6 == 6) && (p7 == 7) && (p8 == 8) && (p9 == 9) && (p10 == 10)) {
212 printf("Passed test #8 (preserve registers - expr)\n");
214 printf("**Failed** test #8 (preserve registers - expr )\n");
215 if (p1 != 1) printf(" parameter #1 is %d not 1\n", p1);
216 if (p2 != 2) printf(" parameter #2 is %d not 2\n", p2);
217 if (p3 != 3) printf(" parameter #3 is %d not 3\n", p3);
218 if (p4 != 4) printf(" parameter #4 is %d not 4\n", p4);
219 if (p5 != 5) printf(" parameter #5 is %d not 5\n", p5);
220 if (p6 != 6) printf(" parameter #6 is %d not 6\n", p6);
221 if (p7 != 7) printf(" parameter #7 is %d not 7\n", p7);
222 if (p8 != 8) printf(" parameter #8 is %d not 8\n", p8);
223 if (p9 != 9) printf(" parameter #9 is %d not 9\n", p9);
224 if (p10 != 10) printf(" parameter #10 is %d not 10\n", p10);
228 void func9_1(int p1, int p2, int p3, int p4, int p5, int p6, int p7,
229 int p8, int p9, int p10)
231 dprintf("func9_1 (...) called\n");
232 if ((p1 == 1) && (p2 == 2) && (p3 == 3) && (p4 == 4) && (p5 == 5) &&
233 (p6 == 6) && (p7 == 7) && (p8 == 8) && (p9 == 9) && (p10 == 10)) {
234 printf("Passed test #9 (preserve registers - funcCall)\n");
236 printf("**Failed** test #9 (preserve registers - funcCall )\n");
237 if (p1 != 1) printf(" parameter #1 is %d not 1\n", p1);
238 if (p2 != 2) printf(" parameter #2 is %d not 2\n", p2);
239 if (p3 != 3) printf(" parameter #3 is %d not 3\n", p3);
240 if (p4 != 4) printf(" parameter #4 is %d not 4\n", p4);
241 if (p5 != 5) printf(" parameter #5 is %d not 5\n", p5);
242 if (p6 != 6) printf(" parameter #6 is %d not 6\n", p6);
243 if (p7 != 7) printf(" parameter #7 is %d not 7\n", p7);
244 if (p8 != 8) printf(" parameter #8 is %d not 8\n", p8);
245 if (p9 != 9) printf(" parameter #9 is %d not 9\n", p9);
246 if (p10 != 10) printf(" parameter #10 is %d not 10\n", p10);
252 if ((globalVariable10_1 == 1) && (globalVariable10_2 == 1) &&
253 (globalVariable10_3 == 1) && (globalVariable10_4 == 3)) {
254 printf("Passed test #10 (insert snippet order)\n");
256 printf("** Failed test #10 (insert snippet order)\n");
257 if (!globalVariable10_1)
258 printf(" call10_1 was not called first\n");
259 if (!globalVariable10_2)
260 printf(" call10_2 was not called second\n");
261 if (!globalVariable10_3)
262 printf(" call10_3 was not called third\n");
267 globalVariable11_1 = 2;
272 globalVariable11_1 = 1;
274 globalVariable11_1 = 3;
284 kill(getpid(), SIGSTOP);
286 if (globalVariable12_1 == 1) {
287 printf("Passed test #12 (insert/remove and malloc/free)\n");
289 printf("**Failed test #12 (insert/remove and malloc/free)\n");
293 void func13_1(int p1, int p2, int p3, int p4, int p5)
295 if ((p1 == 131) && (p2 == 132) && (p3 == 133) &&
296 (p4 == 134) && (p5 == 135) && (globalVariable13_1 == 31)) {
297 printf("Passed test #13 (paramExpr,nullExpr)\n");
299 printf("**Failed test #13 (paramExpr,nullExpr)\n");
300 if (p1 != 131) printf(" parameter 1 is %d, not 131\n", p1);
301 if (p2 != 132) printf(" parameter 2 is %d, not 132\n", p2);
302 if (p3 != 133) printf(" parameter 3 is %d, not 133\n", p3);
303 if (p4 != 134) printf(" parameter 4 is %d, not 134\n", p4);
304 if (p5 != 135) printf(" parameter 5 is %d, not 135\n", p5);
305 if (!(globalVariable13_1 & 1)) printf(" passed param a1 wrong\n");
306 if (!(globalVariable13_1 & 2)) printf(" passed param a2 wrong\n");
307 if (!(globalVariable13_1 & 4)) printf(" passed param a3 wrong\n");
308 if (!(globalVariable13_1 & 8)) printf(" passed param a4 wrong\n");
309 if (!(globalVariable13_1 & 16)) printf(" passed param a5 wrong\n");
313 void fail7Print(int tCase, int fCase, char *op)
316 printf(" operator %s was not true when it should be\n", op);
318 printf(" operator %s was not false when it should be\n", op);
321 void main(int argc, char *argv[])
323 if (argc == 2 && !strcmp(argv[1], "-verbose")) {
328 dprintf("Value of globalVariable1_1 is %d.\n", globalVariable1_1);
330 dprintf("Value of globalVariable1_1 is now %d.\n", globalVariable1_1);
332 if (globalVariable1_1 == 11)
333 printf("\nPassed test #1 (zero arg function call)\n");
335 printf("\n**Failed** test #1 (zero arg function call)\n");
345 if (globalVariable4_1 == 41) {
346 printf("**Failed** test #4 (sequence)\n");
347 printf(" none of the items were executed\n");
348 } else if (globalVariable4_1 == 42) {
349 printf("**Failed** test #4 (sequence)\n");
350 printf(" first item was the last (or only) one to execute\n");
351 } else if (globalVariable4_1 == 43) {
352 printf("Passed test #4 (sequence)\n");
357 if ((globalVariable5_1 == 51) && (globalVariable5_2 == 53)) {
358 printf("Passed test #5 (if w.o. else)\n");
360 printf("**Failed** test #5 (if w.o. else)\n");
361 if (globalVariable5_1 != 51) {
362 printf(" condition executed for false\n");
364 if (globalVariable5_2 != 53) {
365 printf(" condition not executed for true\n");
370 if ((globalVariable6_1 == 60+2) && (globalVariable6_2 == 64-1) &&
371 (globalVariable6_3 == 66/3) && (globalVariable6_4 == 67/3) &&
372 (globalVariable6_5 == 6 * 5) && (globalVariable6_6 == 3)) {
373 printf("Passed test #6 (arithmetic operators)\n");
375 printf("**Failed** test #6 (arithmetic operators)\n");
376 if (globalVariable6_1 != 60+2)
377 printf(" addition error 60+2 got %d\n", globalVariable6_1);
378 if (globalVariable6_2 != 64-1)
379 printf(" subtraction error 64-1 got %d\n", globalVariable6_2);
380 if (globalVariable6_3 != 66/3)
381 printf(" division error 66/3 got %d\n", globalVariable6_3);
382 if (globalVariable6_4 != 67/3)
383 printf(" division error 67/3 got %d\n", globalVariable6_4);
384 if (globalVariable6_5 != 6 * 5)
385 printf(" mult error 6*5 got %d\n", globalVariable6_5);
386 if (globalVariable6_6 != 3)
387 printf(" mod error 10,3 got %d\n", globalVariable6_6);
391 if ((globalVariable7_1 == 72) && (globalVariable7_2 == 71) &&
392 (globalVariable7_3 == 72) && (globalVariable7_4 == 71) &&
393 (globalVariable7_5 == 72) && (globalVariable7_6 == 71) &&
394 (globalVariable7_7 == 72) && (globalVariable7_8 == 71) &&
395 (globalVariable7_9 == 72) && (globalVariable7_10 == 71) &&
396 (globalVariable7_11 == 72) && (globalVariable7_12 == 71) &&
397 (globalVariable7_13 == 72) && (globalVariable7_14 == 71) &&
398 (globalVariable7_15 == 72) && (globalVariable7_16 == 71)) {
399 printf("Passed test #7 (relational operators)\n");
401 printf("**Failed** test #7 (relational operators)\n");
402 fail7Print(globalVariable7_1, globalVariable7_2, "BPatch_lt");
403 fail7Print(globalVariable7_3, globalVariable7_4, "BPatch_eq");
404 fail7Print(globalVariable7_5, globalVariable7_6, "BPatch_gt");
405 fail7Print(globalVariable7_7, globalVariable7_8, "BPatch_le");
406 fail7Print(globalVariable7_9, globalVariable7_10, "BPatch_ne");
407 fail7Print(globalVariable7_11, globalVariable7_12, "BPatch_ge");
408 fail7Print(globalVariable7_13, globalVariable7_14, "BPatch_and");
409 fail7Print(globalVariable7_15, globalVariable7_16, "BPatch_or");
412 func8_1(1,2,3,4,5,6,7,8,9,10);
414 func9_1(1,2,3,4,5,6,7,8,9,10);
422 func13_1(131,132,133,134,135);