Skip to content

speed up some long running tests #941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions examples/junit/src/test/java/com/example/DictionaryFuzzTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DictionaryFuzzTests {
private static final byte[] FLAG_SHA256 =
Base64.getDecoder().decode("vCLInoVuMxJonT4UKjsMl0LPXTowkYS7t0uBpw0pRo8=");

@DictionaryEntries({"a_", "53Cr\"3T_", "fl4G"})
@DictionaryEntries({"a_53Cr\"3T_fl4G"})
@FuzzTest
public void inlineTest(FuzzedDataProvider data)
throws NoSuchAlgorithmException, TestSuccessfulException {
Expand All @@ -54,15 +54,42 @@ public void fileTest(FuzzedDataProvider data)
}
}

@DictionaryEntries("a_")
/**
* This test uses multiple dictionaries, one of which is loaded on-the-fly. The other two are
* loaded from files. The test will only succeed if entries from all three dictionaries have been
* used at least once to generate fuzzer data input completely.
*/
private static final byte[] ON_THE_FLY_FLAG_SHA256 =
Base64.getDecoder().decode("YgF0VLwI07ls++qMJ/Ptmc9Q7xlIErMXXXK1enpNqKw=");

private static final byte[] FILE_TEST2_FLAG_SHA256 =
Base64.getDecoder().decode("nIQ780j1iRJbOouWMvwhmS63i5lcHlhBf780CFmXvdc=");
private static final byte[] FILE_TEST3_FLAG_SHA256 =
Base64.getDecoder().decode("JR9EuaWZ5hyEHy2Ynfh1KCLI60UL8evAYYTAoJhCcaY=");

private static boolean onTheFlyDictionaryFound =
false; // =o1pPß?1bHJAfas => YgF0VLwI07ls++qMJ/Ptmc9Q7xlIErMXXXK1enpNqKw=
private static boolean fileTest2DictFound =
false; // 0Z1o21ka => nIQ780j1iRJbOouWMvwhmS63i5lcHlhBf780CFmXvdc=
private static boolean fileTest3DictFound =
false; // A)716&=Ko => JR9EuaWZ5hyEHy2Ynfh1KCLI60UL8evAYYTAoJhCcaY=

@DictionaryEntries("=o1pPß?1bHJAfas")
@DictionaryFile(resourcePath = "test2.dict")
@DictionaryFile(resourcePath = "/com/example/test3.dict")
@FuzzTest
public void mixedTest(FuzzedDataProvider data)
throws NoSuchAlgorithmException, TestSuccessfulException {
String s = data.consumeRemainingAsString();
byte[] hash = MessageDigest.getInstance("SHA-256").digest(s.getBytes(StandardCharsets.UTF_8));
if (MessageDigest.isEqual(hash, FLAG_SHA256)) {
if (MessageDigest.isEqual(hash, ON_THE_FLY_FLAG_SHA256)) {
onTheFlyDictionaryFound = true;
} else if (MessageDigest.isEqual(hash, FILE_TEST2_FLAG_SHA256)) {
fileTest2DictFound = true;
} else if (MessageDigest.isEqual(hash, FILE_TEST3_FLAG_SHA256)) {
fileTest3DictFound = true;
}
if (onTheFlyDictionaryFound && fileTest2DictFound && fileTest3DictFound) {
throw new TestSuccessfulException("error found");
}
}
Expand Down
4 changes: 1 addition & 3 deletions examples/junit/src/test/resources/com/example/test.dict
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# test dictionary
"a_"
"53Cr\"3T_"
"fl4G"
"a_53Cr\"3T_fl4G"
2 changes: 1 addition & 1 deletion examples/junit/src/test/resources/com/example/test2.dict
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"53Cr\"3T_"
"0Z1o21ka"
2 changes: 1 addition & 1 deletion examples/junit/src/test/resources/com/example/test3.dict
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"fl4G"
"A)716&=Ko"