Update copyright to LGPL on all files
[dyninst.git] / testsuite / src / dyninst / test1_25.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_25.C,v 1.1 2008/10/30 19:18:31 legendre Exp $
33 /*
34  * #Name: test1_25
35  * #Desc: Unary Operators
36  * #Dep: 
37  * #Arch: !mips_sgi_irix6_4_test
38  * #Notes: A small part of this test is excluded on most platforms
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_25_Mutator : public DyninstMutator {
50         virtual test_results_t executeTest();
51 };
52
53 extern "C" DLLEXPORT  TestMutator *test1_25_factory() 
54 {
55         return new test1_25_Mutator();
56 }
57
58 //
59 // Start Test Case #25 - unary operators
60 //
61
62 test_results_t test1_25_Mutator::executeTest() 
63 {
64         // Used as hack for Fortran to allow assignment of a pointer to an int
65         BPatch::bpatch->setTypeChecking (false);
66
67         // First verify that we can find a local variable in test1_25_call1
68         const char *funcName = "test1_25_call1";
69         BPatch_Vector<BPatch_function *> found_funcs;
70
71         if ((NULL == appImage->findFunction(funcName, found_funcs))
72                         || !found_funcs.size()) 
73         {
74                 logerror("    Unable to find function %s\n", funcName);
75                 return FAILED;
76         }
77
78         if (1 < found_funcs.size()) 
79         {
80                 logerror("%s[%d]:  WARNING  : found %d functions named %s.  Using the first.\n", 
81                                 __FILE__, __LINE__, found_funcs.size(), funcName);
82         }
83
84         BPatch_Vector<BPatch_point *> *point25_1 = found_funcs[0]->findPoint(BPatch_entry);
85
86         assert(point25_1);
87         //    assert(point25_1 && (point25_1->size() == 1));
88
89         BPatch_variableExpr *gvar[8];
90
91         for (int i=1; i <= 7; i++) 
92         {
93                 char name[80];
94
95                 sprintf (name, "test1_25_globalVariable%d", i);
96                 gvar [i] = findVariable (appImage, name, point25_1);
97
98                 if (!gvar[i]) 
99                 {
100                         logerror("**Failed** test #25 (unary operaors)\n");
101                         logerror("  can't find variable %s\n", name);
102                         return FAILED;
103                 }
104         }
105
106         //     globalVariable25_2 = &globalVariable25_1
107 #if !defined(sparc_sun_solaris2_4_test) \
108         && !defined(rs6000_ibm_aix4_1_test) \
109         && !defined(alpha_dec_osf4_0_test) \
110         && !defined(i386_unknown_linux2_0_test) \
111         && !defined(x86_64_unknown_linux2_4_test) /* Blind duplication - Ray */ \
112         && !defined(ia64_unknown_linux2_4_test) \
113         && !defined(i386_unknown_solaris2_5_test) \
114         && !defined(ppc64_linux_test) \
115         && !defined(i386_unknown_nt4_0_test)
116
117         // without type info need to inform
118         BPatch_type *type = appImage->findType("void *");
119         assert(type);
120         gvar[2]->setType(type);
121 #endif
122
123         BPatch_arithExpr assignment1(BPatch_assign, *gvar[2],
124                         BPatch_arithExpr(BPatch_addr, *gvar[1]));
125
126         appAddrSpace->insertSnippet(assignment1, *point25_1);
127
128         //         globalVariable25_3 = *globalVariable25_2
129         //              Need to make sure this happens after the first one
130         BPatch_arithExpr assignment2(BPatch_assign, *gvar[3],
131                         BPatch_arithExpr(BPatch_deref, *gvar[2]));
132         appAddrSpace->insertSnippet(assignment2, *point25_1,  BPatch_callBefore,
133                         BPatch_lastSnippet);
134
135         //         globalVariable25_5 = -globalVariable25_4
136         BPatch_arithExpr assignment3(BPatch_assign, *gvar[5],
137                         BPatch_arithExpr(BPatch_negate, *gvar[4]));
138         appAddrSpace->insertSnippet(assignment3, *point25_1);
139
140         //         globalVariable25_7 = -globalVariable25_6
141         BPatch_arithExpr assignment4(BPatch_assign, *gvar[7],
142                         BPatch_arithExpr(BPatch_negate, *gvar[6]));
143         appAddrSpace->insertSnippet(assignment4, *point25_1);
144
145         // Check removed because MIPS is no longer supported
146         // #endif // !MIPS
147
148         BPatch::bpatch->setTypeChecking (true);
149         return PASSED;
150 }
151