summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/test
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-10-19 00:12:03 +0000
committerKostya Serebryany <kcc@google.com>2016-10-19 00:12:03 +0000
commit95b1a434d2d2bc03ea6f8470a98189f8429c9720 (patch)
tree3283d29b1c79349074e0a09a994a18c78470e7ad /llvm/lib/Fuzzer/test
parentd3fd70dedd75f9b27f7198840a1ada82d54b95ab (diff)
downloadbcm5719-llvm-95b1a434d2d2bc03ea6f8470a98189f8429c9720.tar.gz
bcm5719-llvm-95b1a434d2d2bc03ea6f8470a98189f8429c9720.zip
[libFuzzer] extend -print_coverage to also print uncovered lines, functions, and files.
Example of output: COVERAGE: COVERED: in DSO2(int) /pathto/DSO2.cpp:6 COVERED: in DSO2(int) /pathto/DSO2.cpp:8 COVERED: in DSO1(int) /pathto/DSO1.cpp:6 COVERED: in DSO1(int) /pathto/DSO1.cpp:8 COVERED: in LLVMFuzzerTestOneInput /pathto/DSOTestMain.cpp:16 COVERED: in LLVMFuzzerTestOneInput /pathto/DSOTestMain.cpp:19 COVERED: in LLVMFuzzerTestOneInput /pathto/DSOTestMain.cpp:25 COVERED: in LLVMFuzzerTestOneInput /pathto/DSOTestMain.cpp:26 MODULE_WITH_COVERAGE: /pathto/libLLVMFuzzer-DSO1.so UNCOVERED_LINE: in DSO1(int) /pathto/DSO1.cpp:9 UNCOVERED_FUNC: in Uncovered1() MODULE_WITH_COVERAGE: /pathto/libLLVMFuzzer-DSO2.so UNCOVERED_LINE: in DSO2(int) /pathto/DSO2.cpp:9 UNCOVERED_FUNC: in Uncovered2() MODULE_WITH_COVERAGE: /pathto/LLVMFuzzer-DSOTest UNCOVERED_LINE: in LLVMFuzzerTestOneInput /pathto/DSOTestMain.cpp:21 UNCOVERED_LINE: in LLVMFuzzerTestOneInput /pathto/DSOTestMain.cpp:27 UNCOVERED_FILE: /pathto/DSOTestExtra.cpp Several things are not perfect here: * we are using objdump+awk instead of sancov because sancov does not support DSOs yet. * this breaks in the presence of ASAN_OPTIONS=strip_path_prefix=... (need to implement another API to get the module name by PC) llvm-svn: 284554
Diffstat (limited to 'llvm/lib/Fuzzer/test')
-rw-r--r--llvm/lib/Fuzzer/test/DSO1.cpp1
-rw-r--r--llvm/lib/Fuzzer/test/DSO2.cpp1
-rw-r--r--llvm/lib/Fuzzer/test/DSOTestMain.cpp16
-rw-r--r--llvm/lib/Fuzzer/test/coverage.test12
4 files changed, 24 insertions, 6 deletions
diff --git a/llvm/lib/Fuzzer/test/DSO1.cpp b/llvm/lib/Fuzzer/test/DSO1.cpp
index c362593f779..4a293890f4b 100644
--- a/llvm/lib/Fuzzer/test/DSO1.cpp
+++ b/llvm/lib/Fuzzer/test/DSO1.cpp
@@ -9,3 +9,4 @@ int DSO1(int a) {
return 1;
}
+void Uncovered1() { }
diff --git a/llvm/lib/Fuzzer/test/DSO2.cpp b/llvm/lib/Fuzzer/test/DSO2.cpp
index 46c80e4b6fe..04b308d193a 100644
--- a/llvm/lib/Fuzzer/test/DSO2.cpp
+++ b/llvm/lib/Fuzzer/test/DSO2.cpp
@@ -9,3 +9,4 @@ int DSO2(int a) {
return 1;
}
+void Uncovered2() {}
diff --git a/llvm/lib/Fuzzer/test/DSOTestMain.cpp b/llvm/lib/Fuzzer/test/DSOTestMain.cpp
index 49cd185e97d..3e225d88612 100644
--- a/llvm/lib/Fuzzer/test/DSOTestMain.cpp
+++ b/llvm/lib/Fuzzer/test/DSOTestMain.cpp
@@ -11,17 +11,21 @@ extern int DSO1(int a);
extern int DSO2(int a);
extern int DSOTestExtra(int a);
+static volatile int *nil = 0;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
- if (Size < sizeof(int) * 3) return 0;
int x, y, z;
- memcpy(&x, Data + 0 * sizeof(int), sizeof(int));
- memcpy(&y, Data + 1 * sizeof(int), sizeof(int));
- memcpy(&z, Data + 2 * sizeof(int), sizeof(int));
- int sum = DSO1(x) + DSO2(y) + DSOTestExtra(z);
+ if (Size < sizeof(int) * 3) {
+ x = y = z = 0;
+ } else {
+ memcpy(&x, Data + 0 * sizeof(int), sizeof(int));
+ memcpy(&y, Data + 1 * sizeof(int), sizeof(int));
+ memcpy(&z, Data + 2 * sizeof(int), sizeof(int));
+ }
+ int sum = DSO1(x) + DSO2(y) + (z ? DSOTestExtra(z) : 0);
if (sum == 3) {
fprintf(stderr, "BINGO %d %d %d\n", x, y, z);
- exit(1);
+ *nil = 0;
}
return 0;
}
diff --git a/llvm/lib/Fuzzer/test/coverage.test b/llvm/lib/Fuzzer/test/coverage.test
index f6b43048417..b41a262c462 100644
--- a/llvm/lib/Fuzzer/test/coverage.test
+++ b/llvm/lib/Fuzzer/test/coverage.test
@@ -4,3 +4,15 @@ CHECK-DAG: COVERED: {{.*}}in LLVMFuzzerTestOneInput {{.*}}NullDerefTest.cpp:14
CHECK-DAG: COVERED: {{.*}}in LLVMFuzzerTestOneInput {{.*}}NullDerefTest.cpp:16
CHECK-DAG: COVERED: {{.*}}in LLVMFuzzerTestOneInput {{.*}}NullDerefTest.cpp:19
RUN: not LLVMFuzzer-NullDerefTest-TracePC -print_coverage=1 2>&1 | FileCheck %s
+
+RUN: LLVMFuzzer-DSOTest -print_coverage=1 -runs=0 2>&1 | FileCheck %s --check-prefix=DSO
+DSO: COVERAGE:
+DSO-DAG: COVERED:{{.*}}DSO1{{.*}}DSO1.cpp
+DSO-DAG: COVERED:{{.*}}DSO2{{.*}}DSO2.cpp
+DSO-DAG: COVERED:{{.*}}LLVMFuzzerTestOneInput{{.*}}DSOTestMain
+DSO-DAG: UNCOVERED_LINE:{{.*}}DSO1{{.*}}DSO1.cpp
+DSO-DAG: UNCOVERED_LINE:{{.*}}DSO2{{.*}}DSO2.cpp
+DSO-DAG: UNCOVERED_FUNC: in Uncovered1
+DSO-DAG: UNCOVERED_FUNC: in Uncovered2
+DSO-DAG: UNCOVERED_LINE: in LLVMFuzzerTestOneInput
+DSO-DAG: UNCOVERED_FILE:{{.*}}DSOTestExtra.cpp
OpenPOWER on IntegriCloud