blob: d63d11273bbbdfc16e73a7df0bc140a0d99801aa [file] [log] [blame]
Vladimir Marko7dac8642019-11-06 17:09:30 +00001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import dalvik.annotation.optimization.FastNative;
18import dalvik.annotation.optimization.CriticalNative;
19
20public class Main {
21
22 public static void main(String[] args) throws Exception {
23 System.loadLibrary(args[0]);
24
25 if (!checkAppImageLoaded()) {
26 System.out.println("AppImage not loaded.");
27 }
28 // To avoid going through resolution trampoline, make test classes visibly initialized.
29 new Test();
30 new TestFast();
31 new TestCritical();
32 new TestMissing();
33 new TestMissingFast();
34 new TestMissingCritical();
35 makeVisiblyInitialized(); // Make sure they are visibly initialized.
36
37 // FIXME: @FastNative and @CriticalNative fail a state check in artFindNativeMethod().
38 test();
39 // testFast();
40 // testCritical();
41 testMissing();
42 // testMissingFast();
43 // testMissingCritical();
44 }
45
46 static void test() {
47 System.out.println("test");
48 assertEquals(42, Test.nativeMethod(42));
49 assertEquals(42, Test.nativeMethodWithManyParameters(
50 11, 12L, 13.0f, 14.0d,
51 21, 22L, 23.0f, 24.0d,
52 31, 32L, 33.0f, 34.0d,
53 41, 42L, 43.0f, 44.0d,
54 51, 52L, 53.0f, 54.0d,
55 61, 62L, 63.0f, 64.0d,
56 71, 72L, 73.0f, 74.0d,
57 81, 82L, 83.0f, 84.0d));
58 }
59
60 static void testFast() {
61 System.out.println("testFast");
62 assertEquals(42, TestFast.nativeMethod(42));
63 assertEquals(42, TestFast.nativeMethodWithManyParameters(
64 11, 12L, 13.0f, 14.0d,
65 21, 22L, 23.0f, 24.0d,
66 31, 32L, 33.0f, 34.0d,
67 41, 42L, 43.0f, 44.0d,
68 51, 52L, 53.0f, 54.0d,
69 61, 62L, 63.0f, 64.0d,
70 71, 72L, 73.0f, 74.0d,
71 81, 82L, 83.0f, 84.0d));
72 }
73
74 static void testCritical() {
75 System.out.println("testCritical");
76 assertEquals(42, TestCritical.nativeMethod(42));
77 assertEquals(42, TestCritical.nativeMethodWithManyParameters(
78 11, 12L, 13.0f, 14.0d,
79 21, 22L, 23.0f, 24.0d,
80 31, 32L, 33.0f, 34.0d,
81 41, 42L, 43.0f, 44.0d,
82 51, 52L, 53.0f, 54.0d,
83 61, 62L, 63.0f, 64.0d,
84 71, 72L, 73.0f, 74.0d,
85 81, 82L, 83.0f, 84.0d));
86 }
87
88 static void testMissing() {
89 System.out.println("testMissing");
90
91 try {
92 TestMissing.nativeMethod(42);
93 throw new Error("UNREACHABLE");
94 } catch (LinkageError expected) {}
95
96 try {
97 TestMissing.nativeMethodWithManyParameters(
98 11, 12L, 13.0f, 14.0d,
99 21, 22L, 23.0f, 24.0d,
100 31, 32L, 33.0f, 34.0d,
101 41, 42L, 43.0f, 44.0d,
102 51, 52L, 53.0f, 54.0d,
103 61, 62L, 63.0f, 64.0d,
104 71, 72L, 73.0f, 74.0d,
105 81, 82L, 83.0f, 84.0d);
106 throw new Error("UNREACHABLE");
107 } catch (LinkageError expected) {}
108 }
109
110 static void testMissingFast() {
111 System.out.println("testMissingFast");
112
113 try {
114 TestMissingFast.nativeMethod(42);
115 throw new Error("UNREACHABLE");
116 } catch (LinkageError expected) {}
117
118 try {
119 TestMissingFast.nativeMethodWithManyParameters(
120 11, 12L, 13.0f, 14.0d,
121 21, 22L, 23.0f, 24.0d,
122 31, 32L, 33.0f, 34.0d,
123 41, 42L, 43.0f, 44.0d,
124 51, 52L, 53.0f, 54.0d,
125 61, 62L, 63.0f, 64.0d,
126 71, 72L, 73.0f, 74.0d,
127 81, 82L, 83.0f, 84.0d);
128 throw new Error("UNREACHABLE");
129 } catch (LinkageError expected) {}
130 }
131
132 static void testMissingCritical() {
133 System.out.println("testMissingCritical");
134
135 try {
136 TestMissingCritical.nativeMethod(42);
137 throw new Error("UNREACHABLE");
138 } catch (LinkageError expected) {}
139
140 try {
141 TestMissingCritical.nativeMethodWithManyParameters(
142 11, 12L, 13.0f, 14.0d,
143 21, 22L, 23.0f, 24.0d,
144 31, 32L, 33.0f, 34.0d,
145 41, 42L, 43.0f, 44.0d,
146 51, 52L, 53.0f, 54.0d,
147 61, 62L, 63.0f, 64.0d,
148 71, 72L, 73.0f, 74.0d,
149 81, 82L, 83.0f, 84.0d);
150 throw new Error("UNREACHABLE");
151 } catch (LinkageError expected) {}
152 }
153
154 static void assertEquals(int expected, int actual) {
155 if (expected != actual) {
156 throw new AssertionError("Expected " + expected + " got " + actual);
157 }
158 }
159
160 public static native boolean checkAppImageLoaded();
161 public static native void makeVisiblyInitialized();
162}
163
164class Test {
165 public static native int nativeMethod(int i);
166
167 public static native int nativeMethodWithManyParameters(
168 int i1, long l1, float f1, double d1,
169 int i2, long l2, float f2, double d2,
170 int i3, long l3, float f3, double d3,
171 int i4, long l4, float f4, double d4,
172 int i5, long l5, float f5, double d5,
173 int i6, long l6, float f6, double d6,
174 int i7, long l7, float f7, double d7,
175 int i8, long l8, float f8, double d8);
176}
177
178class TestFast {
179 @FastNative
180 public static native int nativeMethod(int i);
181
182 @FastNative
183 public static native int nativeMethodWithManyParameters(
184 int i1, long l1, float f1, double d1,
185 int i2, long l2, float f2, double d2,
186 int i3, long l3, float f3, double d3,
187 int i4, long l4, float f4, double d4,
188 int i5, long l5, float f5, double d5,
189 int i6, long l6, float f6, double d6,
190 int i7, long l7, float f7, double d7,
191 int i8, long l8, float f8, double d8);
192}
193
194class TestCritical {
195 @CriticalNative
196 public static native int nativeMethod(int i);
197
198 @CriticalNative
199 public static native int nativeMethodWithManyParameters(
200 int i1, long l1, float f1, double d1,
201 int i2, long l2, float f2, double d2,
202 int i3, long l3, float f3, double d3,
203 int i4, long l4, float f4, double d4,
204 int i5, long l5, float f5, double d5,
205 int i6, long l6, float f6, double d6,
206 int i7, long l7, float f7, double d7,
207 int i8, long l8, float f8, double d8);
208}
209
210class TestMissing {
211 public static native int nativeMethod(int i);
212
213 public static native int nativeMethodWithManyParameters(
214 int i1, long l1, float f1, double d1,
215 int i2, long l2, float f2, double d2,
216 int i3, long l3, float f3, double d3,
217 int i4, long l4, float f4, double d4,
218 int i5, long l5, float f5, double d5,
219 int i6, long l6, float f6, double d6,
220 int i7, long l7, float f7, double d7,
221 int i8, long l8, float f8, double d8);
222}
223
224class TestMissingFast {
225 @FastNative
226 public static native int nativeMethod(int i);
227
228 @FastNative
229 public static native int nativeMethodWithManyParameters(
230 int i1, long l1, float f1, double d1,
231 int i2, long l2, float f2, double d2,
232 int i3, long l3, float f3, double d3,
233 int i4, long l4, float f4, double d4,
234 int i5, long l5, float f5, double d5,
235 int i6, long l6, float f6, double d6,
236 int i7, long l7, float f7, double d7,
237 int i8, long l8, float f8, double d8);
238}
239
240class TestMissingCritical {
241 @CriticalNative
242 public static native int nativeMethod(int i);
243
244 @CriticalNative
245 public static native int nativeMethodWithManyParameters(
246 int i1, long l1, float f1, double d1,
247 int i2, long l2, float f2, double d2,
248 int i3, long l3, float f3, double d3,
249 int i4, long l4, float f4, double d4,
250 int i5, long l5, float f5, double d5,
251 int i6, long l6, float f6, double d6,
252 int i7, long l7, float f7, double d7,
253 int i8, long l8, float f8, double d8);
254}