-
Notifications
You must be signed in to change notification settings - Fork 714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: run fuzz tests in parallel and generate coverage report #4960
Changes from all commits
88a5716
37a5205
224a017
ce73ffa
6352fe4
daab18d
e1b3a1d
4a4a322
6e12ef2
be23009
a2e4156
a5fdc9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). | ||
# You may not use this file except in compliance with the License. | ||
# A copy of the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0 | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
# express or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
# | ||
|
||
for FUZZ_TEST in tests/fuzz/*.c; do | ||
# extract file name without extension | ||
TEST_NAME=$(basename "$FUZZ_TEST") | ||
TEST_NAME="${TEST_NAME%.*}" | ||
|
||
# temp corpus folder to store downloaded corpus files | ||
TEMP_CORPUS_DIR="./tests/fuzz/temp_corpus_${TEST_NAME}" | ||
|
||
# Check if corpus.zip exists in the specified S3 location. | ||
# `> /dev/null 2>&1` redirects output to /dev/null. | ||
# If the file is not found, `aws s3 ls` returns a non-zero exit code. | ||
if aws s3 ls "s3://s2n-tls-fuzz-corpus/${TEST_NAME}/corpus.zip" > /dev/null 2>&1; then | ||
aws s3 cp "s3://s2n-tls-fuzz-corpus/${TEST_NAME}/corpus.zip" "${TEMP_CORPUS_DIR}/corpus.zip" | ||
unzip -o "${TEMP_CORPUS_DIR}/corpus.zip" -d "${TEMP_CORPUS_DIR}" > /dev/null 2>&1 | ||
else | ||
printf "corpus.zip not found for ${TEST_NAME}" | ||
fi | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). | ||
# You may not use this file except in compliance with the License. | ||
# A copy of the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0 | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
# express or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
# | ||
|
||
for FUZZ_TEST in tests/fuzz/*.c; do | ||
# extract file name without extension | ||
TEST_NAME=$(basename "$FUZZ_TEST") | ||
TEST_NAME="${TEST_NAME%.*}" | ||
|
||
# Upload generated corpus files to the S3 bucket. | ||
zip -r ./tests/fuzz/corpus/${TEST_NAME}.zip ./tests/fuzz/corpus/${TEST_NAME}/ > /dev/null 2>&1 | ||
aws s3 cp ./tests/fuzz/corpus/${TEST_NAME}.zip s3://s2n-tls-fuzz-corpus/${TEST_NAME}/corpus.zip | ||
done | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/bash | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). | ||
# You may not use this file except in compliance with the License. | ||
# A copy of the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0 | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
# express or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
# | ||
|
||
set -e | ||
|
||
usage() { | ||
echo "Usage: fuzz_coverage_report.sh" | ||
exit 1 | ||
} | ||
|
||
if [ "$#" -ne "0" ]; then | ||
usage | ||
fi | ||
|
||
FUZZ_TEST_DIR="tests/fuzz" | ||
FUZZCOV_SOURCES="api bin crypto error stuffer tls utils" | ||
|
||
# generate coverage report for each fuzz test | ||
printf "Generating coverage reports... \n" | ||
|
||
mkdir -p coverage/fuzz | ||
for FUZZ_TEST in "$FUZZ_TEST_DIR"/*.c; do | ||
# extract file name without extension | ||
TEST_NAME=$(basename "$FUZZ_TEST") | ||
TEST_NAME="${TEST_NAME%.*}" | ||
|
||
# merge multiple .profraw files into a single .profdata file | ||
llvm-profdata merge \ | ||
-sparse tests/fuzz/profiles/${TEST_NAME}/*.profraw \ | ||
-o tests/fuzz/profiles/${TEST_NAME}/${TEST_NAME}.profdata | ||
|
||
# generate a coverage report in text format | ||
llvm-cov report \ | ||
-instr-profile=tests/fuzz/profiles/${TEST_NAME}/${TEST_NAME}.profdata build/lib/libs2n.so ${FUZZCOV_SOURCES} \ | ||
-show-functions \ | ||
> coverage/fuzz/${TEST_NAME}_cov.txt | ||
|
||
# exports coverage data in LCOV format | ||
llvm-cov export \ | ||
-instr-profile=tests/fuzz/profiles/${TEST_NAME}/${TEST_NAME}.profdata build/lib/libs2n.so ${FUZZCOV_SOURCES} \ | ||
-format=lcov \ | ||
> coverage/fuzz/${TEST_NAME}_cov.info | ||
|
||
# convert to HTML format | ||
genhtml -q -o coverage/html/${TEST_NAME} coverage/fuzz/${TEST_NAME}_cov.info > /dev/null 2>&1 | ||
done | ||
|
||
# merge all coverage reports into a single report that shows total s2n coverage | ||
printf "Calculating total s2n coverage... \n" | ||
llvm-profdata merge \ | ||
-sparse tests/fuzz/profiles/*/*.profdata \ | ||
-o tests/fuzz/profiles/merged_fuzz.profdata | ||
|
||
llvm-cov report \ | ||
-instr-profile=tests/fuzz/profiles/merged_fuzz.profdata build/lib/libs2n.so ${FUZZCOV_SOURCES} \ | ||
> s2n_fuzz_coverage.txt | ||
|
||
llvm-cov export \ | ||
-instr-profile=tests/fuzz/profiles/merged_fuzz.profdata build/lib/libs2n.so ${FUZZCOV_SOURCES} \ | ||
-format=lcov \ | ||
> s2n_fuzz_cov.info | ||
|
||
genhtml s2n_fuzz_cov.info --branch-coverage -q -o coverage/fuzz/total_fuzz_coverage |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,55 +13,10 @@ | |||||||||||
# limitations under the License. | ||||||||||||
version: 0.2 | ||||||||||||
|
||||||||||||
batch: | ||||||||||||
build-matrix: | ||||||||||||
static: | ||||||||||||
env: | ||||||||||||
privileged-mode: true | ||||||||||||
dynamic: | ||||||||||||
env: | ||||||||||||
compute-type: | ||||||||||||
- BUILD_GENERAL1_LARGE | ||||||||||||
image: | ||||||||||||
- 024603541914.dkr.ecr.us-west-2.amazonaws.com/docker:ubuntu22codebuild | ||||||||||||
privileged-mode: true | ||||||||||||
variables: | ||||||||||||
S2N_LIBCRYPTO: | ||||||||||||
- awslc | ||||||||||||
FUZZ_TESTS: | ||||||||||||
- "s2n_cert_req_recv_test" | ||||||||||||
- "s2n_certificate_extensions_parse_test" | ||||||||||||
- "s2n_client_ccs_recv_test" | ||||||||||||
- "s2n_client_cert_recv_test" | ||||||||||||
- "s2n_client_cert_verify_recv_test" | ||||||||||||
- "s2n_client_finished_recv_test" | ||||||||||||
- "s2n_client_fuzz_test" | ||||||||||||
- "s2n_client_hello_recv_fuzz_test" | ||||||||||||
- "s2n_client_key_recv_fuzz_test" | ||||||||||||
- "s2n_deserialize_resumption_state_test" | ||||||||||||
- "s2n_encrypted_extensions_recv_test" | ||||||||||||
- "s2n_extensions_client_key_share_recv_test" | ||||||||||||
- "s2n_extensions_client_supported_versions_recv_test" | ||||||||||||
- "s2n_extensions_server_key_share_recv_test" | ||||||||||||
- "s2n_extensions_server_supported_versions_recv_test" | ||||||||||||
- "s2n_hybrid_ecdhe_kyber_r3_fuzz_test" | ||||||||||||
- "s2n_kyber_r3_recv_ciphertext_fuzz_test" | ||||||||||||
- "s2n_kyber_r3_recv_public_key_fuzz_test" | ||||||||||||
- "s2n_memory_leak_negative_test" | ||||||||||||
- "s2n_openssl_diff_pem_parsing_test" | ||||||||||||
- "s2n_recv_client_supported_groups_test" | ||||||||||||
- "s2n_select_server_cert_test" | ||||||||||||
- "s2n_server_ccs_recv_test" | ||||||||||||
- "s2n_server_cert_recv_test" | ||||||||||||
- "s2n_server_extensions_recv_test" | ||||||||||||
- "s2n_server_finished_recv_test" | ||||||||||||
- "s2n_server_fuzz_test" | ||||||||||||
- "s2n_server_hello_recv_test" | ||||||||||||
- "s2n_stuffer_pem_fuzz_test" | ||||||||||||
- "s2n_tls13_cert_req_recv_test" | ||||||||||||
- "s2n_tls13_cert_verify_recv_test" | ||||||||||||
- "s2n_tls13_client_finished_recv_test" | ||||||||||||
- "s2n_tls13_server_finished_recv_test" | ||||||||||||
env: | ||||||||||||
variables: | ||||||||||||
S2N_LIBCRYPTO: "awslc" | ||||||||||||
COMPILER: clang | ||||||||||||
|
||||||||||||
phases: | ||||||||||||
pre_build: | ||||||||||||
|
@@ -76,13 +31,23 @@ phases: | |||||||||||
- | | ||||||||||||
cmake . -Bbuild \ | ||||||||||||
-DCMAKE_PREFIX_PATH=/usr/local/$S2N_LIBCRYPTO \ | ||||||||||||
-DCMAKE_C_COMPILER=/usr/bin/$COMPILER \ | ||||||||||||
-DS2N_FUZZ_TEST=on \ | ||||||||||||
-DFUZZ_TIMEOUT_SEC=27000 | ||||||||||||
-DCOVERAGE=on \ | ||||||||||||
-DBUILD_SHARED_LIBS=on | ||||||||||||
- cmake --build ./build -- -j $(nproc) | ||||||||||||
post_build: | ||||||||||||
on-failure: ABORT | ||||||||||||
commands: | ||||||||||||
- ./codebuild/bin/fuzz_corpus_download.sh | ||||||||||||
# -L: Restrict tests to labels matching the pattern 'fuzz' | ||||||||||||
# -R: Run the single fuzz test defined in ${FUZZ_TESTS} | ||||||||||||
# --timeout: override ctest's default timeout of 1500 | ||||||||||||
- cmake --build build/ --target test -- ARGS="-L fuzz -R ${FUZZ_TESTS} --output-on-failure --timeout 28800" | ||||||||||||
- cmake --build build/ --target test -- ARGS="-L fuzz --output-on-failure -j $(nproc) --timeout 28800" | ||||||||||||
- ./codebuild/bin/fuzz_corpus_upload.sh | ||||||||||||
- ./codebuild/bin/fuzz_coverage_report.sh | ||||||||||||
|
||||||||||||
artifacts: | ||||||||||||
# upload all files in the fuzz_coverage_report directory | ||||||||||||
files: | ||||||||||||
- '**/*' | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The broad file mask should keep this from failing, but have you tested the use of artifact uploads? (they have been flaky). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wildcard match looks a little bit suspicious to me. Won't this upload everything? I'd expect the pattern to be something more like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
documentation: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#:~:text=artifacts/base%2Ddirectory Alternatively I could probably just specify s2n-tls/codebuild/spec/buildspec_unit_coverage.yml Lines 41 to 45 in aaae641
Either way, I will test this to confirm the behavior, and paste the result. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, I just missed the "base-directory" field 🤦 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tested uploading coverage files to S3 bucket and is working. I uploaded a folder |
||||||||||||
base-directory: coverage/fuzz/total_fuzz_coverage |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above; if timeout is an env. var we can over-ride it later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I suspect we won't be running fuzz tests for more than 28800 secs though. I'm also not exactly sure how I make this into env, probably something like this?