blob: bec774009b319af75aae94a976d3406c05f64308 [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
Vladimir Marko7dac8642019-11-06 17:09:30 +000025 // To avoid going through resolution trampoline, make test classes visibly initialized.
26 new Test();
27 new TestFast();
28 new TestCritical();
29 new TestMissing();
30 new TestMissingFast();
31 new TestMissingCritical();
32 makeVisiblyInitialized(); // Make sure they are visibly initialized.
33
34 // FIXME: @FastNative and @CriticalNative fail a state check in artFindNativeMethod().
35 test();
Vladimir Marko08d09842019-12-02 12:38:49 +000036 testFast();
Vladimir Marko7dac8642019-11-06 17:09:30 +000037 // testCritical();
38 testMissing();
Vladimir Marko08d09842019-12-02 12:38:49 +000039 testMissingFast();
Vladimir Marko7dac8642019-11-06 17:09:30 +000040 // testMissingCritical();
41 }
42
43 static void test() {
44 System.out.println("test");
45 assertEquals(42, Test.nativeMethod(42));
46 assertEquals(42, Test.nativeMethodWithManyParameters(
47 11, 12L, 13.0f, 14.0d,
48 21, 22L, 23.0f, 24.0d,
49 31, 32L, 33.0f, 34.0d,
50 41, 42L, 43.0f, 44.0d,
51 51, 52L, 53.0f, 54.0d,
52 61, 62L, 63.0f, 64.0d,
53 71, 72L, 73.0f, 74.0d,
54 81, 82L, 83.0f, 84.0d));
55 }
56
57 static void testFast() {
58 System.out.println("testFast");
59 assertEquals(42, TestFast.nativeMethod(42));
60 assertEquals(42, TestFast.nativeMethodWithManyParameters(
61 11, 12L, 13.0f, 14.0d,
62 21, 22L, 23.0f, 24.0d,
63 31, 32L, 33.0f, 34.0d,
64 41, 42L, 43.0f, 44.0d,
65 51, 52L, 53.0f, 54.0d,
66 61, 62L, 63.0f, 64.0d,
67 71, 72L, 73.0f, 74.0d,
68 81, 82L, 83.0f, 84.0d));
69 }
70
71 static void testCritical() {
72 System.out.println("testCritical");
73 assertEquals(42, TestCritical.nativeMethod(42));
74 assertEquals(42, TestCritical.nativeMethodWithManyParameters(
75 11, 12L, 13.0f, 14.0d,
76 21, 22L, 23.0f, 24.0d,
77 31, 32L, 33.0f, 34.0d,
78 41, 42L, 43.0f, 44.0d,
79 51, 52L, 53.0f, 54.0d,
80 61, 62L, 63.0f, 64.0d,
81 71, 72L, 73.0f, 74.0d,
82 81, 82L, 83.0f, 84.0d));
83 }
84
85 static void testMissing() {
86 System.out.println("testMissing");
87
88 try {
89 TestMissing.nativeMethod(42);
90 throw new Error("UNREACHABLE");
91 } catch (LinkageError expected) {}
92
93 try {
94 TestMissing.nativeMethodWithManyParameters(
95 11, 12L, 13.0f, 14.0d,
96 21, 22L, 23.0f, 24.0d,
97 31, 32L, 33.0f, 34.0d,
98 41, 42L, 43.0f, 44.0d,
99 51, 52L, 53.0f, 54.0d,
100 61, 62L, 63.0f, 64.0d,
101 71, 72L, 73.0f, 74.0d,
102 81, 82L, 83.0f, 84.0d);
103 throw new Error("UNREACHABLE");
104 } catch (LinkageError expected) {}
105 }
106
107 static void testMissingFast() {
108 System.out.println("testMissingFast");
109
110 try {
111 TestMissingFast.nativeMethod(42);
112 throw new Error("UNREACHABLE");
113 } catch (LinkageError expected) {}
114
115 try {
116 TestMissingFast.nativeMethodWithManyParameters(
117 11, 12L, 13.0f, 14.0d,
118 21, 22L, 23.0f, 24.0d,
119 31, 32L, 33.0f, 34.0d,
120 41, 42L, 43.0f, 44.0d,
121 51, 52L, 53.0f, 54.0d,
122 61, 62L, 63.0f, 64.0d,
123 71, 72L, 73.0f, 74.0d,
124 81, 82L, 83.0f, 84.0d);
125 throw new Error("UNREACHABLE");
126 } catch (LinkageError expected) {}
127 }
128
129 static void testMissingCritical() {
130 System.out.println("testMissingCritical");
131
132 try {
133 TestMissingCritical.nativeMethod(42);
134 throw new Error("UNREACHABLE");
135 } catch (LinkageError expected) {}
136
137 try {
138 TestMissingCritical.nativeMethodWithManyParameters(
139 11, 12L, 13.0f, 14.0d,
140 21, 22L, 23.0f, 24.0d,
141 31, 32L, 33.0f, 34.0d,
142 41, 42L, 43.0f, 44.0d,
143 51, 52L, 53.0f, 54.0d,
144 61, 62L, 63.0f, 64.0d,
145 71, 72L, 73.0f, 74.0d,
146 81, 82L, 83.0f, 84.0d);
147 throw new Error("UNREACHABLE");
148 } catch (LinkageError expected) {}
149 }
150
151 static void assertEquals(int expected, int actual) {
152 if (expected != actual) {
153 throw new AssertionError("Expected " + expected + " got " + actual);
154 }
155 }
156
Vladimir Marko7dac8642019-11-06 17:09:30 +0000157 public static native void makeVisiblyInitialized();
158}
159
160class Test {
161 public static native int nativeMethod(int i);
162
163 public static native int nativeMethodWithManyParameters(
164 int i1, long l1, float f1, double d1,
165 int i2, long l2, float f2, double d2,
166 int i3, long l3, float f3, double d3,
167 int i4, long l4, float f4, double d4,
168 int i5, long l5, float f5, double d5,
169 int i6, long l6, float f6, double d6,
170 int i7, long l7, float f7, double d7,
171 int i8, long l8, float f8, double d8);
172}
173
174class TestFast {
175 @FastNative
176 public static native int nativeMethod(int i);
177
178 @FastNative
179 public static native int nativeMethodWithManyParameters(
180 int i1, long l1, float f1, double d1,
181 int i2, long l2, float f2, double d2,
182 int i3, long l3, float f3, double d3,
183 int i4, long l4, float f4, double d4,
184 int i5, long l5, float f5, double d5,
185 int i6, long l6, float f6, double d6,
186 int i7, long l7, float f7, double d7,
187 int i8, long l8, float f8, double d8);
188}
189
190class TestCritical {
191 @CriticalNative
192 public static native int nativeMethod(int i);
193
194 @CriticalNative
195 public static native int nativeMethodWithManyParameters(
196 int i1, long l1, float f1, double d1,
197 int i2, long l2, float f2, double d2,
198 int i3, long l3, float f3, double d3,
199 int i4, long l4, float f4, double d4,
200 int i5, long l5, float f5, double d5,
201 int i6, long l6, float f6, double d6,
202 int i7, long l7, float f7, double d7,
203 int i8, long l8, float f8, double d8);
204}
205
206class TestMissing {
207 public static native int nativeMethod(int i);
208
209 public static native int nativeMethodWithManyParameters(
210 int i1, long l1, float f1, double d1,
211 int i2, long l2, float f2, double d2,
212 int i3, long l3, float f3, double d3,
213 int i4, long l4, float f4, double d4,
214 int i5, long l5, float f5, double d5,
215 int i6, long l6, float f6, double d6,
216 int i7, long l7, float f7, double d7,
217 int i8, long l8, float f8, double d8);
218}
219
220class TestMissingFast {
221 @FastNative
222 public static native int nativeMethod(int i);
223
224 @FastNative
225 public static native int nativeMethodWithManyParameters(
226 int i1, long l1, float f1, double d1,
227 int i2, long l2, float f2, double d2,
228 int i3, long l3, float f3, double d3,
229 int i4, long l4, float f4, double d4,
230 int i5, long l5, float f5, double d5,
231 int i6, long l6, float f6, double d6,
232 int i7, long l7, float f7, double d7,
233 int i8, long l8, float f8, double d8);
234}
235
236class TestMissingCritical {
237 @CriticalNative
238 public static native int nativeMethod(int i);
239
240 @CriticalNative
241 public static native int nativeMethodWithManyParameters(
242 int i1, long l1, float f1, double d1,
243 int i2, long l2, float f2, double d2,
244 int i3, long l3, float f3, double d3,
245 int i4, long l4, float f4, double d4,
246 int i5, long l5, float f5, double d5,
247 int i6, long l6, float f6, double d6,
248 int i7, long l7, float f7, double d7,
249 int i8, long l8, float f8, double d8);
250}