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

Commit 71bd182

Browse files
committed
Return Result from get_expand() and implement for the rest of the configs
1 parent cb8c2c6 commit 71bd182

File tree

10 files changed

+859
-379
lines changed

10 files changed

+859
-379
lines changed

src/agent/onefuzz-task/src/config_test_utils.rs

Lines changed: 229 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub mod arbitraries {
1717
use reqwest::Url;
1818
use uuid::Uuid;
1919

20-
use crate::tasks::{config::CommonConfig, analysis, merge};
20+
use crate::tasks::{config::CommonConfig, analysis, merge, coverage, report, fuzz};
2121

2222
prop_compose! {
2323
fn arb_uuid()(
@@ -46,7 +46,8 @@ pub mod arbitraries {
4646
prop_compose! {
4747
fn arb_url()(
4848
// Don't use this for any url that isn't just being used for a string comparison (as for the config tests)
49-
url in r"https?://(www\.)?[-a-zA-Z0-9]{1,256}\.[a-zA-Z]{1,6}([-a-zA-Z]*)"
49+
// basically all that matters here is that we generate a parsable url
50+
url in r"https?://(www\.)?[-a-zA-Z0-9]{1,256}\.com"
5051
) -> Url {
5152
match Url::parse(&url) {
5253
Ok(url) => url,
@@ -123,7 +124,7 @@ pub mod arbitraries {
123124
extra_output in option::of(arb_synced_dir()),
124125
min_available_memory_mb in any::<u64>(),
125126
machine_identity in arb_machine_identity(),
126-
tags in prop::collection::hash_map(".*", ".*", 10),
127+
tags in prop::collection::hash_map(".*", ".*", 3),
127128
from_agent_to_task_endpoint in ".*",
128129
from_task_to_agent_endpoint in ".*",
129130
) -> CommonConfig {
@@ -240,4 +241,229 @@ pub mod arbitraries {
240241
arb_merge_config().boxed()
241242
}
242243
}
244+
245+
prop_compose! {
246+
fn arb_coverage_config()(
247+
target_exe in arb_pathbuf(),
248+
target_env in prop::collection::hash_map(".*", ".*", 10),
249+
target_options in arb_string_vec_no_vars(),
250+
target_timeout in option::of(any::<u64>()),
251+
coverage_filter in option::of(".*"),
252+
module_allowlist in option::of(".*"),
253+
source_allowlist in option::of(".*"),
254+
input_queue in Just(None),
255+
readonly_inputs in prop::collection::vec(arb_synced_dir(), 10),
256+
coverage in arb_synced_dir(),
257+
common in arb_common_config(),
258+
) -> coverage::generic::Config {
259+
coverage::generic::Config {
260+
target_exe,
261+
target_env,
262+
target_options,
263+
target_timeout,
264+
coverage_filter,
265+
module_allowlist,
266+
source_allowlist,
267+
input_queue,
268+
readonly_inputs,
269+
coverage,
270+
common,
271+
}
272+
}
273+
}
274+
275+
impl Arbitrary for coverage::generic::Config {
276+
type Parameters = ();
277+
type Strategy = BoxedStrategy<Self>;
278+
279+
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
280+
arb_coverage_config().boxed()
281+
}
282+
}
283+
284+
prop_compose! {
285+
fn arb_dotnet_coverage_config()(
286+
target_exe in arb_pathbuf(),
287+
target_env in prop::collection::hash_map(".*", ".*", 10),
288+
target_options in arb_string_vec_no_vars(),
289+
target_timeout in option::of(any::<u64>()),
290+
input_queue in Just(None),
291+
readonly_inputs in prop::collection::vec(arb_synced_dir(), 10),
292+
coverage in arb_synced_dir(),
293+
tools in arb_synced_dir(),
294+
common in arb_common_config(),
295+
) -> coverage::dotnet::Config {
296+
coverage::dotnet::Config {
297+
target_exe,
298+
target_env,
299+
target_options,
300+
target_timeout,
301+
input_queue,
302+
readonly_inputs,
303+
coverage,
304+
tools,
305+
common,
306+
}
307+
}
308+
}
309+
310+
impl Arbitrary for coverage::dotnet::Config {
311+
type Parameters = ();
312+
type Strategy = BoxedStrategy<Self>;
313+
314+
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
315+
arb_dotnet_coverage_config().boxed()
316+
}
317+
}
318+
319+
prop_compose! {
320+
fn arb_dotnet_report_config()(
321+
target_exe in arb_pathbuf(),
322+
target_env in prop::collection::hash_map(".*", ".*", 10),
323+
target_options in arb_string_vec_no_vars(),
324+
target_timeout in option::of(any::<u64>()),
325+
input_queue in Just(None),
326+
crashes in option::of(arb_synced_dir()),
327+
reports in option::of(arb_synced_dir()),
328+
unique_reports in option::of(arb_synced_dir()),
329+
no_repro in option::of(arb_synced_dir()),
330+
tools in arb_synced_dir(),
331+
check_fuzzer_help in any::<bool>(),
332+
check_retry_count in any::<u64>(),
333+
minimized_stack_depth in option::of(any::<usize>()),
334+
check_queue in any::<bool>(),
335+
common in arb_common_config(),
336+
) -> report::dotnet::generic::Config {
337+
report::dotnet::generic::Config {
338+
target_exe,
339+
target_env,
340+
target_options,
341+
target_timeout,
342+
input_queue,
343+
crashes,
344+
reports,
345+
unique_reports,
346+
no_repro,
347+
tools,
348+
check_fuzzer_help,
349+
check_retry_count,
350+
minimized_stack_depth,
351+
check_queue,
352+
common,
353+
}
354+
}
355+
}
356+
357+
impl Arbitrary for report::dotnet::generic::Config {
358+
type Parameters = ();
359+
type Strategy = BoxedStrategy<Self>;
360+
361+
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
362+
arb_dotnet_report_config().boxed()
363+
}
364+
}
365+
366+
prop_compose! {
367+
fn arb_generator_fuzz_config()(
368+
generator_exe in Just("src/lib.rs".to_string()),
369+
generator_env in prop::collection::hash_map(".*", ".*", 10),
370+
generator_options in arb_string_vec_no_vars(),
371+
readonly_inputs in prop::collection::vec(arb_synced_dir(), 10),
372+
crashes in arb_synced_dir(),
373+
tools in option::of(arb_synced_dir()),
374+
target_exe in arb_pathbuf(),
375+
target_env in prop::collection::hash_map(".*", ".*", 10),
376+
target_options in arb_string_vec_no_vars(),
377+
target_timeout in option::of(any::<u64>()),
378+
check_asan_log in any::<bool>(),
379+
check_debugger in any::<bool>(),
380+
check_retry_count in any::<u64>(),
381+
rename_output in any::<bool>(),
382+
ensemble_sync_delay in option::of(any::<u64>()),
383+
common in arb_common_config(),
384+
) -> fuzz::generator::Config {
385+
fuzz::generator::Config {
386+
generator_exe,
387+
generator_env,
388+
generator_options,
389+
readonly_inputs,
390+
crashes,
391+
tools,
392+
target_exe,
393+
target_env,
394+
target_options,
395+
target_timeout,
396+
check_asan_log,
397+
check_debugger,
398+
check_retry_count,
399+
rename_output,
400+
ensemble_sync_delay,
401+
common,
402+
}
403+
}
404+
}
405+
406+
impl Arbitrary for fuzz::generator::Config {
407+
type Parameters = ();
408+
type Strategy = BoxedStrategy<Self>;
409+
410+
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
411+
arb_generator_fuzz_config().boxed()
412+
}
413+
}
414+
415+
prop_compose! {
416+
fn arb_supervisor_config()(
417+
inputs in arb_synced_dir(),
418+
crashes in arb_synced_dir(),
419+
crashdumps in option::of(arb_synced_dir()),
420+
supervisor_exe in Just("src/lib.rs".to_string()),
421+
supervisor_env in prop::collection::hash_map(".*", ".*", 0),
422+
supervisor_options in arb_string_vec_no_vars(),
423+
supervisor_input_marker in option::of(".*"),
424+
target_exe in option::of(arb_pathbuf()),
425+
target_options in option::of(arb_string_vec_no_vars()),
426+
tools in option::of(arb_synced_dir()),
427+
wait_for_files in Just(None),
428+
stats_file in Just(None),
429+
stats_format in Just(None),
430+
ensemble_sync_delay in Just(None),
431+
reports in option::of(arb_synced_dir()),
432+
unique_reports in Just(None),
433+
no_repro in Just(None),
434+
coverage in option::of(arb_synced_dir()),
435+
common in arb_common_config(),
436+
) -> fuzz::supervisor::SupervisorConfig {
437+
fuzz::supervisor::SupervisorConfig {
438+
inputs,
439+
crashes,
440+
crashdumps,
441+
supervisor_exe,
442+
supervisor_env,
443+
supervisor_options,
444+
supervisor_input_marker,
445+
target_exe,
446+
target_options,
447+
tools,
448+
wait_for_files,
449+
stats_file,
450+
stats_format,
451+
ensemble_sync_delay,
452+
reports,
453+
unique_reports,
454+
no_repro,
455+
coverage,
456+
common,
457+
}
458+
}
459+
}
460+
461+
impl Arbitrary for fuzz::supervisor::SupervisorConfig {
462+
type Parameters = ();
463+
type Strategy = BoxedStrategy<Self>;
464+
465+
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
466+
arb_supervisor_config().boxed()
467+
}
468+
}
243469
}

src/agent/onefuzz-task/src/tasks/analysis/generic.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ pub struct Config {
4949
}
5050

5151
impl GetExpand for Config {
52-
fn get_expand<'a>(&'a self) -> Expand<'a> {
53-
self.common.get_expand()
52+
fn get_expand<'a>(&'a self) -> Result<Expand<'a>> {
53+
Ok(
54+
self.common.get_expand()?
5455
.analyzer_exe(&self.analyzer_exe)
5556
.analyzer_options(&self.analyzer_options)
5657
.target_exe(&self.target_exe)
@@ -74,6 +75,7 @@ impl GetExpand for Config {
7475
|expand, container| expand.crashes_container(container),
7576
)
7677
})
78+
)
7779
}
7880
}
7981

