2 /* Test application (Mutatee) */
4 /* $Id: test1.mutatee.c,v 1.72 2001/07/11 21:21:09 gurari Exp $ */
13 #ifdef i386_unknown_nt4_0
14 #define WIN32_LEAN_AND_MEAN
27 int mutateeCplusplus = 1;
29 int mutateeCplusplus = 0;
35 const char Builder_id[]=COMPILER; /* defined on compile line */
37 #if defined(sparc_sun_solaris2_4) || \
38 defined(alpha_dec_osf4_0) || \
39 defined(i386_unknown_linux2_0) || \
40 defined(i386_unknown_solaris2_5)
41 #include <dlfcn.h> /* For replaceFunction test */
44 /* Empty functions are sometimes compiled too tight for entry and exit
45 points. The following macro is used to flesh out these
46 functions. (expanded to use on all platforms for non-gcc compilers jkh 10/99) */
47 volatile int dummy3__;
49 #define DUMMY_FN_BODY \
52 dummy3__ = dummy1__ + dummy2__
54 /* XXX Currently, there's a bug in the library that prevents a subroutine call
55 * instrumentation point from being recognized if it is the first instruction
56 * in a function. The following variable is used in this program in a number
57 * of kludges to get around this.
61 /* control debug printf statements */
62 #define dprintf if (debugPrint) printf
70 int runTest[MAX_TEST+1];
71 int passedTest[MAX_TEST+1];
73 #if defined(sparc_sun_solaris2_4) || defined(alpha_dec_osf4_0)
74 #if defined(mips_sgi_irix6_4) && (_MIPS_SIM == _MIPS_SIM_NABI32)
75 static char *libNameA = "libtestA_n32.so";
77 static char *libNameA = "libtestA.so";
81 #define RET13_1 1300100
83 #define RAN17_1 1701000
85 #define RET17_1 1700100
86 #define RET17_2 1700200
88 #define MAGIC19_1 1900100
89 #define MAGIC19_2 1900200
91 /* These are copied in libtestA.c and libtestB.c */
92 #define MAGIC22_1 2200100
93 #define MAGIC22_2 2200200
94 #define MAGIC22_3 2200300
95 #define MAGIC22_4 2200400
96 #define MAGIC22_5A 2200510
97 #define MAGIC22_5B 2200520
98 #define MAGIC22_6 2200600
99 #define MAGIC22_7 2200700
103 #if defined(mips_sgi_irix6_4)
104 int pointerSize = sizeof(void *);
107 int globalVariable1_1 = 0;
108 int globalVariable3_1 = 31;
109 int globalVariable4_1 = 41;
110 int globalVariable5_1 = 51;
111 int globalVariable5_2 = 51;
128 int globalVariable6_1 = (int)0xdeadbeef;
129 int globalVariable6_2 = (int)0xdeadbeef;
130 int globalVariable6_3 = (int)0xdeadbeef;
131 int globalVariable6_4 = (int)0xdeadbeef;
132 int globalVariable6_5 = (int)0xdeadbeef;
133 int globalVariable6_6 = (int)0xdeadbeef;
134 int globalVariable6_1a = (int)0xdeadbeef;
135 int globalVariable6_2a = (int)0xdeadbeef;
136 int globalVariable6_3a = (int)0xdeadbeef;
137 int globalVariable6_4a = (int)0xdeadbeef;
138 int globalVariable6_5a = (int)0xdeadbeef;
139 int globalVariable6_6a = (int)0xdeadbeef;
141 int globalVariable7_1 = 71, globalVariable7_2 = 71,
142 globalVariable7_3 = 71, globalVariable7_4 = 71,
143 globalVariable7_5 = 71, globalVariable7_6 = 71,
144 globalVariable7_7 = 71, globalVariable7_8 = 71,
145 globalVariable7_9 = 71, globalVariable7_10 = 71,
146 globalVariable7_11 = 71, globalVariable7_12 = 71,
147 globalVariable7_13 = 71, globalVariable7_14 = 71,
148 globalVariable7_15 = 71, globalVariable7_16 = 71;
151 int globalVariable7_1a = 73, globalVariable7_2a = 73,
152 globalVariable7_3a = 73, globalVariable7_4a = 73,
153 globalVariable7_5a = 73, globalVariable7_6a = 73,
154 globalVariable7_7a = 73, globalVariable7_8a = 73,
155 globalVariable7_9a = 73, globalVariable7_10a = 73,
156 globalVariable7_11a = 73, globalVariable7_12a = 73,
157 globalVariable7_13a = 73, globalVariable7_14a = 73,
158 globalVariable7_15a = 73, globalVariable7_16a = 73;
160 int globalVariable8_1 = 1;
162 int globalVariable10_1 = 0, globalVariable10_2 = 0,
163 globalVariable10_3 = 0, globalVariable10_4 = 0;
165 int globalVariable11_1 = 0, globalVariable11_2 = 0,
166 globalVariable11_3 = 0, globalVariable11_4 = 0, globalVariable11_5 = 0;
168 int globalVariable12_1 = 0;
170 int globalVariable13_1 = 0;
172 int globalVariable14_1 = 0;
173 int globalVariable14_2 = 0;
175 int globalVariable15_1 = 0;
176 int globalVariable15_2 = 0;
177 int globalVariable15_3 = 0;
178 int globalVariable15_4 = 0;
180 int globalVariable16_1 = 0;
181 int globalVariable16_2 = 0;
182 int globalVariable16_3 = 0;
183 int globalVariable16_4 = 0;
184 int globalVariable16_5 = 0;
185 int globalVariable16_6 = 0;
186 int globalVariable16_7 = 0;
187 int globalVariable16_8 = 0;
188 int globalVariable16_9 = 0;
189 int globalVariable16_10 = 0;
191 int globalVariable17_1 = 0;
192 int globalVariable17_2 = 0;
194 int globalVariable18_1 = 42;
196 int globalVariable19_1 = (int)0xdeadbeef;
197 int globalVariable19_2 = (int)0xdeadbeef;
199 int globalVariable20_1 = (int)0xdeadbeef;
200 double globalVariable20_2 = 0.0;
202 int globalVariable22_1 = 0;
203 int globalVariable22_2 = 0;
204 int globalVariable22_3 = 0;
205 int globalVariable22_4 = 0;
207 unsigned globalVariable30_1 = 0;
208 unsigned globalVariable30_2 = 0;
210 unsigned globalVariable30_3 = 0;
211 unsigned globalVariable30_4 = 0;
212 unsigned globalVariable30_5 = 0;
213 unsigned globalVariable30_6 = 0;
215 int globalVariable31_1 = 0;
216 int globalVariable31_2 = 0;
217 int globalVariable31_3 = 0;
218 int globalVariable31_4 = 0;
220 int globalVariable32_1 = 0;
221 int globalVariable32_2 = 0;
222 int globalVariable32_3 = 0;
223 int globalVariable32_4 = 0;
229 #define TEST20_TIMES 41
232 * Check to see if the mutator has attached to us.
234 int checkIfAttached()
240 * Stop the process (in order to wait for the mutator to finish what it's
241 * doing and restart us).
243 #if defined(alpha_dec_osf4_0) && defined(__GNUC__)
244 static long long int beginFP;
247 #ifdef DETACH_ON_THE_FLY
249 All this to stop ourselves. We may be detached, but the mutator
250 needs to notice the stop. We must send a SIGILL to ourselves, not
251 SIGSTOP, to get the mutator to notice.
253 DYNINSTsigill is a runtime library function that does this. Here we
254 obtain a pointer to DYNINSTsigill from the runtime loader and then
255 call it. Note that this depends upon the mutatee having
256 DYNINSTAPI_RT_LIB defined (with the same value as mutator) in its
257 environment, so this technique does not work for ordinary mutatees.
259 We could call kill to send ourselves SIGILL, but this is unsupported
260 because it complicates the SIGILL signal handler. */
266 static void (*DYNINSTsigill)() = NULL;
268 if (!DYNINSTsigill) {
269 /* Obtain the name of the runtime library linked with this process */
270 rtlib = getenv("DYNINSTAPI_RT_LIB");
272 fprintf(stderr, "ERROR: Mutatee can't find the runtime library pathname\n");
276 /* Obtain a handle for the runtime library */
277 h = dlopen(rtlib, RTLD_LAZY); /* It should already be loaded */
279 fprintf(stderr, "ERROR: Mutatee can't find its runtime library: %s\n",
284 /* Obtain a pointer to the function DYNINSTsigill in the runtime library */
285 DYNINSTsigill = (void(*)()) dlsym(h, "DYNINSTsigill");
286 if (!DYNINSTsigill) {
287 fprintf(stderr, "ERROR: Mutatee can't find DYNINSTsigill in the runtime library: %s\n",
294 #endif /* DETACH_ON_THE_FLY */
298 #ifdef i386_unknown_nt4_0
302 #if defined(alpha_dec_osf4_0) && defined(__GNUC__)
303 /* This GCC-specific hack doesn't compile with other compilers,
304 which is unfortunate, since the native build test fails part 15
305 with the error "process did not signal mutator via stop". */
306 /* It also doesn't appear to be necessary when compiling with gcc-2.8.1,
307 which makes its existance even more curious. */
308 register long int fp asm("15");
313 #ifdef DETACH_ON_THE_FLY
318 #ifndef USE_IRIX_FIXES
319 kill(getpid(), SIGSTOP);
321 kill(getpid(), SIGEMT);
324 #if defined(alpha_dec_osf4_0) && defined(__GNUC__)
332 * Determine if two doubles are close to being equal (for our purposes, that
333 * means to ten decimal places).
335 int eq_doubles(double a, double b)
339 if (diff < 0) diff = -diff;
341 if (diff < 0.00000000001) return 1;
346 * Verify that a scalar value of a variable is what is expected
349 void verifyScalarValue(char *name, int a, int value, int testNum, char *testName)
352 if (passedTest[testNum])
353 printf("**Failed** test %d (%s)\n", testNum, testName);
354 printf(" %s = %d, not %d\n", name, a, value);
355 passedTest[testNum] = FALSE;
360 * Verify that a passed array has the correct value in the passed element.
363 void verifyValue(char *name, int *a, int index, int value, int tst, char *tn)
365 if (a[index] != value) {
366 if (passedTest[tst]) printf("**Failed** test #%d (%s)\n", tst, tn);
367 printf(" %s[%d] = %d, not %d\n",
368 name, index, a[index], value);
369 passedTest[tst] = FALSE;
375 dprintf("call1() called - setting globalVariable1_1 = 11\n");
376 globalVariable1_1 = 11;
379 void call2_1(int arg1, int arg2, char *arg3, void *arg4)
381 assert(TEST_PTR_SIZE == sizeof(void *));
383 if ((arg1 == 1) && (arg2 == 2) && (!strcmp(arg3, "testString2_1")) &&
384 (arg4 == TEST_PTR)) {
385 printf("Passed test #2 (four parameter function)\n");
386 passedTest[2] = TRUE;
388 printf("**Failed** test #2 (four parameter function)\n");
390 printf(" arg1 = %d, should be 1\n", arg1);
392 printf(" arg2 = %d, should be 2\n", arg2);
393 if (strcmp(arg3, "testString2_1"))
394 printf(" arg3 = %s, should be \"testString2_1\"\n", arg3);
395 if (arg4 != TEST_PTR)
396 printf(" arg4 = 0x%p, should be 0x%p\n", arg4, TEST_PTR);
400 void call3_1(int arg1, int arg2)
402 if ((arg1 == 31) && (arg2 == 32)) {
403 printf("Passed test #3 (passing variables to functions)\n");
404 passedTest[3] = TRUE;
406 printf("**Failed** test #3 (passing variables to functions)\n");
407 printf(" arg1 = %d, should be 31\n", arg1);
408 printf(" arg2 = %d, should be 32\n", arg2);
412 int call9_1(int p1, int p2, int p3, int p4, int p5)
415 x = (((p1 + p2) + (p3 + p4) + (p5)));
416 if (x != (91 + 92 + 93 + 94 + 95 )) {
417 printf("**Failed** test case #9 (preserve registers - funcCall)\n");
418 if (p1 != 91) printf(" call9_1 parameter 1 is %d not 91\n", p1);
419 if (p2 != 92) printf(" call9_1 parameter 2 is %d not 92\n", p2);
420 if (p3 != 93) printf(" call9_1 parameter 2 is %d not 93\n", p3);
421 if (p4 != 94) printf(" call9_1 parameter 4 is %d not 94\n", p4);
422 if (p5 != 95) printf(" call9_1 parameter 5 is %d not 95\n", p5);
425 dprintf("inside call9_1\n");
431 if (globalVariable10_4 == 0) {
432 globalVariable10_4 = 1; /* update marker of call order */
433 globalVariable10_1 = 1; /* flag that this was called first */
440 if (globalVariable10_4 == 1) {
441 globalVariable10_4 = 2; /* update marker of call order */
442 globalVariable10_2 = 1; /* flag that this was called first */
448 if (globalVariable10_4 == 2) {
449 globalVariable10_4 = 3; /* update marker of call order */
450 globalVariable10_3 = 1; /* flag that this was called first */
456 if (globalVariable11_1 == 0) globalVariable11_2 = 1;
461 if (globalVariable11_1 == 1) globalVariable11_3 = 1;
466 if (globalVariable11_1 == 2) globalVariable11_4 = 1;
471 if (globalVariable11_1 == 3) globalVariable11_5 = 1;
473 if (globalVariable11_2 && globalVariable11_3 &&
474 globalVariable11_4 && globalVariable11_5) {
475 printf("Passed test #11 (snippets at entry,exit,call)\n");
476 passedTest[11] = TRUE;
478 printf("**Failed test #11 (snippets at entry,exit,call)\n");
479 if (!globalVariable11_2)
480 printf(" entry snippet not called at the correct time\n");
481 if (!globalVariable11_3)
482 printf(" pre call snippet not called at the correct time\n");
483 if (!globalVariable11_4)
484 printf(" post call snippet not called at the correct time\n");
485 if (!globalVariable11_5)
486 printf(" exit snippet not called at the correct time\n");
492 globalVariable12_1++;
495 void call13_1(int a1, int a2, int a3, int a4, int a5)
497 if (a1 == 131) globalVariable13_1 |= 1;
498 if (a2 == 132) globalVariable13_1 |= 2;
499 if (a3 == 133) globalVariable13_1 |= 4;
500 if (a4 == 134) globalVariable13_1 |= 8;
501 if (a5 == 135) globalVariable13_1 |= 16;
502 dprintf("a1 = %d\n", a1);
503 dprintf("a2 = %d\n", a2);
504 dprintf("a3 = %d\n", a3);
505 dprintf("a4 = %d\n", a4);
506 dprintf("a5 = %d\n", a5);
509 void call13_2(int ret)
511 if (ret == RET13_1) globalVariable13_1 |= 32;
516 globalVariable14_1 = 1;
521 globalVariable15_1++;
526 globalVariable15_2++;
531 globalVariable15_3++;
536 /* make sure the function uses lots of registers */
538 int a1, a2, a3, a4, a5, a6, a7;
540 dprintf("call17_1 (p1=%d)\n", p1);
541 assert(p1!=0); /* shouldn't try to divide by zero! */
542 assert(p1==1); /* actually only expect calls with p1==1 */
552 dprintf("call17_1 (ret=%d)\n", a7);
559 /* make sure the function uses lots of registers */
561 int a1, a2, a3, a4, a5, a6, a7;
563 dprintf("call17_2 (p1=%d)\n", p1);
564 assert(p1!=0); /* shouldn't try to divide by zero! */
565 assert(p1==1); /* actually only expect calls with p1==1 */
574 globalVariable17_2 = RAN17_1;
576 dprintf("call17_2 (ret=%d)\n", a7);
583 globalVariable19_1 = MAGIC19_1;
588 globalVariable19_2 = MAGIC19_2;
591 volatile int ta = TEST20_A;
592 volatile double tb = TEST20_B;
596 globalVariable20_1 = ta+(ta+(ta+(ta+(ta+(ta+(ta+(ta+(ta+(ta+
597 (ta+(ta+(ta+(ta+(ta+(ta+(ta+(ta+(ta+(ta+
598 (ta+(ta+(ta+(ta+(ta+(ta+(ta+(ta+(ta+(ta+
599 (ta+(ta+(ta+(ta+(ta+(ta+(ta+(ta+(ta+(ta+(ta
600 ))))))))))))))))))))))))))))))))))))))));
602 globalVariable20_2 = tb+(tb+(tb+(tb+(tb+(tb+(tb+(tb+(tb+(tb+
603 (tb+(tb+(tb+(tb+(tb+(tb+(tb+(tb+(tb+(tb+
604 (tb+(tb+(tb+(tb+(tb+(tb+(tb+(tb+(tb+(tb+
605 (tb+(tb+(tb+(tb+(tb+(tb+(tb+(tb+(tb+(tb+(tb
606 ))))))))))))))))))))))))))))))))))))))));
611 globalVariable22_1 += x;
612 globalVariable22_1 += MAGIC22_1;
617 globalVariable22_1 += x;
618 globalVariable22_1 += MAGIC22_2;
623 globalVariable22_2 += x;
624 globalVariable22_2 += MAGIC22_3;
629 globalVariable22_4 += x;
630 globalVariable22_4 += MAGIC22_7;
633 #if defined(sparc_sun_solaris2_4) || \
634 defined(i386_unknown_solaris2_5) || \
635 defined(i386_unknown_linux2_0) || \
636 defined(i386_unknown_nt4_0) ||\
637 defined(rs6000_ibm_aix4_1) || \
638 defined(alpha_dec_osf4_0)
640 /* this function has to be only 1 line for test30 to pass */
641 /* these two lines has to be together otherwise test30 will fail */
642 unsigned globalVariable30_7 = __LINE__;
643 void call30_1(){ globalVariable30_1 = __LINE__; globalVariable30_2 = (unsigned)call30_1;}
648 * This is a series of nearly empty functions to attach code to
658 dprintf("Value of globalVariable1_1 is %d.\n", globalVariable1_1);
662 dprintf("Value of globalVariable1_1 is now %d.\n", globalVariable1_1);
664 if (globalVariable1_1 == 11) {
665 printf("\nPassed test #1 (zero arg function call)\n");
666 passedTest[1] = TRUE;
668 printf("\n**Failed** test #1 (zero arg function call)\n");
672 void func1_2() { dprintf("func1_2 () called\n"); }
678 void func2_1() { dprintf("func2_1 () called\n"); }
683 void func3_1() { dprintf("func3_1 () called\n"); }
686 * Start of Test #4 - sequence
687 * Run two expressions and verify correct ordering.
693 kludge = 1; /* Here so that the following function call isn't the first
696 if (globalVariable4_1 == 41) {
697 printf("**Failed** test #4 (sequence)\n");
698 printf(" none of the items were executed\n");
699 } else if (globalVariable4_1 == 42) {
700 printf("**Failed** test #4 (sequence)\n");
701 printf(" first item was the last (or only) one to execute\n");
702 } else if (globalVariable4_1 == 43) {
703 printf("Passed test #4 (sequence)\n");
704 passedTest[4] = TRUE;
708 void func4_2() { dprintf("func4_1 () called\n"); }
712 * Start of Test #5 - if w.o. else
713 * Execute two if statements, one true and one false.
720 if ((globalVariable5_1 == 51) && (globalVariable5_2 == 53)) {
721 printf("Passed test #5 (if w.o. else)\n");
722 passedTest[5] = TRUE;
724 printf("**Failed** test #5 (if w.o. else)\n");
725 if (globalVariable5_1 != 51) {
726 printf(" condition executed for false\n");
728 if (globalVariable5_2 != 53) {
729 printf(" condition not executed for true\n");
734 void func5_2() { dprintf("func5_1 () called\n"); }
738 * Start of Test #6 - arithmetic operators
739 * Verify arithmetic operators:
740 * constant integer addition
741 * constant integer subtraction
742 * constant integer divide (using large constants)
743 * constant integer divide (small consts)
744 * constant integer multiply
745 * constant comma operator
746 * variable integer addition
747 * variable integer subtraction
748 * variable integer divide (using large constants)
749 * variable integer divide (small consts)
750 * variable integer multiply
751 * variable comma operator
753 * constant - use constant expressions
754 * variable - use variables in the expressions
761 if ((globalVariable6_1 == 60+2) && (globalVariable6_2 == 64-1) &&
762 (globalVariable6_3 == 66/3) && (globalVariable6_4 == 67/3) &&
763 (globalVariable6_5 == 6 * 5) && (globalVariable6_6 == 3) &&
764 (globalVariable6_1a == 60+2) && (globalVariable6_2a == 64-1) &&
765 (globalVariable6_3a == 66/3) && (globalVariable6_4a == 67/3) &&
766 (globalVariable6_5a == 6 * 5) && (globalVariable6_6a == 3)) {
767 printf("Passed test #6 (arithmetic operators)\n");
768 passedTest[6] = TRUE;
770 printf("**Failed** test #6 (arithmetic operators)\n");
771 if (globalVariable6_1 != 60+2)
772 printf(" addition error 60+2 got %d\n", globalVariable6_1);
773 if (globalVariable6_2 != 64-1)
774 printf(" subtraction error 64-1 got %d\n", globalVariable6_2);
775 if (globalVariable6_3 != 66/3)
776 printf(" division error 66/3 got %d\n", globalVariable6_3);
777 if (globalVariable6_4 != 67/3)
778 printf(" division error 67/3 got %d\n", globalVariable6_4);
779 if (globalVariable6_5 != 6 * 5)
780 printf(" mult error 6*5 got %d\n", globalVariable6_5);
781 if (globalVariable6_6 != 3)
782 printf(" comma error 10,3 got %d\n", globalVariable6_6);
783 if (globalVariable6_1a != 60+2)
784 printf(" addition error 60+2 got %d\n", globalVariable6_1a);
785 if (globalVariable6_2a != 64-1)
786 printf(" subtraction error 64-1 got %d\n", globalVariable6_2a);
787 if (globalVariable6_3a != 66/3)
788 printf(" division error 66/3 got %d\n", globalVariable6_3a);
789 if (globalVariable6_4a != 67/3)
790 printf(" division error 67/3 got %d\n", globalVariable6_4a);
791 if (globalVariable6_5a != 6 * 5)
792 printf(" mult error 6*5 got %d\n", globalVariable6_5a);
793 if (globalVariable6_6a != 3)
794 printf(" comma error 10,3 got %d\n", globalVariable6_6a);
798 void func6_2() { dprintf("func6_2 () called\n"); }
802 * Start Test Case #7 - relational operators
803 * Generate all relational operators (eq, gt, le, ne, ge, and, or)
804 * in both the true and false forms.
807 void fail7Print(int tCase, int fCase, char *op)
810 printf(" operator %s was not true when it should be - const expr\n",
813 printf(" operator %s was not false when it should be - const expr\n",
817 void fail7aPrint(int tCase, int fCase, char *op)
820 printf(" operator %s was not true when it should be - var expr\n", op);
822 printf(" operator %s was not false when it should be - var expr\n",op);
830 if ((globalVariable7_1 == 72) && (globalVariable7_2 == 71) &&
831 (globalVariable7_3 == 72) && (globalVariable7_4 == 71) &&
832 (globalVariable7_5 == 72) && (globalVariable7_6 == 71) &&
833 (globalVariable7_7 == 72) && (globalVariable7_8 == 71) &&
834 (globalVariable7_9 == 72) && (globalVariable7_10 == 71) &&
835 (globalVariable7_11 == 72) && (globalVariable7_12 == 71) &&
836 (globalVariable7_13 == 72) && (globalVariable7_14 == 71) &&
837 (globalVariable7_15 == 72) && (globalVariable7_16 == 71) &&
838 (globalVariable7_1a == 74) && (globalVariable7_2a == 73) &&
839 (globalVariable7_3a == 74) && (globalVariable7_4a == 73) &&
840 (globalVariable7_5a == 74) && (globalVariable7_6a == 73) &&
841 (globalVariable7_7a == 74) && (globalVariable7_8a == 73) &&
842 (globalVariable7_9a == 74) && (globalVariable7_10a == 73) &&
843 (globalVariable7_11a == 74) && (globalVariable7_12a == 73) &&
844 (globalVariable7_13a == 74) && (globalVariable7_14a == 73) &&
845 (globalVariable7_15a == 74) && (globalVariable7_16a == 73)) {
846 printf("Passed test #7 (relational operators)\n");
847 passedTest[7] = TRUE;
849 printf("**Failed** test #7 (relational operators)\n");
850 fail7Print(globalVariable7_1, globalVariable7_2, "BPatch_lt");
851 fail7Print(globalVariable7_3, globalVariable7_4, "BPatch_eq");
852 fail7Print(globalVariable7_5, globalVariable7_6, "BPatch_gt");
853 fail7Print(globalVariable7_7, globalVariable7_8, "BPatch_le");
854 fail7Print(globalVariable7_9, globalVariable7_10, "BPatch_ne");
855 fail7Print(globalVariable7_11, globalVariable7_12, "BPatch_ge");
856 fail7Print(globalVariable7_13, globalVariable7_14, "BPatch_and");
857 fail7Print(globalVariable7_15, globalVariable7_16, "BPatch_or");
859 fail7aPrint(globalVariable7_1a, globalVariable7_2a, "BPatch_lt");
860 fail7aPrint(globalVariable7_3a, globalVariable7_4a, "BPatch_eq");
861 fail7aPrint(globalVariable7_5a, globalVariable7_6a, "BPatch_gt");
862 fail7aPrint(globalVariable7_7a, globalVariable7_8a, "BPatch_le");
863 fail7aPrint(globalVariable7_9a, globalVariable7_10a, "BPatch_ne");
864 fail7aPrint(globalVariable7_11a, globalVariable7_12a, "BPatch_ge");
865 fail7aPrint(globalVariable7_13a, globalVariable7_14a, "BPatch_and");
866 fail7aPrint(globalVariable7_15a, globalVariable7_16a, "BPatch_or");
870 void func7_2() { dprintf("func7_2 () called\n"); }
873 * Test #8 - preserve registers - expr
874 * Verify the complex AST expressions do not clobber application
875 * paramter registers.
877 void func8_1(int p1, int p2, int p3, int p4, int p5, int p6, int p7,
878 int p8, int p9, int p10)
880 dprintf("func8_1 (...) called\n");
881 if ((p1 == 1) && (p2 == 2) && (p3 == 3) && (p4 == 4) && (p5 == 5) &&
882 (p6 == 6) && (p7 == 7) && (p8 == 8) && (p9 == 9) && (p10 == 10)) {
883 printf("Passed test #8 (preserve registers - expr)\n");
884 passedTest[8] = TRUE;
886 printf("**Failed** test #8 (preserve registers - expr )\n");
887 if (p1 != 1) printf(" parameter #1 is %d not 1\n", p1);
888 if (p2 != 2) printf(" parameter #2 is %d not 2\n", p2);
889 if (p3 != 3) printf(" parameter #3 is %d not 3\n", p3);
890 if (p4 != 4) printf(" parameter #4 is %d not 4\n", p4);
891 if (p5 != 5) printf(" parameter #5 is %d not 5\n", p5);
892 if (p6 != 6) printf(" parameter #6 is %d not 6\n", p6);
893 if (p7 != 7) printf(" parameter #7 is %d not 7\n", p7);
894 if (p8 != 8) printf(" parameter #8 is %d not 8\n", p8);
895 if (p9 != 9) printf(" parameter #9 is %d not 9\n", p9);
896 if (p10 != 10) printf(" parameter #10 is %d not 10\n", p10);
901 * Test #9 - reserve registers - funcCall
902 * Verify the a snippet that calls a function does not clobber the
903 * the parameter registers.
905 void func9_1(int p1, int p2, int p3, int p4, int p5, int p6, int p7,
906 int p8, int p9, int p10)
908 dprintf("func9_1 (...) called\n");
909 if ((p1 == 1) && (p2 == 2) && (p3 == 3) && (p4 == 4) && (p5 == 5) &&
910 (p6 == 6) && (p7 == 7) && (p8 == 8) && (p9 == 9) && (p10 == 10)) {
911 printf("Passed test #9 (preserve registers - funcCall)\n");
912 passedTest[9] = TRUE;
914 printf("**Failed** test #9 (preserve registers - funcCall )\n");
915 if (p1 != 1) printf(" parameter #1 is %d not 1\n", p1);
916 if (p2 != 2) printf(" parameter #2 is %d not 2\n", p2);
917 if (p3 != 3) printf(" parameter #3 is %d not 3\n", p3);
918 if (p4 != 4) printf(" parameter #4 is %d not 4\n", p4);
919 if (p5 != 5) printf(" parameter #5 is %d not 5\n", p5);
920 if (p6 != 6) printf(" parameter #6 is %d not 6\n", p6);
921 if (p7 != 7) printf(" parameter #7 is %d not 7\n", p7);
922 if (p8 != 8) printf(" parameter #8 is %d not 8\n", p8);
923 if (p9 != 9) printf(" parameter #9 is %d not 9\n", p9);
924 if (p10 != 10) printf(" parameter #10 is %d not 10\n", p10);
929 * Test #10 - insert snippet order
930 * Verify that a snippet are inserted in the requested order. We insert
931 * one snippet and then request two more to be inserted. One before
932 * the first snippet and one after it.
936 if ((globalVariable10_1 == 1) && (globalVariable10_2 == 1) &&
937 (globalVariable10_3 == 1) && (globalVariable10_4 == 3)) {
938 printf("Passed test #10 (insert snippet order)\n");
939 passedTest[10] = TRUE;
941 printf("** Failed test #10 (insert snippet order)\n");
942 if (!globalVariable10_1)
943 printf(" call10_1 was not called first\n");
944 if (!globalVariable10_2)
945 printf(" call10_2 was not called second\n");
946 if (!globalVariable10_3)
947 printf(" call10_3 was not called third\n");
952 * Test #11 - snippets at entry,exit,call
955 globalVariable11_1 = 2;
960 globalVariable11_1 = 1;
962 globalVariable11_1 = 3;
967 * Test #12 - insert/remove and malloc/free
976 kludge = 1; /* Here so that the following function call isn't the first
981 if (globalVariable12_1 == 1) {
982 printf("Passed test #12 (insert/remove and malloc/free)\n");
983 passedTest[12] = TRUE;
985 printf("**Failed test #12 (insert/remove and malloc/free)\n");
986 printf("ZANDY: #12 failed because globalVariable12_1 == %d\n", globalVariable12_1);
991 * Test #13 - paramExpr,retExpr,nullExpr
992 * Test various expressions
999 void func13_1(int p1, int p2, int p3, int p4, int p5)
1003 if ((p1 == 131) && (p2 == 132) && (p3 == 133) &&
1004 (p4 == 134) && (p5 == 135) && (globalVariable13_1 == 63)) {
1005 printf("Passed test #13 (paramExpr,retExpr,nullExpr)\n");
1006 passedTest[13] = TRUE;
1008 printf("**Failed test #13 (paramExpr,retExpr,nullExpr)\n");
1009 if (p1 != 131) printf(" parameter 1 is %d, not 131\n", p1);
1010 if (p2 != 132) printf(" parameter 2 is %d, not 132\n", p2);
1011 if (p3 != 133) printf(" parameter 3 is %d, not 133\n", p3);
1012 if (p4 != 134) printf(" parameter 4 is %d, not 134\n", p4);
1013 if (p5 != 135) printf(" parameter 5 is %d, not 135\n", p5);
1014 if (!(globalVariable13_1 & 1)) printf(" passed param a1 wrong\n");
1015 if (!(globalVariable13_1 & 2)) printf(" passed param a2 wrong\n");
1016 if (!(globalVariable13_1 & 4)) printf(" passed param a3 wrong\n");
1017 if (!(globalVariable13_1 & 8)) printf(" passed param a4 wrong\n");
1018 if (!(globalVariable13_1 & 16)) printf(" passed param a5 wrong\n");
1019 if (!(globalVariable13_1 & 32)) printf(" return value wrong\n");
1025 * Test #14 - replace function call
1029 globalVariable14_1 = 2;
1034 globalVariable14_2 = 1;
1039 kludge = 1; /* Here so that the following function call isn't the first
1045 if (globalVariable14_1 == 1 && globalVariable14_2 == 0) {
1046 printf("Passed test #14 (replace/remove function call)\n");
1047 passedTest[14] = TRUE;
1049 printf("**Failed test #14 (replace/remove function call)\n");
1050 if (globalVariable14_1 != 1)
1051 printf(" call to func14_2() was not replaced\n");
1052 if (globalVariable14_2 != 0)
1053 printf(" call to func14_3() was not removed\n");
1059 * Test #15 - setMutationsActive
1061 void check15result(char *varname, int value, int expected,
1062 char *errstr, int *failed)
1064 if (value != expected) {
1066 printf("**failed test #15 (setMutationsActive)\n");
1069 printf(" %s = %d %s\n", varname, value, errstr);
1081 globalVariable15_3 = 100;
1082 /* increment a dummy variable to keep alpha code generator from assuming
1083 too many free registers on the call into func15_3. jkh 3/7/00 */
1084 globalVariable15_4++;
1089 kludge = 1; /* Here so that the following function call isn't the first
1101 check15result("globalVariable15_1", globalVariable15_1, 1,
1102 "after first call to instrumented function", &failed);
1104 #if defined(sparc_sun_sunos4_1_3) || defined(sparc_sun_solaris2_4)
1105 /* Test a function that makes a system call (is a special case on Sparc) */
1107 check15result("globalVariable15_2", globalVariable15_2, 2,
1108 "after first call to instrumented function", &failed);
1112 check15result("globalVariable15_3", globalVariable15_3, 1,
1113 "after first call to instrumented function", &failed);
1115 /***********************************************************/
1120 check15result("globalVariable15_1", globalVariable15_1, 1,
1121 "after second call to instrumented function", &failed);
1123 #if defined(sparc_sun_sunos4_1_3) || defined(sparc_sun_solaris2_4)
1125 check15result("globalVariable15_2", globalVariable15_2, 2,
1126 "after second call to instrumented function", &failed);
1130 check15result("globalVariable15_3", globalVariable15_3, 100,
1131 "after second call to instrumented function", &failed);
1133 /***********************************************************/
1138 check15result("globalVariable15_1", globalVariable15_1, 2,
1139 "after third call to instrumented function", &failed);
1141 #if defined(sparc_sun_sunos4_1_3) || defined(sparc_sun_solaris2_4)
1143 check15result("globalVariable15_2", globalVariable15_2, 4,
1144 "after third call to instrumented function", &failed);
1148 check15result("globalVariable15_3", globalVariable15_3, 101,
1149 "after third call to instrumented function", &failed);
1152 printf("Passed test #15 (setMutationsActive)\n");
1153 passedTest[15] = TRUE;
1159 * Test #16 - if-else
1160 * Test if-then-else clauses
1163 void func16_2() { dprintf("func16_2 () called\n"); }
1164 void func16_3() { dprintf("func16_3 () called\n"); }
1165 void func16_4() { dprintf("func16_4 () called\n"); }
1172 if (globalVariable16_1 != 1 || globalVariable16_2 != 0) {
1173 printf("**Failed test #16 (if-else)\n");
1174 if (globalVariable16_1 != 1)
1175 printf(" True clause of first if should have been executed but was not.\n");
1176 if (globalVariable16_2 != 0)
1177 printf(" False clause of first if should not have been executed but was.\n");
1182 if (globalVariable16_3 != 0 || globalVariable16_4 != 1) {
1183 printf("**Failed test #16 (if-else)\n");
1184 if (globalVariable16_3 != 1)
1185 printf(" True clause of second if should not have been executed but was.\n");
1186 if (globalVariable16_4 != 0)
1187 printf(" False clause of second if should have been executed but was not.\n");
1192 if ((globalVariable16_5 != 0 || globalVariable16_6 != 1) ||
1193 (globalVariable16_7 != 0 || globalVariable16_8 != 1) ||
1194 (globalVariable16_9 != 0 || globalVariable16_10 != 1)) {
1195 printf(" failed large if clauses tests.\n");
1200 printf("Passed test #16 (if-else)\n");
1201 passedTest[16] = TRUE;
1206 * Test #17 - return values from func calls
1207 * See test1.C for a detailed comment
1215 kludge = 1; /* Here so that the following function call isn't the first
1218 ret17_1 = func17_2();
1221 if ((ret17_1 != RET17_1) ||
1222 (globalVariable17_1 != RET17_2) ||
1223 (globalVariable17_2 != RAN17_1)) {
1224 printf("**Failed** test case #17 (return values from func calls)\n");
1225 if (ret17_1 != RET17_1) {
1226 printf(" return value was %d, not %d\n", ret17_1, RET17_1);
1228 if (globalVariable17_1 != RET17_2) {
1229 printf(" return value was %d, not %d\n",
1230 globalVariable17_1, RET17_2);
1232 if (globalVariable17_2 != RAN17_1) {
1233 printf(" function call17_2 was not inserted\n");
1236 printf("Passed test #17 (return values from func calls)\n");
1237 passedTest[17] = TRUE;
1253 globalVariable17_1 = func17_4();
1258 * Test #18 - read/write a variable in the mutatee
1262 if (globalVariable18_1 == 17) {
1263 printf("Passed test #18 (read/write a variable in the mutatee)\n");
1264 passedTest[18] = TRUE;
1266 printf("**Failed test #18 (read/write a variable in the mutatee)\n");
1267 if (globalVariable18_1 == 42)
1268 printf(" globalVariable18_1 still contains 42 (probably it was not written to)\n");
1270 printf(" globalVariable18_1 contained %d, not 17 as expected\n",
1271 globalVariable18_1);
1276 * Test #19 - oneTimeCode
1282 if (globalVariable19_1 != MAGIC19_1) {
1283 printf("**Failed test #19 (oneTimeCode)\n");
1284 printf(" globalVariable19_1 contained %d, not %d as expected\n",
1285 globalVariable19_1, MAGIC19_1);
1290 if (globalVariable19_2 == MAGIC19_2) {
1291 printf("Passed test #19 (oneTimeCode)\n");
1292 passedTest[19] = TRUE;
1294 printf("**Failed test #19 (oneTimeCode)\n");
1295 printf(" globalVariable19_2 contained %d, not %d as expected\n",
1296 globalVariable19_2, MAGIC19_2);
1302 * Test #20 - instrumentation at arbitrary points
1313 volatile int tc = TEST20_C;
1314 volatile double td = TEST20_D;
1315 int test20_iter = 50;
1317 int func20_2(int *int_val, double *double_val)
1321 *int_val = tc+(tc+(tc+(tc+(tc+(tc+(tc+(tc+(tc+(tc+
1322 (tc+(tc+(tc+(tc+(tc+(tc+(tc+(tc+(tc+(tc+
1323 (tc+(tc+(tc+(tc+(tc+(tc+(tc+(tc+(tc+(tc+
1324 (tc+(tc+(tc+(tc+(tc+(tc+(tc+(tc+(tc+(tc+(tc
1325 ))))))))))))))))))))))))))))))))))))))));
1327 *double_val = td+(td+(td+(td+(td+(td+(td+(td+(td+(td+
1328 (td+(td+(td+(td+(td+(td+(td+(td+(td+(td+
1329 (td+(td+(td+(td+(td+(td+(td+(td+(td+(td+
1330 (td+(td+(td+(td+(td+(td+(td+(td+(td+(td+(td
1331 ))))))))))))))))))))))))))))))))))))))));
1333 for (i = 0; i < test20_iter; i++) {
1337 } else if (i < 10) {
1339 } else if (i > 20) {
1344 /* The answer we expect from the above is: */
1345 #define TEST20_ANSWER 1088896211
1352 #if !defined(rs6000_ibm_aix4_1) && \
1353 !defined(alpha_dec_osf4_0) && \
1354 !defined(mips_sgi_irix6_4) && \
1355 !defined(sparc_sun_solaris2_4)
1357 printf("Skipped test #20 (instrument arbitrary points)\n");
1358 printf("\t- not implemented on this platform\n");
1359 passedTest[20] = TRUE;
1365 ret = func20_2(&int_val, &double_val);
1367 if (globalVariable20_1 == (TEST20_A * TEST20_TIMES) &&
1368 eq_doubles(globalVariable20_2, (TEST20_B * (double)TEST20_TIMES)) &&
1369 int_val == (TEST20_C * TEST20_TIMES) &&
1370 eq_doubles(double_val, (TEST20_D * (double)TEST20_TIMES)) &&
1371 ret == TEST20_ANSWER) {
1372 printf("Passed test #20 (instrument arbitrary points)\n");
1373 passedTest[20] = TRUE;
1375 printf("**Failed test #20 (instrument arbitrary points)\n");
1376 if (globalVariable20_1 != (TEST20_A * TEST20_TIMES))
1377 printf(" globalVariable20_1 contained %d, not %d as expected\n",
1378 globalVariable20_1, TEST20_A * TEST20_TIMES);
1379 if (!eq_doubles(globalVariable20_2, (TEST20_B * (double)TEST20_TIMES)))
1380 printf(" globalVariable20_2 contained %g, not %g as expected\n",
1381 globalVariable20_2, TEST20_B * (double)TEST20_TIMES);
1382 if (int_val != (TEST20_C * TEST20_TIMES))
1383 printf(" int_val contained %d, not %d as expected\n",
1384 int_val, TEST20_C * TEST20_TIMES);
1385 if (!eq_doubles(double_val, (TEST20_D * (double)TEST20_TIMES)))
1386 printf(" double_val contained %g, not %g as expected\n",
1387 double_val, TEST20_D * (double)TEST20_TIMES);
1388 if (ret != TEST20_ANSWER)
1389 printf(" ret contained %d, not %d as expected\n",
1390 ret, TEST20_ANSWER);
1396 * Test #21 - findFunction in module
1400 /* Nothing for the mutatee to do in this test (findFunction in module) */
1401 #if defined(sparc_sun_solaris2_4) \
1402 || defined(mips_sgi_irix6_4) \
1403 || defined(i386_unknown_solaris2_5) \
1404 || defined(i386_unknown_linux2_0) \
1405 || defined(alpha_dec_osf4_0) \
1406 || defined(rs6000_ibm_aix4_1)
1408 printf("Passed test #21 (findFunction in module)\n");
1409 passedTest[21] = TRUE;
1411 printf("Skipped test #21 (findFunction in module)\n");
1412 printf("\t- not implemented on this platform\n");
1413 passedTest[21] = TRUE;
1418 * Test #22 - replace function
1420 * These are defined in libtestA.so
1422 extern void call22_5A(int);
1423 extern void call22_6(int);
1425 volatile int _unused; /* move decl here to dump compiler warning - jkh */
1429 #if !defined(sparc_sun_solaris2_4) && \
1430 !defined(alpha_dec_osf4_0)
1432 printf("Skipped test #22 (replace function)\n");
1433 printf("\t- not implemented on this platform\n");
1434 passedTest[22] = TRUE;
1436 /* libtestA.so should already be loaded (by the mutator), but we
1437 need to use the dl interface to get pointers to the functions
1439 void (*call22_5)(int);
1440 void (*call22_6)(int);
1443 char dlopenName[128];
1444 #if defined(sparc_sun_solaris2_4)
1445 int dlopenMode = RTLD_NOW | RTLD_GLOBAL;
1447 int dlopenMode = RTLD_NOW;
1449 _unused = sprintf(dlopenName, "./%s", libNameA);
1450 handleA = dlopen(dlopenName, dlopenMode);
1452 printf("**Failed test #22 (replaceFunction)\n");
1453 printf(" Mutatee couldn't get handle for %s\n", libNameA);
1456 call22_5 = (void(*)(int))dlsym(handleA, "call22_5");
1458 printf("**Failed test #22 (replaceFunction)\n");
1459 printf(" Mutatee couldn't get handle for call22_5 in %s\n", libNameA);
1461 call22_6 = (void(*)(int))dlsym(handleA, "call22_6");
1463 printf("**Failed test #22 (replaceFunction)\n");
1464 printf(" Mutatee couldn't get handle for call22_6 in %s\n", libNameA);
1467 /* Call functions that have been replaced by the mutator. The
1468 side effects of these calls (replaced, not replaced, or
1469 otherwise) are independent of each other. */
1470 call22_1(10); /* replaced by call22_2 */
1471 if (globalVariable22_1 != 10 + MAGIC22_2) {
1472 printf("**Failed test #22 (replace function) (a.out -> a.out)\n");
1475 call22_3(20); /* replaced by call22_4 */
1476 if (globalVariable22_2 != 20 + MAGIC22_4) {
1477 printf("**Failed test #22 (replace function) (a.out -> shlib)\n");
1480 call22_5(30); /* replaced by call22_5 (in libtestB) */
1481 if (globalVariable22_3 != 30 + MAGIC22_5B) {
1482 printf("globalVariable22_3 = %d\n", globalVariable22_3);
1483 printf("30 + MAGIC22_5B = %d\n", 30 + MAGIC22_5B);
1484 printf("**Failed test #22 (replace function) (shlib -> shlib)\n");
1487 call22_6(40); /* replaced by call22_6 */
1488 if (globalVariable22_4 != 40 + MAGIC22_7) {
1489 printf("**Failed test #22 (replace function) (shlib -> a.out)\n");
1492 printf("Passed test #22 (replace function)\n");
1493 passedTest[22] = TRUE;
1499 * Test #23 - local variables
1501 int shadowVariable23_1 = 2300010;
1502 int shadowVariable23_2 = 2300020;
1503 int globalShadowVariable23_1 = (int)0xdeadbeef;
1504 int globalShadowVariable23_2 = (int)0xdeadbeef;
1505 int globalVariable23_1 = 2300000;
1507 void verifyScalarValue23(char *name, int a, int value)
1509 verifyScalarValue(name, a, value, 23, "local variables");
1514 /* copy shadowed global variables to visible global variables to permit
1515 * checking their values
1517 globalShadowVariable23_1 = shadowVariable23_1;
1518 globalShadowVariable23_2 = shadowVariable23_2;
1523 int localVariable23_1 = 2300019;
1524 int shadowVariable23_1 = 2300011;
1525 int shadowVariable23_2 = 2300021;
1527 call23_2(); /* place to manipulate local variables */
1529 passedTest[23] = TRUE;
1531 /* snippet didn't update local variable */
1532 verifyScalarValue23("localVariable23_1", localVariable23_1, 2300001);
1534 /* did snippet update shadow variable (in the global scope) */
1535 verifyScalarValue23("globalShadowVariable23_1", globalShadowVariable23_1,
1538 /* did snippet correctly update shadow variable call23_2 */
1539 verifyScalarValue23("shadowVariable23_1", shadowVariable23_1, 2300012);
1541 /* did snippet correctly update shadow variable via global
1542 scope in call23_2 */
1543 verifyScalarValue23("shadowVariable23_2", shadowVariable23_2, 2300021);
1545 /* did snippet correctly update shadow variable via global
1546 scope in call23_2 */
1547 verifyScalarValue23("globalShadowVariable23_2", globalShadowVariable23_2,
1550 /* did snippet correctly read local variable in call23_2 */
1551 verifyScalarValue23("globalVariable23_1", globalVariable23_1, 2300001);
1556 #if !defined(sparc_sun_solaris2_4) && \
1557 !defined(rs6000_ibm_aix4_1) && \
1558 !defined(alpha_dec_osf4_0) && \
1559 !defined(i386_unknown_linux2_0) && \
1560 !defined(i386_unknown_solaris2_5) && \
1561 !defined(i386_unknown_nt4_0)
1563 printf("Skipped test #23 (local variables)\n");
1564 printf("\t- not implemented on this platform\n");
1565 passedTest[23] = TRUE;
1569 if (passedTest[23]) printf("Passed test #23 (local variables)\n");
1574 * Test #24 - arrary variables
1579 int globalVariable24_1[100];
1580 int globalVariable24_2 = 53;
1581 int globalVariable24_3;
1582 int globalVariable24_4 = 83;
1583 int globalVariable24_5;
1585 /* to hold values from local array */
1586 int globalVariable24_6;
1587 int globalVariable24_7;
1589 /* for 2-d arrays - array is not square and we avoid using diagonal elements
1590 * to make sure we test address computation
1592 int globalVariable24_8[10][15];
1593 int globalVariable24_9;
1595 void verifyValue24(char *name, int *a, int index, int value)
1597 verifyValue(name, a, index, value, 24, "array variables");
1600 void verifyScalarValue24(char *name, int a, int value)
1602 verifyScalarValue(name, a, value, 24, "array variables");
1611 #ifdef sparc_sun_solaris2_4
1612 unsigned i=0; /* hack to prevent g++'s optimizer making func uninstr'uble */
1616 int localVariable24_1[100];
1618 for (i=0; i < 100; i++) localVariable24_1[i] = 2400000;
1620 localVariable24_1[79] = 2400007;
1621 localVariable24_1[83] = 2400008;
1625 verifyValue24("localVariable24_1", localVariable24_1, 1, 2400005);
1626 verifyValue24("localVariable24_1", localVariable24_1, 53, 2400006);
1631 #if !defined(sparc_sun_solaris2_4) && \
1632 !defined(rs6000_ibm_aix4_1) && \
1633 !defined(alpha_dec_osf4_0) && \
1634 !defined(i386_unknown_linux2_0) && \
1635 !defined(i386_unknown_solaris2_5) && \
1636 !defined(i386_unknown_nt4_0)
1638 printf("Skipped test #24 (arrary variables)\n");
1639 printf("\t- not implemented on this platform\n");
1640 passedTest[24] = TRUE;
1644 passedTest[24] = TRUE;
1647 for (i=0; i < 100; i++) globalVariable24_1[i] = 2400000;
1648 globalVariable24_1[79] = 2400003;
1649 globalVariable24_1[83] = 2400004;
1651 for (i=0; i < 10; i++) {
1652 for (j=0; j < 15; j++) {
1653 globalVariable24_8[i][j] = 2400010;
1656 globalVariable24_8[7][9] = 2400012;
1658 /* inst code we put into this function:
1660 * globalVariable24_1[1] = 2400001
1661 * globalVariable24_1[globalVariable24_2] = 2400002
1662 * globalVariable24_3 = globalVariable24_1[79]
1663 * globalVariable24_5 = globalVariable24_1[globalVariable24_4]
1664 * localVariable24_1[1] = 2400001
1665 * localVariable24_1[globalVariable24_2] = 2400002
1666 * globalVariable24_8[2][3] = 2400011
1667 * globalVariable24_6 = localVariable24_1[79]
1668 * globalVariable24_7 = localVariable24_1[globalVariable24_4]
1672 for (i=0; i < 100; i++) {
1674 /* 1st element should be modified by the snippet (constant index) */
1675 verifyValue24("globalVariable24_1", globalVariable24_1, 1, 2400001);
1676 } else if (i == 53) {
1677 /* 53rd element should be modified by the snippet (variable index) */
1678 verifyValue24("globalVariable24_1", globalVariable24_1, 53, 2400002);
1679 } else if (i == 79) {
1680 /* 79th element was modified by us */
1681 verifyValue24("globalVariable24_1", globalVariable24_1, 79, 2400003);
1682 } else if (i == 83) {
1683 /* 83rd element was modified by us */
1684 verifyValue24("globalVariable24_1", globalVariable24_1, 83, 2400004);
1685 } else if (globalVariable24_1[i] != 2400000) {
1686 /* rest should still be the original value */
1687 verifyValue24("globalVariable24_1", globalVariable24_1, i, 2400000);
1691 verifyScalarValue24("globalVariable24_3", globalVariable24_3, 2400003);
1692 verifyScalarValue24("globalVariable24_5", globalVariable24_5, 2400004);
1694 /* now for the two elements read from the local variable */
1695 verifyScalarValue24("globalVariable24_6", globalVariable24_6, 2400007);
1696 verifyScalarValue24("globalVariable24_7", globalVariable24_7, 2400008);
1698 /* verify 2-d element use */
1699 verifyScalarValue24("globalVariable24_8[2][3]", globalVariable24_8[2][3],
1701 verifyScalarValue24("globalVariable24_9", globalVariable24_9, 2400012);
1703 if (passedTest[24]) printf("Passed test #24 (array variables)\n");
1708 * Test #25 - unary operators
1710 int globalVariable25_1;
1711 int *globalVariable25_2; /* used to hold addres of globalVariable25_1 */
1712 int globalVariable25_3;
1713 int globalVariable25_4;
1714 int globalVariable25_5;
1715 int globalVariable25_6;
1716 int globalVariable25_7;
1725 #if defined(mips_sgi_irix6_4)
1726 printf("Skipped test #25 (unary operators)\n");
1727 printf("\t- not implemented on this platform\n");
1728 passedTest[25] = TRUE;
1731 passedTest[25] = TRUE;
1733 globalVariable25_1 = 25000001;
1734 globalVariable25_2 = (int *) 25000002;
1735 globalVariable25_3 = 25000003;
1736 globalVariable25_4 = 25000004;
1737 globalVariable25_5 = 25000005;
1738 globalVariable25_6 = -25000006;
1739 globalVariable25_7 = 25000007;
1741 /* inst code we put into this function:
1743 * globalVariable25_2 = &globalVariable25_1
1744 * globalVariable25_3 = *globalVariable25_2
1745 * globalVariable25_5 = -globalVariable25_4
1746 * globalVariable25_7 = -globalVariable25_6
1751 if ((int *) globalVariable25_2 != &globalVariable25_1) {
1752 if (passedTest[25]) printf("**Failed** test #25 (unary operators)\n");
1753 passedTest[25] = FALSE;
1754 printf(" globalVariable25_2 = %p, not %p\n",
1755 globalVariable25_2, (void *) &globalVariable25_1);
1758 if (globalVariable25_3 != globalVariable25_1) {
1759 if (passedTest[25]) printf("**Failed** test #25 (unary operators)\n");
1760 passedTest[25] = FALSE;
1761 printf(" globalVariable25_3 = %d, not %d\n",
1762 globalVariable25_3, globalVariable25_1);
1765 if (globalVariable25_5 != -globalVariable25_4) {
1766 if (passedTest[25]) printf("**Failed** test #25 (unary operators)\n");
1767 passedTest[25] = FALSE;
1768 printf(" globalVariable25_5 = %d, not %d\n",
1769 globalVariable25_5, -globalVariable25_4);
1772 if (globalVariable25_7 != -globalVariable25_6) {
1773 if (passedTest[25]) printf("**Failed** test #25 (unary operators)\n");
1774 passedTest[25] = FALSE;
1775 printf(" globalVariable25_7 = %d, not %d\n",
1776 globalVariable25_7, -globalVariable25_6);
1779 if (passedTest[25]) printf("Passed test #25 (unary operators)\n");
1784 * Test #26 - field operators
1796 struct struct26_1 field4;
1799 struct struct26_2 globalVariable26_1;
1800 int globalVariable26_2 = 26000000;
1801 int globalVariable26_3 = 26000000;
1802 int globalVariable26_4 = 26000000;
1803 int globalVariable26_5 = 26000000;
1804 int globalVariable26_6 = 26000000;
1805 int globalVariable26_7 = 26000000;
1807 int globalVariable26_8 = 26000000;
1808 int globalVariable26_9 = 26000000;
1809 int globalVariable26_10 = 26000000;
1810 int globalVariable26_11 = 26000000;
1811 int globalVariable26_12 = 26000000;
1812 int globalVariable26_13 = 26000000;
1814 void verifyScalarValue26(char *name, int a, int value)
1816 verifyScalarValue(name, a, value, 26, "field operators");
1826 struct struct26_2 localVariable26_1;
1828 localVariable26_1.field1 = 26002001;
1829 localVariable26_1.field2 = 26002002;
1830 for (i=0; i < 10; i++) localVariable26_1.field3[i] = 26002003 + i;
1831 localVariable26_1.field4.field1 = 26002013;
1832 localVariable26_1.field4.field2 = 26002014;
1834 /* check local variables at this point (since we known locals are still
1835 on the stack here. */
1842 #if !defined(sparc_sun_solaris2_4) && \
1843 !defined(rs6000_ibm_aix4_1) && \
1844 !defined(alpha_dec_osf4_0) && \
1845 !defined(i386_unknown_linux2_0) && \
1846 !defined(i386_unknown_solaris2_5) && \
1847 !defined(i386_unknown_nt4_0)
1849 printf("Skipped test #26 (struct elements)\n");
1850 printf("\t- not implemented on this platform\n");
1851 passedTest[26] = TRUE;
1855 passedTest[26] = TRUE;
1857 globalVariable26_1.field1 = 26001001;
1858 globalVariable26_1.field2 = 26001002;
1859 for (i=0; i < 10; i++) globalVariable26_1.field3[i] = 26001003 + i;
1860 globalVariable26_1.field4.field1 = 26000013;
1861 globalVariable26_1.field4.field2 = 26000014;
1865 verifyScalarValue26("globalVariable26_2", globalVariable26_2, 26001001);
1866 verifyScalarValue26("globalVariable26_3", globalVariable26_3, 26001002);
1867 verifyScalarValue26("globalVariable26_4", globalVariable26_4, 26001003);
1868 verifyScalarValue26("globalVariable26_5", globalVariable26_5, 26001003+5);
1869 verifyScalarValue26("globalVariable26_6", globalVariable26_6, 26000013);
1870 verifyScalarValue26("globalVariable26_7", globalVariable26_7, 26000014);
1872 /* local variables */
1873 verifyScalarValue26("globalVariable26_8", globalVariable26_8, 26002001);
1874 verifyScalarValue26("globalVariable26_9", globalVariable26_9, 26002002);
1875 verifyScalarValue26("globalVariable26_10", globalVariable26_10, 26002003);
1876 verifyScalarValue26("globalVariable26_11", globalVariable26_11, 26002003+5);
1877 verifyScalarValue26("globalVariable26_12", globalVariable26_12, 26002013);
1878 verifyScalarValue26("globalVariable26_13", globalVariable26_13, 26002014);
1880 if (passedTest[26]) printf("Passed test #26 (field operators)\n");
1885 * Test #27 - type compatibility
1889 /* void *field27_11; */
1895 /* void *field27_21; */
1902 struct struct26_2 field4;
1907 struct struct26_2 field4;
1910 int globalVariable27_1;
1911 /* Note for future reference: -Wl,-bgcbypass:3 is NECESSARY for
1912 compilation (gcc) on AIX. Damn efficient linkers. */
1913 int globalVariable27_5[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
1914 int globalVariable27_6[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
1915 float globalVariable27_7[10] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0,
1916 6.0, 7.0, 8.0, 9.0};
1917 float globalVariable27_8[12];
1919 /* need this variables or some compilers (AIX xlc) will removed unused
1920 typedefs - jkh 10/13/99 */
1929 #if !defined(sparc_sun_solaris2_4) && \
1930 !defined(rs6000_ibm_aix4_1) && \
1931 !defined(alpha_dec_osf4_0) && \
1932 !defined(i386_unknown_linux2_0) && \
1933 !defined(i386_unknown_solaris2_5) && \
1934 !defined(i386_unknown_nt4_0)
1936 printf("Skipped test #27 (type compatibility)\n");
1937 printf("\t- not implemented on this platform\n");
1938 passedTest[27] = TRUE;
1940 passedTest[27] = (globalVariable27_1 == 1);
1942 if (passedTest[27]) printf("Passed test #27 (type compatibility)\n");
1947 * Test #28 - field operators
1959 struct struct28_1 field4;
1962 char globalVariable28_1[sizeof(struct struct28_2)];
1963 struct struct28_2 *temp;
1964 int globalVariable28_2 = 28000000;
1965 int globalVariable28_3 = 28000000;
1966 int globalVariable28_4 = 28000000;
1967 int globalVariable28_5 = 28000000;
1968 int globalVariable28_6 = 28000000;
1969 int globalVariable28_7 = 28000000;
1971 void verifyScalarValue28(char *name, int a, int value)
1973 verifyScalarValue(name, a, value, 28, "user defined fields");
1982 for (j=0; j < 400; j++);
1985 int globalVariable29_1;
1991 passedTest[28] = TRUE;
1994 temp = (struct struct28_2 *) globalVariable28_1;
1996 temp->field1 = 28001001;
1997 temp->field2 = 28001002;
1998 for (i=0; i < 10; i++) temp->field3[i] = 28001003 + i;
1999 temp->field4.field1 = 28000013;
2000 temp->field4.field2 = 28000014;
2004 verifyScalarValue28("globalVariable28_2", globalVariable28_2, 28001001);
2005 verifyScalarValue28("globalVariable28_3", globalVariable28_3, 28001002);
2006 verifyScalarValue28("globalVariable28_4", globalVariable28_4, 28001003);
2007 verifyScalarValue28("globalVariable28_5", globalVariable28_5, 28001003+5);
2008 verifyScalarValue28("globalVariable28_6", globalVariable28_6, 28000013);
2009 verifyScalarValue28("globalVariable28_7", globalVariable28_7, 28000014);
2011 if (passedTest[28]) printf("Passed test #28 (user defined fields)\n");
2016 passedTest[29] = (globalVariable29_1 == 1);
2018 if (passedTest[29]) printf("Passed test #29 (BPatch_srcObj class)\n");
2028 /* variables to keep the base addr and last addr of call30_1 */
2029 unsigned globalVariable30_8 = 0;
2030 unsigned globalVariable30_9 = 0;
2033 kludge = 1; /* Here so that the following function call isn't the first
2036 #if defined(sparc_sun_solaris2_4) || \
2037 defined(i386_unknown_solaris2_5) || \
2038 defined(i386_unknown_linux2_0) || \
2039 defined(i386_unknown_nt4_0) ||\
2040 defined(rs6000_ibm_aix4_1) || \
2041 defined(alpha_dec_osf4_0)
2045 passedTest[30] = !globalVariable30_3 ||
2046 #if defined(rs6000_ibm_aix4_1)
2047 ((globalVariable30_8 <= globalVariable30_3) &&
2049 ((globalVariable30_2 <= globalVariable30_3) &&
2051 (globalVariable30_3 <= globalVariable30_9));
2052 if (!passedTest[30]){
2053 printf("**Failed** test #30 (line information) in %s[%d]\n", __FILE__, __LINE__ );
2057 passedTest[30] = !globalVariable30_4 ||
2058 #if defined(rs6000_ibm_aix4_1)
2059 ((globalVariable30_8 <= globalVariable30_4) &&
2061 ((globalVariable30_2 <= globalVariable30_4) &&
2063 (globalVariable30_4 <= globalVariable30_9));
2064 if (!passedTest[30]){
2065 printf("**Failed** test #30 (line information) in %s[%d]\n", __FILE__, __LINE__ );
2069 passedTest[30] = !globalVariable30_5 ||
2070 #if defined(rs6000_ibm_aix4_1)
2071 ((globalVariable30_8 <= globalVariable30_5) &&
2073 ((globalVariable30_2 <= globalVariable30_5) &&
2075 (globalVariable30_5 <= globalVariable30_9));
2076 if (!passedTest[30]){
2077 printf("**Failed** test #30 (line information) in %s[%d]\n", __FILE__, __LINE__ );
2081 passedTest[30] = !globalVariable30_6 ||
2082 (globalVariable30_1 == globalVariable30_6);
2083 if (!passedTest[30]){
2084 printf("**Failed** test #30 (line information) in %s[%d]\n", __FILE__, __LINE__ );
2088 printf("Passed test #30 (line information)\n");
2091 printf("Skipped test #30 (line information)\n");
2092 printf("\t- not implemented on this platform\n");
2093 passedTest[30] = TRUE;
2098 /****************************************************************************/
2099 /****************************************************************************/
2100 /****************************************************************************/
2104 globalVariable31_2 = 1;
2109 globalVariable31_3 = 1;
2112 void func31_4( int value )
2116 printf( "func_31_4 called with value = 0 !\n" );
2119 globalVariable31_4 += value;
2124 #if defined(alpha_dec_osf4_0)
2125 printf( "Skipped test #31 (non-recursive base tramp guard)\n" );
2126 printf( "\t- not implemented on this platform\n" );
2127 passedTest[ 31 ] = TRUE;
2131 globalVariable31_1 = 0;
2132 globalVariable31_2 = 0;
2133 globalVariable31_3 = 0;
2134 globalVariable31_4 = 0;
2138 passedTest[ 31 ] = ( globalVariable31_3 == 1 );
2139 if( ! passedTest[ 31 ] )
2141 printf( "**Failed** test #31 (non-recursive base tramp guard)\n" );
2142 printf( " globalVariable31_3 = %d, should be 1 (no instrumentation got executed?).\n",
2143 globalVariable31_3 );
2147 passedTest[ 31 ] = ( globalVariable31_4 == 0 );
2148 if( ! passedTest[ 31 ] )
2150 printf( "**Failed** test #31 (non-recursive base tramp guard)\n" );
2151 printf( " globalVariable31_4 = %d, should be 0.\n",
2152 globalVariable31_4 );
2153 switch( globalVariable31_4 )
2155 case 0: printf( " Recursive guard works fine.\n" ); break;
2156 case 1: printf( " Pre-instr recursive guard does not work.\n" ); break;
2157 case 2: printf( " Post-instr recursive guard does not work.\n" ); break;
2158 case 3: printf( " None of the recursive guards work.\n" ); break;
2159 default: printf( " Something is really wrong.\n" ); break;
2164 passedTest[ 31 ] = TRUE;
2165 printf( "Passed test #31 (non-recursive base tramp guard)\n" );
2171 /****************************************************************************/
2172 /****************************************************************************/
2173 /****************************************************************************/
2177 globalVariable32_2 = 1;
2182 globalVariable32_3 = 1;
2185 void func32_4( int value )
2189 printf( "func_32_4 called with value = 0 !\n" );
2192 globalVariable32_4 += value;
2197 globalVariable32_1 = 0;
2198 globalVariable32_2 = 0;
2199 globalVariable32_3 = 0;
2200 globalVariable32_4 = 0;
2204 passedTest[ 32 ] = ( globalVariable32_3 == 1 );
2205 if( ! passedTest[ 32 ] )
2207 printf( "**Failed** test #32 (non-recursive base tramp guard)\n" );
2208 printf( " globalVariable32_3 = %d, should be 1 (no instrumentation got executed?).\n",
2209 globalVariable32_3 );
2213 passedTest[ 32 ] = ( globalVariable32_4 == 3 );
2214 if( ! passedTest[ 32 ] )
2216 printf( "**Failed** test #32 (non-recursive base tramp guard)\n" );
2217 printf( " globalVariable32_4 = %d, should be 3.\n",
2218 globalVariable32_4 );
2219 switch( globalVariable32_4 )
2221 case 0: printf( " Recursive guard works fine.\n" ); break;
2222 case 1: printf( " Pre-instr recursive guard does not work.\n" ); break;
2223 case 2: printf( " Post-instr recursive guard does not work.\n" ); break;
2224 case 3: printf( " None of the recursive guards work.\n" ); break;
2225 default: printf( " Something is really wrong.\n" ); break;
2230 passedTest[ 32 ] = TRUE;
2231 printf( "Passed test #32 (recursive base tramp guard)\n" );
2236 /****************************************************************************/
2237 /****************************************************************************/
2238 /****************************************************************************/
2240 void func33_2(int x)
2245 printf("Goodbye.\n");
2247 printf("See you.\n");
2250 printf("That's all.\n");
2307 /* The only possible failures occur in the mutator. */
2309 passedTest[ 33 ] = TRUE;
2310 printf( "Passed test #33 (control flow graphs)\n" );
2313 /****************************************************************************/
2314 /****************************************************************************/
2315 /****************************************************************************/
2324 /* There are four loops in total. */
2325 for (i = 0; i < 10; i++) { /* Contains two loops. */
2326 printf("i = %d\n", i);
2328 for (j = 0; j < 10; j++) { /* Contains one loop. */
2329 printf("j = %d\n", j);
2333 printf("k = %d\n", k);
2340 printf("j = %d\n", j);
2348 /* The only possible failures occur in the mutator. */
2350 passedTest[ 34 ] = TRUE;
2351 printf( "Passed test #34 (loop information)\n" );
2354 #if defined(i386_unknown_solaris2_5) || defined(i386_unknown_linux2_0) || defined(sparc_sun_solaris2_4)
2356 extern "C" int call35_1();
2358 extern int call35_1();
2364 #if defined(i386_unknown_solaris2_5) || defined(i386_unknown_linux2_0) || defined(sparc_sun_solaris2_4)
2371 printf( "**Failed** test #35 (function relocation)\n" );
2373 printf( " total = %d, should be 35.\n", value );
2377 case 1: printf( " Entry instrumentation did not work.\n" ); break;
2378 case 2: printf( " Exit instrumentation did not work.\n" ); break;
2379 default: printf(" Take a look at the call to call35_2.\n" ); break;
2381 passedTest[ 35 ] = FALSE;
2385 passedTest[ 35 ] = TRUE;
2386 printf( "Passed test #35 (function relocation)\n" );
2388 passedTest[ 35 ] = TRUE;
2389 printf( "Skipped test #35 (function relocation)\n" );
2390 #if defined(i386_unknown_nt4_0)
2391 printf( "\t- test not implemented for this platform\n" );
2393 printf( "\t- not implemented on this platform\n" );
2398 /****************************************************************************/
2399 /****************************************************************************/
2400 /****************************************************************************/
2402 /* "replaceFunctionCall()" on Irix usually requires that the new
2403 callee have a GOT entry. This dummy function forces GOT entries to
2404 be created for these functions. */
2405 #if defined(mips_sgi_irix6_4)
2406 void dummy_force_got_entries()
2413 #ifdef i386_unknown_nt4_0
2414 #define USAGE "Usage: test1.mutatee [-attach] [-verbose] -run <num> .."
2416 #define USAGE "Usage: test1.mutatee [-attach <fd>] [-verbose] -run <num> .."
2419 int main(int iargc, char *argv[])
2420 { /* despite different conventions */
2421 unsigned argc=(unsigned)iargc; /* make argc consistently unsigned */
2423 unsigned int testsFailed = 0;
2424 int useAttach = FALSE;
2425 #ifndef i386_unknown_nt4_0
2429 for (j=0; j <= MAX_TEST; j++) {
2431 passedTest[j] = FALSE;
2434 for (i=1; i < argc; i++) {
2435 if (!strcmp(argv[i], "-verbose")) {
2437 } else if (!strcmp(argv[i], "-attach")) {
2439 #ifndef i386_unknown_nt4_0
2441 fprintf(stderr, "%s\n", USAGE);
2444 pfd = atoi(argv[i]);
2446 } else if (!strcmp(argv[i], "-runall")) {
2447 dprintf("selecting all tests\n");
2448 for (j=1; j <= MAX_TEST; j++) runTest[j] = TRUE;
2449 } else if (!strcmp(argv[i], "-run")) {
2450 for (j=i+1; j < argc; j++) {
2451 unsigned int testId;
2452 if ((testId = atoi(argv[j]))) {
2453 if ((testId > 0) && (testId <= MAX_TEST)) {
2454 dprintf("selecting test %d\n", testId);
2455 runTest[testId] = TRUE;
2457 printf("invalid test %d requested\n", testId);
2461 /* end of test list */
2467 fprintf(stderr, "%s\n", USAGE);
2472 if ((argc==1) || debugPrint)
2473 printf("Mutatee %s [%s]:\"%s\"\n", argv[0],
2474 mutateeCplusplus ? "C++" : "C", Builder_id);
2475 if (argc==1) exit(0);
2478 #ifndef i386_unknown_nt4_0
2480 if (write(pfd, &ch, sizeof(char)) != sizeof(char)) {
2481 fprintf(stderr, "*ERROR*: Writing to pipe\n");
2486 printf("Waiting for mutator to attach...\n");
2487 while (!checkIfAttached()) ;
2488 printf("Mutator attached. Mutatee continuing.\n");
2491 if (runTest[1]) func1_1();
2492 if (runTest[2]) func2_1();
2493 if (runTest[3]) func3_1();
2494 if (runTest[4]) func4_1();
2495 if (runTest[5]) func5_1();
2496 if (runTest[6]) func6_1();
2497 if (runTest[7]) func7_1();
2498 if (runTest[8]) func8_1(1,2,3,4,5,6,7,8,9,10);
2499 if (runTest[9]) func9_1(1,2,3,4,5,6,7,8,9,10);
2500 if (runTest[10]) func10_1();
2501 if (runTest[11]) func11_1();
2502 if (runTest[12]) func12_1();
2503 if (runTest[13]) func13_1(131,132,133,134,135);
2504 if (runTest[14]) func14_1();
2505 if (runTest[15]) func15_1();
2506 if (runTest[16]) func16_1();
2507 if (runTest[17]) func17_1();
2508 if (runTest[18]) func18_1();
2509 if (runTest[19]) func19_1();
2510 if (runTest[20]) func20_1();
2511 if (runTest[21]) func21_1();
2512 if (runTest[22]) func22_1();
2513 if (runTest[23]) func23_1();
2514 if (runTest[24]) func24_1();
2515 if (runTest[25]) func25_1();
2516 if (runTest[26]) func26_1();
2517 if (runTest[27]) func27_1();
2518 if (runTest[28]) func28_1();
2519 if (runTest[29]) func29_1();
2520 if (runTest[30]) func30_1();
2522 if (runTest[31]) func31_1();
2523 if (runTest[32]) func32_1();
2525 if (runTest[33]) func33_1();
2526 if (runTest[33]) func34_1();
2527 if (runTest[35]) func35_1();
2529 /* See how we did running the tests. */
2530 for (i=1; i <= MAX_TEST; i++) {
2531 if (runTest[i] && !passedTest[i]) testsFailed++;
2535 printf("All tests passed\n");
2537 printf("**Failed** %d test%c\n",testsFailed,(testsFailed>1)?'s':' ');
2540 dprintf("Mutatee %s terminating.\n", argv[0]);
2541 return (testsFailed ? 127 : 0);