blob: 7b7f294f1e2868274c0e4c50375e53ad39deb1ce [file] [log] [blame]
buzbeec143c552011-08-20 17:38:58 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#include "class_linker.h"
4#include "common_test.h"
5#include "dex_file.h"
6#include "heap.h"
7#include "object.h"
8#include "scoped_ptr.h"
9
10#include <stdint.h>
11#include <stdio.h>
12#include "gtest/gtest.h"
13
14namespace art {
15
16class CompilerTest : public CommonTest {
17};
18
19#if defined(__arm__)
20TEST_F(CompilerTest, BasicCodegen) {
21 scoped_ptr<DexFile> dex_file(OpenDexFileBase64(kFibonacciDex,
22 "kFibonacciDex"));
23 PathClassLoader* class_loader = AllocPathClassLoader(dex_file.get());
24
25 Thread::Current()->SetClassLoaderOverride(class_loader);
26
27 JNIEnv* env = Thread::Current()->GetJniEnv();
28
29 jclass c = env->FindClass("Fibonacci");
30 ASSERT_TRUE(c != NULL);
31
32 jmethodID m = env->GetStaticMethodID(c, "fibonacci", "(I)I");
33 ASSERT_TRUE(m != NULL);
34
35 jint result = env->CallStaticIntMethod(c, m, 10);
36 LOG(INFO) << "Fibonacci[10] is " << result;
37
38 ASSERT_EQ(55, result);
39}
buzbee3ea4ec52011-08-22 17:37:19 -070040
41TEST_F(CompilerTest, UnopTest) {
42 scoped_ptr<DexFile> dex_file(OpenDexFileBase64(kIntMathDex,
43 "kIntMathDex"));
44 PathClassLoader* class_loader = AllocPathClassLoader(dex_file.get());
45
46 Thread::Current()->SetClassLoaderOverride(class_loader);
47
48 JNIEnv* env = Thread::Current()->GetJniEnv();
49
50 jclass c = env->FindClass("IntMath");
51 ASSERT_TRUE(c != NULL);
52
53 jmethodID m = env->GetStaticMethodID(c, "unopTest", "(I)I");
54 ASSERT_TRUE(m != NULL);
55
56 jint result = env->CallStaticIntMethod(c, m, 38);
57 LOG(INFO) << "unopTest(38) == " << result;
58
59 ASSERT_EQ(37, result);
60}
61
62#if 0 // Does filled array - needs load-time class resolution
63TEST_F(CompilerTest, ShiftTest1) {
64 scoped_ptr<DexFile> dex_file(OpenDexFileBase64(kIntMathDex,
65 "kIntMathDex"));
66 PathClassLoader* class_loader = AllocPathClassLoader(dex_file.get());
67
68 Thread::Current()->SetClassLoaderOverride(class_loader);
69
70 JNIEnv* env = Thread::Current()->GetJniEnv();
71
72 jclass c = env->FindClass("IntMath");
73 ASSERT_TRUE(c != NULL);
74
75 jmethodID m = env->GetStaticMethodID(c, "shiftTest1", "()I");
76 ASSERT_TRUE(m != NULL);
77
78 jint result = env->CallStaticIntMethod(c, m);
79
80 ASSERT_EQ(0, result);
81}
buzbeec143c552011-08-20 17:38:58 -070082#endif
83
buzbee3ea4ec52011-08-22 17:37:19 -070084TEST_F(CompilerTest, ShiftTest2) {
85 scoped_ptr<DexFile> dex_file(OpenDexFileBase64(kIntMathDex,
86 "kIntMathDex"));
87 PathClassLoader* class_loader = AllocPathClassLoader(dex_file.get());
88
89 Thread::Current()->SetClassLoaderOverride(class_loader);
90
91 JNIEnv* env = Thread::Current()->GetJniEnv();
92
93 jclass c = env->FindClass("IntMath");
94 ASSERT_TRUE(c != NULL);
95
96 jmethodID m = env->GetStaticMethodID(c, "shiftTest2", "()I");
97 ASSERT_TRUE(m != NULL);
98
99 jint result = env->CallStaticIntMethod(c, m);
100
101 ASSERT_EQ(0, result);
102}
buzbee3ea4ec52011-08-22 17:37:19 -0700103
104TEST_F(CompilerTest, UnsignedShiftTest) {
105 scoped_ptr<DexFile> dex_file(OpenDexFileBase64(kIntMathDex,
106 "kIntMathDex"));
107 PathClassLoader* class_loader = AllocPathClassLoader(dex_file.get());
108
109 Thread::Current()->SetClassLoaderOverride(class_loader);
110
111 JNIEnv* env = Thread::Current()->GetJniEnv();
112
113 jclass c = env->FindClass("IntMath");
114 ASSERT_TRUE(c != NULL);
115
116 jmethodID m = env->GetStaticMethodID(c, "unsignedShiftTest", "()I");
117 ASSERT_TRUE(m != NULL);
118
119 jint result = env->CallStaticIntMethod(c, m);
120
121 ASSERT_EQ(0, result);
122}
123
124#if 0 // Fail subtest #3, long to int conversion w/ truncation.
125TEST_F(CompilerTest, ConvTest) {
126 scoped_ptr<DexFile> dex_file(OpenDexFileBase64(kIntMathDex,
127 "kIntMathDex"));
128 PathClassLoader* class_loader = AllocPathClassLoader(dex_file.get());
129
130 Thread::Current()->SetClassLoaderOverride(class_loader);
131
132 JNIEnv* env = Thread::Current()->GetJniEnv();
133
134 jclass c = env->FindClass("IntMath");
135 ASSERT_TRUE(c != NULL);
136
137 jmethodID m = env->GetStaticMethodID(c, "convTest", "()I");
138 ASSERT_TRUE(m != NULL);
139
140 jint result = env->CallStaticIntMethod(c, m);
141
142 ASSERT_EQ(0, result);
143}
144#endif
145
146TEST_F(CompilerTest, CharSubTest) {
147 scoped_ptr<DexFile> dex_file(OpenDexFileBase64(kIntMathDex,
148 "kIntMathDex"));
149 PathClassLoader* class_loader = AllocPathClassLoader(dex_file.get());
150
151 Thread::Current()->SetClassLoaderOverride(class_loader);
152
153 JNIEnv* env = Thread::Current()->GetJniEnv();
154
155 jclass c = env->FindClass("IntMath");
156 ASSERT_TRUE(c != NULL);
157
158 jmethodID m = env->GetStaticMethodID(c, "charSubTest", "()I");
159 ASSERT_TRUE(m != NULL);
160
161 jint result = env->CallStaticIntMethod(c, m);
162
163 ASSERT_EQ(0, result);
164}
165
166#if 0 // Needs array allocation & r9 to be set up with Thread*
167TEST_F(CompilerTest, IntOperTest) {
168 scoped_ptr<DexFile> dex_file(OpenDexFileBase64(kIntMathDex,
169 "kIntMathDex"));
170 PathClassLoader* class_loader = AllocPathClassLoader(dex_file.get());
171
172 Thread::Current()->SetClassLoaderOverride(class_loader);
173
174 JNIEnv* env = Thread::Current()->GetJniEnv();
175
176 jclass c = env->FindClass("IntMath");
177 ASSERT_TRUE(c != NULL);
178
179 jmethodID m = env->GetStaticMethodID(c, "intOperTest", "(II)I");
180 ASSERT_TRUE(m != NULL);
181
182 jint result = env->CallStaticIntMethod(c, m, 70000, -3);
183
184 ASSERT_EQ(0, result);
185}
186#endif
187
188#if 0 // Needs array allocation & r9 to be set up with Thread*
189TEST_F(CompilerTest, Lit16Test) {
190 scoped_ptr<DexFile> dex_file(OpenDexFileBase64(kIntMathDex,
191 "kIntMathDex"));
192 PathClassLoader* class_loader = AllocPathClassLoader(dex_file.get());
193
194 Thread::Current()->SetClassLoaderOverride(class_loader);
195
196 JNIEnv* env = Thread::Current()->GetJniEnv();
197
198 jclass c = env->FindClass("IntMath");
199 ASSERT_TRUE(c != NULL);
200
201 jmethodID m = env->GetStaticMethodID(c, "lit16Test", "(I)I");
202 ASSERT_TRUE(m != NULL);
203
204 jint result = env->CallStaticIntMethod(c, m, 77777);
205
206 ASSERT_EQ(0, result);
207}
208#endif
209
210#if 0 // Needs array allocation & r9 to be set up with Thread*
211TEST_F(CompilerTest, Lit8Test) {
212 scoped_ptr<DexFile> dex_file(OpenDexFileBase64(kIntMathDex,
213 "kIntMathDex"));
214 PathClassLoader* class_loader = AllocPathClassLoader(dex_file.get());
215
216 Thread::Current()->SetClassLoaderOverride(class_loader);
217
218 JNIEnv* env = Thread::Current()->GetJniEnv();
219
220 jclass c = env->FindClass("IntMath");
221 ASSERT_TRUE(c != NULL);
222
223 jmethodID m = env->GetStaticMethodID(c, "lit8Test", "(I)I");
224 ASSERT_TRUE(m != NULL);
225
226 jint result = env->CallStaticIntMethod(c, m, -55555);
227
228 ASSERT_EQ(0, result);
229}
230#endif
231
232#if 0 // Needs array allocation & r9 to be set up with Thread*
233TEST_F(CompilerTest, Lit8Test) {
234 scoped_ptr<DexFile> dex_file(OpenDexFileBase64(kIntMathDex,
235 "kIntMathDex"));
236 PathClassLoader* class_loader = AllocPathClassLoader(dex_file.get());
237
238 Thread::Current()->SetClassLoaderOverride(class_loader);
239
240 JNIEnv* env = Thread::Current()->GetJniEnv();
241
242 jclass c = env->FindClass("IntMath");
243 ASSERT_TRUE(c != NULL);
244
245 jmethodID m = env->GetStaticMethodID(c, "lit8Test", "(I)I");
246 ASSERT_TRUE(m != NULL);
247
248 jint result = env->CallStaticIntMethod(c, m, -55555);
249
250 ASSERT_EQ(0, result);
251}
252#endif
253
254#if 0 // Needs array allocation & r9 to be set up with Thread*
255TEST_F(CompilerTest, IntShiftTest) {
256 scoped_ptr<DexFile> dex_file(OpenDexFileBase64(kIntMathDex,
257 "kIntMathDex"));
258 PathClassLoader* class_loader = AllocPathClassLoader(dex_file.get());
259
260 Thread::Current()->SetClassLoaderOverride(class_loader);
261
262 JNIEnv* env = Thread::Current()->GetJniEnv();
263
264 jclass c = env->FindClass("IntMath");
265 ASSERT_TRUE(c != NULL);
266
267 jmethodID m = env->GetStaticMethodID(c, "intShiftTest", "(II)I");
268 ASSERT_TRUE(m != NULL);
269
270 jint result = env->CallStaticIntMethod(c, m, 0xff00aa01, 8);
271
272 ASSERT_EQ(0, result);
273}
274#endif
275
276#if 0 // Needs array allocation & r9 to be set up with Thread*
277TEST_F(CompilerTest, LongOperTest) {
278 scoped_ptr<DexFile> dex_file(OpenDexFileBase64(kIntMathDex,
279 "kIntMathDex"));
280 PathClassLoader* class_loader = AllocPathClassLoader(dex_file.get());
281
282 Thread::Current()->SetClassLoaderOverride(class_loader);
283
284 JNIEnv* env = Thread::Current()->GetJniEnv();
285
286 jclass c = env->FindClass("IntMath");
287 ASSERT_TRUE(c != NULL);
288
289 jmethodID m = env->GetStaticMethodID(c, "longOperTest", "(LL)I");
290 ASSERT_TRUE(m != NULL);
291
292 jint result = env->CallStaticIntMethod(c, m, 70000000000L, 3);
293
294 ASSERT_EQ(0, result);
295}
296#endif
297
298#if 0 // Needs array allocation & r9 to be set up with Thread*
299TEST_F(CompilerTest, LongShiftTest) {
300 scoped_ptr<DexFile> dex_file(OpenDexFileBase64(kIntMathDex,
301 "kIntMathDex"));
302 PathClassLoader* class_loader = AllocPathClassLoader(dex_file.get());
303
304 Thread::Current()->SetClassLoaderOverride(class_loader);
305
306 JNIEnv* env = Thread::Current()->GetJniEnv();
307
308 jclass c = env->FindClass("IntMath");
309 ASSERT_TRUE(c != NULL);
310
311 jmethodID m = env->GetStaticMethodID(c, "longShiftTest", "(LL)I");
312 ASSERT_TRUE(m != NULL);
313
314 jint result = env->CallStaticIntMethod(c, m, 0xd5aa96deff00aa01, 8);
315
316 ASSERT_EQ(0, result);
317}
318#endif
319
320#endif // Arm
buzbeec143c552011-08-20 17:38:58 -0700321} // namespace art