@@ -236,7 +238,7 @@ pub async fn run_tool(
236238
let target_exe =
237239
try_resolve_setup_relative_path(&config.common.setup_dir, &config.target_exe).await?;
238240

239-
let expand = config.get_expand()
241+
let expand = config.get_expand()?
240242
.input_path(&input) // Only this one is dynamic, the other two should probably be a part of the config
241243
.target_exe(&target_exe)
242244
.set_optional_ref(reports_dir, Expand::reports_dir);
@@ -310,7 +312,10 @@ mod tests {
310312
fn test_get_expand_values_match_config(
311313
config in any::<Config>(),
312314
) {
313-
let expand = config.get_expand();
315+
let expand = match config.get_expand() {
316+
Ok(expand) => expand,
317+
Err(err) => panic!("error getting expand: {}", err),
318+
};
314319
let params = config.get_expand_fields();
315320

316321
for (param, expected) in params.iter() {

src/agent/onefuzz-task/src/tasks/config.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ impl CommonConfig {
126126
}
127127

128128
impl GetExpand for CommonConfig {
129-
fn get_expand<'a>(&'a self) -> Expand<'a> {
130-
Expand::new(&self.machine_identity)
129+
fn get_expand<'a>(&'a self) -> Result<Expand<'a>> {
130+
Ok(
131+
Expand::new(&self.machine_identity)
131132
.machine_id()
132133
.job_id(&self.job_id)
133134
.task_id(&self.task_id)
@@ -147,6 +148,7 @@ impl GetExpand for CommonConfig {
147148
.set_optional_ref(&self.extra_output, |expand, extra_output| {
148149
expand.extra_output_dir(extra_output.local_path.as_path())
149150
})
151+
)
150152
}
151153
}
152154

@@ -429,7 +431,12 @@ mod tests {
429431
fn test_get_expand_values_match_config(
430432
config in any::<CommonConfig>(),
431433
) {
432-
let expand = config.get_expand();
434+
// This function implementation is repeated across all config tests
435+
// There might be a way to share it by taking advantage of the `GetExpandFields` trait, but I'm not sure how
436+
let expand = match config.get_expand() {
437+
Ok(expand) => expand,
438+
Err(err) => panic!("error getting expand: {}", err),
439+
};
433440
let params = config.get_expand_fields();
434441

435442
for (param, expected) in params.iter() {

0 commit comments

Comments
 (0)