Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit a11f5e8

Browse files
authored
Add basic coverage test
1 parent bd2b109 commit a11f5e8

File tree

7 files changed

+26
-17
lines changed

7 files changed

+26
-17
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ env:
1818
CARGO_TERM_COLOR: always
1919
SCCACHE_DIR: ${{github.workspace}}/sccache/
2020
SCCACHE_CACHE_SIZE: 1G
21-
ACTIONS_CACHE_KEY_DATE: 2022-11-21-02
21+
ACTIONS_CACHE_KEY_DATE: 2023-04-19
2222
CI: true
2323

2424
jobs:

src/agent/Cargo.lock

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/agent/coverage/examples/coverage.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,19 @@ fn dump_cobertura(binary: &BinaryCoverage) -> Result<()> {
167167

168168
Ok(())
169169
}
170+
171+
#[cfg(test)]
172+
mod test {
173+
use super::*;
174+
175+
#[test]
176+
fn can_run_coverage() {
177+
let cmd = command(&["ls".to_string()], None);
178+
let recorded = CoverageRecorder::new(cmd)
179+
.timeout(Duration::from_secs(5))
180+
.record()
181+
.unwrap();
182+
183+
assert!(recorded.coverage.modules.len() > 0);
184+
}
185+
}

src/agent/onefuzz-agent/src/agent.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the MIT License.
33

44
#![allow(clippy::too_many_arguments)]
5+
use std::time::Duration;
6+
57
use anyhow::{Error, Result};
68
use tokio::time;
79

@@ -29,6 +31,7 @@ pub struct Agent {
2931
last_poll_command: Result<Option<NodeCommand>, PollCommandError>,
3032
managed: bool,
3133
machine_id: uuid::Uuid,
34+
sleep_duration: Duration,
3235
}
3336

3437
impl Agent {
@@ -59,6 +62,7 @@ impl Agent {
5962
last_poll_command,
6063
managed,
6164
machine_id,
65+
sleep_duration: Duration::from_secs(30),
6266
}
6367
}
6468

@@ -365,8 +369,7 @@ impl Agent {
365369
}
366370

367371
async fn sleep(&self) {
368-
let delay = time::Duration::from_secs(30);
369-
time::sleep(delay).await;
372+
time::sleep(self.sleep_duration).await;
370373
}
371374
}
372375

src/agent/onefuzz-agent/src/agent/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ impl Fixture {
8484

8585
#[tokio::test]
8686
async fn test_update_free_no_work() {
87-
let agent = Fixture.agent();
87+
let mut agent = Fixture.agent();
88+
agent.sleep_duration = Duration::from_secs(5);
8889

8990
let (agent, done) = agent.update().await.unwrap();
9091
assert!(!done);

src/ci/agent.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export RUST_BACKTRACE=full
6060

6161
# Run tests and collect coverage
6262
# https://github.com/taiki-e/cargo-llvm-cov
63-
cargo llvm-cov --locked --workspace --lcov --output-path "$output_dir/lcov.info"
63+
cargo llvm-cov nextest --all-targets --locked --workspace --lcov --output-path "$output_dir/lcov.info"
6464

6565
# TODO: re-enable integration tests.
6666
# cargo test --release --manifest-path ./onefuzz-task/Cargo.toml --features integration_test -- --nocapture

src/ci/rust-prereqs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
set -ex
77

8-
cargo install sccache cargo-license@0.4.2 cargo-llvm-cov cargo-deny cargo-insta
8+
cargo install sccache cargo-license@0.4.2 cargo-llvm-cov cargo-deny cargo-insta cargo-nextest
99

1010
# sccache --start-server
1111
# export RUSTC_WRAPPER=$(which sccache)

0 commit comments

Comments
 (0)