Skip to content

Commit

Permalink
ci: criterion bindings for s2nc/d
Browse files Browse the repository at this point in the history
  • Loading branch information
dougch committed May 20, 2022
1 parent d0456d1 commit 1f142cd
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bindings/rust/integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ publish = false
s2n-tls = { path = "../s2n-tls", features = ["testing"] }
s2n-tls-sys = { path = "../s2n-tls-sys" }
criterion = { version = "0.3", features = ["html_reports"] }
subprocess = "0.2.8"

[[bench]]
name = "handshake"
harness = false

[[bench]]
name = "s2nc"
harness = false

[[bench]]
name = "s2nd"
harness = false
40 changes: 40 additions & 0 deletions bindings/rust/integration/benches/s2nc.rs
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);
34 changes: 34 additions & 0 deletions bindings/rust/integration/benches/s2nd.rs
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);
62 changes: 62 additions & 0 deletions bindings/rust/integration/benches/utils.rs
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();
}

0 comments on commit 1f142cd

Please sign in to comment.