Skip to content

Commit

Permalink
Added more snapshot tests for different scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
john-sharratt committed Mar 16, 2023
1 parent 987bc4a commit d7e2129
Show file tree
Hide file tree
Showing 37 changed files with 176 additions and 32 deletions.
3 changes: 1 addition & 2 deletions lib/wasi/src/os/task/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ impl WasiProcess {
}

/// Signals a particular thread in the process
pub fn signal_thread(&self, tid: &WasiThreadId, signal: Signal)
{
pub fn signal_thread(&self, tid: &WasiThreadId, signal: Signal) {
// Sometimes we will signal the process rather than the thread hence this libc hardcoded value
let mut tid = tid.raw();
if tid == 1073741823 {
Expand Down
17 changes: 16 additions & 1 deletion tests/integration/cli/tests/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct TestSpec {
pub stdin: Option<Vec<u8>>,
pub debug_output: bool,
pub enable_threads: bool,
pub enable_network: bool,
}

impl std::fmt::Debug for TestSpec {
Expand Down Expand Up @@ -73,6 +74,7 @@ impl TestBuilder {
stdin: None,
debug_output: false,
enable_threads: true,
enable_network: false,
},
}
}
Expand Down Expand Up @@ -125,6 +127,11 @@ impl TestBuilder {
self
}

pub fn enable_network(mut self, enabled: bool) -> Self {
self.spec.enable_network = enabled;
self
}

pub fn run_file(self, path: impl AsRef<Path>) -> TestSnapshot {
snapshot_file(path.as_ref(), self.spec)
}
Expand Down Expand Up @@ -185,8 +192,10 @@ pub fn run_test(spec: TestSpec, code: &[u8]) -> TestResult {
if spec.enable_threads {
cmd.arg("--enable-threads");
}
if spec.enable_network {
cmd.arg("--net");
}
cmd.arg("--allow-multiple-wasi-versions");
cmd.arg("--net");

for pkg in &spec.use_packages {
cmd.args(&["--use", &pkg]);
Expand Down Expand Up @@ -367,6 +376,9 @@ fn test_snapshot_file_copy() {
let snapshot = TestBuilder::new()
.with_name(function!())
.use_coreutils()
.stdin_str("hi")
.arg("/dev/stdin")
.arg("/dev/stdout")
.run_wasm(include_bytes!("./wasm/example-file-copy.wasm"));
assert_json_snapshot!(snapshot);
}
Expand All @@ -375,17 +387,20 @@ fn test_snapshot_file_copy() {
fn test_snapshot_execve() {
let snapshot = TestBuilder::new()
.with_name(function!())
.use_coreutils()
.run_wasm(include_bytes!("./wasm/example-execve.wasm"));
assert_json_snapshot!(snapshot);
}

/*
#[test]
fn test_snapshot_web_server() {
let snapshot = TestBuilder::new()
.with_name(function!())
.run_wasm(include_bytes!("./wasm/web-server.wasm"));
assert_json_snapshot!(snapshot);
}
*/

// The ability to fork the current process and run a different image but retain
// the existing open file handles (which is needed for stdin and stdout redirection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ expression: snapshot
10
],
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ expression: snapshot
10
],
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ expression: snapshot
10
],
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ expression: snapshot
10
],
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ expression: snapshot
10
],
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ expression: snapshot
10
],
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ expression: snapshot
119
],
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ expression: snapshot
"cli_args": [],
"stdin": null,
"debug_output": true,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ expression: snapshot
10
],
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ expression: snapshot
10
],
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ expression: snapshot
10
],
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ expression: snapshot
50
],
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ expression: snapshot
116
],
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ expression: snapshot
39
],
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ expression: snapshot
],
"stdin": null,
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: tests/integration/cli/tests/snapshot.rs
assertion_line: 363
expression: snapshot
---
{
"spec": {
"name": "snapshot::test_snapshot_epoll",
"use_packages": [],
"cli_args": [],
"stdin": null,
"debug_output": false,
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
"stdout": "EFD_NONBLOCK:4\nsuccess write to efd, write 8 bytes(4)\nsuccess read from efd, read 8 bytes(4)\nsuccess write to efd, write 8 bytes(4)\nsuccess read from efd, read 8 bytes(4)\nsuccess write to efd, write 8 bytes(4)\nsuccess read from efd, read 8 bytes(4)\nsuccess write to efd, write 8 bytes(4)\nsuccess read from efd, read 8 bytes(4)\nsuccess write to efd, write 8 bytes(4)\nsuccess read from efd, read 8 bytes(4)\n",
"stderr": "",
"exit_code": 8
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: tests/integration/cli/tests/snapshot.rs
assertion_line: 381
expression: snapshot
---
{
"spec": {
"name": "snapshot::test_snapshot_execve",
"use_packages": [
"sharrattj/coreutils"
],
"cli_args": [],
"stdin": null,
"debug_output": false,
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
"stdout": "Main program started\nexecve: echo hi-from-child\nhi-from-child\nChild(2) exited with 0\nexecve: echo hi-from-parent\nhi-from-parent\n",
"stderr": "",
"exit_code": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
source: tests/integration/cli/tests/snapshot.rs
assertion_line: 374
expression: snapshot
---
{
"spec": {
"name": "snapshot::test_snapshot_file_copy",
"use_packages": [
"sharrattj/coreutils"
],
"cli_args": [
"/dev/stdin",
"/dev/stdout"
],
"stdin": [
104,
105
],
"debug_output": false,
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
"stdout": "hi",
"stderr": "",
"exit_code": 0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ expression: snapshot
"cli_args": [],
"stdin": null,
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
"stdout": "Parent has x = 0\nChild has x = 2\nParent memory is good\nChild memory is good\nChild(2) exited with 3\n",
"stdout": "Parent has x = 0\nParent memory is good\nChild has x = 2\nChild memory is good\nChild(2) exited with 3\n",
"stderr": "",
"exit_code": 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ expression: snapshot
"cli_args": [],
"stdin": null,
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ expression: snapshot
"cli_args": [],
"stdin": null,
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ expression: snapshot
"cli_args": [],
"stdin": null,
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ expression: snapshot
"cli_args": [],
"stdin": null,
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ expression: snapshot
"cli_args": [],
"stdin": null,
"debug_output": true,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ expression: snapshot
"cli_args": [],
"stdin": null,
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ expression: snapshot
"cli_args": [],
"stdin": null,
"debug_output": false,
"enable_threads": true
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
Expand Down
Loading

0 comments on commit d7e2129

Please sign in to comment.