diff options
author | Mark <mteffeteller@google.com> | 2023-06-21 23:30:18 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-06-21 23:30:18 +0000 |
commit | 54819157eaa66e14f2c68b54609bd6bfa360b708 (patch) | |
tree | 68cf332a40b94b2d28b256b19b916f99220bb0c4 /src/test/java/com/code_intelligence/jazzer/junit/HermeticInstrumentationTest.java | |
parent | ba37c2e361c2ba91bacc47fcae5383c52e50f6be (diff) | |
parent | e73be1680dae58cb83d869104def1c59102d59b2 (diff) | |
download | jazzer-api-54819157eaa66e14f2c68b54609bd6bfa360b708.tar.gz |
Sync jazzer in AOSP with upstream repo (new SHA: 30decf81a147c66fa5a098072c38ab6924ba0aa6) am: 9350e0ab03 am: 99d9a79746 am: 34a8e5c8aa am: e73be1680d
Original change: https://android-review.googlesource.com/c/platform/external/jazzer-api/+/2627336
Change-Id: I1b97ed5cdcf2adda4d443148cc0d447974e51785
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'src/test/java/com/code_intelligence/jazzer/junit/HermeticInstrumentationTest.java')
-rw-r--r-- | src/test/java/com/code_intelligence/jazzer/junit/HermeticInstrumentationTest.java | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/test/java/com/code_intelligence/jazzer/junit/HermeticInstrumentationTest.java b/src/test/java/com/code_intelligence/jazzer/junit/HermeticInstrumentationTest.java new file mode 100644 index 00000000..dabbf352 --- /dev/null +++ b/src/test/java/com/code_intelligence/jazzer/junit/HermeticInstrumentationTest.java @@ -0,0 +1,108 @@ +// Copyright 2022 Code Intelligence GmbH +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.code_intelligence.jazzer.junit; + +import static org.junit.Assume.assumeTrue; +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; +import static org.junit.platform.testkit.engine.EventConditions.container; +import static org.junit.platform.testkit.engine.EventConditions.displayName; +import static org.junit.platform.testkit.engine.EventConditions.event; +import static org.junit.platform.testkit.engine.EventConditions.finishedSuccessfully; +import static org.junit.platform.testkit.engine.EventConditions.finishedWithFailure; +import static org.junit.platform.testkit.engine.EventConditions.test; +import static org.junit.platform.testkit.engine.EventConditions.type; +import static org.junit.platform.testkit.engine.EventConditions.uniqueIdSubstrings; +import static org.junit.platform.testkit.engine.EventType.DYNAMIC_TEST_REGISTERED; +import static org.junit.platform.testkit.engine.EventType.FINISHED; +import static org.junit.platform.testkit.engine.EventType.REPORTING_ENTRY_PUBLISHED; +import static org.junit.platform.testkit.engine.EventType.STARTED; +import static org.junit.platform.testkit.engine.TestExecutionResultConditions.instanceOf; + +import com.code_intelligence.jazzer.api.FuzzerSecurityIssueLow; +import java.nio.file.Path; +import java.util.regex.PatternSyntaxException; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.platform.testkit.engine.EngineExecutionResults; +import org.junit.platform.testkit.engine.EngineTestKit; +import org.junit.rules.TemporaryFolder; + +public class HermeticInstrumentationTest { + private static final String ENGINE = "engine:junit-jupiter"; + private static final String CLAZZ = "class:com.example.HermeticInstrumentationFuzzTest"; + private static final String FUZZ_TEST_1 = "test-template:fuzzTest1([B)"; + private static final String FUZZ_TEST_2 = "test-template:fuzzTest2([B)"; + private static final String UNIT_TEST_1 = "method:unitTest1()"; + private static final String UNIT_TEST_2 = "method:unitTest2()"; + private static final String INVOCATION = "test-template-invocation:#1"; + @Rule public TemporaryFolder temp = new TemporaryFolder(); + Path baseDir; + + @Before + public void setup() { + baseDir = temp.getRoot().toPath(); + } + + private EngineExecutionResults executeTests() { + return EngineTestKit.engine("junit-jupiter") + .selectors(selectClass("com.example.HermeticInstrumentationFuzzTest")) + .configurationParameter( + "jazzer.instrument", "com.other.package.**,com.example.**,com.yet.another.package.*") + .configurationParameter("jazzer.internal.basedir", baseDir.toAbsolutePath().toString()) + .configurationParameter("junit.jupiter.execution.parallel.enabled", "true") + .execute(); + } + + @Test + public void fuzzingDisabled() { + assumeTrue(System.getenv("JAZZER_FUZZ") == null); + + EngineExecutionResults results = executeTests(); + + results.containerEvents().assertEventsMatchLoosely(event(type(STARTED), container(ENGINE)), + event(type(STARTED), container(uniqueIdSubstrings(ENGINE, CLAZZ))), + event(type(STARTED), container(uniqueIdSubstrings(ENGINE, CLAZZ, FUZZ_TEST_1))), + event(type(REPORTING_ENTRY_PUBLISHED), + container(uniqueIdSubstrings(ENGINE, CLAZZ, FUZZ_TEST_1))), + event(type(FINISHED), container(uniqueIdSubstrings(ENGINE, CLAZZ, FUZZ_TEST_1))), + event(type(STARTED), container(uniqueIdSubstrings(ENGINE, CLAZZ, FUZZ_TEST_2))), + event(type(REPORTING_ENTRY_PUBLISHED), + container(uniqueIdSubstrings(ENGINE, CLAZZ, FUZZ_TEST_2))), + event(type(FINISHED), container(uniqueIdSubstrings(ENGINE, CLAZZ, FUZZ_TEST_2))), + event(type(FINISHED), container(uniqueIdSubstrings(ENGINE, CLAZZ)), finishedSuccessfully()), + event(type(FINISHED), container(ENGINE), finishedSuccessfully())); + + results.testEvents().assertEventsMatchLoosely( + event(type(DYNAMIC_TEST_REGISTERED), test(uniqueIdSubstrings(ENGINE, CLAZZ, FUZZ_TEST_1))), + event(type(STARTED), test(uniqueIdSubstrings(ENGINE, CLAZZ, FUZZ_TEST_1, INVOCATION)), + displayName("<empty input>")), + event(type(FINISHED), test(uniqueIdSubstrings(ENGINE, CLAZZ, FUZZ_TEST_1, INVOCATION)), + displayName("<empty input>"), + finishedWithFailure(instanceOf(FuzzerSecurityIssueLow.class))), + event(type(STARTED), test(uniqueIdSubstrings(ENGINE, CLAZZ, UNIT_TEST_1))), + event(type(FINISHED), test(uniqueIdSubstrings(ENGINE, CLAZZ, UNIT_TEST_1)), + finishedWithFailure(instanceOf(PatternSyntaxException.class))), + event(type(DYNAMIC_TEST_REGISTERED), test(uniqueIdSubstrings(ENGINE, CLAZZ, FUZZ_TEST_2))), + event(type(STARTED), test(uniqueIdSubstrings(ENGINE, CLAZZ, FUZZ_TEST_2, INVOCATION)), + displayName("<empty input>")), + event(type(FINISHED), test(uniqueIdSubstrings(ENGINE, CLAZZ, FUZZ_TEST_2, INVOCATION)), + displayName("<empty input>"), + finishedWithFailure(instanceOf(FuzzerSecurityIssueLow.class))), + event(type(STARTED), test(uniqueIdSubstrings(ENGINE, CLAZZ, UNIT_TEST_2))), + event(type(FINISHED), test(uniqueIdSubstrings(ENGINE, CLAZZ, UNIT_TEST_2)), + finishedWithFailure(instanceOf(PatternSyntaxException.class)))); + } +} |