Add task_id & job_id to variable expansion (#481)

Fixes #479 

Note, this is built on top of #480
This commit is contained in:
bmc-msft
2021-01-29 10:35:59 -05:00
committed by GitHub
parent 9c7eb33149
commit 5acb59e5b9
6 changed files with 46 additions and 16 deletions

View File

@ -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
@ -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`

View File

@ -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)?;

View File

@ -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);

View File

@ -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);

View File

@ -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)?;

View File

@ -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),
@ -35,6 +36,8 @@ pub enum PlaceHolder {
SupervisorOptions,
SetupDir,
ReportsDir,
JobId,
TaskId,
}
impl PlaceHolder {
@ -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()
}
@ -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,