use std::path::PathBuf;
use anyhow::anyhow;
use clap::Parser;
use scan_core::{Oracle, Scan, Tracer};
const ALL_PROPS_ERR: &str =
"the --all flag is incompatible with individually-specified properties.\n
Examples:
'scan PATH/TO/MODEL trace' executes the model once and writes the trace to disk
'scan PATH/TO/MODEL verify PROPERTY_1 PROPERTY_2' executes the model once and writes the trace to disk, classifying it according to verification outcome of the properties PROPERTY_1 and PROPERTY_2 together over the model
'scan PATH/TO/MODEL verify --all' executes the model once and writes the trace to disk, and classifying it according to verification outcome of all specified properties together over the model";
#[derive(Debug, Clone, Parser)]
#[deny(missing_docs)]
pub(crate) struct TraceArgs {
pub(crate) properties: Vec<String>,
#[arg(short, long)]
pub(crate) all: bool,
#[arg(long, default_value_t = 1)]
pub(crate) traces: usize,
#[arg(long)]
pub(crate) single_thread: bool,
}
impl TraceArgs {
pub(crate) fn validate(&self) -> anyhow::Result<()> {
if !self.properties.is_empty() && self.all {
Err(anyhow!(ALL_PROPS_ERR))
} else {
Ok(())
}
}
pub(crate) fn trace<'a, Od, Tr>(&self, scan: &'a Scan<Od>, path: PathBuf, model: &Tr::ModelData)
where
Od: Oracle + Clone + Sync + 'a,
Tr: Tracer,
Tr::ModelData: Sync,
{
if self.single_thread {
scan.traces::<Tr>(self.traces, path, model);
} else {
scan.par_traces::<Tr>(self.traces, path, model);
}
}
}