Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[runtime] Add more tests for wasm runtime #68

Merged
merged 5 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: get submodule
run: git submodule update --init --recursive
- name: install deps
run: |
sudo make install-deps
make /opt/wasi-sdk
wget https://github.com/tinygo-org/tinygo/releases/download/v0.27.0/tinygo_0.27.0_amd64.deb
sudo dpkg -i tinygo_0.27.0_amd64.deb
make tinygo
- name: Cache
uses: actions/cache@v3.3.0
with:
path: |
Makefile
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: get submodule
run: git submodule update --init --recursive
- name: make
run: make -C runtime/cpp
- name: make build-lib
Expand All @@ -32,4 +37,4 @@ jobs:
- name: Upload build result
uses: actions/upload-artifact@v2.3.1
with:
path: "wasm-bpf"
path: "wasm-bpf"
25 changes: 12 additions & 13 deletions .github/workflows/deploy-asserts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,24 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: get submodule
run: git submodule update --init --recursive
- name: install deps
run: |
sudo make install-deps
make /opt/wasi-sdk
wget https://github.com/tinygo-org/tinygo/releases/download/v0.27.0/tinygo_0.27.0_amd64.deb
sudo dpkg -i tinygo_0.27.0_amd64.deb
make tinygo
- name: Cache
uses: actions/cache@v3.3.0

with:
path: |
Makefile
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: get submodule
run: git submodule update --init --recursive
- name: make
run: make -C runtime/cpp
- name: Install rust stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: examples with rust runtime
run: IMPL=rust make -C examples
- name: examples with cpp runtime
run: IMPL=cpp make -C examples
run: IMPL=cpp make -C examples

- name: Setup Pages
uses: actions/configure-pages@v1
Expand All @@ -58,5 +57,5 @@ jobs:
# Upload entire repository
path: '.'
- name: Deploy to GitHub Pages
id: deployment
id: deploymen
uses: actions/deploy-pages@main
18 changes: 12 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: get submodule
run: git submodule update --init --recursive
- name: Install dependencies
- name: install deps
run: |
sudo make install-deps
make /opt/wasi-sdk
wget https://github.com/tinygo-org/tinygo/releases/download/v0.27.0/tinygo_0.27.0_amd64.deb
sudo dpkg -i tinygo_0.27.0_amd64.deb
make tinygo
- name: Cache
uses: actions/cache@v3.3.0

with:
path: |
Makefile
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: get submodule
run: git submodule update --init --recursive
- name: Build
run: make build-rust
- name: test wasm-bpf-rs
Expand All @@ -41,4 +47,4 @@ jobs:
- name: Upload build result
uses: actions/upload-artifact@v2.3.1
with:
path: "wasm-bpf-rs"
path: "wasm-bpf-rs"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
build/
examples/wasm-bpf
wasi-sdk-*-linux.tar.gz
tinygo_0.27.0_amd64.deb
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ install-deps: ## install deps
tar -zxf wasi-sdk-17.0-linux.tar.gz
sudo mkdir -p /opt/wasi-sdk/ && sudo mv wasi-sdk-17.0/* /opt/wasi-sdk/

tinygo:
wget https://github.com/tinygo-org/tinygo/releases/download/v0.27.0/tinygo_0.27.0_amd64.deb
sudo dpkg -i tinygo_0.27.0_amd64.deb

test:
rm -rf runtime/cpp/build
cd runtime/cpp && mkdir build && cd build && cmake .. && make
16 changes: 16 additions & 0 deletions examples/go-execve/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# go example of execve

## build

install go and tinygo:

```sh
wget https://github.com/tinygo-org/tinygo/releases/download/v0.27.0/tinygo_0.27.0_amd64.deb
sudo dpkg -i tinygo_0.27.0_amd64.deb
```

run make:

```
make
```
1 change: 0 additions & 1 deletion examples/go-execve/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var obj []byte

//export go-callback
func callback(ctx, data, size uint32) uint32 {
// I'm not good at Go...
/*
#define COMM_SIZE 352
struct comm_event {
Expand Down
62 changes: 49 additions & 13 deletions runtime/wasm-bpf-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub struct Config {
impl Default for Config {
fn default() -> Self {
Self {
callback_export_name: String::default(),
wrapper_module_name: String::default(),
callback_export_name: String::from("callback-wrapper"),
wrapper_module_name: String::from("go-callback"),
stdin: Box::new(stdio::stdin()),
stdout: Box::new(stdio::stdout()),
stderr: Box::new(stdio::stderr()),
Expand Down Expand Up @@ -130,13 +130,15 @@ pub fn run_wasm_bpf_module(

#[cfg(test)]
mod tests {
use wasi_common::pipe::WritePipe;

use super::*;
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use std::thread;

fn test_example(name: &str, config: Config) {
fn test_example(name: &str, config: Config, timeout_sec: u64) {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("tests");
path.push(name);
Expand All @@ -149,18 +151,52 @@ mod tests {
let result = run_wasm_bpf_module(&buffer, &args, config);
assert!(result.is_ok());
});
thread::sleep(std::time::Duration::from_secs(3));
thread::sleep(std::time::Duration::from_secs(timeout_sec));
// kill the thread
}

#[test]
fn test_run_tracing_wasm_bpf_module() {
test_example("execve.wasm", Config::default(), 3);
test_example("bootstrap.wasm", Config::default(), 3);
test_example("opensnoop.wasm", Config::default(), 3);
test_example("lsm.wasm", Config::default(), 3);
test_example("rust-bootstrap.wasm", Config::default(), 3);
}

#[test]
fn test_run_network_wasm_bpf_module() {
test_example("sockfilter.wasm", Config::default(), 3);
test_example("sockops.wasm", Config::default(), 3);
}

#[test]
fn test_run_wasm_bpf_module_maps() {
test_example("runqlat.wasm", Config::default(), 3);
}

#[test]
fn test_run_wasm_bpf_module_with_callback() {
let mut config = Config::default();
config.set_callback_values(
String::from("go-callback"),
String::from("callback-wrapper"),
);
test_example("go-execve.wasm", config, 3);
}

#[test]
fn test_run_wasm_bpf_module() {
test_example("execve.wasm", Config::default());
test_example("bootstrap.wasm", Config::default());
test_example("runqlat.wasm", Config::default());
test_example("opensnoop.wasm", Config::default());
test_example("lsm.wasm", Config::default());
test_example("rust-bootstrap.wasm", Config::default());
test_example("sockfilter.wasm", Config::default());
test_example("sockops.wasm", Config::default());
fn test_receive_wasm_bpf_module_output() {
let stdout = WritePipe::new_in_memory();
let stderr = WritePipe::new_in_memory();
let config = Config::new(
String::from("go-callback"),
String::from("callback-wrapper"),
Box::new(stdio::stdin()),
Box::new(stdout.clone()),
Box::new(stderr),
);
test_example("execve.wasm", config, 3);
// read from the WritePipe
}
}
Binary file added runtime/wasm-bpf-rs/tests/go-execve.wasm
Binary file not shown.