Stop CaliperRunner ignoring errors
CaliperRunner printed out the stack trace of exceptions thrown
by Caliper itself but otherwise ignored them. This treats them
as failures.
Change-Id: If20d7b58c17dc11248a0adadb2db36e1c43a85d3
diff --git a/src/vogar/target/CaliperRunner.java b/src/vogar/target/CaliperRunner.java
index 1d760b7..eb752a6 100644
--- a/src/vogar/target/CaliperRunner.java
+++ b/src/vogar/target/CaliperRunner.java
@@ -67,13 +67,15 @@
}
ImmutableList<String> argList = builder.build();
String[] arguments = argList.toArray(new String[argList.size()]);
+ Result result = Result.EXEC_FAILED;
try {
if (profiler != null) {
profiler.start();
}
- PrintWriter stdout = new PrintWriter(System.out);
- PrintWriter stderr = new PrintWriter(System.err);
- CaliperMain.exitlessMain(arguments, stdout, stderr);
+ PrintWriter stdout = new PrintWriter(System.out);
+ PrintWriter stderr = new PrintWriter(System.err);
+ CaliperMain.exitlessMain(arguments, stdout, stderr);
+ result = Result.SUCCESS;
} catch (Exception ex) {
ex.printStackTrace();
} finally {
@@ -81,7 +83,7 @@
profiler.stop();
}
}
- monitor.outcomeFinished(Result.SUCCESS);
+ monitor.outcomeFinished(result);
return true;
}
}
diff --git a/test/vogar/target/TestRunnerTest.java b/test/vogar/target/TestRunnerTest.java
index bcf9ca6..ab93c9e 100644
--- a/test/vogar/target/TestRunnerTest.java
+++ b/test/vogar/target/TestRunnerTest.java
@@ -105,7 +105,8 @@
}
}
- @TestRunnerProperties(testClass = CaliperBenchmark.class, runnerType = RunnerType.CALIPER)
+ @TestRunnerProperties(testClass = CaliperBenchmarkFailing.class,
+ runnerType = RunnerType.CALIPER)
@Test
public void testConstructor_CaliperBenchmark() throws Exception {
TestRunner runner = testRunnerRule.createTestRunner("-i", "runtime");
@@ -115,7 +116,7 @@
// Remove stack trace from output.
out = out.replaceAll("\t[^\n]+\\n", "");
assertEquals(""
- + "//00xx{\"outcome\":\"" + CaliperBenchmark.class.getName() + "\"}\n"
+ + "//00xx{\"outcome\":\"" + CaliperBenchmarkFailing.class.getName() + "\"}\n"
+ "Experiment selection: \n"
+ " Benchmark Methods: [timeMethod]\n"
+ " Instruments: [runtime]\n"
@@ -128,10 +129,20 @@
+ ": An exception was thrown from the benchmark code\n"
+ "Caused by: " + IllegalStateException.class.getName()
+ ": " + CaliperBenchmark.CALIPER_BENCHMARK_MESSAGE + "\n"
- + "//00xx{\"result\":\"SUCCESS\"}\n"
+ + "//00xx{\"result\":\"EXEC_FAILED\"}\n"
+ "//00xx{\"completedNormally\":true}\n", out);
}
+ public static class CaliperBenchmarkFailing {
+
+ static final String CALIPER_BENCHMARK_MESSAGE = "Aborting test to save time";
+
+ @Benchmark
+ public long timeMethod(long reps) {
+ throw new IllegalStateException(CALIPER_BENCHMARK_MESSAGE);
+ }
+ }
+
/**
* Ensure that requesting profiling doesn't send an invalid option to Caliper.
*
@@ -166,10 +177,7 @@
+ " Selection type: Full cartesian product\n"
+ "\n"
+ "This selection yields 1 experiments.\n"
- + UserCodeException.class.getName()
- + ": An exception was thrown from the benchmark code\n"
- + "Caused by: " + IllegalStateException.class.getName()
- + ": " + CaliperBenchmark.CALIPER_BENCHMARK_MESSAGE + "\n"
+ + "1\n"
+ "//00xx{\"result\":\"SUCCESS\"}\n"
+ "//00xx{\"completedNormally\":true}\n", out);
}
@@ -180,7 +188,8 @@
@Benchmark
public long timeMethod(long reps) {
- throw new IllegalStateException(CALIPER_BENCHMARK_MESSAGE);
+ System.out.println(reps);
+ return reps;
}
}