You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: tests/fuzz/Readme.md
+14-1
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# Fuzz Tests
2
-
Every test in this directory will be run as a Fuzz test for several minutes during builds. To run all fuzz tests simply run `make fuzz` from the top `s2n` directory to compile s2n with the proper flags and run the fuzz tests.
2
+
By default, every test in this directory will be run as a fuzz test for several minutes each during builds. To run all fuzz tests simply run `make fuzz` from the top `s2n` directory to compile s2n with the proper flags and run the fuzz tests. To run a specific subset of fuzz tests, simply set the FUZZ_TESTS variable as follows:
3
+
4
+
> FUZZ_TESTS="test1 test2 test3"
3
5
4
6
#### Each Fuzz Test should conform to the following rules:
5
7
1. End in either `*_test.c` or `*_negative_test.c`.
@@ -10,6 +12,17 @@ Every test in this directory will be run as a Fuzz test for several minutes duri
10
12
4. Have a function `int LLVMFuzzerInitialize(const uint8_t *buf, size_t len)` that will perform any initialization that will be run only once at startup.
11
13
5. Have a function `int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)` that will pass `buf` to one of s2n's API's
12
14
15
+
## Fuzz Test Coverage
16
+
To generate coverage reports for fuzz tests, simply set the FUZZ_COVERAGE environment variable to any non-null value and run `make fuzz`. This will report the target function coverage and overall S2N coverage when running the tests. In order to define target functions for a fuzz test, simply add the following line to your fuzz test below the copyright notice:
As the tests run, more detailed coverage reports are placed in the following directory:
21
+
22
+
> s2n/coverage/fuzz
23
+
24
+
Each test outputs an HTML file which displays line by line coverage statistics and a .txt report which gives per-function coverage statistics in human-readable ASCII. After all fuzz tests have ran, a matching pair of coverage reports is generated for the total coverage of S2N by the entire set of tests performed.
25
+
13
26
## Fuzz Test Directory Structure
14
27
For a test with name `$TEST_NAME`, its files should be laid out with the following structure:
# Print number of new files and branches found in new Inputs (if any)
94
147
RESULTS=`grep -Eo "[0-9]+ new files .*$"${TEST_NAME}_results.txt | tail -1`
95
148
printf", ${RESULTS}\n"
96
-
149
+
97
150
if [ "$TESTS_PER_SEC"-lt$MIN_TEST_PER_SEC ];then
98
151
printf"\033[33;1mWARNING!\033[0m ${TEST_NAME} is only ${TESTS_PER_SEC} tests/sec, which is below ${MIN_TEST_PER_SEC}/sec! Fuzz tests are more effective at higher rates.\n\n"
99
152
fi
@@ -103,7 +156,7 @@ then
103
156
exit -1;
104
157
fi
105
158
fi
106
-
159
+
107
160
else
108
161
cat ${TEST_NAME}_output.txt
109
162
printf"\033[31;1mFAILED\033[0m %10d tests, %6d features covered\n"$TEST_COUNT$FEATURE_COVERAGE
0 commit comments