Skip to content

Commit

Permalink
Improve code coverage, closes #151
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Mar 31, 2024
1 parent a39a6c3 commit 10ff794
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 65 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
run: sccache --start-server
- uses: taiki-e/install-action@v2
with:
tool: just,cargo-llvm-cov,cargo-nextest
tool: just,cargo-nextest
- name: Run unit tests and h2spec
run: |
cd ${{ github.workspace }}
Expand All @@ -92,6 +92,7 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
file: coverage/lcov.info
- name: Upload h2spec Report
uses: actions/upload-artifact@v3
if: always() # always run even if the previous step fails
Expand Down
30 changes: 1 addition & 29 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,7 @@ _default:
ci-test:
#!/bin/bash -eux
just build-testbed

export RUSTUP_TOOLCHAIN=nightly
rustup component add llvm-tools
cargo llvm-cov --version

cargo llvm-cov show-env --branch --export-prefix > /tmp/llvm-cov-env
echo "======= LLVM cov env ======="
cat /tmp/llvm-cov-env
echo "============================"
source /tmp/llvm-cov-env

cargo llvm-cov clean --workspace

cargo nextest run --verbose --release --profile ci --manifest-path crates/fluke-hpack/Cargo.toml --features interop-tests --release
cargo nextest run --verbose --release --profile ci --manifest-path crates/fluke/Cargo.toml
cargo nextest run --verbose --release --profile ci --manifest-path test-crates/fluke-curl-tests/Cargo.toml

cargo build --release --manifest-path test-crates/fluke-h2spec/Cargo.toml
# skip if SKIP_H2SPEC is set to 1
if [[ "${SKIP_H2SPEC:-0}" == "1" ]]; then
echo "Skipping h2spec suites"
else
for suite in generic hpack http2; do
"${CARGO_TARGET_DIR}"/release/fluke-h2spec "${suite}" -j "target/h2spec-${suite}.xml"
done
fi

cargo llvm-cov report --release --lcov --output-path coverage.lcov
cargo llvm-cov report --release --html
just cov

cov:
scripts/cov.sh
Expand Down
4 changes: 0 additions & 4 deletions crates/fluke/src/h2/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,3 @@ impl fmt::Debug for H2EventPayload {
}
}
}

#[derive(thiserror::Error, Debug)]
#[error("the peer closed the connection unexpectedly")]
pub(crate) struct ConnectionClosed;
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
default = bin;
};
devShells.default = mkShell {
inputsFrom = [ bin ];
packages = with pkgs; [ just nixpkgs-fmt cargo-nextest ];
packages = with pkgs; [ clang mold curl just nixpkgs-fmt cargo-nextest libiconv ];
};
}
);
Expand Down
36 changes: 20 additions & 16 deletions scripts/cov.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash -eux

export RUSTFLAGS='-C instrument-coverage --cfg=coverage --cfg=trybuild_no_target'
export RUSTUP_TOOLCHAIN=nightly
export RUSTFLAGS='-C instrument-coverage -Z coverage-options=branch --cfg=coverage --cfg=trybuild_no_target'

export CARGO_INCREMENTAL=0
export CARGO_TARGET_DIR="${PWD}/target-cov"

rustup component add llvm-tools

export COVERAGE_DIR="${PWD}/coverage"
rm -rf "${COVERAGE_DIR}"

Expand All @@ -21,18 +24,18 @@ LLVM_PROFDATA="${LLVM_TOOLS_PATH}/llvm-profdata"
LLVM_COV="${LLVM_TOOLS_PATH}/llvm-cov"
"${LLVM_COV}" --version

cargo nextest run --verbose --profile ci --manifest-path crates/fluke-hpack/Cargo.toml --features interop-tests --release
cargo nextest run --verbose --profile ci --manifest-path crates/fluke/Cargo.toml
cargo nextest run --verbose --profile ci --manifest-path test-crates/fluke-curl-tests/Cargo.toml
cargo nextest run --release --verbose --profile ci --manifest-path crates/fluke-hpack/Cargo.toml --features interop-tests
cargo nextest run --release --verbose --profile ci --manifest-path crates/fluke/Cargo.toml
cargo nextest run --release --verbose --profile ci --manifest-path test-crates/fluke-curl-tests/Cargo.toml

cargo build --manifest-path test-crates/fluke-h2spec/Cargo.toml
cargo build --release --manifest-path test-crates/fluke-h2spec/Cargo.toml
# skip if SKIP_H2SPEC is set to 1
if [[ "${SKIP_H2SPEC:-0}" == "1" ]]; then
echo "Skipping h2spec suites"
else
for suite in generic hpack http2; do
"${CARGO_TARGET_DIR}"/debug/fluke-h2spec "${suite}" -j "target/h2spec-${suite}.xml"
done
for suite in generic hpack http2; do
"${CARGO_TARGET_DIR}"/release/fluke-h2spec "${suite}" -j "target/h2spec-${suite}.xml"
done
fi

# merge all profiles
Expand All @@ -42,19 +45,20 @@ fi
cover_args=()
cover_args+=(--instr-profile "${COVERAGE_DIR}/fluke.profdata")
cover_args+=(--ignore-filename-regex "rustc|.cargo|test-crates|non_uring")
cover_args+=("${CARGO_TARGET_DIR}"/debug/fluke-h2spec)
cover_args+=("${CARGO_TARGET_DIR}"/release/fluke-h2spec)

# pass *all* binaries/libraries to llvm-cov, including release ones
# because the fluke-hpack conformance tests are too slow in debug.
objects=("${CARGO_TARGET_DIR}"/debug/deps/* "${CARGO_TARGET_DIR}"/release/deps/*)
objects=("${CARGO_TARGET_DIR}"/release/deps/*)
for object in "${objects[@]}"; do
# skip directories
[[ -d $object ]] && continue

# skip debug files '.d'
[[ $object =~ \.d$ ]] && continue
[[ $object =~ \.d$ ]] && continue

# skip rust metadata files '.rmeta'
[[ $object =~ \.rmeta$ ]] && continue
# skip rust metadata files '.rmeta'
[[ $object =~ \.rmeta$ ]] && continue

cover_args+=(-object "$object")
cover_args+=(-object "$object")
done

"${LLVM_COV}" export --format=lcov "${cover_args[@]}" > coverage/lcov.info
Expand Down
2 changes: 1 addition & 1 deletion test-crates/fluke-h2spec/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub(crate) async fn spawn_server(addr: SocketAddr) -> color_eyre::Result<SocketA
pub(crate) async fn run_server(ln: TcpListener) -> color_eyre::Result<()> {
loop {
let (stream, addr) = ln.accept().await?;
tracing::info!(%addr, "Accepted connection from");
tracing::debug!(%addr, "Accepted connection from");
let conf = Rc::new(fluke::h2::ServerConf::default());
let client_buf = RollMut::alloc()?;
let driver = Rc::new(SDriver);
Expand Down

0 comments on commit 10ff794

Please sign in to comment.