Skip to content

Commit

Permalink
Adds missing autobahn directories
Browse files Browse the repository at this point in the history
  • Loading branch information
SirCipher committed May 22, 2024
1 parent 133a31b commit de6b72f
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 3 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

.idea

ratchet_rs/autobahn/client
ratchet_rs/autobahn/server

**/.DS_Store

ratchet_rs/autobahn/client/results
Expand Down
9 changes: 9 additions & 0 deletions ratchet_rs/autobahn/client/Cargo.toml
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 }
9 changes: 9 additions & 0 deletions ratchet_rs/autobahn/client/fuzzingserver.json
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": {}
}
97 changes: 97 additions & 0 deletions ratchet_rs/autobahn/client/src/main.rs
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(())
}
9 changes: 9 additions & 0 deletions ratchet_rs/autobahn/server/Cargo.toml
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 }
15 changes: 15 additions & 0 deletions ratchet_rs/autobahn/server/fuzzingclient.json
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": {}
}
81 changes: 81 additions & 0 deletions ratchet_rs/autobahn/server/src/main.rs
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(())
}

0 comments on commit de6b72f

Please sign in to comment.