diff --git a/src/agent/onefuzz-agent/src/local/coverage.rs b/src/agent/onefuzz-agent/src/local/coverage.rs index 920d092521..ea9fadc4aa 100644 --- a/src/agent/onefuzz-agent/src/local/coverage.rs +++ b/src/agent/onefuzz-agent/src/local/coverage.rs @@ -88,6 +88,7 @@ pub fn build_shared_args(local_job: bool) -> Vec> { .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"), diff --git a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs index 7124e427c0..16fce812ec 100644 --- a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs +++ b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs @@ -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; @@ -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; @@ -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 { let expand = Expand::new() .input_path(input) diff --git a/src/agent/onefuzz/src/expand.rs b/src/agent/onefuzz/src/expand.rs index a83a250a05..6e02c9d5dc 100644 --- a/src/agent/onefuzz/src/expand.rs +++ b/src/agent/onefuzz/src/expand.rs @@ -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}", @@ -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(()) + } }