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

Commit

Permalink
Add task_id & job_id to variable expansion (#481)
Browse files Browse the repository at this point in the history
Fixes #479 

Note, this is built on top of #480
  • Loading branch information
bmc-msft authored Jan 29, 2021
1 parent 9c7eb33 commit 5acb59e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 16 deletions.
29 changes: 17 additions & 12 deletions docs/command-replacements.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The following values are replaced with the specific values at runtime.
* `{runtime_dir}`: Path to the runtime directory for the task
* `{tools_dir}`: Path to the task specific `tools` directory
* `{setup_dir}` : Path to the setup directory
* `{job_id}`: UUID that indicates the Job ID
* `{task_id}`: UUID that indicates the Task ID

## Example

Expand All @@ -38,15 +40,18 @@ If you need `supervisor_options` to expand to: `"a", "b", "c", "d"`, you should

These are currently used in the following tasks:

* libfuzzer_fuzz: `target_exe`, `target_options`, `input_corpus`, `crashes`
* libfuzzer_crash_report: `target_exe`, `target_options`, `input`
* libfuzzer_merge: `target_exe`, `target_options`, `input_corpus`
* libfuzzer_coverage: None
* generic_analysis: `input`, `target_exe`, `target_options`, `analyzer_exe`,
`anayzer_options`, `output_dir`, `tools_dir`
* generic_generator: `generated_inputs`, `input_corpus`, `tools_dir`,
`generator_exe`, `generator_options`, `target_exe`, `target_options`, `input`
* generic_supervisor: `crashes`, `runtime_dir`, `target_exe`, `target_options`,
`input_corpus`, `input`, `supervisor_exe`, `supervisor_options`, `tools_dir`
* generic_merge: `input`, `input_corpus`, `output_dir`, `target_exe`,
`target_options`, `supervisor_exe`, `supervisor_options`, `tools_dir`
* libfuzzer\_fuzz: `target_exe`, `target_options`, `input_corpus`, `crashes`
* libfuzzer\_crash\_report: `target_exe`, `target_options`, `input`
* libfuzzer\_merge: `target_exe`, `target_options`, `input_corpus`
* libfuzzer\_coverage: None
* generic\_analysis: `input`, `target_exe`, `target_options`, `analyzer_exe`,
`anayzer_options`, `output_dir`, `tools_dir`, `job_id`, `task_id`
* generic\_generator: `generated_inputs`, `input_corpus`, `tools_dir`,
`generator_exe`, `generator_options`, `target_exe`, `target_options`,
`input`, `job_id`, `task_id`
* generic\_supervisor: `crashes`, `runtime_dir`, `target_exe`, `target_options`,
`input_corpus`, `input`, `supervisor_exe`, `supervisor_options`, `tools_dir`,
`job_id`, `task_id`
* generic\_merge: `input`, `input_corpus`, `output_dir`, `target_exe`,
`target_options`, `supervisor_exe`, `supervisor_options`, `tools_dir`,
`job_id`, `task_id`
4 changes: 3 additions & 1 deletion src/agent/onefuzz-agent/src/tasks/analysis/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ pub async fn run_tool(input: impl AsRef<Path>, config: &Config) -> Result<()> {
.analyzer_options(&config.analyzer_options)
.output_dir(&config.analysis.path)
.tools_dir(&config.tools.path)
.setup_dir(&config.common.setup_dir);
.setup_dir(&config.common.setup_dir)
.job_id(&config.common.job_id)
.task_id(&config.common.task_id);

let analyzer_path = expand.evaluate_value(&config.analyzer_exe)?;

Expand Down
4 changes: 3 additions & 1 deletion src/agent/onefuzz-agent/src/tasks/fuzz/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ impl GeneratorTask {
.generated_inputs(&output_dir)
.input_corpus(&corpus_dir)
.generator_exe(&self.config.generator_exe)
.generator_options(&self.config.generator_options);
.generator_options(&self.config.generator_options)
.job_id(&self.config.common.job_id)
.task_id(&self.config.common.task_id);

if let Some(tools) = &self.config.tools {
expand.tools_dir(&tools.path);
Expand Down
4 changes: 3 additions & 1 deletion src/agent/onefuzz-agent/src/tasks/fuzz/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ async fn start_supervisor(
.crashes(&crashes.path)
.input_corpus(&inputs.path)
.reports_dir(&reports_dir)
.setup_dir(&config.common.setup_dir);
.setup_dir(&config.common.setup_dir)
.job_id(&config.common.job_id)
.task_id(&config.common.task_id);

if let Some(tools) = &config.tools {
expand.tools_dir(&tools.path);
Expand Down
4 changes: 3 additions & 1 deletion src/agent/onefuzz-agent/src/tasks/merge/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ async fn merge(config: &Config, output_dir: impl AsRef<Path>) -> Result<()> {
.generated_inputs(output_dir)
.target_exe(&config.target_exe)
.setup_dir(&config.common.setup_dir)
.tools_dir(&config.tools.path);
.tools_dir(&config.tools.path)
.job_id(&config.common.job_id)
.task_id(&config.common.task_id);

let supervisor_path = expand.evaluate_value(&config.supervisor_exe)?;

Expand Down
17 changes: 17 additions & 0 deletions src/agent/onefuzz/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::collections::HashMap;
use std::path::{Path, PathBuf};
use strum::IntoEnumIterator;
use strum_macros::EnumIter;
use uuid::Uuid;

pub enum ExpandedValue<'a> {
Path(String),
Expand Down Expand Up @@ -35,6 +36,8 @@ pub enum PlaceHolder {
SupervisorOptions,
SetupDir,
ReportsDir,
JobId,
TaskId,
}

impl PlaceHolder {
Expand All @@ -59,6 +62,8 @@ impl PlaceHolder {
Self::SupervisorOptions => "{supervisor_options}",
Self::SetupDir => "{setup_dir}",
Self::ReportsDir => "{reports_dir}",
Self::JobId => "{job_id}",
Self::TaskId => "{task_id}",
}
.to_string()
}
Expand Down Expand Up @@ -233,6 +238,18 @@ impl<'a> Expand<'a> {
self
}

pub fn task_id(&mut self, arg: &Uuid) -> &mut Self {
let value = arg.to_hyphenated().to_string();
self.set_value(PlaceHolder::TaskId, ExpandedValue::Scalar(value));
self
}

pub fn job_id(&mut self, arg: &Uuid) -> &mut Self {
let value = arg.to_hyphenated().to_string();
self.set_value(PlaceHolder::JobId, ExpandedValue::Scalar(value));
self
}

fn replace_value(
&self,
fmtstr: &str,
Expand Down

0 comments on commit 5acb59e

Please sign in to comment.