comparison compiler-rt/test/fuzzer/only-some-bytes.test @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children 2e18cbf3894f
comparison
equal deleted inserted replaced
147:c2174574ed3a 150:1d019706d866
1 # Tests the data flow tracer.
2 REQUIRES: linux, x86_64
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
6 RUN: %no_fuzzer_cpp_compiler -c -fno-sanitize=all -fPIC %S/../../lib/fuzzer/dataflow/DataFlowCallbacks.cpp -o %t-DataFlowCallbacks.o
7 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
8 RUN: %cpp_compiler %S/OnlySomeBytesTest.cpp -o %t-Fuzz
9
10 # Prepare the inputs.
11 RUN: rm -rf %t/*
12 RUN: mkdir -p %t/IN
13 RUN: echo -n 0123456789012345678901234567890123456789012345678901234567891234 > %t/IN/6
14 RUN: cat %t/IN/6 %t/IN/6 %t/IN/6 %t/IN/6 > %t/IN/8
15 RUN: cat %t/IN/8 %t/IN/8 %t/IN/8 %t/IN/8 > %t/IN/10
16 RUN: 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
19 RUN: %t-Fuzz -focus_function='fB(unsigned char const*)' -runs=0 %t/IN 2>&1 | FileCheck %s --check-prefix=FOCUS_fB
20 FOCUS_fB: Focus function is set to 'fB(unsigned char const*)'
21
22 RUN: %t-Fuzz -focus_function=f0 -runs=0 %t/IN 2>&1 | FileCheck %s --check-prefix=NO_FOCUSED_INPUT
23 NO_FOCUSED_INPUT: Focus function is set to 'f0'
24 NO_FOCUSED_INPUT: INFO: 0/2 inputs touch the focus function
25
26 RUN: (echo -n ABC; cat %t/IN/12) > %t/IN/ABC
27 RUN: %t-Fuzz -focus_function=f0 -runs=0 %t/IN 2>&1 | FileCheck %s --check-prefix=ONE_FOCUSED_INPUT
28 ONE_FOCUSED_INPUT: INFO: 1/3 inputs touch the focus function
29
30 RUN: rm -rf %t/IN_DFT
31 RUN: %t-Fuzz -collect_data_flow=%t-DFT %t/IN -data_flow_trace=%t/IN_DFT > /dev/null 2>&1
32
33 # Repeat twice to make sure that the inputs with DFT are not removed from the corpus.
34 RUN: %t-Fuzz -focus_function=f0 -data_flow_trace=%t/IN_DFT -runs=100 %t/IN 2>&1 | FileCheck %s --check-prefix=HAVE_DFT
35 RUN: %t-Fuzz -focus_function=f0 -data_flow_trace=%t/IN_DFT -runs=100 %t/IN 2>&1 | FileCheck %s --check-prefix=HAVE_DFT
36 HAVE_DFT: INFO: 1/{{.*}} inputs have the Data Flow Trace
37
38 # Collect DFT, then use it.
39 RUN: rm -rf %t/C %t/C1 && mkdir %t/C %t/C1 && cp %t/IN/* %t/C
40 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
41 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
42 RUN: grep BINGO %t/log
43
44 # 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.
47 RUN: %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
48 AUTOFOCUS: INFO: AUTOFOCUS: {{.*}} f0
49 AUTOFOCUS: INFO: AUTOFOCUS: {{.*f[ABC]}}(unsigned char const*)
50
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.
53 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
54 RUN: grep BINGO %t/log