diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-12-26 17:21:49 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-12-26 17:21:49 +0000 |
commit | 010480a957c52e14172049aea3e692447be8cdfe (patch) | |
tree | fefd20b8aa3da4d7771a46121fc03d8fb1c5dad0 /src/bin/obnam-benchmark.rs | |
parent | 9f170606eb4fc24086274b446bb77cc1195280f0 (diff) | |
parent | abfeccd0d839eef9e90397dcff40f0bf918ed477 (diff) | |
download | obnam-benchmark-010480a957c52e14172049aea3e692447be8cdfe.tar.gz |
Merge branch 'random' into 'main'
feat: generate test data with junk contents
See merge request obnam/obnam-benchmark!3
Diffstat (limited to 'src/bin/obnam-benchmark.rs')
-rw-r--r-- | src/bin/obnam-benchmark.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/bin/obnam-benchmark.rs b/src/bin/obnam-benchmark.rs index 85ef3f9..1a26ae0 100644 --- a/src/bin/obnam-benchmark.rs +++ b/src/bin/obnam-benchmark.rs @@ -1,4 +1,5 @@ use log::{debug, error, info}; +use obnam_benchmark::junk::junk; use obnam_benchmark::result::Result; use obnam_benchmark::specification::Specification; use obnam_benchmark::suite::Suite; @@ -24,6 +25,7 @@ fn real_main() -> anyhow::Result<()> { debug!("parsed: {:#?}", opt); match opt.cmd { + Command::GenerateJunk(x) => x.run()?, Command::Run(x) => x.run()?, Command::Spec(x) => x.run()?, } @@ -44,6 +46,9 @@ enum Command { /// Dump the specification as JSON Spec(Spec), + + /// Generate some junk data in a file. + GenerateJunk(GenerateJunk), } #[derive(Debug, StructOpt)] @@ -98,3 +103,27 @@ impl Spec { Ok(()) } } + +#[derive(Debug, StructOpt)] +struct GenerateJunk { + /// Number of bytes of junk to create + #[structopt()] + bytes: u64, + + /// Name of the output file + #[structopt(parse(from_os_str))] + filename: PathBuf, +} + +impl GenerateJunk { + fn run(&self) -> anyhow::Result<()> { + info!( + "generating {} bytes of junk into {}", + self.bytes, + self.filename.display() + ); + let mut output = File::create(&self.filename)?; + junk(&mut output, self.bytes)?; + Ok(()) + } +} |