Skip to content

Commit

Permalink
update: match all commits from testing branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwample authored and Erik Chi committed Oct 22, 2023
1 parent e9b0371 commit f6980c2
Show file tree
Hide file tree
Showing 24 changed files with 114 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

[workspace]
members = ["crates/*", "examples/water_bins/*", "examples/clients/*"]
members = ["crates/*", "examples/water_bins/*", "examples/clients/*", "tests"]
# exclude = ["crates/foo", "path/to/other"]
default-members = ["crates/*"]
resolver="2"
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ nc 127.0.0.1 9005
```
you should see `> CONNECTED` in the terminal of running WASM, then you can connect a bunch like this and input anything to see how it echos.


## Running tests

```sh
# runs ALL tests
cargo test --workspace --verbose

# run tests for a single crate
cargo test -p <crate_name> --verbose
```

## TODOs
- [ ] wasm_config sharing implementation
- [ ] Generalize Host export TCP listener helper function
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/clients/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name="cli"
name="cli-dev"
version = "0.1.0"
authors.workspace = true
description.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion examples/water_bins/echo_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ url = { version = "2.2.2", features = ["serde"] }
libc = "0.2.147"

# water wasm lib import
water-wasm = { path = "../../../crates/water_wasm/", version = "0.1.0" }
water-wasm = { path = "../../../crates/wasm/", version = "0.1.0" }
2 changes: 1 addition & 1 deletion examples/water_bins/ss_client_wasm_v1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ futures = "0.3.28"
pin-project = "1.1.2"

# water wasm lib import
water-wasm = { path = "../../../crates/water_wasm/", version = "0.1.0" }
water-wasm = { path = "../../../crates/wasm/", version = "0.1.0" }
18 changes: 18 additions & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "tests"
version = "0.1.0"
authors.workspace = true
description.workspace = true
edition.workspace = true
publish = false


[dev-dependencies]
water-wasm = { path = "../crates/wasm" }
water = { path = "../crates/water" }

tracing = "0.1"
tracing-subscriber = "0.3.17"
rand = "0.8"
pprof = { version = "0.11.1", features = ["flamegraph", "protobuf-codec", "prost-codec"] }
anyhow = "1.0.7"
90 changes: 51 additions & 39 deletions tests/benchmarking_v0.rs → tests/benches/benchmarking_v0.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
// use cap_std::net::TcpStream;
use water::*;
use rand;

use pprof::protos::Message;
use std::net::{TcpListener, TcpStream};
// use std::net::{TcpListener, TcpStream};
use std::net::TcpListener;
use std::thread;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
// use std::sync::atomic::{AtomicBool, Ordering};
// use std::sync::Arc;

use tracing_subscriber;
use tracing::Level;

use std::time::Instant;
use tracing::info;

use std::io::{Read, Write, ErrorKind};
use std::thread::sleep;
use std::time::Duration;
use std::io::{Read, Write};
// use std::io::{Read, Write, ErrorKind};
// use std::thread::sleep;
// use std::time::Duration;

#[test]
fn benchmarking_v0_echo() -> Result<(), anyhow::Error> {
tracing_subscriber::fmt()
.with_max_level(Level::INFO)
.init();
tracing_subscriber::fmt().with_max_level(Level::INFO).init();

thread::spawn(move || {
let listener = TcpListener::bind("127.0.0.1:8080").unwrap();
Expand All @@ -39,7 +37,7 @@ fn benchmarking_v0_echo() -> Result<(), anyhow::Error> {
if n == 0 {
break; // Connection was closed.
}

// Echo data back to client.
if let Err(e) = stream.write_all(&buf[..n]) {
eprintln!("Error writing to client: {:?}", e);
Expand Down Expand Up @@ -68,20 +66,28 @@ fn benchmarking_v0_echo() -> Result<(), anyhow::Error> {
// --------- start to dial the listener ---------
let dial_handle = std::thread::spawn(|| -> Result<(), anyhow::Error> {
// Measure initialization time
let conf = config::WATERConfig::init(String::from("./tests/test_wasm/proxy.wasm"), String::from("_dial"), String::from("./tests/test_data/config.json"), 0, true)?;
let conf = config::WATERConfig::init(
String::from("./tests/test_wasm/proxy.wasm"),
String::from("_dial"),
String::from("./tests/test_data/config.json"),
0,
true,
)?;
let mut water_client = runtime::WATERClient::new(conf)?;
water_client.connect("", 0)?;

// let mut water_client = TcpStream::connect(("127.0.0.1", 8088))?;

// Not measuring the profiler guard initialization since it's unrelated to the read/write ops
let guard = pprof::ProfilerGuard::new(100).unwrap();

let single_data_size = 1024; // Bytes per iteration
let total_iterations = 1;

let random_data: Vec<u8> = (0..single_data_size).map(|_| rand::random::<u8>()).collect();


let random_data: Vec<u8> = (0..single_data_size)
.map(|_| rand::random::<u8>())
.collect();

let start = Instant::now();
for _ in 0..total_iterations {
water_client.write(&random_data)?;
Expand All @@ -94,14 +100,18 @@ fn benchmarking_v0_echo() -> Result<(), anyhow::Error> {
let total_data_size_mb = (total_iterations * single_data_size) as f64;
let avg_bandwidth = total_data_size_mb / elapsed_time / 1024.0 / 1024.0;

info!("avg bandwidth: {:.2} MB/s (N={})", avg_bandwidth, total_iterations);


info!(
"avg bandwidth: {:.2} MB/s (N={})",
avg_bandwidth, total_iterations
);

let single_data_size = 1024; // Bytes per iteration
let total_iterations = 100;

let random_data: Vec<u8> = (0..single_data_size).map(|_| rand::random::<u8>()).collect();


let random_data: Vec<u8> = (0..single_data_size)
.map(|_| rand::random::<u8>())
.collect();

let start = Instant::now();
for _ in 0..total_iterations {
water_client.write(&random_data)?;
Expand All @@ -114,14 +124,17 @@ fn benchmarking_v0_echo() -> Result<(), anyhow::Error> {
let total_data_size_mb = (total_iterations * single_data_size) as f64;
let avg_bandwidth = total_data_size_mb / elapsed_time / 1024.0 / 1024.0;

info!("avg bandwidth: {:.2} MB/s (N={})", avg_bandwidth, total_iterations);

info!(
"avg bandwidth: {:.2} MB/s (N={})",
avg_bandwidth, total_iterations
);

// ================== test more iterations ==================
// let single_data_size = 1024; // Bytes per iteration
// let total_iterations = 10000;

// let random_data: Vec<u8> = (0..single_data_size).map(|_| rand::random::<u8>()).collect();

// let start = Instant::now();
// for _ in 0..total_iterations {
// water_client.write(&random_data)?;
Expand All @@ -135,13 +148,12 @@ fn benchmarking_v0_echo() -> Result<(), anyhow::Error> {
// let avg_bandwidth = total_data_size_mb / elapsed_time / 1024.0 / 1024.0;

// info!("avg bandwidth: {:.2} MB/s (N={})", avg_bandwidth, total_iterations);



// let single_data_size = 1024; // Bytes per iteration
// let total_iterations = 43294;

// let random_data: Vec<u8> = (0..single_data_size).map(|_| rand::random::<u8>()).collect();

// let start = Instant::now();
// for _ in 0..total_iterations {
// water_client.write(&random_data)?;
Expand All @@ -155,19 +167,19 @@ fn benchmarking_v0_echo() -> Result<(), anyhow::Error> {
// let avg_bandwidth = total_data_size_mb / elapsed_time / 1024.0 / 1024.0;

// info!("avg bandwidth: {:.2} MB/s (N={})", avg_bandwidth, total_iterations);

// Stop and report profiler data
if let Ok(report) = guard.report().build() {
// println!("{:?}", report);
// report.flamegraph(std::io::stdout())?;
let mut file = std::fs::File::create("flamegraph.svg")?;
let file = std::fs::File::create("flamegraph.svg")?;
report.flamegraph(file)?;

// let mut file = std::fs::File::create("profile.pb")?;
// report.pprof(file)?;
let mut file = std::fs::File::create("profile.pb").unwrap();
let profile = report.pprof().unwrap();

let mut content = Vec::new();
// profile.encode(&mut content).unwrap();
profile.write_to_vec(&mut content).unwrap();
Expand Down Expand Up @@ -197,7 +209,7 @@ fn benchmarking_v0_echo() -> Result<(), anyhow::Error> {
// // water_client.execute();

// // Ok(())

// let tcp = std::net::TcpListener::bind(("127.0.0.1", 8088)).unwrap();

// loop {
Expand Down Expand Up @@ -257,14 +269,14 @@ fn benchmarking_v0_echo() -> Result<(), anyhow::Error> {
// // keep reading from stdin and call read and write function from water_client.stream
// let mut buf = String::new();
// std::io::stdin().read_line(&mut buf)?;

// water_client.write(buf.as_bytes())?;

// let mut buf = vec![0; 1024];
// water_client.read(&mut buf)?;

// println!("read: {:?}", String::from_utf8_lossy(&buf));
// }

// Ok(())
// }
// }
61 changes: 30 additions & 31 deletions tests/SS_testing.rs → tests/tests/ss_testing.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
// use cap_std::net::TcpStream;
use water::*;
use rand;
// use rand;

use pprof::protos::Message;
use std::net::{TcpListener, TcpStream};
use std::thread;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
// use pprof::protos::Message;
// use std::net::{TcpListener, TcpStream};
// use std::thread;
// use std::sync::atomic::{AtomicBool, Ordering};
// use std::sync::Arc;

use tracing_subscriber;
use tracing::Level;

use std::time::Instant;
use tracing::info;
// use std::time::Instant;
// use tracing::info;

use std::io::{Read, Write, ErrorKind};
use std::thread::sleep;
use std::time::Duration;
// use std::io::{Read, Write, ErrorKind};
// use std::thread::sleep;
// use std::time::Duration;

#[test]
fn wasm_managed_shadowsocks_async() {
tracing_subscriber::fmt()
.with_max_level(Level::INFO)
.init();
let conf = config::WATERConfig::init(String::from("./tests/test_wasm/ss_client_wasm.wasm"),
String::from("ss_client_execute"),
String::from("./tests/test_data/config.json"),
2,
true).unwrap();
tracing_subscriber::fmt().with_max_level(Level::INFO).init();
let conf = config::WATERConfig::init(
String::from("./test_wasm/ss_client_wasm.wasm"),
String::from("ss_client_execute"),
String::from("./test_data/config.json"),
2,
true,
)
.unwrap();

let mut water_client = runtime::WATERClient::new(conf).unwrap();
water_client.execute().unwrap();
Expand Down Expand Up @@ -69,15 +69,15 @@ fn wasm_managed_shadowsocks_async() {
// water_client.connect("", 0)?;

// // let mut water_client = TcpStream::connect(("127.0.0.1", 8088))?;

// // Not measuring the profiler guard initialization since it's unrelated to the read/write ops
// let guard = pprof::ProfilerGuard::new(100).unwrap();

// let single_data_size = 1024; // Bytes per iteration
// let total_iterations = 1;

// let random_data: Vec<u8> = (0..single_data_size).map(|_| rand::random::<u8>()).collect();

// let start = Instant::now();
// for _ in 0..total_iterations {
// water_client.write(&random_data)?;
Expand All @@ -91,13 +91,12 @@ fn wasm_managed_shadowsocks_async() {
// let avg_bandwidth = total_data_size_mb / elapsed_time / 1024.0 / 1024.0;

// info!("avg bandwidth: {:.2} MB/s (N={})", avg_bandwidth, total_iterations);



// let single_data_size = 1024; // Bytes per iteration
// let total_iterations = 100;

// let random_data: Vec<u8> = (0..single_data_size).map(|_| rand::random::<u8>()).collect();

// let start = Instant::now();
// for _ in 0..total_iterations {
// water_client.write(&random_data)?;
Expand All @@ -111,19 +110,19 @@ fn wasm_managed_shadowsocks_async() {
// let avg_bandwidth = total_data_size_mb / elapsed_time / 1024.0 / 1024.0;

// info!("avg bandwidth: {:.2} MB/s (N={})", avg_bandwidth, total_iterations);

// // Stop and report profiler data
// if let Ok(report) = guard.report().build() {
// // println!("{:?}", report);
// // report.flamegraph(std::io::stdout())?;
// let mut file = std::fs::File::create("flamegraph.svg")?;
// report.flamegraph(file)?;

// // let mut file = std::fs::File::create("profile.pb")?;
// // report.pprof(file)?;
// let mut file = std::fs::File::create("profile.pb").unwrap();
// let profile = report.pprof().unwrap();

// let mut content = Vec::new();
// // profile.encode(&mut content).unwrap();
// profile.write_to_vec(&mut content).unwrap();
Expand All @@ -139,4 +138,4 @@ fn wasm_managed_shadowsocks_async() {
// // should_stop.store(true, Ordering::Relaxed);

// Ok(())
// }
// }

0 comments on commit f6980c2

Please sign in to comment.