Remove old testsuite
[dyninst.git] / newtestsuite / src / dyninst / test1_6.C
1 /*
2  * Copyright (c) 1996-2004 Barton P. Miller
3  * 
4  * We provide the Paradyn Parallel Performance Tools (below
5  * described as "Paradyn") on an AS IS basis, and do not warrant its
6  * validity or performance.  We reserve the right to update, modify,
7  * or discontinue this software at any time.  We shall have no
8  * obligation to supply such updates or modifications or any other
9  * form of support to you.
10  * 
11  * This license is for research uses.  For such uses, there is no
12  * charge. We define "research use" to mean you may freely use it
13  * inside your organization for whatever purposes you see fit. But you
14  * may not re-distribute Paradyn or parts of Paradyn, in any form
15  * source or binary (including derivatives), electronic or otherwise,
16  * to any other organization or entity without our permission.
17  * 
18  * (for other uses, please contact us at paradyn@cs.wisc.edu)
19  * 
20  * All warranties, including without limitation, any warranty of
21  * merchantability or fitness for a particular purpose, are hereby
22  * excluded.
23  * 
24  * By your use of Paradyn, you understand and agree that we (or any
25  * other person or entity with proprietary rights in Paradyn) are
26  * under no obligation to provide either maintenance services,
27  * update services, notices of latent defects, or correction of
28  * defects for Paradyn.
29  * 
30  * Even if advised of the possibility of such damages, under no
31  * circumstances shall we (or any other person or entity with
32  * proprietary rights in the software licensed hereunder) be liable
33  * to you or any third party for direct, indirect, or consequential
34  * damages of any character regardless of type of action, including,
35  * without limitation, loss of profits, loss of use, loss of good
36  * will, or computer failure or malfunction.  You agree to indemnify
37  * us (and any other person or entity with proprietary rights in the
38  * software licensed hereunder) for any and all liability it may
39  * incur to third parties resulting from your use of Paradyn.
40  */
41
42 // $Id: test1_6.C,v 1.1 2008/10/30 19:19:48 legendre Exp $
43 /*
44  * #Name: test1_6
45  * #Desc: Mutator Side - Arithmetic Operators
46  * #Arch: all
47  * #Dep: 
48  */
49
50 #include "BPatch.h"
51 #include "BPatch_Vector.h"
52 #include "BPatch_thread.h"
53 #include "BPatch_snippet.h"
54
55 #include "test_lib.h"
56 #include "dyninst_comp.h"
57
58 class test1_6_Mutator : public DyninstMutator {
59         virtual test_results_t executeTest();
60 };
61
62 extern "C" DLLEXPORT  TestMutator *test1_6_factory() 
63 {
64         return new test1_6_Mutator();
65 }
66
67 //
68 // Start Test Case #6 - mutator side (arithmetic operators)
69 //
70
71 test_results_t test1_6_Mutator::executeTest() 
72 {
73         // Find the entry point to the procedure "func6_2"
74         const char *funcName = "test1_6_func2";
75         BPatch_Vector<BPatch_function *> found_funcs;
76         if ((NULL == appImage->findFunction(funcName, found_funcs))
77                         || !found_funcs.size()) 
78         {
79                 logerror("    Unable to find function %s\n", funcName);
80                 return FAILED;
81         }
82
83         if (1 < found_funcs.size()) 
84         {
85                 logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
86                                 __FILE__, __LINE__, found_funcs.size(), funcName);
87         }
88
89         BPatch_Vector<BPatch_point *> *point6_1 = found_funcs[0]->findPoint(BPatch_entry);  
90
91         if (!point6_1 || ((*point6_1).size() == 0)) 
92         {
93                 logerror("Unable to find entry point to \"%s\".\n", funcName);
94                 return FAILED;
95         }
96
97         const char *funcName2 = "test1_6_func1";
98         BPatch_Vector<BPatch_function *> found_funcs2;
99
100         if ((NULL == appImage->findFunction(funcName2, found_funcs2)) 
101                         || !found_funcs2.size()) 
102         {
103                 logerror("    Unable to find function %s\n", funcName2);
104                 return FAILED;
105         }
106
107         if (1 < found_funcs2.size()) 
108         {
109                 logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
110                                 __FILE__, __LINE__, found_funcs2.size(), funcName2);
111         }
112
113         BPatch_Vector<BPatch_point *> *point6_2 = found_funcs2[0]->findPoint(BPatch_subroutine);  
114
115         if (!point6_2 || ((*point6_2).size() == 0)) 
116         {
117                 logerror("Unable to find subroutine points in \"%s\".\n", funcName2);
118                 return FAILED;
119         }
120
121         BPatch_variableExpr *expr6_1, *expr6_2, *expr6_3, *expr6_4, *expr6_5, *expr6_6,
122                                                 *expr6_1a, *expr6_2a, *expr6_3a, *expr6_4a, *expr6_5a, *expr6_6a,
123                                                 *constVar1, *constVar2, *constVar3, *constVar5, *constVar6,
124                                                 *constVar10, *constVar60, *constVar64, *constVar66, *constVar67;
125
126         expr6_1 = findVariable(appImage, "test1_6_globalVariable1", point6_2);
127         expr6_2 = findVariable(appImage, "test1_6_globalVariable2", point6_2);
128         expr6_3 = findVariable(appImage, "test1_6_globalVariable3", point6_2);
129         expr6_4 = findVariable(appImage, "test1_6_globalVariable4", point6_2);
130         expr6_5 = findVariable(appImage, "test1_6_globalVariable5", point6_2);
131         expr6_6 = findVariable(appImage, "test1_6_globalVariable6", point6_2);
132         expr6_1a = findVariable(appImage, "test1_6_globalVariable1a", point6_2);
133         expr6_2a = findVariable(appImage, "test1_6_globalVariable2a", point6_2);
134         expr6_3a = findVariable(appImage, "test1_6_globalVariable3a", point6_2);
135         expr6_4a = findVariable(appImage, "test1_6_globalVariable4a", point6_2);
136         expr6_5a = findVariable(appImage, "test1_6_globalVariable5a", point6_2);
137         expr6_6a = findVariable(appImage, "test1_6_globalVariable6a", point6_2);
138
139         constVar1 = findVariable(appImage, "test1_6_constVar1", point6_2);
140         constVar2 = findVariable(appImage, "test1_6_constVar2", point6_2);
141         constVar3 = findVariable(appImage, "test1_6_constVar3", point6_2);
142         constVar5 = findVariable(appImage, "test1_6_constVar5", point6_2);
143         constVar6 = findVariable(appImage, "test1_6_constVar6", point6_2);
144         constVar10 = findVariable(appImage, "test1_6_constVar10", point6_2);
145         constVar60 = findVariable(appImage, "test1_6_constVar60", point6_2);
146         constVar64 = findVariable(appImage, "test1_6_constVar64", point6_2);
147         constVar66 = findVariable(appImage, "test1_6_constVar66", point6_2);
148         constVar67 = findVariable(appImage, "test1_6_constVar67", point6_2);
149
150         if (!expr6_1 || !expr6_2 || !expr6_3 || !expr6_4 ||
151                         !expr6_5 || !expr6_6 || !expr6_1a || !expr6_2a || !expr6_3a ||
152                         !expr6_4a || !expr6_5a || !expr6_6a) 
153         {
154                 logerror("**Failed** test #6 (arithmetic operators)\n");
155                 logerror("    Unable to locate one of test1_6_globalVariable?\n");
156                 return FAILED;
157         }
158
159         if (!constVar1 || !constVar2 || !constVar3 || !constVar5 ||
160                         !constVar6 || !constVar10 || !constVar60 || !constVar64 || 
161                         !constVar66 || !constVar67) 
162         {
163                 logerror("**Failed** test #6 (arithmetic operators)\n");
164                 logerror("    Unable to locate one of constVar?\n");
165                 return FAILED;
166         }
167
168         BPatch_Vector<BPatch_snippet*> vect6_1;
169
170         // test1_6_globalVariable1 = 60 + 2
171         BPatch_arithExpr arith6_1 (BPatch_assign, *expr6_1,
172                         BPatch_arithExpr(BPatch_plus,BPatch_constExpr(60), BPatch_constExpr(2)));
173         vect6_1.push_back(&arith6_1);
174
175         // test1_6_globalVariable2 = 64 - 1
176         BPatch_arithExpr arith6_2 (BPatch_assign, *expr6_2, 
177                         BPatch_arithExpr(BPatch_minus,BPatch_constExpr(64),BPatch_constExpr(1)));
178         vect6_1.push_back(&arith6_2);
179
180         // test1_6_globalVariable3 = 553648128 / 25165824 = 22
181         //    - make these big constants to test loading constants larger than
182         //      small immediate - jkh 6/22/98
183
184         BPatch_arithExpr arith6_3 (BPatch_assign, *expr6_3, BPatch_arithExpr(
185                                 BPatch_divide,BPatch_constExpr(553648128),BPatch_constExpr(25165824)));
186         vect6_1.push_back(&arith6_3);
187
188         // test1_6_globalVariable4 = 67 / 3
189         BPatch_arithExpr arith6_4 (BPatch_assign, *expr6_4, BPatch_arithExpr(
190                                 BPatch_divide,BPatch_constExpr(67),BPatch_constExpr(3)));
191         vect6_1.push_back(&arith6_4);
192         // test1_6_globalVariable5 = 6 * 5
193         BPatch_arithExpr arith6_5 (BPatch_assign, *expr6_5, BPatch_arithExpr(
194                                 BPatch_times,BPatch_constExpr(6),BPatch_constExpr(5)));
195         vect6_1.push_back(&arith6_5);
196
197         // test1_6_globalVariable6 = 10,3
198         BPatch_arithExpr arith6_6 (BPatch_assign, *expr6_6, 
199                         BPatch_arithExpr(BPatch_seq,BPatch_constExpr(10),BPatch_constExpr(3)));
200         vect6_1.push_back(&arith6_6);
201
202         // test1_6_globalVariable1a = 60 + 2
203         BPatch_arithExpr arith6_1a (BPatch_assign, *expr6_1a, 
204                         BPatch_arithExpr(BPatch_plus, *constVar60, *constVar2));
205         vect6_1.push_back(&arith6_1a);
206
207         // test1_6_globalVariable2a = 64 - 1
208         BPatch_arithExpr arith6_2a (BPatch_assign, *expr6_2a, 
209                         BPatch_arithExpr(BPatch_minus, *constVar64, *constVar1));
210         vect6_1.push_back(&arith6_2a);
211
212         // test1_6_globalVariable3a = 66 / 3
213         BPatch_arithExpr arith6_3a (BPatch_assign, *expr6_3a, BPatch_arithExpr(
214                                 BPatch_divide, *constVar66, *constVar3));
215         vect6_1.push_back(&arith6_3a);
216
217         // test1_6_globalVariable4a = 67 / 3
218         BPatch_arithExpr arith6_4a (BPatch_assign, *expr6_4a, BPatch_arithExpr(
219                                 BPatch_divide, *constVar67, *constVar3));
220         vect6_1.push_back(&arith6_4a);
221
222         // test1_6_globalVariable5a = 6 * 5
223         BPatch_arithExpr arith6_5a (BPatch_assign, *expr6_5a, BPatch_arithExpr(
224                                 BPatch_times, *constVar6, *constVar5));
225         vect6_1.push_back(&arith6_5a);
226
227         // test1_6_globalVariable6a = 10,3
228         // BPatch_arithExpr arith6_6a (BPatch_assign, *expr6_6a, *constVar3);
229         //      BPatch_arithExpr(BPatch_seq, *constVar10, BPatch_constExpr(3)));
230         BPatch_arithExpr arith6_6a (BPatch_assign, *expr6_6a,
231                         BPatch_arithExpr(BPatch_seq, *constVar10, *constVar3));
232         vect6_1.push_back(&arith6_6a);
233
234         checkCost(BPatch_sequence(vect6_1));
235         appAddrSpace->insertSnippet( BPatch_sequence(vect6_1), *point6_1);
236
237         return PASSED;
238 }