mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-17 20:38:06 +00:00
Adding timeout to local run (#735)
This commit is contained in:
@ -1,8 +1,11 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::{App, SubCommand};
|
||||
use clap::{App, Arg, SubCommand};
|
||||
use tokio::time::timeout;
|
||||
|
||||
use crate::local::{
|
||||
common::add_common_config, generic_analysis, generic_crash_report, generic_generator,
|
||||
@ -22,28 +25,52 @@ const GENERIC_GENERATOR: &str = "generator";
|
||||
const GENERIC_ANALYSIS: &str = "analysis";
|
||||
const GENERIC_TEST_INPUT: &str = "test-input";
|
||||
|
||||
const TIMEOUT: &str = "timeout";
|
||||
|
||||
pub async fn run(args: &clap::ArgMatches<'_>) -> Result<()> {
|
||||
match args.subcommand() {
|
||||
(RADAMSA, Some(sub)) => radamsa::run(sub).await,
|
||||
(LIBFUZZER, Some(sub)) => libfuzzer::run(sub).await,
|
||||
(LIBFUZZER_FUZZ, Some(sub)) => libfuzzer_fuzz::run(sub).await,
|
||||
(LIBFUZZER_COVERAGE, Some(sub)) => libfuzzer_coverage::run(sub).await,
|
||||
(LIBFUZZER_CRASH_REPORT, Some(sub)) => libfuzzer_crash_report::run(sub).await,
|
||||
(LIBFUZZER_MERGE, Some(sub)) => libfuzzer_merge::run(sub).await,
|
||||
(GENERIC_ANALYSIS, Some(sub)) => generic_analysis::run(sub).await,
|
||||
(GENERIC_CRASH_REPORT, Some(sub)) => generic_crash_report::run(sub).await,
|
||||
(GENERIC_GENERATOR, Some(sub)) => generic_generator::run(sub).await,
|
||||
(GENERIC_TEST_INPUT, Some(sub)) => test_input::run(sub).await,
|
||||
(LIBFUZZER_TEST_INPUT, Some(sub)) => libfuzzer_test_input::run(sub).await,
|
||||
_ => {
|
||||
anyhow::bail!("missing subcommand\nUSAGE: {}", args.usage());
|
||||
let running_duration = value_t!(args, TIMEOUT, u64).ok();
|
||||
|
||||
let run = async {
|
||||
match args.subcommand() {
|
||||
(RADAMSA, Some(sub)) => radamsa::run(sub).await,
|
||||
(LIBFUZZER, Some(sub)) => libfuzzer::run(sub).await,
|
||||
(LIBFUZZER_FUZZ, Some(sub)) => libfuzzer_fuzz::run(sub).await,
|
||||
(LIBFUZZER_COVERAGE, Some(sub)) => libfuzzer_coverage::run(sub).await,
|
||||
(LIBFUZZER_CRASH_REPORT, Some(sub)) => libfuzzer_crash_report::run(sub).await,
|
||||
(LIBFUZZER_MERGE, Some(sub)) => libfuzzer_merge::run(sub).await,
|
||||
(GENERIC_ANALYSIS, Some(sub)) => generic_analysis::run(sub).await,
|
||||
(GENERIC_CRASH_REPORT, Some(sub)) => generic_crash_report::run(sub).await,
|
||||
(GENERIC_GENERATOR, Some(sub)) => generic_generator::run(sub).await,
|
||||
(GENERIC_TEST_INPUT, Some(sub)) => test_input::run(sub).await,
|
||||
(LIBFUZZER_TEST_INPUT, Some(sub)) => libfuzzer_test_input::run(sub).await,
|
||||
_ => {
|
||||
anyhow::bail!("missing subcommand\nUSAGE: {}", args.usage());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(minutes) = running_duration {
|
||||
if let Ok(run) = timeout(Duration::from_secs(minutes * 60), run).await {
|
||||
run
|
||||
} else {
|
||||
info!("The running timeout period has elapsed");
|
||||
Ok(())
|
||||
}
|
||||
} else {
|
||||
run.await
|
||||
}
|
||||
}
|
||||
|
||||
pub fn args(name: &str) -> App<'static, 'static> {
|
||||
SubCommand::with_name(name)
|
||||
.about("pre-release local fuzzing")
|
||||
.arg(
|
||||
Arg::with_name(TIMEOUT)
|
||||
.long(TIMEOUT)
|
||||
.help("The maximum running time in minutes")
|
||||
.takes_value(true)
|
||||
.required(false),
|
||||
)
|
||||
.subcommand(add_common_config(radamsa::args(RADAMSA)))
|
||||
.subcommand(add_common_config(libfuzzer::args(LIBFUZZER)))
|
||||
.subcommand(add_common_config(libfuzzer_fuzz::args(LIBFUZZER_FUZZ)))
|
||||
|
Reference in New Issue
Block a user