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