Remove old testsuite
[dyninst.git] / newtestsuite / src / dyninst / test1_36.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_36.C,v 1.1 2008/10/30 19:19:19 legendre Exp $
43 /*
44  * #Name: test1_36
45  * #Desc: Callsite Parameter Referencing
46  * #Dep: 
47  * #Arch:
48  * #Notes:
49  */
50
51 #include "BPatch.h"
52 #include "BPatch_Vector.h"
53 #include "BPatch_thread.h"
54 #include "BPatch_snippet.h"
55
56 #include "test_lib.h"
57 #include "dyninst_comp.h"
58
59 class test1_36_Mutator : public DyninstMutator {
60
61         virtual test_results_t executeTest();
62
63         BPatch_arithExpr *makeTest36paramExpr(BPatch_snippet *expr, int paramId);
64 };
65
66 extern "C" DLLEXPORT  TestMutator *test1_36_factory() 
67 {
68         return new test1_36_Mutator();
69 }
70
71 BPatch_arithExpr *test1_36_Mutator::makeTest36paramExpr(BPatch_snippet *expr,
72                 int paramId)
73 {
74         if (isMutateeFortran(appImage)) 
75         {
76                 // Fortran is call by reference
77                 BPatch_arithExpr *derefExpr = new BPatch_arithExpr(BPatch_deref, *(new BPatch_paramExpr(paramId)));
78                 assert(derefExpr);
79                 return new BPatch_arithExpr(BPatch_assign, *expr, *derefExpr);
80         } 
81         else 
82         {
83                 return new BPatch_arithExpr(BPatch_assign, *expr, *(new BPatch_paramExpr(paramId)));
84         }
85 }
86
87 //
88 // Start Test Case #36 - (callsite parameter referencing)
89 //
90
91 test_results_t test1_36_Mutator::executeTest() 
92 {
93         const char *funcName = "test1_36_func1";
94         BPatch_Vector<BPatch_function *> found_funcs;
95
96         if ((NULL == appImage->findFunction(funcName, found_funcs))
97                         || !found_funcs.size()) 
98         {
99                 logerror("    Unable to find function %s\n", funcName);
100                 return FAILED;
101         }
102
103         if (1 < found_funcs.size()) 
104         {
105                 logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
106                                 __FILE__, __LINE__, found_funcs.size(), funcName);
107         }
108
109         BPatch_Vector<BPatch_point *> *all_points36_1 =
110                 found_funcs[0]->findPoint(BPatch_subroutine);
111
112         if (!all_points36_1 || (all_points36_1->size() < 1)) 
113         {
114                 logerror("Unable to find point %s - subroutines.\n", funcName);
115                 return FAILED;
116         }
117
118         const char *funcName2 = "test1_36_call1";
119         BPatch_point *point36_1 = NULL;
120
121         for (unsigned i=0; i<(*all_points36_1).size(); i++) 
122         {
123                 BPatch_point *cur_point = (*all_points36_1)[i];
124                 if (cur_point == NULL) 
125                         continue;
126
127                 BPatch_function *func = cur_point->getCalledFunction();
128                 char funcname[100];
129
130                 if (!func) 
131                         continue;
132
133                 if (func->getName(funcname, 99)) 
134                 {
135                         if (strstr(funcname, funcName2))
136                                 point36_1 = cur_point;
137                 }
138         }
139
140         if (point36_1 == NULL) 
141         {
142                 logerror("Unable to find callsite %s\n", funcName2);
143                 return FAILED;
144         }
145
146         BPatch_variableExpr *expr36_1 = findVariable(appImage,
147                         "test1_36_globalVariable1", 
148                         all_points36_1);
149         BPatch_variableExpr *expr36_2 = findVariable(appImage,
150                         "test1_36_globalVariable2", 
151                         all_points36_1);
152         BPatch_variableExpr *expr36_3 = findVariable(appImage,
153                         "test1_36_globalVariable3", 
154                         all_points36_1);
155         BPatch_variableExpr *expr36_4 = findVariable(appImage,
156                         "test1_36_globalVariable4", 
157                         all_points36_1);
158         BPatch_variableExpr *expr36_5 = findVariable(appImage,
159                         "test1_36_globalVariable5", 
160                         all_points36_1);
161         BPatch_variableExpr *expr36_6 = findVariable(appImage,
162                         "test1_36_globalVariable6", 
163                         all_points36_1);
164         BPatch_variableExpr *expr36_7 = findVariable(appImage,
165                         "test1_36_globalVariable7", 
166                         all_points36_1);
167         BPatch_variableExpr *expr36_8 = findVariable(appImage,
168                         "test1_36_globalVariable8", 
169                         all_points36_1);
170         BPatch_variableExpr *expr36_9 = findVariable(appImage,
171                         "test1_36_globalVariable9", 
172                         all_points36_1);
173         BPatch_variableExpr *expr36_10 = findVariable(appImage,
174                         "test1_36_globalVariable10", 
175                         all_points36_1);
176
177         if (expr36_1 == NULL || expr36_2 == NULL || expr36_3 == NULL ||
178                         expr36_4 == NULL || expr36_5 == NULL || expr36_6 == NULL ||
179                         expr36_7 == NULL || expr36_8 == NULL || expr36_9 == NULL ||
180                         expr36_10 == NULL)
181         {
182                 logerror("**Failed** test #36 (callsite parameter referencing)\n");
183                 logerror("    Unable to locate at least one of "
184                                 "test1_36_globalVariable{1...10}\n");
185                 return FAILED;
186         }
187
188         BPatch_Vector<BPatch_snippet *> snippet_seq;
189         snippet_seq.push_back(makeTest36paramExpr(expr36_1, 0));
190         snippet_seq.push_back(makeTest36paramExpr(expr36_2, 1));
191         snippet_seq.push_back(makeTest36paramExpr(expr36_3, 2));
192         snippet_seq.push_back(makeTest36paramExpr(expr36_4, 3));
193         snippet_seq.push_back(makeTest36paramExpr(expr36_5, 4));
194         snippet_seq.push_back(makeTest36paramExpr(expr36_6, 5));
195 #if !defined(alpha_dec_osf4_0_test) && !defined(arch_x86_64_test)  /* alpha and AMD64 don't handle more than 6 */
196         snippet_seq.push_back(makeTest36paramExpr(expr36_7, 6));
197         snippet_seq.push_back(makeTest36paramExpr(expr36_8, 7));
198
199         // Solaris Fortran skips 9th paramter
200 #if defined(sparc_sun_solaris2_4_test) 
201         if (!isMutateeFortran(appImage))
202 #endif
203                 snippet_seq.push_back(makeTest36paramExpr(expr36_9, 8));
204
205 #if !defined(sparc_sun_solaris2_4_test)
206         snippet_seq.push_back(makeTest36paramExpr(expr36_10, 9));
207 #endif
208 #endif
209         BPatch_sequence seqExpr(snippet_seq);
210
211         checkCost(seqExpr);
212         appAddrSpace->insertSnippet(seqExpr, *point36_1);
213
214         return PASSED;
215 }
216