blob: 9a31ebfc93c1e75caadd2a9015779a7c7dd22934 [file] [log] [blame]
Kostya Serebryany67af9922018-06-07 01:40:20 +00001# Tests the data flow tracer.
Jonathan Metzmanf7212302019-04-30 17:58:54 +00002REQUIRES: linux, x86_64
Kostya Serebryany67af9922018-06-07 01:40:20 +00003
4# Build the tracer and the test.
Matt Morehousee2d0b442020-07-29 18:58:14 +00005RUN: %no_fuzzer_cpp_compiler -c -fno-sanitize=all -fsanitize=dataflow -mllvm -dfsan-fast-16-labels %S/../../lib/fuzzer/dataflow/DataFlow.cpp -o %t-DataFlow.o
Kostya Serebryany679669a2019-06-21 01:39:35 +00006RUN: %no_fuzzer_cpp_compiler -c -fno-sanitize=all -fPIC %S/../../lib/fuzzer/dataflow/DataFlowCallbacks.cpp -o %t-DataFlowCallbacks.o
Matt Morehousee2d0b442020-07-29 18:58:14 +00007RUN: %no_fuzzer_cpp_compiler -fno-sanitize=all -fsanitize=dataflow -mllvm -dfsan-fast-16-labels -fsanitize-coverage=trace-pc-guard,pc-table,bb,trace-cmp %S/OnlySomeBytesTest.cpp %t-DataFlow*.o -o %t-DFT
Kostya Serebryany67af9922018-06-07 01:40:20 +00008RUN: %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
Kostya Serebryany27cf7432019-06-20 01:48:45 +000019RUN: %t-Fuzz -focus_function='fB(unsigned char const*)' -runs=0 %t/IN 2>&1 | FileCheck %s --check-prefix=FOCUS_fB
20FOCUS_fB: Focus function is set to 'fB(unsigned char const*)'
21
Kostya Serebryany67af9922018-06-07 01:40:20 +000022RUN: %t-Fuzz -focus_function=f0 -runs=0 %t/IN 2>&1 | FileCheck %s --check-prefix=NO_FOCUSED_INPUT
Kostya Serebryany27cf7432019-06-20 01:48:45 +000023NO_FOCUSED_INPUT: Focus function is set to 'f0'
Kostya Serebryany67af9922018-06-07 01:40:20 +000024NO_FOCUSED_INPUT: INFO: 0/2 inputs touch the focus function
25
26RUN: (echo -n ABC; cat %t/IN/12) > %t/IN/ABC
27RUN: %t-Fuzz -focus_function=f0 -runs=0 %t/IN 2>&1 | FileCheck %s --check-prefix=ONE_FOCUSED_INPUT
28ONE_FOCUSED_INPUT: INFO: 1/3 inputs touch the focus function
29
Kostya Serebryany6b87e0c2018-07-19 01:23:32 +000030RUN: rm -rf %t/IN_DFT
Kostya Serebryany27d22b62019-05-14 21:47:35 +000031RUN: %t-Fuzz -collect_data_flow=%t-DFT %t/IN -data_flow_trace=%t/IN_DFT > /dev/null 2>&1
Kostya Serebryany67af9922018-06-07 01:40:20 +000032
Kostya Serebryany6b87e0c2018-07-19 01:23:32 +000033# Repeat twice to make sure that the inputs with DFT are not removed from the corpus.
34RUN: %t-Fuzz -focus_function=f0 -data_flow_trace=%t/IN_DFT -runs=100 %t/IN 2>&1 | FileCheck %s --check-prefix=HAVE_DFT
35RUN: %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 +000036HAVE_DFT: INFO: 1/{{.*}} inputs have the Data Flow Trace
Kostya Serebryany6b87e0c2018-07-19 01:23:32 +000037
38# Collect DFT, then use it.
Kostya Serebryanye9aaa552019-05-09 21:29:45 +000039RUN: rm -rf %t/C %t/C1 && mkdir %t/C %t/C1 && cp %t/IN/* %t/C
Kostya Serebryany27d22b62019-05-14 21:47:35 +000040RUN: 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 Serebryanye9aaa552019-05-09 21:29:45 +000041RUN: 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
42RUN: grep BINGO %t/log
43
Kostya Serebryany27cf7432019-06-20 01:48:45 +000044# Test -focus_function=auto: run 100 times and verify that
45# * 'f0' is the most frequent focus function.
46# * the second most frequent is one of fA/fB/fC in a de-mangled form.
47RUN: %t-Fuzz -focus_function=auto -data_flow_trace=%t/C_DFT -runs=0 %t/C -jobs=100 2>&1 | grep AUTOFOCUS | sort | uniq -c | sort -g -r | head -n 2 | FileCheck %s --check-prefix=AUTOFOCUS
Kostya Serebryanye9aaa552019-05-09 21:29:45 +000048AUTOFOCUS: INFO: AUTOFOCUS: {{.*}} f0
Kostya Serebryany27cf7432019-06-20 01:48:45 +000049AUTOFOCUS: INFO: AUTOFOCUS: {{.*f[ABC]}}(unsigned char const*)
Kostya Serebryanye9aaa552019-05-09 21:29:45 +000050
51# Actually execute 50 fuzzing processes with a small number of runs, to test -focus_function=auto for real.
52# We can not test data_flow_trace=auto in just a single run, because it may choose to focus on a wrong function.
53RUN: 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 Serebryany6b87e0c2018-07-19 01:23:32 +000054RUN: grep BINGO %t/log