summaryrefslogtreecommitdiff
path: root/chapter15
diff options
context:
space:
mode:
Diffstat (limited to 'chapter15')
-rw-r--r--chapter15/Makefile5
-rw-r--r--chapter15/src/test/java/com/seaofnodes/simple/FuzzerWrap.java23
-rw-r--r--chapter15/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java14
3 files changed, 37 insertions, 5 deletions
diff --git a/chapter15/Makefile b/chapter15/Makefile
index c7724bc7..ed0a03c9 100644
--- a/chapter15/Makefile
+++ b/chapter15/Makefile
@@ -1,4 +1,5 @@
SHELL := /bin/bash
+# Shared packaging target; included after chapter source variables below.
.DELETE_ON_ERROR:
# for printing variable values
@@ -67,7 +68,7 @@ JVM=nice java -ea -cp "build/classes/main${SEP}${jars}${SEP}$(CLZDIR)/test"
tests: $(default_targets)
@echo "testing " $(test_cp)
- @$(JVM) org.junit.runner.JUnitCore $(test_cp)
+ @$(JVM) org.junit.runner.JUnitCore $(test_cp) com.seaofnodes.simple.FuzzerWrap
fuzzer: $(default_targets)
@echo "fuzzing " $(test_cp)
@@ -96,3 +97,5 @@ lib/hamcrest-core-1.3.jar:
tags: $(main_javas) $(test_javas)
@rm -f TAGS
@$(CTAGS) -e --recurse=yes --extra=+q --fields=+fksaiS $(SRC) $(TST)
+
+include ../build-support/chapter-release.mk
diff --git a/chapter15/src/test/java/com/seaofnodes/simple/FuzzerWrap.java b/chapter15/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
index 699711fc..52c2a014 100644
--- a/chapter15/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
+++ b/chapter15/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
@@ -8,15 +8,30 @@ import org.junit.Ignore;
import static org.junit.Assert.assertTrue;
/**
- * To use the fuzzer run the <code>fuzzPeeps</code> methods.
- * This can be done from IntelliJ Gui or remove the `@Ignore` annotation and start the test case from the command line
- * via <code>mvn clean test -Dtest=com.seaofnodes.simple.Fuzzer08Test#fuzzPeeps</code>
+ * Normal tests run chapter-local regression seeds. Open failures and exploratory
+ * fuzzing are opt-in (run directly in the IDE or temporarily remove Ignore).
+ * Seeds depend on this chapter's generator; do not copy them between chapters.
*/
public class FuzzerWrap {
+ private static final long[] REGRESSION_SEEDS = {
+ };
+
+ private static final long[] OPEN_FAILING_SEEDS = {
+ };
+
+ @Test public void fuzzPeepsRegression () { fuzzPeepsSeeds(REGRESSION_SEEDS); }
+ @Test @Ignore public void fuzzPeepsOpenFailures() { fuzzPeepsSeeds(OPEN_FAILING_SEEDS); }
+
+ private static void fuzzPeepsSeeds(long... seeds) {
+ var fuzzer = new Fuzzer();
+ for (long seed : seeds)
+ fuzzer.fuzzPeepsRegression(seed);
+ }
+
@Ignore
@Test
- public void fuzzPeeps() {
+ public void fuzzPeepsLarge() {
var fuzzer = new Fuzzer();
for (int i=0; i<1000000; i++)
fuzzer.fuzzPeeps(i);
diff --git a/chapter15/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java b/chapter15/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
index 51e39cd0..a82a7517 100644
--- a/chapter15/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
+++ b/chapter15/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
@@ -182,4 +182,18 @@ public class Fuzzer {
public boolean noExceptions() {
return exceptions.isEmpty();
}
+
+ /** Run a fixed chapter-local seed without reducing or swallowing failures. */
+ public void fuzzPeepsRegression(long seed) {
+ var rand = new Random(seed);
+ var sb = new StringBuilder();
+ var valid = new ScriptGenerator(rand, sb, true).genProgram();
+ try {
+ runCheck(sb.toString(), valid);
+ } catch (Throwable e) {
+ AssertionError ae = new AssertionError("Fuzzer regression seed failed: " + seed);
+ ae.initCause(e);
+ throw ae;
+ }
+ }
}