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

verify {input} is used by target_env or target_options in coverage task #1097

Merged
merged 7 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/agent/onefuzz-agent/src/local/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub fn build_shared_args(local_job: bool) -> Vec<Arg<'static, 'static>> {
.multiple(true),
Arg::with_name(TARGET_OPTIONS)
.long(TARGET_OPTIONS)
.default_value("{input}")
.takes_value(true)
.value_delimiter(" ")
.help("Use a quoted string with space separation to denote multiple arguments"),
Expand Down
23 changes: 22 additions & 1 deletion src/agent/onefuzz-agent/src/tasks/coverage/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use async_trait::async_trait;
use coverage::block::CommandBlockCov;
use coverage::cache::ModuleCache;
use coverage::code::{CmdFilter, CmdFilterDef};
use onefuzz::expand::Expand;
use onefuzz::expand::{Expand, PlaceHolder};
use onefuzz::syncdir::SyncedDir;
use onefuzz_telemetry::{warn, Event::coverage_data, EventData};
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -82,6 +82,10 @@ impl CoverageTask {
let heartbeat = self.config.common.init_heartbeat(None).await?;
let mut context = TaskContext::new(cache, &self.config, coverage, filter, heartbeat);

if !context.uses_input() {
bail!("input is not specified on the command line or arguments for the target");
}

context.heartbeat.alive();

let mut seen_inputs = false;
Expand Down Expand Up @@ -245,6 +249,23 @@ impl<'a> TaskContext<'a> {
Ok(coverage)
}

fn uses_input(&self) -> bool {
let input = PlaceHolder::Input.get_string();

for entry in &self.config.target_options {
if entry.contains(&input) {
return true;
}
}
for (k, v) in &self.config.target_env {
if k == &input || v.contains(&input) {
return true;
}
}

false
}

fn command_for_input(&self, input: &Path) -> Result<Command> {
let expand = Expand::new()
.input_path(input)
Expand Down
11 changes: 10 additions & 1 deletion src/agent/onefuzz/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub enum PlaceHolder {
}

impl PlaceHolder {
fn get_string(&self) -> String {
pub fn get_string(&self) -> String {
match self {
Self::Input => "{input}",
Self::Crashes => "{crashes}",
Expand Down Expand Up @@ -469,4 +469,13 @@ mod tests {

Ok(())
}

#[test]
fn test_expand_in_string() -> Result<()> {
let result = Expand::new()
.input_path("src/lib.rs")
.evaluate_value("a {input} b")?;
assert!(result.contains("lib.rs"));
Ok(())
}
}