Added features to dyninstAPI library, including the ability to delete
[dyninst.git] / dyninstAPI / tests / src / test1.C
1
2 //
3 // libdyninst validation suite test #1
4 //    Author: Jeff Hollingsworth (1/7/97)
5 //        derived from a previous test by Bryan Buck
6 //
7
8 //  This program tests the basic features of the dyninst API.  
9 //      The mutatee that goes with this file is test1.mutatee.c
10 //      
11 //  Naming conventions:
12 //      All functions, variables, etc are name funcXX_YY, exprXX_YY, etc.
13 //          XX is the test number
14 //          YY is the instance withing the test
15 //          func1_2 is the second function used in test case #1.
16 //
17
18 /*
19  * $Log: test1.C,v $
20  * Revision 1.2  1997/04/29 16:58:55  buck
21  * Added features to dyninstAPI library, including the ability to delete
22  * inserted snippets and the start of type checking.
23  *
24  * Revision 1.3  1997/04/09 17:20:51  buck
25  * Added test for deleting snippets.
26  *
27  * Revision 1.2  1997/04/03 20:08:56  buck
28  * Added BPatch class and moved global library data/functions into it.
29  *
30  * Revision 1.1.1.1  1997/04/01 20:25:15  buck
31  * Update Maryland repository with latest from Wisconsin.
32  *
33  * Revision 1.1  1997/03/18 19:45:21  buck
34  * first commit of dyninst library.  Also includes:
35  *      moving templates from paradynd to dyninstAPI
36  *      converting showError into a function (in showerror.C)
37  *      many ifdefs for BPATCH_LIBRARY in dyinstAPI/src.
38  *
39  *
40  */
41
42 #include <stdio.h>
43 #include <signal.h>
44
45 #include "BPatch.h"
46 #include "BPatch_Vector.h"
47 #include "BPatch_thread.h"
48 #include "BPatch_snippet.h"
49
50 int debugPrint = 0;
51
52 BPatch *bpatch;
53
54 // control debug printf statements
55 #define dprintf if (debugPrint) printf
56
57 //
58 // Start Test Case #6 - mutator side (arithmetic operators)
59 //
60 void mutatorTest6(BPatch_thread *appThread, BPatch_image *appImage)
61 {
62     // Find the entry point to the procedure "func6_1"
63     BPatch_Vector<BPatch_point *> *point6_1 =
64         appImage->findProcedurePoint("func6_1", BPatch_entry);
65     BPatch_variableExpr *expr6_1 = appImage->findVariable("globalVariable6_1");
66     BPatch_variableExpr *expr6_2 = appImage->findVariable("globalVariable6_2");
67     BPatch_variableExpr *expr6_3 = appImage->findVariable("globalVariable6_3");
68     BPatch_variableExpr *expr6_4 = appImage->findVariable("globalVariable6_4");
69     BPatch_variableExpr *expr6_5 = appImage->findVariable("globalVariable6_5");
70     BPatch_variableExpr *expr6_6 = appImage->findVariable("globalVariable6_6");
71     if (!expr6_1 || !expr6_2 || !expr6_3 || !expr6_4 || 
72         !expr6_5 || !expr6_6) {
73         fprintf(stderr, "**Failed** test #6 (arithmetic operators)\n");
74         fprintf(stderr, "    Unable to locate one of globalVariable6_?\n");
75         exit(1);
76     }
77
78     BPatch_Vector<BPatch_snippet*> vect6_1;
79
80     // globalVariable6_1 = 60 + 2
81     BPatch_arithExpr arith6_1 (BPatch_assign, *expr6_1, 
82       BPatch_arithExpr(BPatch_plus,BPatch_constExpr(60), BPatch_constExpr(2)));
83     vect6_1.push_back(&arith6_1);
84
85     // globalVariable6_2 = 64 - 1
86     BPatch_arithExpr arith6_2 (BPatch_assign, *expr6_2, 
87       BPatch_arithExpr(BPatch_minus,BPatch_constExpr(64),BPatch_constExpr(1)));
88     vect6_1.push_back(&arith6_2);
89
90     // globalVariable6_3 = 66 / 3
91     BPatch_arithExpr arith6_3 (BPatch_assign, *expr6_3, BPatch_arithExpr(
92       BPatch_divide,BPatch_constExpr(66),BPatch_constExpr(3)));
93     vect6_1.push_back(&arith6_3);
94
95     // globalVariable6_4 = 67 / 3
96     BPatch_arithExpr arith6_4 (BPatch_assign, *expr6_4, BPatch_arithExpr(
97       BPatch_divide,BPatch_constExpr(67),BPatch_constExpr(3)));
98     vect6_1.push_back(&arith6_4);
99
100     // globalVariable6_5 = 6 * 5
101     BPatch_arithExpr arith6_5 (BPatch_assign, *expr6_5, BPatch_arithExpr(
102       BPatch_times,BPatch_constExpr(6),BPatch_constExpr(5)));
103     vect6_1.push_back(&arith6_5);
104
105     // globalVariable6_6 = 10,3
106     BPatch_arithExpr arith6_6 (BPatch_assign, *expr6_6, 
107         BPatch_arithExpr(BPatch_seq,BPatch_constExpr(10),BPatch_constExpr(3)));
108     vect6_1.push_back(&arith6_6);
109
110     appThread->insertSnippet( BPatch_sequence(vect6_1), *point6_1);
111 }
112
113 void genRelTest(BPatch_image *appImage,BPatch_Vector<BPatch_snippet*> &vect7_1, 
114                 BPatch_relOp op, int r1, int r2, char *var1)
115 {
116     BPatch_variableExpr *varExpr1 = appImage->findVariable(var1);
117     if (!varExpr1) {
118         fprintf(stderr, "**Failed** test #7 (relational operators)\n");
119         fprintf(stderr, "    Unable to locate variable %s\n", var1);
120         exit(1);
121     }
122     BPatch_ifExpr *tempExpr1 = new BPatch_ifExpr(
123         BPatch_boolExpr(op, BPatch_constExpr(r1), BPatch_constExpr(r2)), 
124         BPatch_arithExpr(BPatch_assign, *varExpr1, BPatch_constExpr(72)));
125     vect7_1.push_back(tempExpr1);
126
127 }
128
129 //
130 // Start Test Case #7 - mutator side (relational operators)
131 //
132 void mutatorTest7(BPatch_thread *appThread, BPatch_image *appImage)
133 {
134     // Find the entry point to the procedure "func7_1"
135     BPatch_Vector<BPatch_point *> *point7_1 =
136         appImage->findProcedurePoint("func7_1", BPatch_entry);
137     BPatch_Vector<BPatch_snippet*> vect7_1;
138
139     genRelTest(appImage, vect7_1, BPatch_lt, 0, 1, "globalVariable7_1");
140     genRelTest(appImage, vect7_1, BPatch_lt, 1, 0, "globalVariable7_2");
141     genRelTest(appImage, vect7_1, BPatch_eq, 2, 2, "globalVariable7_3");
142     genRelTest(appImage, vect7_1, BPatch_eq, 2, 3, "globalVariable7_4");
143     genRelTest(appImage, vect7_1, BPatch_gt, 4, 3, "globalVariable7_5");
144     genRelTest(appImage, vect7_1, BPatch_gt, 3, 4, "globalVariable7_6");
145     genRelTest(appImage, vect7_1, BPatch_le, 3, 4, "globalVariable7_7");
146     genRelTest(appImage, vect7_1, BPatch_le, 4, 3, "globalVariable7_8");
147     genRelTest(appImage, vect7_1, BPatch_ne, 5, 6, "globalVariable7_9");
148     genRelTest(appImage, vect7_1, BPatch_ne, 5, 5, "globalVariable7_10");
149     genRelTest(appImage, vect7_1, BPatch_ge, 9, 7, "globalVariable7_11");
150     genRelTest(appImage, vect7_1, BPatch_ge, 7, 9, "globalVariable7_12");
151     genRelTest(appImage, vect7_1, BPatch_and, 1, 1, "globalVariable7_13");
152     genRelTest(appImage, vect7_1, BPatch_and, 1, 0, "globalVariable7_14");
153     genRelTest(appImage, vect7_1, BPatch_or, 1, 0, "globalVariable7_15");
154     genRelTest(appImage, vect7_1, BPatch_or, 0, 0, "globalVariable7_16");
155
156     dprintf("relops test vector length is %d\n", vect7_1.size());
157
158     appThread->insertSnippet( BPatch_sequence(vect7_1), *point7_1);
159 }
160
161 //
162 // Start Test Case #8 - mutator side (preserve registers - expr)
163 //
164 void mutatorTest8(BPatch_thread *appThread, BPatch_image *appImage)
165 {
166     // Find the entry point to the procedure "func8_1"
167     BPatch_Vector<BPatch_point *> *point8_1 =
168         appImage->findProcedurePoint("func8_1", BPatch_entry);
169     BPatch_Vector<BPatch_snippet*> vect8_1;
170
171     BPatch_variableExpr *expr8_1 = appImage->findVariable("globalVariable8_1");
172     if (!expr8_1) {
173         fprintf(stderr, "**Failed** test #3 (passing variables)\n");
174         fprintf(stderr, "    Unable to locate variable globalVariable8_1\n");
175         exit(1);
176     }
177
178     BPatch_arithExpr arith8_1 (BPatch_assign, *expr8_1, 
179       BPatch_arithExpr(BPatch_plus, 
180             BPatch_arithExpr(BPatch_plus, 
181                 BPatch_arithExpr(BPatch_plus, BPatch_constExpr(81), 
182                                               BPatch_constExpr(82)),
183                 BPatch_arithExpr(BPatch_plus, BPatch_constExpr(83), 
184                                               BPatch_constExpr(84))),
185             BPatch_arithExpr(BPatch_plus, 
186                 BPatch_arithExpr(BPatch_plus, BPatch_constExpr(85), 
187                                               BPatch_constExpr(86)),
188                 BPatch_arithExpr(BPatch_plus, BPatch_constExpr(87), 
189                                               BPatch_constExpr(88)))));
190     vect8_1.push_back(&arith8_1);
191
192     appThread->insertSnippet( BPatch_sequence(vect8_1), *point8_1);
193 }
194
195 //
196 // Start Test Case #9 - mutator side (preserve registers - funcCall)
197 //
198 void mutatorTest9(BPatch_thread *appThread, BPatch_image *appImage)
199 {
200     // Find the entry point to the procedure "func9_1"
201     BPatch_Vector<BPatch_point *> *point9_1 =
202         appImage->findProcedurePoint("func9_1", BPatch_entry);
203
204     BPatch_function *call9_func = appImage->findFunction("call9_1");
205     if (call9_func == NULL) {
206         fprintf(stderr, "Unable to find function \"call9_1.\"\n");
207         exit(1);
208     }
209
210     BPatch_Vector<BPatch_snippet *> call9_args;
211
212     BPatch_constExpr constExpr91(91);
213     call9_args.push_back(&constExpr91);
214
215     BPatch_constExpr constExpr92(92);
216     call9_args.push_back(&constExpr92);
217
218     BPatch_constExpr constExpr93(93);
219     call9_args.push_back(&constExpr93);
220
221     BPatch_constExpr constExpr94(94);
222     call9_args.push_back(&constExpr94);
223
224     BPatch_constExpr constExpr95(95);
225     call9_args.push_back(&constExpr95);
226
227     BPatch_funcCallExpr call9Expr(*call9_func, call9_args);
228
229     appThread->insertSnippet( call9Expr, *point9_1);
230 }
231
232
233 //
234 // Start Test Case #10 - mutator side (insert snippet order)
235 //
236 void mutatorTest10(BPatch_thread *appThread, BPatch_image *appImage)
237 {
238     // Find the entry point to the procedure "func10_1"
239     BPatch_Vector<BPatch_point *> *point10_1 =
240         appImage->findProcedurePoint("func10_1", BPatch_entry);
241
242     BPatch_function *call10_1_func = appImage->findFunction("call10_1");
243     if (call10_1_func == NULL) {
244         fprintf(stderr, "Unable to find function \"call10_1.\"\n");
245         exit(1);
246     }
247
248     BPatch_function *call10_2_func = appImage->findFunction("call10_2");
249     if (call10_2_func == NULL) {
250         fprintf(stderr, "Unable to find function \"call10_2.\"\n");
251         exit(1);
252     }
253
254     BPatch_function *call10_3_func = appImage->findFunction("call10_3");
255     if (call10_3_func == NULL) {
256         fprintf(stderr, "Unable to find function \"call10_3.\"\n");
257         exit(1);
258     }
259
260     BPatch_Vector<BPatch_snippet *> nullArgs;
261     BPatch_funcCallExpr call10_1Expr(*call10_1_func, nullArgs);
262     BPatch_funcCallExpr call10_2Expr(*call10_2_func, nullArgs);
263     BPatch_funcCallExpr call10_3Expr(*call10_3_func, nullArgs);
264
265     appThread->insertSnippet( call10_2Expr, *point10_1);
266     appThread->insertSnippet( call10_1Expr, *point10_1, BPatch_callBefore, 
267                                                         BPatch_firstSnippet);
268     appThread->insertSnippet( call10_3Expr, *point10_1, BPatch_callBefore, 
269                                                         BPatch_lastSnippet);
270 }
271
272
273 //
274 // Start Test Case #11 - mutator side (snippets at entry,exit,call)
275 //
276 void mutatorTest11(BPatch_thread *appThread, BPatch_image *appImage)
277 {
278     // Find the entry point to the procedure "func11_1"
279     BPatch_Vector<BPatch_point *> *point11_1 =
280         appImage->findProcedurePoint("func11_1", BPatch_entry);
281     if (!point11_1) {
282         fprintf(stderr, "Unable to find point func11_1 - entry.\n");
283         exit(-1);
284     }
285
286     // Find the subroutine points for the procedure "func11_1"
287     BPatch_Vector<BPatch_point *> *point11_2 =
288         appImage->findProcedurePoint("func11_1", BPatch_subroutine);
289     if (!point11_2) {
290         fprintf(stderr, "Unable to find point func11_1 - calls.\n");
291         exit(-1);
292     }
293
294     // Find the exit point to the procedure "func11_1"
295     BPatch_Vector<BPatch_point *> *point11_3 =
296         appImage->findProcedurePoint("func11_1", BPatch_exit);
297     if (!point11_3) {
298         fprintf(stderr, "Unable to find point func11_1 - exit.\n");
299         exit(-1);
300     }
301
302     BPatch_function *call11_1_func = appImage->findFunction("call11_1");
303     if (call11_1_func == NULL) {
304         fprintf(stderr, "Unable to find function \"call11_1.\"\n");
305         exit(1);
306     }
307
308     BPatch_function *call11_2_func = appImage->findFunction("call11_2");
309     if (call11_2_func == NULL) {
310         fprintf(stderr, "Unable to find function \"call11_2.\"\n");
311         exit(1);
312     }
313
314     BPatch_function *call11_3_func = appImage->findFunction("call11_3");
315     if (call11_3_func == NULL) {
316         fprintf(stderr, "Unable to find function \"call11_3.\"\n");
317         exit(1);
318     }
319
320     BPatch_function *call11_4_func = appImage->findFunction("call11_4");
321     if (call11_4_func == NULL) {
322         fprintf(stderr, "Unable to find function \"call11_4.\"\n");
323         exit(1);
324     }
325
326     BPatch_Vector<BPatch_snippet *> nullArgs;
327     BPatch_funcCallExpr call11_1Expr(*call11_1_func, nullArgs);
328     BPatch_funcCallExpr call11_2Expr(*call11_2_func, nullArgs);
329     BPatch_funcCallExpr call11_3Expr(*call11_3_func, nullArgs);
330     BPatch_funcCallExpr call11_4Expr(*call11_4_func, nullArgs);
331
332     appThread->insertSnippet(call11_1Expr, *point11_1);
333     appThread->insertSnippet(call11_2Expr, *point11_2, BPatch_callBefore);
334     appThread->insertSnippet(call11_3Expr, *point11_2, BPatch_callAfter);
335     appThread->insertSnippet(call11_4Expr, *point11_3);
336
337 }
338
339 BPatchSnippetHandle *snippetHandle12_1;
340 BPatch_variableExpr *varExpr12_1;
341
342 //
343 // Start Test Case #12 - mutator side (insert/remove and malloc/free)
344 //
345 void mutatorTest12a(BPatch_thread *appThread, BPatch_image *appImage)
346 {
347     // Find the entry point to the procedure "func12_2"
348     BPatch_Vector<BPatch_point *> *point12_2 =
349         appImage->findProcedurePoint("func12_2", BPatch_entry);
350     if (!point12_2) {
351         fprintf(stderr, "Unable to find point func12_2 - entry.\n");
352         exit(-1);
353     }
354
355     varExpr12_1 = appThread->malloc(100);
356     if (!varExpr12_1) {
357         fprintf(stderr, "Unable to allocate 100 bytes in mutatee\n");
358         exit(-1);
359     }
360
361     BPatch_function *call12_1_func = appImage->findFunction("call12_1");
362     if (call12_1_func == NULL) {
363         fprintf(stderr, "Unable to find function \"call12_1.\"\n");
364         exit(1);
365     }
366
367     BPatch_Vector<BPatch_snippet *> nullArgs;
368     BPatch_funcCallExpr call12_1Expr(*call12_1_func, nullArgs);
369     snippetHandle12_1 = appThread->insertSnippet(call12_1Expr, *point12_2);
370     if (!snippetHandle12_1) {
371         fprintf(stderr,
372                 "Unable to insert snippet to call function \"call12_1.\"\n");
373         exit(-1);
374     }
375 }
376
377 void mutatorTest12b(BPatch_thread *appThread, BPatch_image *appImage)
378 {
379     while (!appThread->isStopped() && !appThread->isTerminated()) ;
380     if (appThread->stopSignal() == SIGSTOP) {
381         // remove instrumentation and free memory
382         if (!appThread->deleteSnippet(snippetHandle12_1)) {
383             printf("**Failed test #12 (insert/remove and malloc/free)\n");
384             printf("    deleteSnippet returned an error\n");
385             exit(-1);
386         }
387         appThread->free(*varExpr12_1);
388
389         // continue process
390         appThread->continueExecution();
391     } else if (appThread->isStopped()) {
392         printf("**Failed test #12 (insert/remove and malloc/free)\n");
393         printf("    process stopped on signal %d, not SIGSTOP\n", 
394                 appThread->stopSignal());
395         exit(-1);
396     } else {
397         printf("**Failed test #12 (insert/remove and malloc/free)\n");
398         printf("    process did not signal mutator via SIGSTOP\n");
399         exit(-1);
400     }
401 }
402
403
404 //
405 // Start Test Case #13 - mutator side (paramExpr,nullExpr)
406 //
407 void mutatorTest13(BPatch_thread *appThread, BPatch_image *appImage)
408 {
409     // Find the entry point to the procedure "func13_1"
410     BPatch_Vector<BPatch_point *> *point13_1 =
411         appImage->findProcedurePoint("func13_1", BPatch_entry);
412     if (!point13_1) {
413         fprintf(stderr, "Unable to find point func13_1 - entry.\n");
414         exit(-1);
415     }
416
417     BPatch_function *call13_1_func = appImage->findFunction("call13_1");
418     if (call13_1_func == NULL) {
419         fprintf(stderr, "Unable to find function \"call13_1.\"\n");
420         exit(1);
421     }
422
423     BPatch_Vector<BPatch_snippet *> funcArgs;
424     funcArgs.push_back(new BPatch_paramExpr(0));
425     funcArgs.push_back(new BPatch_paramExpr(1));
426     funcArgs.push_back(new BPatch_paramExpr(2));
427     funcArgs.push_back(new BPatch_paramExpr(3));
428     funcArgs.push_back(new BPatch_paramExpr(4));
429     BPatch_funcCallExpr call13_1Expr(*call13_1_func, funcArgs);
430     BPatch_nullExpr call13_2Expr;
431
432     appThread->insertSnippet(call13_1Expr, *point13_1);
433     // This causes a crash right now jkh 3/7/97
434     // appThread->insertSnippet(call13_2Expr, *point13_1);
435 }
436
437 void mutatorMAIN(char *pathname)
438 {
439     // Create an instance of the bpatch library
440     bpatch = new BPatch;
441
442     // Start the mutatee
443     printf("Starting \"%s\"\n", pathname);
444
445     char *child_argv[] = { pathname, "-verbose", NULL };
446     if (!debugPrint) {
447         // null out the verbose mode if not enabled.
448         child_argv[1] = NULL;
449     }
450     BPatch_thread *appThread =
451         new BPatch_thread(pathname, child_argv, NULL);
452
453     if (appThread->isTerminated()) {
454         fprintf(stderr, "Unable to run test program.\n");
455         exit(1);
456     }
457
458     // Read the program's image and get an associated image object
459     BPatch_image *appImage = appThread->getImage();
460
461     BPatch_Vector<BPatch_function *> *p = appImage->getProcedures();
462     for (int i=0; i < p->size(); i++) {
463         // dprintf("func %s\n", (*p)[i]->name());
464     }
465
466     // Start Test Case #1 - mutator side (call a zero argument function)
467
468     // Find the entry point to the procedure "func1_1"
469     BPatch_Vector<BPatch_point *> *point1_1 =
470         appImage->findProcedurePoint("func1_1", BPatch_entry);
471
472     if ((*point1_1).size() == 0) {
473         fprintf(stderr, "**Failed** test #1 (zero arg function call)\n");
474         fprintf(stderr, "    Unable to find entry point to \"func1_1.\"\n");
475         exit(1);
476     }
477
478     BPatch_function *call1_func = appImage->findFunction("call1_1");
479     if (call1_func == NULL) {
480         fprintf(stderr, "**Failed** test #1 (zero arg function call)\n");
481         fprintf(stderr, "Unable to find function \"call1_1\"\n");
482         exit(1);
483     }
484
485     BPatch_Vector<BPatch_snippet *> call1_args;
486     BPatch_funcCallExpr call1Expr(*call1_func, call1_args);
487
488     dprintf("Inserted snippet2\n");
489     appThread->insertSnippet(call1Expr, *point1_1);
490
491
492     //
493     // Start Test Case #2 - mutator side (call a three argument function)
494     //
495
496     // Find the entry point to the procedure "func2_1"
497     BPatch_Vector<BPatch_point *> *point2_1 =
498         appImage->findProcedurePoint("func2_1", BPatch_entry);
499
500     if (!point2_1 || ((*point2_1).size() == 0)) {
501         fprintf(stderr, "**Failed** test #2 (three parameter function)\n");
502         fprintf(stderr, "    Unable to find entry point to \"func2_1.\"\n");
503         exit(1);
504     }
505
506     BPatch_function *call2_func = appImage->findFunction("call2_1");
507     if (call2_func == NULL) {
508         fprintf(stderr, "**Failed** test #2 (three parameter function)\n");
509         fprintf(stderr, "    Unable to find function \"call2_1.\"\n");
510         exit(1);
511     }
512
513     BPatch_Vector<BPatch_snippet *> call2_args;
514     BPatch_constExpr expr2_1(1);
515     BPatch_constExpr expr2_2(2);
516     BPatch_constExpr expr2_3("testString2_1");
517     call2_args.push_back(&expr2_1);
518     call2_args.push_back(&expr2_2);
519     call2_args.push_back(&expr2_3);
520
521     BPatch_funcCallExpr call2Expr(*call2_func, call2_args);
522
523     dprintf("Inserted snippet2\n");
524     appThread->insertSnippet(call2Expr, *point2_1);
525
526     //
527     // Start Test Case #3 - mutator side (passing variables to function)
528     //
529
530     // Find the entry point to the procedure "func3_1"
531     BPatch_Vector<BPatch_point *> *point3_1 =
532         appImage->findProcedurePoint("func3_1", BPatch_entry);
533
534     if (!point3_1 || ((*point3_1).size() == 0)) {
535         fprintf(stderr, "Unable to find entry point to \"func3_1.\"\n");
536         exit(1);
537     }
538
539     BPatch_function *call3_func = appImage->findFunction("call3_1");
540     if (call3_func == NULL) {
541         fprintf(stderr, "Unable to find function \"call3_1.\"\n");
542         exit(1);
543     }
544
545     BPatch_Vector<BPatch_snippet *> call3_args;
546
547     BPatch_variableExpr *expr3_1 = appImage->findVariable("globalVariable3_1");
548     if (!expr3_1) {
549         fprintf(stderr, "**Failed** test #3 (passing variables)\n");
550         fprintf(stderr, "    Unable to locate variable globalVariable3_1\n");
551         exit(1);
552     }
553
554     BPatch_variableExpr *expr3_2 = appThread->malloc(*appImage->findType("int"));
555     if (!expr3_2) {
556         fprintf(stderr, "**Failed** test #3 (passing variables)\n");
557         fprintf(stderr, "    Unable to create new int variable\n");
558         exit(1);
559     }
560
561     call3_args.push_back(expr3_1);
562     call3_args.push_back(expr3_2);
563
564     BPatch_funcCallExpr call3Expr(*call3_func, call3_args);
565     appThread->insertSnippet(call3Expr, *point3_1);
566
567     BPatch_arithExpr expr3_3(BPatch_assign, *expr3_2, BPatch_constExpr(32));
568     appThread->insertSnippet(expr3_3, *point3_1);
569
570     dprintf("Inserted snippet3\n");
571
572     //
573     // Start Test Case #4 - mutator side (sequence)
574     //
575
576     // Find the entry point to the procedure "func4_1"
577     BPatch_Vector<BPatch_point *> *point4_1 =
578         appImage->findProcedurePoint("func4_1", BPatch_entry);
579
580
581     BPatch_variableExpr *expr4_1 = appImage->findVariable("globalVariable4_1");
582     if (!expr4_1) {
583         fprintf(stderr, "**Failed** test #4 (sequence)\n");
584         fprintf(stderr, "    Unable to locate variable globalVariable4_1\n");
585         exit(1);
586     }
587
588     BPatch_arithExpr expr4_2(BPatch_assign, *expr4_1, BPatch_constExpr(42));
589     BPatch_arithExpr expr4_3(BPatch_assign, *expr4_1, BPatch_constExpr(43));
590
591     BPatch_Vector<BPatch_snippet*> vect4_1;
592     vect4_1.push_back(&expr4_2);
593     vect4_1.push_back(&expr4_3);
594
595     BPatch_sequence expr4_4(vect4_1);
596     appThread->insertSnippet(expr4_4, *point4_1);
597
598     //
599     // Start Test Case #5 - mutator side (if w.o. else)
600     //
601
602     // Find the entry point to the procedure "func5_1"
603     BPatch_Vector<BPatch_point *> *point5_1 =
604         appImage->findProcedurePoint("func5_1", BPatch_entry);
605     BPatch_variableExpr *expr5_1 = appImage->findVariable("globalVariable5_1");
606     BPatch_variableExpr *expr5_2 = appImage->findVariable("globalVariable5_2");
607     if (!expr5_1 || !expr5_2) {
608         fprintf(stderr, "**Failed** test #5 (f w.o. else)\n");
609         fprintf(stderr, "    Unable to locate variable globalVariable5_1 or ");
610         fprintf(stderr, "    variable globalVariable5_2\n");
611         exit(1);
612     }
613
614     BPatch_Vector<BPatch_snippet*> vect5_1;
615
616     // if (0 == 1) globalVariable5_1 = 52;
617     BPatch_ifExpr expr5_3(
618         BPatch_boolExpr(BPatch_eq, BPatch_constExpr(0), BPatch_constExpr(1)), 
619         BPatch_arithExpr(BPatch_assign, *expr5_1, BPatch_constExpr(52)));
620
621     // if (1 == 1) globalVariable5_2 = 53;
622     BPatch_ifExpr expr5_4(
623         BPatch_boolExpr(BPatch_eq, BPatch_constExpr(1), BPatch_constExpr(1)), 
624         BPatch_arithExpr(BPatch_assign, *expr5_2, BPatch_constExpr(53)));
625
626     vect5_1.push_back(&expr5_3);
627     vect5_1.push_back(&expr5_4);
628
629     BPatch_sequence expr5_5(vect5_1);
630     appThread->insertSnippet(expr5_5, *point5_1);
631
632     mutatorTest6(appThread, appImage);
633
634     mutatorTest7(appThread, appImage);
635
636     mutatorTest8(appThread, appImage);
637
638     mutatorTest9(appThread, appImage);
639
640     mutatorTest10(appThread, appImage);
641
642     mutatorTest11(appThread, appImage);
643
644     mutatorTest12a(appThread, appImage);
645
646     mutatorTest13(appThread, appImage);
647
648     // Start of code to continue the process.
649     dprintf("starting program execution.\n");
650     appThread->continueExecution();
651
652     mutatorTest12b(appThread, appImage);
653
654     while (!appThread->isTerminated()) ;
655     dprintf("Done.\n");
656 }
657
658 //
659 // main - decide our role and call the correct "main"
660 //
661 main(int argc, char *argv[])
662 {
663     if (argc == 1) {
664         // become the mutator
665         mutatorMAIN("./test1.mutatee");
666     } else if (argc == 2 && !strcmp(argv[1], "-verbose")) {
667         debugPrint = 1;
668         mutatorMAIN("./test1.mutatee");
669     } else {
670         fprintf(stderr, "Usage: test1 [-verbose]\n");
671         exit(-1);
672     }
673 }