Update copyright to LGPL on all files
[dyninst.git] / testsuite / src / dyninst / test1_6.C
1 /*
2  * Copyright (c) 1996-2009 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  * By your use of Paradyn, you understand and agree that we (or any
12  * other person or entity with proprietary rights in Paradyn) are
13  * under no obligation to provide either maintenance services,
14  * update services, notices of latent defects, or correction of
15  * defects for Paradyn.
16  * 
17  * This library is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU Lesser General Public
19  * License as published by the Free Software Foundation; either
20  * version 2.1 of the License, or (at your option) any later version.
21  * 
22  * This library is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25  * Lesser General Public License for more details.
26  * 
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30  */
31
32 // $Id: test1_6.C,v 1.1 2008/10/30 19:19:48 legendre Exp $
33 /*
34  * #Name: test1_6
35  * #Desc: Mutator Side - Arithmetic Operators
36  * #Arch: all
37  * #Dep: 
38  */
39
40 #include "BPatch.h"
41 #include "BPatch_Vector.h"
42 #include "BPatch_thread.h"
43 #include "BPatch_snippet.h"
44
45 #include "test_lib.h"
46 #include "dyninst_comp.h"
47
48 class test1_6_Mutator : public DyninstMutator {
49         virtual test_results_t executeTest();
50 };
51
52 extern "C" DLLEXPORT  TestMutator *test1_6_factory() 
53 {
54         return new test1_6_Mutator();
55 }
56
57 //
58 // Start Test Case #6 - mutator side (arithmetic operators)
59 //
60
61 test_results_t test1_6_Mutator::executeTest() 
62 {
63         // Find the entry point to the procedure "func6_2"
64         const char *funcName = "test1_6_func2";
65         BPatch_Vector<BPatch_function *> found_funcs;
66         if ((NULL == appImage->findFunction(funcName, found_funcs))
67                         || !found_funcs.size()) 
68         {
69                 logerror("    Unable to find function %s\n", funcName);
70                 return FAILED;
71         }
72
73         if (1 < found_funcs.size()) 
74         {
75                 logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
76                                 __FILE__, __LINE__, found_funcs.size(), funcName);
77         }
78
79         BPatch_Vector<BPatch_point *> *point6_1 = found_funcs[0]->findPoint(BPatch_entry);  
80
81         if (!point6_1 || ((*point6_1).size() == 0)) 
82         {
83                 logerror("Unable to find entry point to \"%s\".\n", funcName);
84                 return FAILED;
85         }
86
87         const char *funcName2 = "test1_6_func1";
88         BPatch_Vector<BPatch_function *> found_funcs2;
89
90         if ((NULL == appImage->findFunction(funcName2, found_funcs2)) 
91                         || !found_funcs2.size()) 
92         {
93                 logerror("    Unable to find function %s\n", funcName2);
94                 return FAILED;
95         }
96
97         if (1 < found_funcs2.size()) 
98         {
99                 logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
100                                 __FILE__, __LINE__, found_funcs2.size(), funcName2);
101         }
102
103         BPatch_Vector<BPatch_point *> *point6_2 = found_funcs2[0]->findPoint(BPatch_subroutine);  
104
105         if (!point6_2 || ((*point6_2).size() == 0)) 
106         {
107                 logerror("Unable to find subroutine points in \"%s\".\n", funcName2);
108                 return FAILED;
109         }
110
111         BPatch_variableExpr *expr6_1, *expr6_2, *expr6_3, *expr6_4, *expr6_5, *expr6_6,
112                                                 *expr6_1a, *expr6_2a, *expr6_3a, *expr6_4a, *expr6_5a, *expr6_6a,
113                                                 *constVar1, *constVar2, *constVar3, *constVar5, *constVar6,
114                                                 *constVar10, *constVar60, *constVar64, *constVar66, *constVar67;
115
116         expr6_1 = findVariable(appImage, "test1_6_globalVariable1", point6_2);
117         expr6_2 = findVariable(appImage, "test1_6_globalVariable2", point6_2);
118         expr6_3 = findVariable(appImage, "test1_6_globalVariable3", point6_2);
119         expr6_4 = findVariable(appImage, "test1_6_globalVariable4", point6_2);
120         expr6_5 = findVariable(appImage, "test1_6_globalVariable5", point6_2);
121         expr6_6 = findVariable(appImage, "test1_6_globalVariable6", point6_2);
122         expr6_1a = findVariable(appImage, "test1_6_globalVariable1a", point6_2);
123         expr6_2a = findVariable(appImage, "test1_6_globalVariable2a", point6_2);
124         expr6_3a = findVariable(appImage, "test1_6_globalVariable3a", point6_2);
125         expr6_4a = findVariable(appImage, "test1_6_globalVariable4a", point6_2);
126         expr6_5a = findVariable(appImage, "test1_6_globalVariable5a", point6_2);
127         expr6_6a = findVariable(appImage, "test1_6_globalVariable6a", point6_2);
128
129         constVar1 = findVariable(appImage, "test1_6_constVar1", point6_2);
130         constVar2 = findVariable(appImage, "test1_6_constVar2", point6_2);
131         constVar3 = findVariable(appImage, "test1_6_constVar3", point6_2);
132         constVar5 = findVariable(appImage, "test1_6_constVar5", point6_2);
133         constVar6 = findVariable(appImage, "test1_6_constVar6", point6_2);
134         constVar10 = findVariable(appImage, "test1_6_constVar10", point6_2);
135         constVar60 = findVariable(appImage, "test1_6_constVar60", point6_2);
136         constVar64 = findVariable(appImage, "test1_6_constVar64", point6_2);
137         constVar66 = findVariable(appImage, "test1_6_constVar66", point6_2);
138         constVar67 = findVariable(appImage, "test1_6_constVar67", point6_2);
139
140         if (!expr6_1 || !expr6_2 || !expr6_3 || !expr6_4 ||
141                         !expr6_5 || !expr6_6 || !expr6_1a || !expr6_2a || !expr6_3a ||
142                         !expr6_4a || !expr6_5a || !expr6_6a) 
143         {
144                 logerror("**Failed** test #6 (arithmetic operators)\n");
145                 logerror("    Unable to locate one of test1_6_globalVariable?\n");
146                 return FAILED;
147         }
148
149         if (!constVar1 || !constVar2 || !constVar3 || !constVar5 ||
150                         !constVar6 || !constVar10 || !constVar60 || !constVar64 || 
151                         !constVar66 || !constVar67) 
152         {
153                 logerror("**Failed** test #6 (arithmetic operators)\n");
154                 logerror("    Unable to locate one of constVar?\n");
155                 return FAILED;
156         }
157
158         BPatch_Vector<BPatch_snippet*> vect6_1;
159
160         // test1_6_globalVariable1 = 60 + 2
161         BPatch_arithExpr arith6_1 (BPatch_assign, *expr6_1,
162                         BPatch_arithExpr(BPatch_plus,BPatch_constExpr(60), BPatch_constExpr(2)));
163         vect6_1.push_back(&arith6_1);
164
165         // test1_6_globalVariable2 = 64 - 1
166         BPatch_arithExpr arith6_2 (BPatch_assign, *expr6_2, 
167                         BPatch_arithExpr(BPatch_minus,BPatch_constExpr(64),BPatch_constExpr(1)));
168         vect6_1.push_back(&arith6_2);
169
170         // test1_6_globalVariable3 = 553648128 / 25165824 = 22
171         //    - make these big constants to test loading constants larger than
172         //      small immediate - jkh 6/22/98
173
174         BPatch_arithExpr arith6_3 (BPatch_assign, *expr6_3, BPatch_arithExpr(
175                                 BPatch_divide,BPatch_constExpr(553648128),BPatch_constExpr(25165824)));
176         vect6_1.push_back(&arith6_3);
177
178         // test1_6_globalVariable4 = 67 / 3
179         BPatch_arithExpr arith6_4 (BPatch_assign, *expr6_4, BPatch_arithExpr(
180                                 BPatch_divide,BPatch_constExpr(67),BPatch_constExpr(3)));
181         vect6_1.push_back(&arith6_4);
182         // test1_6_globalVariable5 = 6 * 5
183         BPatch_arithExpr arith6_5 (BPatch_assign, *expr6_5, BPatch_arithExpr(
184                                 BPatch_times,BPatch_constExpr(6),BPatch_constExpr(5)));
185         vect6_1.push_back(&arith6_5);
186
187         // test1_6_globalVariable6 = 10,3
188         BPatch_arithExpr arith6_6 (BPatch_assign, *expr6_6, 
189                         BPatch_arithExpr(BPatch_seq,BPatch_constExpr(10),BPatch_constExpr(3)));
190         vect6_1.push_back(&arith6_6);
191
192         // test1_6_globalVariable1a = 60 + 2
193         BPatch_arithExpr arith6_1a (BPatch_assign, *expr6_1a, 
194                         BPatch_arithExpr(BPatch_plus, *constVar60, *constVar2));
195         vect6_1.push_back(&arith6_1a);
196
197         // test1_6_globalVariable2a = 64 - 1
198         BPatch_arithExpr arith6_2a (BPatch_assign, *expr6_2a, 
199                         BPatch_arithExpr(BPatch_minus, *constVar64, *constVar1));
200         vect6_1.push_back(&arith6_2a);
201
202         // test1_6_globalVariable3a = 66 / 3
203         BPatch_arithExpr arith6_3a (BPatch_assign, *expr6_3a, BPatch_arithExpr(
204                                 BPatch_divide, *constVar66, *constVar3));
205         vect6_1.push_back(&arith6_3a);
206
207         // test1_6_globalVariable4a = 67 / 3
208         BPatch_arithExpr arith6_4a (BPatch_assign, *expr6_4a, BPatch_arithExpr(
209                                 BPatch_divide, *constVar67, *constVar3));
210         vect6_1.push_back(&arith6_4a);
211
212         // test1_6_globalVariable5a = 6 * 5
213         BPatch_arithExpr arith6_5a (BPatch_assign, *expr6_5a, BPatch_arithExpr(
214                                 BPatch_times, *constVar6, *constVar5));
215         vect6_1.push_back(&arith6_5a);
216
217         // test1_6_globalVariable6a = 10,3
218         // BPatch_arithExpr arith6_6a (BPatch_assign, *expr6_6a, *constVar3);
219         //      BPatch_arithExpr(BPatch_seq, *constVar10, BPatch_constExpr(3)));
220         BPatch_arithExpr arith6_6a (BPatch_assign, *expr6_6a,
221                         BPatch_arithExpr(BPatch_seq, *constVar10, *constVar3));
222         vect6_1.push_back(&arith6_6a);
223
224         checkCost(BPatch_sequence(vect6_1));
225         appAddrSpace->insertSnippet( BPatch_sequence(vect6_1), *point6_1);
226
227         return PASSED;
228 }