blob: 861718384080ac2f852498418b0370fc42cedc54 [file] [log] [blame]
Kostya Serebryany67af9922018-06-07 01:40:20 +00001# Tests the data flow tracer.
2REQUIRES: linux
Kostya Serebryany79bd1472018-07-19 01:54:28 +00003UNSUPPORTED: aarch64
Kostya Serebryany67af9922018-06-07 01:40:20 +00004
5# Build the tracer and the test.
6RUN: %no_fuzzer_cpp_compiler -c -fno-sanitize=all -fsanitize=dataflow %S/../../lib/fuzzer/dataflow/DataFlow.cpp -o %t-DataFlow.o
7RUN: %no_fuzzer_cpp_compiler -fno-sanitize=all -fsanitize=dataflow -fsanitize-coverage=trace-pc-guard,pc-table,func,trace-cmp %S/OnlySomeBytesTest.cpp %t-DataFlow.o -o %t-DFT
8RUN: %cpp_compiler %S/OnlySomeBytesTest.cpp -o %t-Fuzz
9
10# Prepare the inputs.
Kostya Serebryany6b87e0c2018-07-19 01:23:32 +000011RUN: rm -rf %t/*
Kostya Serebryany67af9922018-06-07 01:40:20 +000012RUN: mkdir -p %t/IN
13RUN: echo -n 0123456789012345678901234567890123456789012345678901234567891234 > %t/IN/6
14RUN: cat %t/IN/6 %t/IN/6 %t/IN/6 %t/IN/6 > %t/IN/8
15RUN: cat %t/IN/8 %t/IN/8 %t/IN/8 %t/IN/8 > %t/IN/10
16RUN: cat %t/IN/10 %t/IN/10 %t/IN/10 %t/IN/10 > %t/IN/12
17# %t/IN/12 is 4096 bytes-long.
18
19RUN: %t-Fuzz -focus_function=f0 -runs=0 %t/IN 2>&1 | FileCheck %s --check-prefix=NO_FOCUSED_INPUT
20NO_FOCUSED_INPUT: INFO: 0/2 inputs touch the focus function
21
22RUN: (echo -n ABC; cat %t/IN/12) > %t/IN/ABC
23RUN: %t-Fuzz -focus_function=f0 -runs=0 %t/IN 2>&1 | FileCheck %s --check-prefix=ONE_FOCUSED_INPUT
24ONE_FOCUSED_INPUT: INFO: 1/3 inputs touch the focus function
25
Kostya Serebryany6b87e0c2018-07-19 01:23:32 +000026RUN: rm -rf %t/IN_DFT
27RUN: %libfuzzer_src/scripts/collect_data_flow.py %t-DFT %t/IN %t/IN_DFT > /dev/null 2>&1
Kostya Serebryany67af9922018-06-07 01:40:20 +000028
Kostya Serebryany6b87e0c2018-07-19 01:23:32 +000029# Repeat twice to make sure that the inputs with DFT are not removed from the corpus.
30RUN: %t-Fuzz -focus_function=f0 -data_flow_trace=%t/IN_DFT -runs=100 %t/IN 2>&1 | FileCheck %s --check-prefix=HAVE_DFT
31RUN: %t-Fuzz -focus_function=f0 -data_flow_trace=%t/IN_DFT -runs=100 %t/IN 2>&1 | FileCheck %s --check-prefix=HAVE_DFT
Kostya Serebryany67af9922018-06-07 01:40:20 +000032HAVE_DFT: INFO: 1/{{.*}} inputs have the Data Flow Trace
Kostya Serebryany6b87e0c2018-07-19 01:23:32 +000033
34# Collect DFT, then use it.
35RUN: rm -rf %t/C && mkdir %t/C && cp %t/IN/* %t/C
36RUN: rm -rf %t/C_DFT && %libfuzzer_src/scripts/collect_data_flow.py %t-DFT %t/C %t/C_DFT > /dev/null 2>&1
Kostya Serebryanycedebd52018-08-02 00:24:49 +000037RUN: not %t-Fuzz -focus_function=f0 -data_flow_trace=%t/C_DFT -seed=1 -runs=1000000 -use_value_profile=1 %t/C 2> %t/log
Kostya Serebryany6b87e0c2018-07-19 01:23:32 +000038RUN: grep BINGO %t/log