Kostya Serebryany | 67af992 | 2018-06-07 01:40:20 +0000 | [diff] [blame] | 1 | # Tests the data flow tracer. |
Jonathan Metzman | f721230 | 2019-04-30 17:58:54 +0000 | [diff] [blame] | 2 | REQUIRES: linux, x86_64 |
Kostya Serebryany | 67af992 | 2018-06-07 01:40:20 +0000 | [diff] [blame] | 3 | |
| 4 | # Build the tracer and the test. |
| 5 | RUN: %no_fuzzer_cpp_compiler -c -fno-sanitize=all -fsanitize=dataflow %S/../../lib/fuzzer/dataflow/DataFlow.cpp -o %t-DataFlow.o |
Kostya Serebryany | a27a091 | 2019-05-08 00:43:12 +0000 | [diff] [blame] | 6 | RUN: %no_fuzzer_cpp_compiler -fno-sanitize=all -fsanitize=dataflow -fsanitize-coverage=trace-pc-guard,pc-table,bb,trace-cmp %S/OnlySomeBytesTest.cpp %t-DataFlow.o -o %t-DFT |
Kostya Serebryany | 67af992 | 2018-06-07 01:40:20 +0000 | [diff] [blame] | 7 | RUN: %cpp_compiler %S/OnlySomeBytesTest.cpp -o %t-Fuzz |
| 8 | |
| 9 | # Prepare the inputs. |
Kostya Serebryany | 6b87e0c | 2018-07-19 01:23:32 +0000 | [diff] [blame] | 10 | RUN: rm -rf %t/* |
Kostya Serebryany | 67af992 | 2018-06-07 01:40:20 +0000 | [diff] [blame] | 11 | RUN: mkdir -p %t/IN |
| 12 | RUN: echo -n 0123456789012345678901234567890123456789012345678901234567891234 > %t/IN/6 |
| 13 | RUN: cat %t/IN/6 %t/IN/6 %t/IN/6 %t/IN/6 > %t/IN/8 |
| 14 | RUN: cat %t/IN/8 %t/IN/8 %t/IN/8 %t/IN/8 > %t/IN/10 |
| 15 | RUN: cat %t/IN/10 %t/IN/10 %t/IN/10 %t/IN/10 > %t/IN/12 |
| 16 | # %t/IN/12 is 4096 bytes-long. |
| 17 | |
| 18 | RUN: %t-Fuzz -focus_function=f0 -runs=0 %t/IN 2>&1 | FileCheck %s --check-prefix=NO_FOCUSED_INPUT |
| 19 | NO_FOCUSED_INPUT: INFO: 0/2 inputs touch the focus function |
| 20 | |
| 21 | RUN: (echo -n ABC; cat %t/IN/12) > %t/IN/ABC |
| 22 | RUN: %t-Fuzz -focus_function=f0 -runs=0 %t/IN 2>&1 | FileCheck %s --check-prefix=ONE_FOCUSED_INPUT |
| 23 | ONE_FOCUSED_INPUT: INFO: 1/3 inputs touch the focus function |
| 24 | |
Kostya Serebryany | 6b87e0c | 2018-07-19 01:23:32 +0000 | [diff] [blame] | 25 | RUN: rm -rf %t/IN_DFT |
Kostya Serebryany | 27d22b6 | 2019-05-14 21:47:35 +0000 | [diff] [blame^] | 26 | RUN: %t-Fuzz -collect_data_flow=%t-DFT %t/IN -data_flow_trace=%t/IN_DFT > /dev/null 2>&1 |
Kostya Serebryany | 67af992 | 2018-06-07 01:40:20 +0000 | [diff] [blame] | 27 | |
Kostya Serebryany | 6b87e0c | 2018-07-19 01:23:32 +0000 | [diff] [blame] | 28 | # Repeat twice to make sure that the inputs with DFT are not removed from the corpus. |
| 29 | RUN: %t-Fuzz -focus_function=f0 -data_flow_trace=%t/IN_DFT -runs=100 %t/IN 2>&1 | FileCheck %s --check-prefix=HAVE_DFT |
| 30 | RUN: %t-Fuzz -focus_function=f0 -data_flow_trace=%t/IN_DFT -runs=100 %t/IN 2>&1 | FileCheck %s --check-prefix=HAVE_DFT |
Kostya Serebryany | 67af992 | 2018-06-07 01:40:20 +0000 | [diff] [blame] | 31 | HAVE_DFT: INFO: 1/{{.*}} inputs have the Data Flow Trace |
Kostya Serebryany | 6b87e0c | 2018-07-19 01:23:32 +0000 | [diff] [blame] | 32 | |
| 33 | # Collect DFT, then use it. |
Kostya Serebryany | e9aaa55 | 2019-05-09 21:29:45 +0000 | [diff] [blame] | 34 | RUN: rm -rf %t/C %t/C1 && mkdir %t/C %t/C1 && cp %t/IN/* %t/C |
Kostya Serebryany | 27d22b6 | 2019-05-14 21:47:35 +0000 | [diff] [blame^] | 35 | RUN: rm -rf %t/C_DFT && %t-Fuzz -collect_data_flow=%t-DFT %t/C -data_flow_trace=%t/C_DFT > /dev/null 2>&1 |
Kostya Serebryany | e9aaa55 | 2019-05-09 21:29:45 +0000 | [diff] [blame] | 36 | RUN: not %t-Fuzz -focus_function=f0 -data_flow_trace=%t/C_DFT -seed=1 -runs=1000000 -use_value_profile=1 %t/C1 %t/C 2> %t/log |
| 37 | RUN: grep BINGO %t/log |
| 38 | |
| 39 | # Test -focus_function=auto: run 50 times and verify that 'f0' is the most frequent focus function. |
| 40 | RUN: %t-Fuzz -focus_function=auto -data_flow_trace=%t/C_DFT -runs=0 %t/C -jobs=50 2>&1 | grep AUTOFOCUS | sort | uniq -c | sort -g -r | head -n 1 | FileCheck %s --check-prefix=AUTOFOCUS |
| 41 | AUTOFOCUS: INFO: AUTOFOCUS: {{.*}} f0 |
| 42 | |
| 43 | # Actually execute 50 fuzzing processes with a small number of runs, to test -focus_function=auto for real. |
| 44 | # We can not test data_flow_trace=auto in just a single run, because it may choose to focus on a wrong function. |
| 45 | RUN: not %t-Fuzz -focus_function=auto -data_flow_trace=%t/C_DFT %t/C -jobs=50 -runs=200000 -use_value_profile=1 2> %t/log |
Kostya Serebryany | 6b87e0c | 2018-07-19 01:23:32 +0000 | [diff] [blame] | 46 | RUN: grep BINGO %t/log |