diff options
author | 2022-06-07 20:12:06 +0000 | |
---|---|---|
committer | 2022-07-12 01:20:17 +0000 | |
commit | f4b1c3a7a75fdbdf755d10f476d782c2ffe641c7 (patch) | |
tree | 852f385adb48640b277c96d8af8208771f4a269b /cc/cc_test.go | |
parent | 87d74dc54e41ef9e9077834136fd8dffc1d84f99 (diff) |
Adding support for building AFLpp
Test: Build AFL fuzzers locally and ran them
Change-Id: Ie07ec336892649192a844a4d0d231196673e34a0
Diffstat (limited to 'cc/cc_test.go')
-rw-r--r-- | cc/cc_test.go | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/cc/cc_test.go b/cc/cc_test.go index b6d196cc2..24732bf7d 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -3342,6 +3342,125 @@ func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) { `) } +func TestAFLFuzzTarget(t *testing.T) { + ctx := testCc(t, ` + cc_afl_fuzz { + name: "test_afl_fuzz_target", + srcs: ["foo.c"], + host_supported: true, + static_libs: [ + "afl_fuzz_static_lib", + ], + shared_libs: [ + "afl_fuzz_shared_lib", + ], + } + cc_fuzz { + name: "test_fuzz_target", + srcs: ["foo.c"], + static_libs: [ + "afl_fuzz_static_lib", + "libfuzzer_only_static_lib", + ], + shared_libs: [ + "afl_fuzz_shared_lib", + ], + } + cc_library { + name: "afl_fuzz_static_lib", + host_supported: true, + srcs: ["static_file.c"], + } + cc_library { + name: "libfuzzer_only_static_lib", + host_supported: true, + srcs: ["static_file.c"], + } + cc_library { + name: "afl_fuzz_shared_lib", + host_supported: true, + srcs: ["shared_file.c"], + static_libs: [ + "second_static_lib", + ], + } + cc_library_headers { + name: "libafl_headers", + vendor_available: true, + host_supported: true, + export_include_dirs: [ + "include", + "instrumentation", + ], + } + cc_object { + name: "afl-compiler-rt", + vendor_available: true, + host_supported: true, + cflags: [ + "-fPIC", + ], + srcs: [ + "instrumentation/afl-compiler-rt.o.c", + ], + } + cc_library { + name: "second_static_lib", + host_supported: true, + srcs: ["second_file.c"], + } + filegroup { + name: "aflpp_driver", + srcs: [ + "aflpp_driver.c", + ], + }`) + + checkPcGuardFlag := func( + modName string, variantName string, shouldHave bool) { + cc := ctx.ModuleForTests(modName, variantName).Rule("cc") + + cFlags, ok := cc.Args["cFlags"] + if !ok { + t.Errorf("Could not find cFlags for module %s and variant %s", + modName, variantName) + } + + if strings.Contains( + cFlags, "-fsanitize-coverage=trace-pc-guard") != shouldHave { + t.Errorf("Flag was found: %t. Expected to find flag: %t. "+ + "Test failed for module %s and variant %s", + !shouldHave, shouldHave, modName, variantName) + } + } + + for _, vnt := range ctx.ModuleVariantsForTests("libfuzzer_only_static_lib") { + if strings.Contains(vnt, "fuzzer_afl") { + t.Errorf("libfuzzer_only_static_lib has afl variant and should not") + } + } + + moduleName := "test_afl_fuzz_target" + variantName := "android_arm64_armv8-a_fuzzer_afl" + checkPcGuardFlag(moduleName, variantName, true) + + moduleName = "afl_fuzz_static_lib" + variantName = "android_arm64_armv8-a_static" + checkPcGuardFlag(moduleName, variantName, false) + checkPcGuardFlag(moduleName, variantName+"_fuzzer", false) + checkPcGuardFlag(moduleName, variantName+"_fuzzer_afl", true) + + moduleName = "second_static_lib" + checkPcGuardFlag(moduleName, variantName, false) + checkPcGuardFlag(moduleName, variantName+"_fuzzer", false) + checkPcGuardFlag(moduleName, variantName+"_fuzzer_afl", true) + + ctx.ModuleForTests("afl_fuzz_shared_lib", + "android_arm64_armv8-a_shared").Rule("cc") + ctx.ModuleForTests("afl_fuzz_shared_lib", + "android_arm64_armv8-a_shared_fuzzer_afl").Rule("cc") +} + // Simple smoke test for the cc_fuzz target that ensures the rule compiles // correctly. func TestFuzzTarget(t *testing.T) { |