author | iignatyev |
Thu, 07 Nov 2019 13:39:31 -0800 | |
changeset 58974 | 2b0f2fe82735 |
parent 54732 | 2d012a75d35c |
permissions | -rw-r--r-- |
54732 | 1 |
/* |
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
58974
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
54732
diff
changeset
|
23 |
|
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
54732
diff
changeset
|
24 |
/* |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
54732
diff
changeset
|
25 |
* @test |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
54732
diff
changeset
|
26 |
* @requires vm.jvmci |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
54732
diff
changeset
|
27 |
* @modules jdk.internal.vm.ci/jdk.vm.ci.services:+open |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
54732
diff
changeset
|
28 |
* @library /compiler/jvmci/jdk.vm.ci.hotspot.test/src |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
54732
diff
changeset
|
29 |
* @run testng/othervm |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
54732
diff
changeset
|
30 |
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:-UseJVMCICompiler |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
54732
diff
changeset
|
31 |
* jdk.vm.ci.hotspot.test.TestServices |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
54732
diff
changeset
|
32 |
*/ |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
54732
diff
changeset
|
33 |
|
54732 | 34 |
package jdk.vm.ci.hotspot.test; |
35 |
||
36 |
import java.lang.reflect.Field; |
|
37 |
import java.lang.reflect.Method; |
|
38 |
import java.util.HashMap; |
|
39 |
import java.util.Map; |
|
40 |
||
58974
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
54732
diff
changeset
|
41 |
import org.testng.Assert; |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
54732
diff
changeset
|
42 |
import org.testng.annotations.Test; |
54732 | 43 |
|
44 |
import jdk.vm.ci.services.Services; |
|
45 |
||
46 |
public class TestServices { |
|
47 |
||
48 |
@SuppressWarnings("unchecked") |
|
49 |
@Test |
|
50 |
public void serializeSavedPropertiesTest() throws Exception { |
|
51 |
||
52 |
Field f = Services.class.getDeclaredField("MAX_UTF8_PROPERTY_STRING_LENGTH"); |
|
53 |
f.setAccessible(true); |
|
54 |
int maxUtf8PropertyStringLength = (int) f.get(null); |
|
55 |
||
56 |
Method serializeProperties = Services.class.getDeclaredMethod("serializeProperties", Map.class); |
|
57 |
Method deserializeProperties = Services.class.getDeclaredMethod("deserializeProperties", byte[].class); |
|
58 |
serializeProperties.setAccessible(true); |
|
59 |
deserializeProperties.setAccessible(true); |
|
60 |
||
61 |
Map<String, String> props = new HashMap<>(Services.getSavedProperties()); |
|
62 |
String[] names = { |
|
63 |
new String(new char[maxUtf8PropertyStringLength - 100]).replace('\0', 'x'), |
|
64 |
new String(new char[maxUtf8PropertyStringLength - 1]).replace('\0', 'x'), |
|
65 |
new String(new char[maxUtf8PropertyStringLength]).replace('\0', 'y'), |
|
66 |
new String(new char[maxUtf8PropertyStringLength + 1]).replace('\0', 'z'), |
|
67 |
new String(new char[maxUtf8PropertyStringLength + 100]).replace('\0', 'z') |
|
68 |
}; |
|
69 |
String[] values = { |
|
70 |
new String(new char[maxUtf8PropertyStringLength - 100]).replace('\0', '1'), |
|
71 |
new String(new char[maxUtf8PropertyStringLength - 1]).replace('\0', '1'), |
|
72 |
new String(new char[maxUtf8PropertyStringLength]).replace('\0', '2'), |
|
73 |
new String(new char[maxUtf8PropertyStringLength + 1]).replace('\0', '1'), |
|
74 |
new String(new char[maxUtf8PropertyStringLength + 100]).replace('\0', '3') |
|
75 |
}; |
|
76 |
for (String name : names) { |
|
77 |
for (String value : values) { |
|
78 |
props.put(name, value); |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
byte[] data = (byte[]) serializeProperties.invoke(null, props); |
|
83 |
||
84 |
Map<String, String> newProps = (Map<String, String>) deserializeProperties.invoke(null, data); |
|
85 |
||
86 |
Assert.assertEquals(props.size(), newProps.size()); |
|
87 |
for (String name : props.keySet()) { |
|
88 |
String expect = props.get(name); |
|
89 |
String actual = newProps.get(name); |
|
90 |
Assert.assertEquals(expect, actual); |
|
91 |
} |
|
92 |
} |
|
93 |
} |