-
Notifications
You must be signed in to change notification settings - Fork 13
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
7 changed files
with
220 additions
and
3 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,9 @@ | ||
[package] | ||
name = "client" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
utils = { path = "../utils" } | ||
tokio = { workspace = true, features = ["rt-multi-thread"] } | ||
anyhow = { workspace = true } |
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,9 @@ | ||
{ | ||
"url": "ws://127.0.0.1:9001", | ||
"outdir": "autobahn/results", | ||
"cases": [ | ||
"*" | ||
], | ||
"exclude-cases": [], | ||
"exclude-agent-cases": {} | ||
} |
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,97 @@ | ||
use std::env::current_dir; | ||
use std::process::Stdio; | ||
|
||
use anyhow::{Context, Result}; | ||
use tokio::process::Command; | ||
|
||
use utils::{await_server_start, cargo_command, pipe_logs, validate_results}; | ||
|
||
const PWD_ERR: &str = "Failed to get PWD"; | ||
const CONTAINER_NAME: &str = "fuzzingserver"; | ||
|
||
async fn kill_container() { | ||
Command::new("docker") | ||
.args(["kill", CONTAINER_NAME]) | ||
.stdin(Stdio::null()) | ||
.spawn() | ||
.expect("Failed to spawn command to kill any lingering test container") | ||
.wait() | ||
.await | ||
.expect("Failed to kill any lingering test container"); | ||
} | ||
|
||
fn docker_command() -> Result<Command> { | ||
let mut pwd = current_dir().context(PWD_ERR)?; | ||
pwd.push("ratchet_rs"); | ||
|
||
// mount /pwd/autobahn/client to /autobahn in the volume | ||
let mut volume_arg = pwd.clone(); | ||
volume_arg.push("autobahn/client:/autobahn"); | ||
|
||
let mut cmd = Command::new("docker"); | ||
cmd.args(["run", "-d", "--rm", "-v"]) | ||
.arg(volume_arg) | ||
.args([ | ||
"-p", | ||
"9001:9001", | ||
"--init", | ||
"--platform", | ||
"linux/amd64", | ||
"--name", | ||
CONTAINER_NAME, | ||
"crossbario/autobahn-testsuite:0.8.2", | ||
"wstest", | ||
"-m", | ||
"fuzzingserver", | ||
"-s", | ||
]) | ||
// spec is now available at this directory due to how the host directory was mounted | ||
.arg("autobahn/fuzzingserver.json") | ||
.current_dir(pwd); | ||
|
||
Ok(cmd) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let _server_process = tokio::spawn(async move { | ||
// Just in case there is one lingering after being run locally. | ||
kill_container().await; | ||
|
||
docker_command() | ||
.expect(PWD_ERR) | ||
.spawn() | ||
.expect("Failed to spawn autobahn server") | ||
.wait() | ||
.await | ||
}); | ||
|
||
if let Err(e) = await_server_start(9001).await { | ||
kill_container().await; | ||
return Err(e); | ||
} | ||
|
||
let mut logs_process = match pipe_logs(CONTAINER_NAME).await { | ||
Ok(child) => child, | ||
Err(e) => { | ||
kill_container().await; | ||
return Err(e); | ||
} | ||
}; | ||
|
||
cargo_command("autobahn-client")? | ||
.spawn() | ||
.context("Failed to spawn docker container")? | ||
.wait() | ||
.await | ||
.context("Failed to run autobahn client")?; | ||
|
||
let mut results_dir = current_dir().context(PWD_ERR)?; | ||
results_dir.push("ratchet_rs/autobahn/client/results"); | ||
|
||
validate_results(results_dir)?; | ||
logs_process.kill().await?; | ||
kill_container().await; | ||
|
||
Ok(()) | ||
} |
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,9 @@ | ||
[package] | ||
name = "server" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
utils = { path = "../utils" } | ||
tokio = { workspace = true, features = ["rt-multi-thread"] } | ||
anyhow = { workspace = true } |
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,15 @@ | ||
{ | ||
"outdir": "autobahn/results", | ||
"servers": [ | ||
{ | ||
"agent": "Ratchet", | ||
"url": "ws://127.0.0.1:9002" | ||
} | ||
], | ||
"cases": [ | ||
"*" | ||
], | ||
"exclude-cases": [ | ||
], | ||
"exclude-agent-cases": {} | ||
} |
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,81 @@ | ||
use std::env::current_dir; | ||
use std::sync::Arc; | ||
|
||
use anyhow::{bail, Context, Result}; | ||
use tokio::process::Command; | ||
use tokio::sync::Notify; | ||
use utils::{await_server_start, cargo_command, validate_results}; | ||
|
||
const PWD_ERR: &str = "Failed to get PWD"; | ||
|
||
fn docker_command() -> Result<Command> { | ||
let mut pwd = current_dir().context(PWD_ERR)?; | ||
pwd.push("ratchet_rs"); | ||
|
||
// mount /pwd/autobahn/server to /autobahn in the volume | ||
let mut volume_arg = pwd.clone(); | ||
volume_arg.push("autobahn/server:/autobahn"); | ||
|
||
let mut cmd = Command::new("docker"); | ||
cmd.args(["run", "--rm", "-v"]) | ||
.arg(volume_arg) | ||
.args([ | ||
"--network", | ||
"host", | ||
"--platform", | ||
"linux/amd64", | ||
"crossbario/autobahn-testsuite:0.8.2", | ||
"wstest", | ||
"-m", | ||
"fuzzingclient", | ||
"-s", | ||
]) | ||
// spec is now available at this directory due to how the host directory was mounted | ||
.arg("autobahn/fuzzingclient.json") | ||
.current_dir(pwd); | ||
|
||
Ok(cmd) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let stop = Arc::new(Notify::new()); | ||
let server_stop = stop.clone(); | ||
|
||
let server_process = tokio::spawn(async move { | ||
let mut child = cargo_command("autobahn-server") | ||
.expect(PWD_ERR) | ||
.spawn() | ||
.expect("Failed to spawn autobahn server"); | ||
|
||
server_stop.notified().await; | ||
child.kill().await.expect("Failed to kill process"); | ||
}); | ||
|
||
if let Err(e) = await_server_start(9002).await { | ||
stop.notify_waiters(); | ||
server_process.await.expect("Cargo server process failed"); | ||
return Err(e); | ||
} | ||
|
||
let result = docker_command()? | ||
.spawn() | ||
.context("Failed to spawn docker container")? | ||
.wait() | ||
.await | ||
.context("Autobahn suite failed")?; | ||
|
||
if !result.success() { | ||
bail!("Autobahn suite failed"); | ||
} | ||
|
||
let mut results_dir = current_dir().context(PWD_ERR)?; | ||
results_dir.push("ratchet_rs/autobahn/server/results"); | ||
|
||
validate_results(results_dir)?; | ||
|
||
stop.notify_waiters(); | ||
server_process.await.expect("Cargo server process failed"); | ||
|
||
Ok(()) | ||
} |