-
Notifications
You must be signed in to change notification settings - Fork 722
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use std::{ | ||
dbg, env, | ||
io::{self, Write}, | ||
process::Command, | ||
time::Duration, | ||
}; | ||
mod utils; | ||
|
||
pub fn s2nc(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("s2nc"); | ||
let s2nc_env: &str = &env::var("S2NC_ARGS").unwrap(); | ||
let s2nc_args: utils::Arguments = s2nc_env.into(); | ||
let test_name = format!("s2nc_{}", s2nc_args.get_endpoint().unwrap()); | ||
dbg!("Parsed test_name as: {:?}", &test_name); | ||
group.bench_function(test_name, move |b| { | ||
b.iter(|| { | ||
let s2nc_env: &str = &env::var("S2NC_ARGS").unwrap(); | ||
let s2nc_args: utils::Arguments = s2nc_env.into(); | ||
dbg!("s2nc harness: {:?}", &s2nc_args); | ||
let output = Command::new("/usr/local/bin/s2nc") | ||
.args(s2nc_args.get_vec()) | ||
.output() | ||
.expect("failed to execute process"); | ||
io::stdout().write_all(&output.stdout).unwrap(); | ||
io::stderr().write_all(&output.stderr).unwrap(); | ||
dbg!("DEBUG: return code {:?}", &output.status); | ||
}); | ||
}); | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(name = benches; | ||
config = Criterion::default().sample_size(10).measurement_time(Duration::from_secs(1)); | ||
targets = s2nc); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use std::{ | ||
env, | ||
io::{self, Write}, | ||
process::Command, | ||
}; | ||
|
||
pub fn s2nd(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("s2n_server"); | ||
group.bench_function( | ||
format!("{:?}_s2nd", env::var("TOX_TEST_NAME").unwrap()), | ||
move |b| { | ||
b.iter(|| { | ||
let s2nd_args = env::var("S2ND_ARGS").unwrap(); | ||
assert_ne!(s2nd_args.len(), 0); | ||
let output = Command::new("/usr/local/bin/s2nd") | ||
.arg(s2nd_args) | ||
.output() | ||
.expect("failed to execute process"); | ||
|
||
io::stdout().write_all(&output.stdout).unwrap(); | ||
io::stderr().write_all(&output.stderr).unwrap(); | ||
}); | ||
}, | ||
); | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, s2nd); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#[derive(Debug, Clone)] | ||
pub struct Arguments<'a> { | ||
argument: Vec<&'a str>, | ||
} | ||
|
||
impl<'a> From<&'a str> for Arguments<'a> { | ||
fn from(s: &'a str) -> Arguments<'a> { | ||
assert_ne!(s.len(), 0, "Arguments string can not be empty"); | ||
let s_split = s.split(' '); | ||
Arguments { | ||
argument: s_split.collect::<Vec<&str>>(), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> Arguments<'a> { | ||
#[allow(dead_code)] | ||
pub fn get_dash_c(self) -> Result<&'a str, ()> { | ||
let mut counter = 0; | ||
for element in &self.argument { | ||
counter += 1; | ||
if element.eq(&"-c") { | ||
return Ok(self.argument[counter]); | ||
} | ||
} | ||
Err(()) | ||
} | ||
|
||
pub fn get_endpoint(self) -> Result<&'a str, ()> { | ||
let mut counter = 0; | ||
for element in &self.argument { | ||
counter += 1; | ||
if element.eq(&"-c") { | ||
let result = self.argument[counter + 1] | ||
.trim_end_matches('_') | ||
.trim_start_matches('_'); | ||
return Ok(result); | ||
} | ||
} | ||
Err(()) | ||
} | ||
|
||
pub fn get_vec(self) -> Vec<&'a str> { | ||
self.argument | ||
} | ||
} | ||
|
||
#[test] | ||
fn argument_get_dash_c_test() { | ||
let args: Arguments = "reset --hard --force -c foo.pem".into(); | ||
assert_eq!( | ||
args.get_dash_c().unwrap(), | ||
"foo.pem", | ||
"Failed to fetch the correct argument" | ||
); | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn argument_empty_test() { | ||
let _a: Arguments = "".into(); | ||
} |