Skip to content

Commit 9e312f1

Browse files
authored
Merge pull request #20427 from knn-k/arrayTranslateTest
Add tests for JIT arraytranslate
2 parents a8ea161 + 22ce6b5 commit 9e312f1

File tree

3 files changed

+155
-1
lines changed

3 files changed

+155
-1
lines changed

test/functional/JIT_Test/playlist.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,30 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
578578
<impl>ibm</impl>
579579
</impls>
580580
</test>
581+
<test>
582+
<testCaseName>ArrayTranslateTest</testCaseName>
583+
<variations>
584+
<variation>-Xjit:count=1,limit={*arrayTranslate*},optLevel=scorching,disableAsyncCompilation</variation>
585+
</variations>
586+
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) \
587+
-cp $(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)jitt.jar$(Q) \
588+
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng.xml$(Q) \
589+
-testnames \
590+
ArrayTranslateTest \
591+
-groups $(TEST_GROUP) \
592+
-excludegroups $(DEFAULT_EXCLUDE); \
593+
$(TEST_STATUS)</command>
594+
<levels>
595+
<level>sanity</level>
596+
</levels>
597+
<groups>
598+
<group>functional</group>
599+
</groups>
600+
<impls>
601+
<impl>openj9</impl>
602+
<impl>ibm</impl>
603+
</impls>
604+
</test>
581605
<!-- jit.test.hw tests start here -->
582606
<test>
583607
<testCaseName>jit_hw</testCaseName>
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Copyright IBM Corp. and others 2024
3+
*
4+
* This program and the accompanying materials are made available under
5+
* the terms of the Eclipse Public License 2.0 which accompanies this
6+
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7+
* or the Apache License, Version 2.0 which accompanies this distribution and
8+
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9+
*
10+
* This Source Code may also be made available under the following
11+
* Secondary Licenses when the conditions for such availability set
12+
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13+
* General Public License, version 2 with the GNU Classpath
14+
* Exception [1] and GNU General Public License, version 2 with the
15+
* OpenJDK Assembly Exception [2].
16+
*
17+
* [1] https://www.gnu.org/software/classpath/license.html
18+
* [2] https://openjdk.org/legal/assembly-exception.html
19+
*
20+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
21+
*/
22+
package jit.test.tr.arrayTranslate;
23+
24+
import org.testng.annotations.Test;
25+
import org.testng.AssertJUnit;
26+
27+
@Test(groups = { "level.sanity","component.jit" })
28+
public class ArrayTranslateTest {
29+
30+
private static final int arrSize = 128;
31+
private char[] chars;
32+
private byte[] bytes;
33+
34+
private static final char maxValueTRTO = 127;
35+
private static final char maxValueTRTO255 = 255;
36+
37+
/* JIT-compile this method */
38+
private int arrayTranslateTRTO(char[] sa, int sp, byte[] da, int dp, int len)
39+
{
40+
int i = 0;
41+
for (; i < len; i++) {
42+
char c = sa[sp++];
43+
if (c > maxValueTRTO) break;
44+
da[dp++] = (byte)c;
45+
}
46+
return i;
47+
}
48+
49+
@Test
50+
public void testArrayTranslateTRTO()
51+
{
52+
chars = new char[arrSize];
53+
bytes = new byte[arrSize];
54+
55+
// Fill chars[] with safe characters
56+
for (int i = 0; i < arrSize; i++) {
57+
chars[i] = (char)('0' + (i >> 1));
58+
}
59+
60+
for (int offset = 0; offset <= 16; offset++) {
61+
for (int len = 0; len < arrSize-offset; len++) {
62+
int n = arrayTranslateTRTO(chars, offset, bytes, 0, len);
63+
AssertJUnit.assertEquals("TRTO: Wrong result: length=" + len, len, n);
64+
for (int i = 0; i < len; i++) {
65+
AssertJUnit.assertEquals("TRTO: Wrong value at bytes[" + i + "]", chars[offset+i], (char)bytes[i]);
66+
}
67+
}
68+
}
69+
70+
for (int len = 1; len <= 64; len++) {
71+
for (int i = 0; i < len; i++) {
72+
char c = chars[i];
73+
chars[i] = maxValueTRTO + 1;
74+
int n = arrayTranslateTRTO(chars, 0, bytes, 0, len);
75+
AssertJUnit.assertEquals("TRTO: Wrong result for failure case: length=" + len, i, n);
76+
chars[i] = c;
77+
}
78+
}
79+
}
80+
81+
/* JIT-compile this method */
82+
private int arrayTranslateTRTO255(char[] sa, int sp, byte[] da, int dp, int len)
83+
{
84+
int i = 0;
85+
for (; i < len; i++) {
86+
char c = sa[sp++];
87+
if (c > maxValueTRTO255) break;
88+
da[dp++] = (byte)c;
89+
}
90+
return i;
91+
}
92+
93+
@Test
94+
public void testArrayTranslateTRTO255()
95+
{
96+
chars = new char[arrSize];
97+
bytes = new byte[arrSize];
98+
99+
// Fill chars[] with safe characters
100+
for (int i = 0; i < arrSize; i++) {
101+
chars[i] = (char)('0' + (i >> 1));
102+
}
103+
104+
for (int offset = 0; offset <= 16; offset++) {
105+
for (int len = 0; len < arrSize-offset; len++) {
106+
int n = arrayTranslateTRTO255(chars, offset, bytes, 0, len);
107+
AssertJUnit.assertEquals("TRTO255: Wrong result: length=" + len, len, n);
108+
for (int i = 0; i < len; i++) {
109+
AssertJUnit.assertEquals("TRTO255: Wrong value at bytes[" + i + "]", chars[offset+i], (char)bytes[i]);
110+
}
111+
}
112+
}
113+
114+
for (int len = 1; len <= 64; len++) {
115+
for (int i = 0; i < len; i++) {
116+
char c = chars[i];
117+
chars[i] = maxValueTRTO255 + 1;
118+
int n = arrayTranslateTRTO255(chars, 0, bytes, 0, len);
119+
AssertJUnit.assertEquals("TRTO255: Wrong result for failure case: length=" + len, i, n);
120+
chars[i] = c;
121+
}
122+
}
123+
}
124+
125+
}

test/functional/JIT_Test/testng.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,12 @@
460460
<class name="jit.test.tr.BNDCHKSimplify.BNDCHKSimplifyTest" />
461461
</classes>
462462
</test>
463-
<test name="StringPeepholeTest">
463+
<test name="ArrayTranslateTest">
464+
<classes>
465+
<class name="jit.test.tr.arrayTranslate.ArrayTranslateTest" />
466+
</classes>
467+
</test>
468+
<test name="StringPeepholeTest">
464469
<classes>
465470
<class name="jit.test.tr.stringPeephole.BigDecimalToStringTest" />
466471
</classes>

0 commit comments

Comments
 (0)