From fdc0ca7ad65dc468647ac0184e04dcc1df05deeb Mon Sep 17 00:00:00 2001 From: attila Date: Wed, 8 May 2013 16:48:33 +0200 Subject: [PATCH] 8014225: Rerun only failed 262 tests Reviewed-by: jlaskey, lagergren --- make/project.properties | 2 + .../framework/AbstractScriptRunnable.java | 2 +- .../test/framework/ParallelTestRunner.java | 59 ++++++++++++++----- .../internal/test/framework/TestConfig.java | 3 + .../internal/test/framework/TestFinder.java | 19 ++++++ 5 files changed, 69 insertions(+), 16 deletions(-) diff --git a/make/project.properties b/make/project.properties index bd4cf5d3..2d66dfef 100644 --- a/make/project.properties +++ b/make/project.properties @@ -194,6 +194,8 @@ test262-test-sys-prop.test.js.enable.strict.mode=true test262-test-sys-prop.test.js.exclude.dir=\ ${test262.suite.dir}/intl402/ +test262-test-sys-prop.test.failed.list.file=${build.dir}/test/failedTests + # test262 test frameworks test262-test-sys-prop.test.js.framework=\ -timezone=PST \ diff --git a/test/src/jdk/nashorn/internal/test/framework/AbstractScriptRunnable.java b/test/src/jdk/nashorn/internal/test/framework/AbstractScriptRunnable.java index 3fd5c218..1d0e6fad 100644 --- a/test/src/jdk/nashorn/internal/test/framework/AbstractScriptRunnable.java +++ b/test/src/jdk/nashorn/internal/test/framework/AbstractScriptRunnable.java @@ -117,7 +117,7 @@ public abstract class AbstractScriptRunnable { // run this test - compile or compile-and-run depending on option passed public void runTest() throws IOException { log(toString()); - + Thread.currentThread().setName(testFile.getPath()); if (shouldRun) { // Analysis of failing tests list - // if test is in failing list it must fail diff --git a/test/src/jdk/nashorn/internal/test/framework/ParallelTestRunner.java b/test/src/jdk/nashorn/internal/test/framework/ParallelTestRunner.java index cc0e1cd3..d4269fce 100644 --- a/test/src/jdk/nashorn/internal/test/framework/ParallelTestRunner.java +++ b/test/src/jdk/nashorn/internal/test/framework/ParallelTestRunner.java @@ -25,6 +25,7 @@ package jdk.nashorn.internal.test.framework; +import static jdk.nashorn.internal.test.framework.TestConfig.TEST_FAILED_LIST_FILE; import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_ENABLE_STRICT_MODE; import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_EXCLUDES_FILE; import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_EXCLUDE_LIST; @@ -37,6 +38,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; @@ -324,7 +326,8 @@ public class ParallelTestRunner { }); } - public void run() { + @SuppressWarnings("resource") + public boolean run() throws IOException { final int testCount = tests.size(); int passCount = 0; int doneCount = 0; @@ -371,23 +374,36 @@ public class ParallelTestRunner { }); boolean hasFailed = false; - for (final ScriptRunnable.Result result : results) { - if (!result.passed()) { - if (hasFailed == false) { - hasFailed = true; - System.out.println(); - System.out.println("FAILED TESTS"); - } + final String failedList = System.getProperty(TEST_FAILED_LIST_FILE); + final boolean hasFailedList = failedList != null; + final boolean hadPreviouslyFailingTests = hasFailedList && new File(failedList).length() > 0; + final FileWriter failedFileWriter = hasFailedList ? new FileWriter(failedList) : null; + try { + final PrintWriter failedListWriter = failedFileWriter == null ? null : new PrintWriter(failedFileWriter); + for (final ScriptRunnable.Result result : results) { + if (!result.passed()) { + if (hasFailed == false) { + hasFailed = true; + System.out.println(); + System.out.println("FAILED TESTS"); + } - System.out.println(result.getTest()); - if (result.exception != null) { - final String exceptionString = result.exception instanceof TestFailedError ? result.exception.getMessage() : result.exception.toString(); - System.out.print(exceptionString.endsWith("\n") ? exceptionString : exceptionString + "\n"); - System.out.print(result.out != null ? result.out : ""); + System.out.println(result.getTest()); + if(failedFileWriter != null) { + failedListWriter.println(result.getTest().testFile.getPath()); + } + if (result.exception != null) { + final String exceptionString = result.exception instanceof TestFailedError ? result.exception.getMessage() : result.exception.toString(); + System.out.print(exceptionString.endsWith("\n") ? exceptionString : exceptionString + "\n"); + System.out.print(result.out != null ? result.out : ""); + } } } + } finally { + if(failedFileWriter != null) { + failedFileWriter.close(); + } } - final double timeElapsed = (System.nanoTime() - startTime) / 1e9; // [s] System.out.printf("Tests run: %d/%d tests, passed: %d (%.2f%%), failed: %d. Time elapsed: %.0fmin %.0fs.\n", doneCount, testCount, passCount, 100d * passCount / doneCount, doneCount - passCount, timeElapsed / 60, timeElapsed % 60); System.out.flush(); @@ -397,12 +413,25 @@ public class ParallelTestRunner { if (hasFailed) { throw new AssertionError("TEST FAILED"); } + + if(hasFailedList) { + new File(failedList).delete(); + } + + if(hadPreviouslyFailingTests) { + System.out.println(); + System.out.println("Good job on getting all your previously failing tests pass!"); + System.out.println("NOW re-running all tests to make sure you haven't caused any NEW test failures."); + System.out.println(); + } + + return hadPreviouslyFailingTests; } public static void main(final String[] args) throws Exception { parseArgs(args); - new ParallelTestRunner().run(); + while(new ParallelTestRunner().run()); } private static void parseArgs(final String[] args) { diff --git a/test/src/jdk/nashorn/internal/test/framework/TestConfig.java b/test/src/jdk/nashorn/internal/test/framework/TestConfig.java index cf798f67..05d59dc1 100644 --- a/test/src/jdk/nashorn/internal/test/framework/TestConfig.java +++ b/test/src/jdk/nashorn/internal/test/framework/TestConfig.java @@ -72,4 +72,7 @@ public interface TestConfig { // shared context mode or not static final String TEST_JS_SHARED_CONTEXT = "test.js.shared.context"; + + // file for storing last run's failed tests + static final String TEST_FAILED_LIST_FILE = "test.failed.list.file"; } diff --git a/test/src/jdk/nashorn/internal/test/framework/TestFinder.java b/test/src/jdk/nashorn/internal/test/framework/TestFinder.java index a326a599..776c4e7a 100644 --- a/test/src/jdk/nashorn/internal/test/framework/TestFinder.java +++ b/test/src/jdk/nashorn/internal/test/framework/TestFinder.java @@ -31,6 +31,7 @@ import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_EXPECT_COMP import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_EXPECT_RUN_FAIL; import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_IGNORE_STD_ERROR; import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_RUN; +import static jdk.nashorn.internal.test.framework.TestConfig.TEST_FAILED_LIST_FILE; import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_ENABLE_STRICT_MODE; import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_EXCLUDES_FILE; import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_EXCLUDE_DIR; @@ -41,7 +42,9 @@ import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_LIST; import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_ROOTS; import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_UNCHECKED_DIR; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; import java.io.IOException; import java.nio.file.FileSystem; import java.nio.file.FileSystems; @@ -86,6 +89,22 @@ final class TestFinder { static void findAllTests(final List tests, final Set orphans, final TestFactory testFactory) throws Exception { final String framework = System.getProperty(TEST_JS_FRAMEWORK); final String testList = System.getProperty(TEST_JS_LIST); + final String failedTestFileName = System.getProperty(TEST_FAILED_LIST_FILE); + if(failedTestFileName != null) { + File failedTestFile = new File(failedTestFileName); + if(failedTestFile.exists() && failedTestFile.length() > 0L) { + try(final BufferedReader r = new BufferedReader(new FileReader(failedTestFile))) { + for(;;) { + final String testFileName = r.readLine(); + if(testFileName == null) { + break; + } + handleOneTest(framework, new File(testFileName).toPath(), tests, orphans, testFactory); + } + } + return; + } + } if (testList == null || testList.length() == 0) { // Run the tests under the test roots dir, selected by the // TEST_JS_INCLUDES patterns -- GitLab