Lines 146-152
Link Here
|
146 |
private String getVerifyTestsCode() { |
146 |
private String getVerifyTestsCode() { |
147 |
return |
147 |
return |
148 |
"/*******************************************************************************\n" + |
148 |
"/*******************************************************************************\n" + |
149 |
" * Copyright (c) 2000, 2011 IBM Corporation and others.\n" + |
149 |
" * Copyright (c) 2000, 2012 IBM Corporation and others.\n" + |
150 |
" * All rights reserved. This program and the accompanying materials\n" + |
150 |
" * All rights reserved. This program and the accompanying materials\n" + |
151 |
" * are made available under the terms of the Eclipse Public License v1.0\n" + |
151 |
" * are made available under the terms of the Eclipse Public License v1.0\n" + |
152 |
" * which accompanies this distribution, and is available at\n" + |
152 |
" * which accompanies this distribution, and is available at\n" + |
Lines 162-174
Link Here
|
162 |
"import java.io.File;\n" + |
162 |
"import java.io.File;\n" + |
163 |
"import java.io.FileInputStream;\n" + |
163 |
"import java.io.FileInputStream;\n" + |
164 |
"import java.io.FileNotFoundException;\n" + |
164 |
"import java.io.FileNotFoundException;\n" + |
|
|
165 |
"import java.io.FileWriter;\n" + |
165 |
"import java.io.IOException;\n" + |
166 |
"import java.io.IOException;\n" + |
166 |
"import java.io.InputStream;\n" + |
167 |
"import java.io.InputStream;\n" + |
|
|
168 |
"import java.io.OutputStream;\n" + |
169 |
"import java.io.Writer;\n" + |
167 |
"import java.lang.reflect.InvocationTargetException;\n" + |
170 |
"import java.lang.reflect.InvocationTargetException;\n" + |
168 |
"import java.lang.reflect.Method;\n" + |
171 |
"import java.lang.reflect.Method;\n" + |
169 |
"import java.net.ServerSocket;\n" + |
172 |
"import java.net.ServerSocket;\n" + |
170 |
"import java.net.Socket;\n" + |
173 |
"import java.net.Socket;\n" + |
171 |
"import java.util.StringTokenizer;\n" + |
174 |
"import java.util.StringTokenizer;\n" + |
|
|
175 |
"\n" + |
172 |
"\n" + |
176 |
"\n" + |
173 |
"/******************************************************\n" + |
177 |
"/******************************************************\n" + |
174 |
" *\n" + |
178 |
" *\n" + |
Lines 181-186
Link Here
|
181 |
" int portNumber;\n" + |
185 |
" int portNumber;\n" + |
182 |
" Socket socket;\n" + |
186 |
" Socket socket;\n" + |
183 |
"\n" + |
187 |
"\n" + |
|
|
188 |
" Writer logFile;\n" + |
184 |
"/**\n" + |
189 |
"/**\n" + |
185 |
" * NOTE: Code copied from junit.util.TestCaseClassLoader.\n" + |
190 |
" * NOTE: Code copied from junit.util.TestCaseClassLoader.\n" + |
186 |
" *\n" + |
191 |
" *\n" + |
Lines 230-236
Link Here
|
230 |
" while (st.hasMoreTokens()) {\n" + |
235 |
" while (st.hasMoreTokens()) {\n" + |
231 |
" this.pathItems[i++]= st.nextToken();\n" + |
236 |
" this.pathItems[i++]= st.nextToken();\n" + |
232 |
" }\n" + |
237 |
" }\n" + |
233 |
"\n" + |
|
|
234 |
" }\n" + |
238 |
" }\n" + |
235 |
" public java.net.URL getResource(String name) {\n" + |
239 |
" public java.net.URL getResource(String name) {\n" + |
236 |
" return ClassLoader.getSystemResource(name);\n" + |
240 |
" return ClassLoader.getSystemResource(name);\n" + |
Lines 339-346
Link Here
|
339 |
" throw e.getTargetException();\n" + |
343 |
" throw e.getTargetException();\n" + |
340 |
" }\n" + |
344 |
" }\n" + |
341 |
"}\n" + |
345 |
"}\n" + |
|
|
346 |
"\n" + |
347 |
"VerifyTests(String testName) {\n" + |
348 |
" try {\n" + |
349 |
" logFile = new FileWriter(new File(\"/tmp/test\"+testName+\".log\"));\n" + |
350 |
" } catch (IOException e) {\n" + |
351 |
" }\n" + |
352 |
"}\n" + |
342 |
"public static void main(String[] args) throws IOException {\n" + |
353 |
"public static void main(String[] args) throws IOException {\n" + |
343 |
" VerifyTests verify = new VerifyTests();\n" + |
354 |
" VerifyTests verify = new VerifyTests(args[1]);\n" + |
344 |
" verify.portNumber = Integer.parseInt(args[0]);\n" + |
355 |
" verify.portNumber = Integer.parseInt(args[0]);\n" + |
345 |
" verify.run();\n" + |
356 |
" verify.run();\n" + |
346 |
"}\n" + |
357 |
"}\n" + |
Lines 351-367
Link Here
|
351 |
" server.close();\n" + |
362 |
" server.close();\n" + |
352 |
"\n" + |
363 |
"\n" + |
353 |
" DataInputStream in = new DataInputStream(this.socket.getInputStream());\n" + |
364 |
" DataInputStream in = new DataInputStream(this.socket.getInputStream());\n" + |
354 |
" final DataOutputStream out = new DataOutputStream(this.socket.getOutputStream());\n" + |
365 |
" final OutputStream outputStream = this.socket.getOutputStream();\n" + |
|
|
366 |
" final DataOutputStream out = new DataOutputStream(outputStream);\n" + |
355 |
" while (true) {\n" + |
367 |
" while (true) {\n" + |
356 |
" final String className = in.readUTF();\n" + |
368 |
" final String className = in.readUTF();\n" + |
357 |
" Thread thread = new Thread() {\n" + |
369 |
" Thread thread = new Thread() {\n" + |
358 |
" public void run() {\n" + |
370 |
" public void run() {\n" + |
359 |
" try {\n" + |
371 |
" try {\n" + |
|
|
372 |
" logFile.write(className+\" \"+socket.isClosed()+\"\\n\");\n" + |
373 |
" logFile.flush();\n" + |
360 |
" loadAndRun(className);\n" + |
374 |
" loadAndRun(className);\n" + |
|
|
375 |
" VerifyTests.this.logFile.write(\"\\t \\t-> \"+socket.isClosed()+\"\\n\");\n" + |
376 |
" logFile.flush();\n" + |
361 |
" out.writeBoolean(true);\n" + |
377 |
" out.writeBoolean(true);\n" + |
|
|
378 |
" VerifyTests.this.logFile.write(\"\\t true\\t->\"+socket.isClosed()+\"\\n\");\n" + |
379 |
" logFile.flush();\n" + |
362 |
" System.err.println(VerifyTests.class.getName());\n" + |
380 |
" System.err.println(VerifyTests.class.getName());\n" + |
363 |
" System.out.println(VerifyTests.class.getName());\n" + |
381 |
" System.out.println(VerifyTests.class.getName());\n" + |
364 |
" } catch (Throwable e) {\n" + |
382 |
" } catch (Throwable e) {\n" + |
|
|
383 |
" try {\n" + |
384 |
" logFile.write(\"Exception: \"+e);\n" + |
385 |
" logFile.flush();\n" + |
386 |
" } catch (IOException e2) {\n" + |
387 |
" // nop\n" + |
388 |
" }\n" + |
365 |
" e.printStackTrace();\n" + |
389 |
" e.printStackTrace();\n" + |
366 |
" try {\n" + |
390 |
" try {\n" + |
367 |
" System.err.println(VerifyTests.class.getName());\n" + |
391 |
" System.err.println(VerifyTests.class.getName());\n" + |
Lines 373-378
Link Here
|
373 |
" }\n" + |
397 |
" }\n" + |
374 |
" try {\n" + |
398 |
" try {\n" + |
375 |
" out.flush();\n" + |
399 |
" out.flush();\n" + |
|
|
400 |
" logFile.flush();\n" + |
376 |
" } catch (IOException e) {\n" + |
401 |
" } catch (IOException e) {\n" + |
377 |
" e.printStackTrace();\n" + |
402 |
" e.printStackTrace();\n" + |
378 |
" }\n" + |
403 |
" }\n" + |
Lines 381-387
Link Here
|
381 |
" thread.start();\n" + |
406 |
" thread.start();\n" + |
382 |
" }\n" + |
407 |
" }\n" + |
383 |
"}\n" + |
408 |
"}\n" + |
384 |
"}"; |
409 |
"}\n"; |
385 |
} |
410 |
} |
386 |
private void launchAndRun(String className, String[] classpaths, String[] programArguments, String[] vmArguments) { |
411 |
private void launchAndRun(String className, String[] classpaths, String[] programArguments, String[] vmArguments) { |
387 |
// we won't reuse the vm, shut the existing one if running |
412 |
// we won't reuse the vm, shut the existing one if running |
Lines 450-456
Link Here
|
450 |
} catch (InterruptedException e) { |
475 |
} catch (InterruptedException e) { |
451 |
} |
476 |
} |
452 |
} |
477 |
} |
453 |
private void launchVerifyTestsIfNeeded(String[] classpaths, String[] vmArguments) { |
478 |
private void launchVerifyTestsIfNeeded(String[] classpaths, String[] vmArguments, String testName) { |
454 |
// determine if we can reuse the vm |
479 |
// determine if we can reuse the vm |
455 |
if (this.vm != null && this.vm.isRunning() && this.classpathCache != null) { |
480 |
if (this.vm != null && this.vm.isRunning() && this.classpathCache != null) { |
456 |
if (classpaths.length == this.classpathCache.length) { |
481 |
if (classpaths.length == this.classpathCache.length) { |
Lines 497-503
Link Here
|
497 |
} |
522 |
} |
498 |
launcher.setProgramClass(VerifyTests.class.getName()); |
523 |
launcher.setProgramClass(VerifyTests.class.getName()); |
499 |
int portNumber = Util.getFreePort(); |
524 |
int portNumber = Util.getFreePort(); |
500 |
launcher.setProgramArguments(new String[] {Integer.toString(portNumber)}); |
525 |
launcher.setProgramArguments(new String[] {Integer.toString(portNumber), testName}); |
501 |
try { |
526 |
try { |
502 |
this.vm = launcher.launch(); |
527 |
this.vm = launcher.launch(); |
503 |
final InputStream input = this.vm.getInputStream(); |
528 |
final InputStream input = this.vm.getInputStream(); |
Lines 608-629
Link Here
|
608 |
* Verify that the class files created for the given test file can be loaded by |
633 |
* Verify that the class files created for the given test file can be loaded by |
609 |
* a virtual machine. |
634 |
* a virtual machine. |
610 |
*/ |
635 |
*/ |
611 |
public boolean verifyClassFiles(String sourceFilePath, String className, String expectedSuccessOutputString, String[] classpaths) { |
636 |
public boolean verifyClassFiles(String sourceFilePath, String className, String expectedSuccessOutputString, String[] classpaths, String testName) { |
612 |
return verifyClassFiles(sourceFilePath, className, expectedSuccessOutputString, "", classpaths, null, null); |
637 |
return verifyClassFiles(sourceFilePath, className, expectedSuccessOutputString, "", classpaths, null, null, testName); |
613 |
} |
638 |
} |
614 |
/** |
639 |
/** |
615 |
* Verify that the class files created for the given test file can be loaded by |
640 |
* Verify that the class files created for the given test file can be loaded by |
616 |
* a virtual machine. |
641 |
* a virtual machine. |
617 |
*/ |
642 |
*/ |
618 |
public boolean verifyClassFiles(String sourceFilePath, String className, String expectedSuccessOutputString, String[] classpaths, String[] programArguments, String[] vmArguments) { |
643 |
public boolean verifyClassFiles(String sourceFilePath, String className, String expectedSuccessOutputString, String[] classpaths, String[] programArguments, String[] vmArguments, String testName) { |
619 |
return verifyClassFiles(sourceFilePath, className, expectedSuccessOutputString, "", classpaths, programArguments, vmArguments); |
644 |
return verifyClassFiles(sourceFilePath, className, expectedSuccessOutputString, "", classpaths, programArguments, vmArguments, testName); |
620 |
} |
645 |
} |
621 |
public boolean verifyClassFiles(String sourceFilePath, String className, String expectedOutputString, |
646 |
public boolean verifyClassFiles(String sourceFilePath, String className, String expectedOutputString, |
622 |
String expectedErrorStringStart, String[] classpaths, String[] programArguments, String[] vmArguments) { |
647 |
String expectedErrorStringStart, String[] classpaths, String[] programArguments, String[] vmArguments, String testName) { |
623 |
this.outputBuffer = new StringBuffer(); |
648 |
this.outputBuffer = new StringBuffer(); |
624 |
this.errorBuffer = new StringBuffer(); |
649 |
this.errorBuffer = new StringBuffer(); |
625 |
if (this.reuseVM && programArguments == null) { |
650 |
if (this.reuseVM && programArguments == null) { |
626 |
launchVerifyTestsIfNeeded(classpaths, vmArguments); |
651 |
launchVerifyTestsIfNeeded(classpaths, vmArguments, testName); |
627 |
loadAndRun(className); |
652 |
loadAndRun(className); |
628 |
} else { |
653 |
} else { |
629 |
launchAndRun(className, classpaths, programArguments, vmArguments); |
654 |
launchAndRun(className, classpaths, programArguments, vmArguments); |
Lines 637-647
Link Here
|
637 |
* Verify that the class files created for the given test file can be loaded and run with an expected error contained |
662 |
* Verify that the class files created for the given test file can be loaded and run with an expected error contained |
638 |
* in the expectedSuccessOutputString string. |
663 |
* in the expectedSuccessOutputString string. |
639 |
*/ |
664 |
*/ |
640 |
public boolean verifyClassFilesThrowingError(String sourceFilePath, String className, String expectedSuccessOutputString, String[] classpaths, String[] programArguments, String[] vmArguments) { |
665 |
public boolean verifyClassFilesThrowingError(String sourceFilePath, String className, String expectedSuccessOutputString, String[] classpaths, String[] programArguments, String[] vmArguments, String testName) { |
641 |
this.outputBuffer = new StringBuffer(); |
666 |
this.outputBuffer = new StringBuffer(); |
642 |
this.errorBuffer = new StringBuffer(); |
667 |
this.errorBuffer = new StringBuffer(); |
643 |
if (this.reuseVM && programArguments == null) { |
668 |
if (this.reuseVM && programArguments == null) { |
644 |
launchVerifyTestsIfNeeded(classpaths, vmArguments); |
669 |
launchVerifyTestsIfNeeded(classpaths, vmArguments, testName); |
645 |
loadAndRun(className); |
670 |
loadAndRun(className); |
646 |
} else { |
671 |
} else { |
647 |
launchAndRun(className, classpaths, programArguments, vmArguments); |
672 |
launchAndRun(className, classpaths, programArguments, vmArguments); |