2 /* Test application (Mutatee) */
9 #if defined(sparc_sun_sunos4_1_3) || defined(sparc_sun_solaris2_4)
12 #ifdef i386_unknown_nt4_0
13 #define WIN32_LEAN_AND_MEAN
17 /* XXX Currently, there's a bug in the library that prevents a subroutine call
18 * instrumentation point from being recognized if it is the first instruction
19 * in a function. The following variable is used in this program in a number
20 * of kludges to get around this.
24 // control debug printf statements
25 #define dprintf if (debugPrint) printf
28 #define RET13_1 1300100
30 #define RAN17_1 1701000
32 #define RET17_1 1700100
33 #define RET17_2 1700200
35 #define MAGIC19_1 1900100
42 int globalVariable1_1 = 0;
43 int globalVariable3_1 = 31;
44 int globalVariable4_1 = 41;
45 int globalVariable5_1 = 51;
46 int globalVariable5_2 = 51;
48 int globalVariable6_1 = 0xdeadbeef;
49 int globalVariable6_2 = 0xdeadbeef;
50 int globalVariable6_3 = 0xdeadbeef;
51 int globalVariable6_4 = 0xdeadbeef;
52 int globalVariable6_5 = 0xdeadbeef;
53 int globalVariable6_6 = 0xdeadbeef;
55 int globalVariable7_1 = 71, globalVariable7_2 = 71,
56 globalVariable7_3 = 71, globalVariable7_4 = 71,
57 globalVariable7_5 = 71, globalVariable7_6 = 71,
58 globalVariable7_7 = 71, globalVariable7_8 = 71,
59 globalVariable7_9 = 71, globalVariable7_10 = 71,
60 globalVariable7_11 = 71, globalVariable7_12 = 71,
61 globalVariable7_13 = 71, globalVariable7_14 = 71,
62 globalVariable7_15 = 71, globalVariable7_16 = 71;
65 int globalVariable8_1 = 1;
67 int globalVariable10_1 = 0, globalVariable10_2 = 0,
68 globalVariable10_3 = 0, globalVariable10_4 = 0;
70 int globalVariable11_1 = 0, globalVariable11_2 = 0,
71 globalVariable11_3 = 0, globalVariable11_4 = 0, globalVariable11_5 = 0;
73 int globalVariable12_1 = 0;
75 int globalVariable13_1 = 0;
77 int globalVariable14_1 = 0;
78 int globalVariable14_2 = 0;
80 int globalVariable15_1 = 0;
81 int globalVariable15_2 = 0;
82 int globalVariable15_3 = 0;
84 int globalVariable16_1 = 0;
85 int globalVariable16_2 = 0;
86 int globalVariable16_3 = 0;
87 int globalVariable16_4 = 0;
89 int globalVariable17_1 = 0;
90 int globalVariable17_2 = 0;
92 int globalVariable18_1 = 42;
94 int globalVariable19_1 = 0xdeadbeef;
97 * Check to see if the mutator has attached to us.
105 * Stop the process (in order to wait for the mutator to finish what it's
106 * doing and restart us).
110 #ifdef i386_unknown_nt4_0
113 kill(getpid(), SIGSTOP);
119 dprintf("call1() called - setting globalVariable1_1 = 11\n");
120 globalVariable1_1 = 11;
123 void call2_1(int arg1, int arg2, char *arg3)
125 if ((arg1 == 1) && (arg2 == 2) && (!strcmp(arg3, "testString2_1"))) {
126 printf("Passed test #2 (three parameter function)\n");
128 printf("**Failed** test #2 (three parameter function)\n");
130 printf(" arg1 = %d, should be 1\n", arg1);
132 printf(" arg2 = %d, should be 2\n", arg2);
133 if (strcmp(arg3, "testString2_1"))
134 printf(" arg3 = %s, should be \"testString2_1\"\n", arg3);
138 void call3_1(int arg1, int arg2)
140 if ((arg1 == 31) && (arg2 == 32)) {
141 printf("Passed test #3 (passing variables to functions)\n");
143 printf("**Failed** test #3 (passing variables to functions)\n");
144 printf(" arg1 = %d, should be 31\n", arg1);
145 printf(" arg2 = %d, should be 32\n", arg2);
149 int call9_1(int p1, int p2, int p3, int p4, int p5)
152 x = (((p1 + p2) + (p3 + p4) + (p5)));
153 if (x != (91 + 92 + 93 + 94 + 95 )) {
154 printf("**Failed** test case #9 (preserve registers - funcCall)\n");
155 if (p1 != 91) printf(" call9_1 parameter 1 is %d not 91\n", p1);
156 if (p2 != 92) printf(" call9_1 parameter 2 is %d not 92\n", p2);
157 if (p3 != 93) printf(" call9_1 parameter 2 is %d not 93\n", p3);
158 if (p4 != 94) printf(" call9_1 parameter 4 is %d not 94\n", p4);
159 if (p5 != 95) printf(" call9_1 parameter 5 is %d not 95\n", p5);
162 dprintf("inside call9_1\n");
168 if (globalVariable10_4 == 0) {
169 globalVariable10_4 = 1; // update marker of call order
170 globalVariable10_1 = 1; // flag that this was called first
177 if (globalVariable10_4 == 1) {
178 globalVariable10_4 = 2; // update marker of call order
179 globalVariable10_2 = 1; // flag that this was called first
185 if (globalVariable10_4 == 2) {
186 globalVariable10_4 = 3; // update marker of call order
187 globalVariable10_3 = 1; // flag that this was called first
193 if (globalVariable11_1 == 0) globalVariable11_2 = 1;
198 if (globalVariable11_1 == 1) globalVariable11_3 = 1;
203 if (globalVariable11_1 == 2) globalVariable11_4 = 1;
208 if (globalVariable11_1 == 3) globalVariable11_5 = 1;
210 if (globalVariable11_2 && globalVariable11_3 &&
211 globalVariable11_4 && globalVariable11_5) {
212 printf("Passed test #11 (snippets at entry,exit,call)\n");
214 printf("**Failed test #11 (snippets at entry,exit,call)\n");
215 if (!globalVariable11_2)
216 printf(" entry snippet not called at the correct time\n");
217 if (!globalVariable11_3)
218 printf(" pre call snippet not called at the correct time\n");
219 if (!globalVariable11_4)
220 printf(" post call snippet not called at the correct time\n");
221 if (!globalVariable11_5)
222 printf(" exit snippet not called at the correct time\n");
228 globalVariable12_1++;
231 void call13_1(int a1, int a2, int a3, int a4, int a5)
233 if (a1 == 131) globalVariable13_1 |= 1;
234 if (a2 == 132) globalVariable13_1 |= 2;
235 if (a3 == 133) globalVariable13_1 |= 4;
236 if (a4 == 134) globalVariable13_1 |= 8;
237 if (a5 == 135) globalVariable13_1 |= 16;
238 dprintf("a1 = %d\n", a1);
239 dprintf("a2 = %d\n", a2);
240 dprintf("a3 = %d\n", a3);
241 dprintf("a4 = %d\n", a4);
242 dprintf("a5 = %d\n", a5);
245 void call13_2(int ret)
247 if (ret == RET13_1) globalVariable13_1 |= 32;
252 globalVariable14_1 = 1;
257 globalVariable15_1++;
262 globalVariable15_2++;
267 globalVariable15_3++;
272 /* make sure the function uses lots of registers */
274 int a1, a2, a3, a4, a5, a6, a7;
288 /* make sure the function uses lots of registers */
290 int a1, a2, a3, a4, a5, a6, a7;
299 globalVariable17_2 = RAN17_1;
305 globalVariable19_1 = MAGIC19_1;
310 // This is a series of nearly empty functions to attach code to
312 void func1_1() { dprintf("func1_1 () called\n"); }
313 void func2_1() { dprintf("func2_1 () called\n"); }
314 void func3_1() { dprintf("func3_1 () called\n"); }
315 void func4_1() { dprintf("func4_1 () called\n"); }
316 void func5_1() { dprintf("func5_1 () called\n"); }
317 void func6_1() { dprintf("func7_1 () called\n"); }
318 void func7_1() { dprintf("func7_1 () called\n"); }
320 void func8_1(int p1, int p2, int p3, int p4, int p5, int p6, int p7,
321 int p8, int p9, int p10)
323 dprintf("func8_1 (...) called\n");
324 if ((p1 == 1) && (p2 == 2) && (p3 == 3) && (p4 == 4) && (p5 == 5) &&
325 (p6 == 6) && (p7 == 7) && (p8 == 8) && (p9 == 9) && (p10 == 10)) {
326 printf("Passed test #8 (preserve registers - expr)\n");
328 printf("**Failed** test #8 (preserve registers - expr )\n");
329 if (p1 != 1) printf(" parameter #1 is %d not 1\n", p1);
330 if (p2 != 2) printf(" parameter #2 is %d not 2\n", p2);
331 if (p3 != 3) printf(" parameter #3 is %d not 3\n", p3);
332 if (p4 != 4) printf(" parameter #4 is %d not 4\n", p4);
333 if (p5 != 5) printf(" parameter #5 is %d not 5\n", p5);
334 if (p6 != 6) printf(" parameter #6 is %d not 6\n", p6);
335 if (p7 != 7) printf(" parameter #7 is %d not 7\n", p7);
336 if (p8 != 8) printf(" parameter #8 is %d not 8\n", p8);
337 if (p9 != 9) printf(" parameter #9 is %d not 9\n", p9);
338 if (p10 != 10) printf(" parameter #10 is %d not 10\n", p10);
342 void func9_1(int p1, int p2, int p3, int p4, int p5, int p6, int p7,
343 int p8, int p9, int p10)
345 dprintf("func9_1 (...) called\n");
346 if ((p1 == 1) && (p2 == 2) && (p3 == 3) && (p4 == 4) && (p5 == 5) &&
347 (p6 == 6) && (p7 == 7) && (p8 == 8) && (p9 == 9) && (p10 == 10)) {
348 printf("Passed test #9 (preserve registers - funcCall)\n");
350 printf("**Failed** test #9 (preserve registers - funcCall )\n");
351 if (p1 != 1) printf(" parameter #1 is %d not 1\n", p1);
352 if (p2 != 2) printf(" parameter #2 is %d not 2\n", p2);
353 if (p3 != 3) printf(" parameter #3 is %d not 3\n", p3);
354 if (p4 != 4) printf(" parameter #4 is %d not 4\n", p4);
355 if (p5 != 5) printf(" parameter #5 is %d not 5\n", p5);
356 if (p6 != 6) printf(" parameter #6 is %d not 6\n", p6);
357 if (p7 != 7) printf(" parameter #7 is %d not 7\n", p7);
358 if (p8 != 8) printf(" parameter #8 is %d not 8\n", p8);
359 if (p9 != 9) printf(" parameter #9 is %d not 9\n", p9);
360 if (p10 != 10) printf(" parameter #10 is %d not 10\n", p10);
366 if ((globalVariable10_1 == 1) && (globalVariable10_2 == 1) &&
367 (globalVariable10_3 == 1) && (globalVariable10_4 == 3)) {
368 printf("Passed test #10 (insert snippet order)\n");
370 printf("** Failed test #10 (insert snippet order)\n");
371 if (!globalVariable10_1)
372 printf(" call10_1 was not called first\n");
373 if (!globalVariable10_2)
374 printf(" call10_2 was not called second\n");
375 if (!globalVariable10_3)
376 printf(" call10_3 was not called third\n");
381 globalVariable11_1 = 2;
386 globalVariable11_1 = 1;
388 globalVariable11_1 = 3;
400 if (globalVariable12_1 == 1) {
401 printf("Passed test #12 (insert/remove and malloc/free)\n");
403 printf("**Failed test #12 (insert/remove and malloc/free)\n");
412 void func13_1(int p1, int p2, int p3, int p4, int p5)
416 if ((p1 == 131) && (p2 == 132) && (p3 == 133) &&
417 (p4 == 134) && (p5 == 135) && (globalVariable13_1 == 63)) {
418 printf("Passed test #13 (paramExpr,retExpr,nullExpr)\n");
420 printf("**Failed test #13 (paramExpr,retExpr,nullExpr)\n");
421 if (p1 != 131) printf(" parameter 1 is %d, not 131\n", p1);
422 if (p2 != 132) printf(" parameter 2 is %d, not 132\n", p2);
423 if (p3 != 133) printf(" parameter 3 is %d, not 133\n", p3);
424 if (p4 != 134) printf(" parameter 4 is %d, not 134\n", p4);
425 if (p5 != 135) printf(" parameter 5 is %d, not 135\n", p5);
426 if (!(globalVariable13_1 & 1)) printf(" passed param a1 wrong\n");
427 if (!(globalVariable13_1 & 2)) printf(" passed param a2 wrong\n");
428 if (!(globalVariable13_1 & 4)) printf(" passed param a3 wrong\n");
429 if (!(globalVariable13_1 & 8)) printf(" passed param a4 wrong\n");
430 if (!(globalVariable13_1 & 16)) printf(" passed param a5 wrong\n");
431 if (!(globalVariable13_1 & 32)) printf(" return value wrong\n");
438 globalVariable14_1 = 2;
443 globalVariable14_2 = 1;
448 kludge = 1; // Here so that the following function call isn't the first
454 if (globalVariable14_1 == 1 && globalVariable14_2 == 0) {
455 printf("Passed test #14 (replace/remove function call)\n");
457 printf("**Failed test #14 (replace/remove function call)\n");
458 if (globalVariable14_1 != 1)
459 printf(" call to func14_2() was not replaced\n");
460 if (globalVariable14_2 != 0)
461 printf(" call to func14_3() was not removed\n");
466 void check15result(char *varname, int value, int expected,
467 char *errstr, int *failed)
469 if (value != expected) {
471 printf("**failed test #15 (setMutationsActive)\n");
474 printf(" %s = %d %s\n", varname, value, errstr);
485 globalVariable15_3 = 100;
490 kludge = 1; // Here so that the following function call isn't the first
502 check15result("globalVariable15_1", globalVariable15_1, 1,
503 "after first call to instrumented function", &failed);
505 #if defined(sparc_sun_sunos4_1_3) || defined(sparc_sun_solaris2_4)
506 // Test a function that makes a system call (is a special case on Sparc)
508 check15result("globalVariable15_2", globalVariable15_2, 2,
509 "after first call to instrumented function", &failed);
513 check15result("globalVariable15_3", globalVariable15_3, 1,
514 "after first call to instrumented function", &failed);
516 /***********************************************************/
521 check15result("globalVariable15_1", globalVariable15_1, 1,
522 "after second call to instrumented function", &failed);
524 #if defined(sparc_sun_sunos4_1_3) || defined(sparc_sun_solaris2_4)
526 check15result("globalVariable15_2", globalVariable15_2, 2,
527 "after second call to instrumented function", &failed);
531 check15result("globalVariable15_3", globalVariable15_3, 100,
532 "after second call to instrumented function", &failed);
534 /***********************************************************/
539 check15result("globalVariable15_1", globalVariable15_1, 2,
540 "after third call to instrumented function", &failed);
542 #if defined(sparc_sun_sunos4_1_3) || defined(sparc_sun_solaris2_4)
544 check15result("globalVariable15_2", globalVariable15_2, 4,
545 "after third call to instrumented function", &failed);
549 check15result("globalVariable15_3", globalVariable15_3, 101,
550 "after third call to instrumented function", &failed);
553 printf("Passed test #15 (setMutationsActive)\n");
558 void func16_2() { dprintf("func16_2 () called\n"); }
559 void func16_3() { dprintf("func16_3 () called\n"); }
566 if (globalVariable16_1 != 1 || globalVariable16_2 != 0) {
567 printf("**Failed test #16 (if-else)\n");
568 if (globalVariable16_1 != 1)
569 printf(" True clause of first if should have been executed but was not.\n");
570 if (globalVariable16_2 != 0)
571 printf(" False clause of first if should not have been executed but was.\n");
576 if (globalVariable16_3 != 0 || globalVariable16_4 != 1) {
577 printf("**Failed test #16 (if-else)\n");
578 if (globalVariable16_3 != 1)
579 printf(" True clause of second if should not have been executed but was.\n");
580 if (globalVariable16_4 != 0)
581 printf(" False clause of second if should have been executed but was not.\n");
586 printf("Passed test #16 (if-else)\n");
602 globalVariable17_1 = func17_3();
608 if (globalVariable18_1 == 17) {
609 printf("Passed test #18 (read/write a variable in the mutatee)\n");
611 printf("**Failed test #18 (read/write a variable in the mutatee)\n");
612 if (globalVariable18_1 == 42)
613 printf(" globalVariable18_1 still contains 42 (probably it was not written to)\n");
615 printf(" globalVariable18_1 contained %d, not 17 as expected\n",
624 if (globalVariable19_1 == MAGIC19_1) {
625 printf("Passed test #19 (oneTimeCode)\n");
627 printf("**Failed test #19 (oneTimeCode)\n");
628 printf(" globalVariable19_1 contained %d, not %d as expected\n",
629 globalVariable19_1, MAGIC19_1);
633 void fail7Print(int tCase, int fCase, char *op)
636 printf(" operator %s was not true when it should be\n", op);
638 printf(" operator %s was not false when it should be\n", op);
641 void main(int argc, char *argv[])
645 int useAttach = FALSE;
647 for (i=1; i < argc; i++) {
648 if (!strcmp(argv[i], "-verbose")) {
650 } else if (!strcmp(argv[i], "-attach")) {
653 fprintf(stderr, "Usage: test1 [-attach] [-verbose]\n");
659 printf("Waiting for mutator to attach...\n");
660 while (!checkIfAttached()) ;
661 printf("Mutator attached. Mutatee continuing.\n");
665 dprintf("Value of globalVariable1_1 is %d.\n", globalVariable1_1);
667 dprintf("Value of globalVariable1_1 is now %d.\n", globalVariable1_1);
669 if (globalVariable1_1 == 11)
670 printf("\nPassed test #1 (zero arg function call)\n");
672 printf("\n**Failed** test #1 (zero arg function call)\n");
682 if (globalVariable4_1 == 41) {
683 printf("**Failed** test #4 (sequence)\n");
684 printf(" none of the items were executed\n");
685 } else if (globalVariable4_1 == 42) {
686 printf("**Failed** test #4 (sequence)\n");
687 printf(" first item was the last (or only) one to execute\n");
688 } else if (globalVariable4_1 == 43) {
689 printf("Passed test #4 (sequence)\n");
694 if ((globalVariable5_1 == 51) && (globalVariable5_2 == 53)) {
695 printf("Passed test #5 (if w.o. else)\n");
697 printf("**Failed** test #5 (if w.o. else)\n");
698 if (globalVariable5_1 != 51) {
699 printf(" condition executed for false\n");
701 if (globalVariable5_2 != 53) {
702 printf(" condition not executed for true\n");
707 if ((globalVariable6_1 == 60+2) && (globalVariable6_2 == 64-1) &&
708 (globalVariable6_3 == 66/3) && (globalVariable6_4 == 67/3) &&
709 (globalVariable6_5 == 6 * 5) && (globalVariable6_6 == 3)) {
710 printf("Passed test #6 (arithmetic operators)\n");
712 printf("**Failed** test #6 (arithmetic operators)\n");
713 if (globalVariable6_1 != 60+2)
714 printf(" addition error 60+2 got %d\n", globalVariable6_1);
715 if (globalVariable6_2 != 64-1)
716 printf(" subtraction error 64-1 got %d\n", globalVariable6_2);
717 if (globalVariable6_3 != 66/3)
718 printf(" division error 66/3 got %d\n", globalVariable6_3);
719 if (globalVariable6_4 != 67/3)
720 printf(" division error 67/3 got %d\n", globalVariable6_4);
721 if (globalVariable6_5 != 6 * 5)
722 printf(" mult error 6*5 got %d\n", globalVariable6_5);
723 if (globalVariable6_6 != 3)
724 printf(" mod error 10,3 got %d\n", globalVariable6_6);
728 if ((globalVariable7_1 == 72) && (globalVariable7_2 == 71) &&
729 (globalVariable7_3 == 72) && (globalVariable7_4 == 71) &&
730 (globalVariable7_5 == 72) && (globalVariable7_6 == 71) &&
731 (globalVariable7_7 == 72) && (globalVariable7_8 == 71) &&
732 (globalVariable7_9 == 72) && (globalVariable7_10 == 71) &&
733 (globalVariable7_11 == 72) && (globalVariable7_12 == 71) &&
734 (globalVariable7_13 == 72) && (globalVariable7_14 == 71) &&
735 (globalVariable7_15 == 72) && (globalVariable7_16 == 71)) {
736 printf("Passed test #7 (relational operators)\n");
738 printf("**Failed** test #7 (relational operators)\n");
739 fail7Print(globalVariable7_1, globalVariable7_2, "BPatch_lt");
740 fail7Print(globalVariable7_3, globalVariable7_4, "BPatch_eq");
741 fail7Print(globalVariable7_5, globalVariable7_6, "BPatch_gt");
742 fail7Print(globalVariable7_7, globalVariable7_8, "BPatch_le");
743 fail7Print(globalVariable7_9, globalVariable7_10, "BPatch_ne");
744 fail7Print(globalVariable7_11, globalVariable7_12, "BPatch_ge");
745 fail7Print(globalVariable7_13, globalVariable7_14, "BPatch_and");
746 fail7Print(globalVariable7_15, globalVariable7_16, "BPatch_or");
749 func8_1(1,2,3,4,5,6,7,8,9,10);
751 func9_1(1,2,3,4,5,6,7,8,9,10);
759 func13_1(131,132,133,134,135);
767 ret17_1 = func17_1();
770 if ((ret17_1 != RET17_1) ||
771 (globalVariable17_1 != RET17_2) ||
772 (globalVariable17_2 != RAN17_1)) {
773 printf("**Failed** test case #17 (return values from func calls)\n");
774 if (ret17_1 != RET17_1) {
775 printf(" return value was %d, not %d\n", ret17_1, RET17_1);
777 if (globalVariable17_1 != RET17_2) {
778 printf(" return value was %d, not %d\n",
779 globalVariable17_1, RET17_2);
781 if (globalVariable17_2 != RAN17_1) {
782 printf(" function call17_2 was not inserted\n");
785 printf("Passed test #17 (return values from func calls)\n");