Update copyright to LGPL on all files
[dyninst.git] / testsuite / src / dyninst / test1_24.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_24.C,v 1.1 2008/10/30 19:18:29 legendre Exp $
33 /*
34  * #Name: test1_24
35  * #Desc: Mutator Side - Array Variables
36  * #Dep: 
37  * #Arch: !mips_sgi_irix6_4_test
38  * #Notes:
39  */
40
41 #include "BPatch.h"
42 #include "BPatch_Vector.h"
43 #include "BPatch_thread.h"
44 #include "BPatch_snippet.h"
45
46 #include "test_lib.h"
47 #include "dyninst_comp.h"
48
49 class test1_24_Mutator : public DyninstMutator {
50         virtual test_results_t executeTest();
51 };
52
53 extern "C" DLLEXPORT  TestMutator *test1_24_factory() 
54 {
55         return new test1_24_Mutator();
56 }
57
58 //
59 // Start Test Case #24 - array variables
60 //
61
62 test_results_t test1_24_Mutator::executeTest() 
63 {
64         if (isMutateeFortran(appImage)) 
65         {
66                 return SKIPPED;
67         }
68
69         // This test is skipped on some (no?) platforms
70 #if !defined(sparc_sun_solaris2_4_test) \
71         && !defined(rs6000_ibm_aix4_1_test) \
72         && !defined(alpha_dec_osf4_0_test) \
73         && !defined(i386_unknown_linux2_0_test) \
74         && !defined(x86_64_unknown_linux2_4_test) /* Blind duplication - Ray */ \
75         && !defined(i386_unknown_solaris2_5_test) \
76         && !defined(i386_unknown_nt4_0_test) \
77         && !defined(ia64_unknown_linux2_4_test) \
78         && !defined(os_linux_test) /* Use OS #define instead of platform - Greg */
79         return SKIPPED;
80 #endif
81
82         //     First verify that we can find function call24_1
83         BPatch_Vector<BPatch_function *> bpfv;
84         char *fn = "test1_24_call1";
85
86         if (NULL == appImage->findFunction(fn, bpfv) || !bpfv.size()
87                         || NULL == bpfv[0])
88         {
89                 logerror("    Unable to find function %s\n", fn);
90                 return FAILED;
91         }
92
93         BPatch_function *call24_1_func = bpfv[0];
94
95         BPatch_Vector<BPatch_point *> *temp = call24_1_func->findPoint(BPatch_subroutine);
96
97         //     Then verify that we can find a local variable in call24_1
98         if (!temp || (temp->size() == 0)) 
99         {
100                 logerror("**Failed** test #24 (array variables)\n");
101                 logerror("  can't find function %s\n", fn);
102                 return FAILED;
103         } 
104         else 
105         {
106                 dprintf("Found %d callsites in function %s\n", temp->size(), fn);
107         }
108
109         BPatch_Vector<BPatch_point *> *point24_1  =
110                 new (BPatch_Vector<BPatch_point *>);
111         point24_1->push_back((*temp)[0]);
112
113         BPatch_Vector<BPatch_point *> *point24_2 = call24_1_func->findPoint(BPatch_exit);
114         BPatch_Vector<BPatch_point *> *point24_3 = call24_1_func->findPoint(BPatch_entry);
115
116         if (!point24_1 || !point24_2 || !point24_3) 
117         {
118                 logerror("**Failed** test #24 (array variables)\n");
119
120                 if (!point24_1) 
121                 {
122                         logerror("    can't find subroutine instrumentation point\n");
123                 }
124
125                 if (!point24_2) 
126                 {
127                         logerror("    can't find exit instrumentation point\n");
128                 }
129
130                 if (!point24_3) 
131                 {
132                         logerror("    can't find entry instrumentation point\n");
133                 }
134                 return FAILED;
135         }
136
137         BPatch_variableExpr *lvar;
138         BPatch_variableExpr *gvar[10];
139
140         for (int i=1; i <= 9; i++) 
141         {
142                 char name[80];
143
144                 sprintf(name, "test1_24_globalVariable%d", i);
145                 gvar[i] = appImage->findVariable(name);
146
147                 if (!gvar[i]) 
148                 {
149                         logerror("**Failed** test #24 (array variables)\n");
150                         logerror("  can't find variable %s\n", name);
151                         return FAILED;
152                 }
153         }
154
155         lvar = appImage->findVariable(*(*point24_1)[0], "localVariable24_1");
156
157         if (!lvar) 
158         {
159                 logerror("**Failed** test #24 (array variables)\n");
160                 logerror("  can't find variable localVariable24_1\n");
161                 return FAILED;
162         }
163
164         //     globalVariable24_1[1] = 2400001
165         BPatch_arithExpr assignment1(BPatch_assign,
166                         BPatch_arithExpr(BPatch_ref, *gvar[1], BPatch_constExpr(1)),
167                         BPatch_constExpr(2400001));
168         if (!appAddrSpace->insertSnippet(assignment1, *point24_1))
169                 return FAILED;
170
171         //     globalVariable24_1[globalVariable24_2] = 2400002
172         BPatch_arithExpr assignment2(BPatch_assign,
173                         BPatch_arithExpr(BPatch_ref, *gvar[1], *gvar[2]),
174                         BPatch_constExpr(2400002));
175         if (!appAddrSpace->insertSnippet(assignment2, *point24_1))
176                 return FAILED;
177
178         //     globalVariable24_3 = globalVariable24_1[79]
179         BPatch_arithExpr assignment3(BPatch_assign, *gvar[3],
180                         BPatch_arithExpr(BPatch_ref, *gvar[1], BPatch_constExpr(79)));
181         if (!appAddrSpace->insertSnippet(assignment3, *point24_1))
182                 return FAILED;
183
184         //     globalVariable24_5 = globalVariable24_1[globalVariable24_4]
185         BPatch_arithExpr assignment4(BPatch_assign, *gvar[5],
186                         BPatch_arithExpr(BPatch_ref, *gvar[1], *gvar[4]));
187         appAddrSpace->insertSnippet(assignment4, *point24_1);
188
189         // now the local variables
190         //     localVariable24_1[1] = 2400005
191         BPatch_arithExpr *bpae = new BPatch_arithExpr(BPatch_ref, 
192                         *lvar, 
193                         BPatch_constExpr(1));
194         BPatch_constExpr *bpce = new BPatch_constExpr(2400005);
195         BPatch_arithExpr assignment5(BPatch_assign, *bpae, *bpce);
196         if (!appAddrSpace->insertSnippet(assignment5, *point24_1))
197                 return FAILED;
198
199         //     localVariable24_1[globalVariable24_2] = 2400006
200         BPatch_arithExpr assignment6(BPatch_assign,
201                         BPatch_arithExpr(BPatch_ref, *lvar, *gvar[2]),
202                         BPatch_constExpr(2400006));
203         if (!appAddrSpace->insertSnippet(assignment6, *point24_1))
204                 return FAILED;
205
206         //     globalVariable24_6 = localVariable24_1[79]
207         BPatch_arithExpr *ae = 
208                 new BPatch_arithExpr(BPatch_ref, *lvar, BPatch_constExpr(79));
209         BPatch_arithExpr assignment7(BPatch_assign, *gvar[6],*ae);
210         if (!appAddrSpace->insertSnippet(assignment7, *point24_1))
211                 return FAILED;
212
213         //     globalVariable24_7 = localVariable24_1[globalVariable24_4]
214         BPatch_arithExpr assignment8(BPatch_assign, *gvar[7],
215                         BPatch_arithExpr(BPatch_ref, *lvar, *gvar[4]));
216         if (!appAddrSpace->insertSnippet(assignment8, *point24_1))
217                 return FAILED;
218
219         // now test multi-dimensional arrays
220         //         globalVariable24_8[2][3] = 2400011
221         BPatch_arithExpr assignment9(BPatch_assign,
222                         BPatch_arithExpr(BPatch_ref, BPatch_arithExpr(BPatch_ref, *gvar[8],
223                                         BPatch_constExpr(2)), BPatch_constExpr(3)), BPatch_constExpr(2400011));
224         if (!appAddrSpace->insertSnippet(assignment9, *point24_1))
225                 return FAILED;
226
227         // globalVariable24_9 = globalVariable24_8[7][9]
228         BPatch_arithExpr assignment10(BPatch_assign, *gvar[9],
229                         BPatch_arithExpr(BPatch_ref, BPatch_arithExpr(BPatch_ref, *gvar[8],
230                                         BPatch_constExpr(7)), BPatch_constExpr(9)));
231         if (!appAddrSpace->insertSnippet(assignment10, *point24_1))
232                 return FAILED;
233
234         return PASSED;
235 }