Skip to content

Commit

Permalink
Fixes for snapshot tests
Browse files Browse the repository at this point in the history
-- Fixed some linting issues on the "--" argument fix of the wasmer command
- 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
- Added a step that explictily flushes the stdout and stderr on cleanup of an exited process
  • Loading branch information
john-sharratt committed Mar 16, 2023
1 parent 0537a7c commit 8312c2e
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 8 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: 4 additions & 0 deletions lib/wasi/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ impl WasiFs {
pub async fn close_all(&self) {
// TODO: this should close all uniquely owned files instead of just flushing.

// Make sure the STDOUT and STDERR are explicitely flushed
self.flush(__WASI_STDOUT_FILENO).await.ok();
self.flush(__WASI_STDERR_FILENO).await.ok();

let to_close = {
if let Ok(map) = self.fd_map.read() {
map.keys().copied().collect::<Vec<_>>()
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi/src/os/command/builtins/cmd_wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl CmdWasmer {
mut args: Vec<String>,
) -> Result<TaskJoinHandle, VirtualBusError> {
// If the first argument is a '--' then skip it
if args.iter().next().map(|a| a.as_str()) == Some("--") {
if args.first().map(|a| a.as_str()) == Some("--") {
args = args.into_iter().skip(1).collect();
}

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 8312c2e

Please sign in to comment.