-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Rust coverage report (for Suricata) #4697
Changes from all commits
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,51 @@ | ||
#!/bin/bash -eu | ||
# Copyright 2020 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License 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. | ||
# | ||
# This is a wrapper around calling cargo | ||
# This just expands RUSTFLAGS in case of a coverage build | ||
# We need this until https://github.com/rust-lang/cargo/issues/5450 is merged | ||
# because cargo uses relative paths for the current crate | ||
# and absolute paths for its dependencies | ||
# | ||
################################################################################ | ||
|
||
export PATH="/rust/bin:$PATH" | ||
|
||
if [ "$SANITIZER" = "coverage" ] && [ $1 = "build" ] | ||
then | ||
crate_src_abspath=`cargo metadata --no-deps --format-version 1 | jq -r '.workspace_root'` | ||
export RUSTFLAGS="$RUSTFLAGS --remap-path-prefix src=$crate_src_abspath/src" | ||
fi | ||
|
||
if [ "$SANITIZER" = "coverage" ] && [ $1 = "fuzz" ] | ||
then | ||
fuzz_src_abspath=`pwd` | ||
export RUSTFLAGS="$RUSTFLAGS --remap-path-prefix fuzz_targets=$fuzz_src_abspath/fuzz_targets" | ||
# hack to turn cargo fuzz build into cargo build so as to get coverage | ||
# cargo fuzz adds "--target" "x86_64-unknown-linux-gnu" | ||
( | ||
# go into fuzz directory if not already the case | ||
cd fuzz || true | ||
# do not optimize with --release, leading to Malformed instrumentation profile data | ||
cargo build --bins | ||
# copies the build output in the expected target directory | ||
cd target | ||
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. I think that this is causing a build failure for wasmtime because we include the Perhaps this could use something like:
to extract the target directory for the fuzz project? 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. Another alternative, if the goal is simply to not optimize, is to set 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. Thanks @alexcrichton for debugging this cf #5366
The goal is more than to not optimize Another solution could be to have 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. I think ideally yeah it'd be best to codify this in |
||
mkdir -p x86_64-unknown-linux-gnu/release | ||
cp -r debug/* x86_64-unknown-linux-gnu/release/ | ||
) | ||
exit 0 | ||
fi | ||
|
||
cargo "$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ RUN apt-get update && apt-get install -y \ | |
python3 \ | ||
python3-pip \ | ||
wget \ | ||
curl \ | ||
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. Should be there already now. 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. Same: I see it in base-builder but not base-runner... 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. Should it be moved to base-image or some other generic image ? |
||
zip | ||
|
||
RUN git clone https://chromium.googlesource.com/chromium/src/tools/code_coverage /opt/code_coverage && \ | ||
|
@@ -83,6 +84,13 @@ ENV UBSAN_OPTIONS="print_stacktrace=1:print_summary=1:silence_unsigned_overflow= | |
ENV FUZZER_ARGS="-rss_limit_mb=2560 -timeout=25" | ||
ENV AFL_FUZZER_ARGS="-m none" | ||
|
||
# Install rustfilt for symbol demangling. | ||
ENV CARGO_HOME=/rust | ||
ENV RUSTUP_HOME=/rust/rustup | ||
ENV PATH=$PATH:/rust/bin | ||
RUN curl https://sh.rustup.rs | sh -s -- -y --default-toolchain=nightly | ||
RUN cargo install rustfilt | ||
|
||
# Install OpenJDK 15 and trim its size by removing unused components. | ||
ENV JAVA_HOME=/usr/lib/jvm/java-15-openjdk-amd64 | ||
ENV JVM_LD_LIBRARY_PATH=$JAVA_HOME/lib/server | ||
|
@@ -103,6 +111,7 @@ COPY bad_build_check \ | |
dataflow_tracer.py \ | ||
download_corpus \ | ||
minijail0 \ | ||
rcfilt \ | ||
reproduce \ | ||
run_fuzzer \ | ||
run_minijail \ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash -u | ||
# Copyright 2020 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License 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. | ||
# | ||
# Symbol demangling for both C++ and Rust | ||
# | ||
################################################################################ | ||
|
||
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. Add file description here. 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. ok |
||
# simply pipe | ||
rustfilt | c++filt -n | ||
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 seems to work for ecc-diff-fuzzer which has rust and C++ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License 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. | ||
|
||
import sys | ||
import subprocess | ||
|
||
#disable coverage for crate brotli_decompressor | ||
sys.argv[0] = "rustc" | ||
if "brotli_decompressor" in sys.argv: | ||
try: | ||
sys.argv.remove("-Zinstrument-coverage") | ||
except: | ||
pass | ||
print(sys.argv) | ||
subprocess.call(sys.argv) |
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.
Hack is to use this cargo which come first in
PATH
So we can change
RUSTFLAGS
for this executionthen execute
/rust/bin/cargo