Update copyright to LGPL on all files
[dyninst.git] / testsuite / src / dyninst / test1_23.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_23.C,v 1.1 2008/10/30 19:18:27 legendre Exp $
33 /*
34  * #Name: test1_23
35  * #Desc: Local Variables
36  * #Dep: !mips_sgi_irix6_4_test
37  * #Notes:
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_23_Mutator : public DyninstMutator {
49         virtual test_results_t executeTest();
50 };
51
52 extern "C" DLLEXPORT  TestMutator *test1_23_factory() 
53 {
54         return new test1_23_Mutator();
55 }
56
57 //
58 // Start Test Case #23 - local variables
59 //
60
61 test_results_t test1_23_Mutator::executeTest() 
62 {
63         const char *funcName = "test1_23_call1";
64         BPatch_Vector<BPatch_function *> found_funcs;
65
66         if ((NULL == appImage->findFunction(funcName, found_funcs, 1)) 
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 *> *point23_calls = found_funcs[0]->findPoint(BPatch_subroutine);    
80
81         if (!point23_calls || (point23_calls->size() < 1)) 
82         {
83                 logerror("**Failed** test #23 (local variables)\n");
84                 logerror("  Unable to find point %s - subroutine calls\n", funcName);
85                 return FAILED;
86         }
87
88         /* We only want the first one... */
89         BPatch_Vector<BPatch_point *> point23_1;
90         point23_1.push_back((*point23_calls)[0]);
91
92         BPatch_variableExpr *var1 = appImage->findVariable(*(point23_1[0]),
93                         "localVariable23_1");
94         BPatch_variableExpr *var2 = appImage->findVariable(*(point23_1[0]),
95                         "test1_23_shadowVariable1");
96         BPatch_variableExpr *var3 = appImage->findVariable("test1_23_shadowVariable2");
97         BPatch_variableExpr *var4 = appImage->findVariable("test1_23_globalVariable1");
98
99         if (!var1 || !var2 || !var3 || !var4) 
100         {
101                 logerror("**Failed** test #23 (local variables)\n");
102
103                 if (!var1)
104                 {
105                         logerror("  can't find local variable localVariable23_1\n");
106                         BPatch_function *f = point23_1[0]->getCalledFunction();
107                         assert(f);
108                         BPatch_Vector<BPatch_localVar *> *lvars = f->getVars();
109                         assert(lvars);
110                         logerror("%s[%d]:  have vars\n", FILE__, __LINE__);
111                         for (unsigned int i = 0; i < lvars->size(); ++i)
112                         {
113                                 logerror("\t%s\n", (*lvars)[i]->getName());
114                         }
115                 }
116                 if (!var2)
117                         logerror("  can't find local variable test1_23_shadowVariable1\n");
118                 if (!var3)
119                         logerror("  can't find global variable test1_23_shadowVariable2\n");
120                 return FAILED;
121         }
122
123         BPatch_arithExpr expr23_1(BPatch_assign, *var1, BPatch_constExpr(2300001));
124         BPatch_arithExpr expr23_2(BPatch_assign, *var2, BPatch_constExpr(2300012));
125         BPatch_arithExpr expr23_3(BPatch_assign, *var3, BPatch_constExpr(2300023));
126         BPatch_arithExpr expr23_4(BPatch_assign, *var4, *var1);
127
128         BPatch_Vector<BPatch_snippet *> exprs;
129
130         exprs.push_back(&expr23_1);
131         exprs.push_back(&expr23_2);
132         exprs.push_back(&expr23_3);
133         exprs.push_back(&expr23_4);
134
135         BPatch_sequence allParts(exprs);
136
137
138         appAddrSpace->insertSnippet(allParts, point23_1);
139
140         return PASSED;
141 }