Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdLineTests/shareClassTests/SCHelperCompatTests/PartitioningURLClassPathHelperURLHelperStaleEntryCompatibilityTest.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2005, 2020 IBM Corp. and others
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] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
import java.io.BufferedReader;
23
import java.io.FileInputStream;
24
import java.io.InputStreamReader;
25
import java.net.URL;
26
import java.util.Properties;
27
28
import CustomCLs.CustomPartitioningURLCL;
29
import CustomCLs.CustomPartitioningURLLoader;
30
import Utilities.StringManipulator;
31
import Utilities.URLClassPathCreator;
32
33
/**
34
* @author Matthew Kilner
35
*/
36
public class PartitioningURLClassPathHelperURLHelperStaleEntryCompatibilityTest {
37
38
StringManipulator manipulator = new StringManipulator();
39
40
public static void main(String[] args) {
41
42
if(args.length != 4){
43
System.out.println("\n Incorrect usage");
44
System.out.println("\n Please specifiy -testfile <filename> -javacdir <path to javac>");
45
}
46
47
PartitioningURLClassPathHelperURLHelperStaleEntryCompatibilityTest test = new PartitioningURLClassPathHelperURLHelperStaleEntryCompatibilityTest();
48
49
String testFile = args[1];
50
String javacdir = args[3];
51
52
test.run(testFile, javacdir);
53
54
}
55
56
public void run(String testFile, String javacpath){
57
58
Properties props = new Properties();
59
try{
60
FileInputStream PropertiesFile = new FileInputStream(testFile);
61
props.load(PropertiesFile);
62
63
PropertiesFile.close();
64
} catch (Exception e){
65
e.printStackTrace();
66
}
67
68
String classPath = props.getProperty("Classpath");
69
String partition = props.getProperty("Partition");
70
71
String ctl = props.getProperty("NumberOfClassesToLoad");
72
Integer intctl = Integer.valueOf(ctl);
73
int numberOfClassesToLoad = intctl.intValue();
74
75
String classesString = props.getProperty("LoadClasses");
76
String [] classesToLoad = new String[numberOfClassesToLoad];
77
for(int index = 0; index < numberOfClassesToLoad; index++){
78
classesToLoad[index] = manipulator.getStringElement(index, classesString);
79
}
80
81
String numberOfUrlsString = props.getProperty("NumberOfUrls");
82
Integer tempNumberOfUrls = Integer.valueOf(numberOfUrlsString);
83
int numberOfUrls = tempNumberOfUrls.intValue();
84
85
int maxClassesToFind = 0;
86
String[] urls = new String[numberOfUrls];
87
String [] partitionStrings = new String[numberOfUrls];
88
for(int index = 0; index < numberOfUrls; index++){
89
urls[index] = props.getProperty("Url"+index);
90
partitionStrings[index] = props.getProperty("urlPartition"+index);
91
String ctf = props.getProperty("NumberOfClassesToFind"+index);
92
Integer intctf = Integer.valueOf(ctl);
93
maxClassesToFind = ((intctl.intValue() > maxClassesToFind) ? intctl.intValue() : maxClassesToFind);
94
}
95
96
String[][] classesToFind = new String[numberOfUrls][maxClassesToFind];
97
String[][] results = new String[numberOfUrls][maxClassesToFind];
98
99
for(int urlIndex = 0; urlIndex < numberOfUrls; urlIndex++){
100
String findClasses = props.getProperty("FindClasses"+urlIndex);
101
String result = props.getProperty("Results"+urlIndex);
102
String ctf = props.getProperty("NumberOfClassesToFind"+urlIndex);
103
Integer intctf = Integer.valueOf(ctf);
104
int numberOfClassesToFind = intctf.intValue();
105
for(int classToFindIndex = 0; classToFindIndex < numberOfClassesToFind; classToFindIndex++){
106
classesToFind[urlIndex][classToFindIndex] = manipulator.getStringElement(classToFindIndex, findClasses);
107
results[urlIndex][classToFindIndex] = manipulator.getStringElement(classToFindIndex, result);
108
}
109
}
110
111
String batchFile = props.getProperty("BatchFileToRun");
112
113
boolean passed = executeTest(classPath, partition, classesToLoad, urls, partitionStrings, classesToFind, results, batchFile, javacpath);
114
115
if(passed){
116
System.out.println("\nTEST PASSED");
117
} else {
118
System.out.println("\nTEST FAILED");
119
}
120
}
121
122
private boolean executeTest(String classPath, String partition, String[] classesToLoad, String[] urls, String[] partitionStrings, String[][] classesToFind, String[][] results, String batchFile, String javacpath) {
123
124
URLClassPathCreator creator = new URLClassPathCreator(classPath);
125
URL[] urlPath;
126
urlPath = creator.createURLClassPath();
127
128
CustomPartitioningURLCL cl = new CustomPartitioningURLCL(urlPath, this.getClass().getClassLoader());
129
cl.setPartition(partition);
130
for(int classIndex = 0; classIndex < classesToLoad.length; classIndex++){
131
String classToLoad = classesToLoad[classIndex];
132
if (classToLoad != null){
133
try{
134
cl.loadClass(classToLoad);
135
} catch (Exception e){
136
e.printStackTrace();
137
}
138
}
139
}
140
141
if(0 != batchFile.length()){
142
runBatchFile(batchFile, javacpath);
143
}
144
145
String urlsString = urls[0];
146
for(int index = 1; index < urls.length; index++){
147
urlsString = new StringBuffer(urls[index].length() + 1).append(urlsString).append(urls[index]).toString();
148
}
149
150
URLClassPathCreator creator2 = new URLClassPathCreator(urlsString);
151
URL[] urlPath2;
152
urlPath2 = creator2.createURLClassPath();
153
CustomPartitioningURLLoader urlcl = new CustomPartitioningURLLoader(urlPath2, this.getClass().getClassLoader());
154
155
boolean result = true;
156
157
for(int urlIndex = 0; urlIndex < urls.length; urlIndex++){
158
urlcl.setPartition(partitionStrings[urlIndex]);
159
for(int classIndex = 0; classIndex < classesToFind[urlIndex].length; classIndex++){
160
String classToFind = classesToFind[urlIndex][classIndex];
161
String expectedResult = results[urlIndex][classIndex];
162
if(classToFind != null){
163
String testResult = String.valueOf(urlcl.isClassInSharedCache(urlIndex, classToFind));
164
if(!(expectedResult.equals(testResult))){
165
System.out.println("\nFailure finding class: "+classToFind+" on path: "+urls[urlIndex]+" which is index: "+urlIndex+" result: "+testResult+" expecting: "+expectedResult);
166
result = false;
167
}
168
}
169
}
170
}
171
return result;
172
}
173
174
private void runBatchFile(String batch, String javacpath){
175
String command = new StringBuffer(batch.length()+javacpath.length()+1).append(batch).append(" ").append(javacpath).toString();
176
System.out.println("\n** Running: "+command);
177
String s = null;
178
try{
179
Process p = Runtime.getRuntime().exec(command);
180
181
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
182
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
183
184
System.out.println("Here is the standard output of the command:\n");
185
while ((s = stdInput.readLine()) != null) {
186
System.out.println(s);
187
}
188
189
System.out.println("Here is the standard error of the command (if any):\n");
190
while ((s = stdError.readLine()) != null) {
191
System.out.println(s);
192
}
193
194
} catch (Exception e){
195
e.printStackTrace();
196
}
197
}
198
}
199
200