Skip to content

Commit

Permalink
Fixes for snapshot tests
Browse files Browse the repository at this point in the history
- Fixed the unit tests for dash and bash subprocesses
- Fixed the order of the flushing of files so that processes are notified of exit only after the open file handles are flushed
  • Loading branch information
john-sharratt committed Mar 16, 2023
1 parent 408e57e commit 32c0b3c
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/wasi/src/bin_factory/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ pub fn spawn_exec_module(
} else {
Errno::Success.into()
};
debug!("wasi[{pid}]::main() has exited with {code}");
thread.thread.set_status_finished(ret.map(|a| a.into()));

// Cleanup the environment
wasi_env.data(&store).blocking_cleanup(Some(code));

debug!("wasi[{pid}]::main() has exited with {code}");
thread.thread.set_status_finished(ret.map(|a| a.into()));
}
};

Expand Down
4 changes: 2 additions & 2 deletions lib/wasi/tests/runners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod wasi {
WasiError::Exit(code) => *code,
other => unreachable!("Something else went wrong: {:?}", other),
};
assert_eq!(exit_code, 1);
assert_eq!(exit_code.is_success(), true);
}

#[tokio::test]
Expand All @@ -77,7 +77,7 @@ mod wasi {
WasiError::Exit(code) => *code,
other => unreachable!("Something else went wrong: {:?}", other),
};
assert_eq!(exit_code, 42);
assert_eq!(exit_code.raw(), 42);
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/integration/cli/tests/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ fn test_snapshot_dash_dash() {
let snapshot = TestBuilder::new()
.with_name(function!())
.use_dash()
.stdin_str("/bin/dash\necho hi\nexit\necho hi2\n")
.stdin_str("/bin/dash\necho hi\nexit\nexit\n")
.run_wasm(include_bytes!("./wasm/dash.wasm"));
assert_json_snapshot!(snapshot);
}
Expand All @@ -556,7 +556,7 @@ fn test_snapshot_dash_bash() {
let snapshot = TestBuilder::new()
.with_name(function!())
.use_bash()
.stdin_str("/bin/bash\necho hi\nexit\necho hi2\n")
.stdin_str("/bin/bash\necho hi\nexit\nexit\n")
.run_wasm(include_bytes!("./wasm/dash.wasm"));
assert_json_snapshot!(snapshot);
}
Expand Down Expand Up @@ -617,7 +617,7 @@ fn test_snapshot_bash_dash() {
let snapshot = TestBuilder::new()
.with_name(function!())
.use_dash()
.stdin_str("/bin/dash\necho hi\nexit\necho hi2\n")
.stdin_str("/bin/dash\necho hi\nexit\nexit\n")
.run_wasm(include_bytes!("./wasm/bash.wasm"));
assert_json_snapshot!(snapshot);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
source: tests/integration/cli/tests/snapshot.rs
assertion_line: 594
expression: snapshot
---
{
"spec": {
"name": "snapshot::test_snapshot_bash_bash",
"use_packages": [
"sharrattj/bash"
],
"cli_args": [],
"stdin": [
47,
98,
105,
110,
47,
98,
97,
115,
104,
10,
101,
99,
104,
111,
32,
104,
105,
10,
101,
120,
105,
116,
10,
101,
99,
104,
111,
32,
104,
105,
50,
10
],
"debug_output": false,
"enable_threads": true
},
"result": {
"Success": {
"stdout": "hi\nhi2\n",
"stderr": "test.wasm-5.1# bash-5.1# bash-5.1# exit\ntest.wasm-5.1# test.wasm-5.1# exit\n",
"exit_code": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
source: tests/integration/cli/tests/snapshot.rs
assertion_line: 622
expression: snapshot
---
{
"spec": {
"name": "snapshot::test_snapshot_bash_dash",
"use_packages": [
"sharrattj/dash"
],
"cli_args": [],
"stdin": [
47,
98,
105,
110,
47,
100,
97,
115,
104,
10,
101,
99,
104,
111,
32,
104,
105,
10,
101,
120,
105,
116,
10,
101,
120,
105,
116,
10
],
"debug_output": false,
"enable_threads": true
},
"result": {
"Success": {
"stdout": "hi\n",
"stderr": "test.wasm-5.1# # # test.wasm-5.1# exit\n",
"exit_code": 78
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
source: tests/integration/cli/tests/snapshot.rs
assertion_line: 561
expression: snapshot
---
{
"spec": {
"name": "snapshot::test_snapshot_dash_bash",
"use_packages": [
"sharrattj/bash"
],
"cli_args": [],
"stdin": [
47,
98,
105,
110,
47,
98,
97,
115,
104,
10,
101,
99,
104,
111,
32,
104,
105,
10,
101,
120,
105,
116,
10,
101,
120,
105,
116,
10
],
"debug_output": false,
"enable_threads": true
},
"result": {
"Success": {
"stdout": "hi\n",
"stderr": "# bash-5.1# exit\n# # ",
"exit_code": 78
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
source: tests/integration/cli/tests/snapshot.rs
assertion_line: 551
expression: snapshot
---
{
"spec": {
"name": "snapshot::test_snapshot_dash_dash",
"use_packages": [
"sharrattj/dash"
],
"cli_args": [],
"stdin": [
47,
98,
105,
110,
47,
100,
97,
115,
104,
10,
101,
99,
104,
111,
32,
104,
105,
10,
101,
120,
105,
116,
10,
101,
120,
105,
116,
10
],
"debug_output": false,
"enable_threads": true
},
"result": {
"Success": {
"stdout": "hi\n",
"stderr": "# # \n# # ",
"exit_code": 78
}
}
}
Binary file modified tests/integration/cli/tests/wasm/web-server.wasm
Binary file not shown.

0 comments on commit 32c0b3c

Please sign in to comment.