diff --git a/lib/wasi/src/bin_factory/exec.rs b/lib/wasi/src/bin_factory/exec.rs index 6f441add77b..133304193c0 100644 --- a/lib/wasi/src/bin_factory/exec.rs +++ b/lib/wasi/src/bin_factory/exec.rs @@ -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())); } }; diff --git a/lib/wasi/src/fs/mod.rs b/lib/wasi/src/fs/mod.rs index e69294e07f7..244579946bd 100644 --- a/lib/wasi/src/fs/mod.rs +++ b/lib/wasi/src/fs/mod.rs @@ -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::>() diff --git a/lib/wasi/src/os/command/builtins/cmd_wasmer.rs b/lib/wasi/src/os/command/builtins/cmd_wasmer.rs index ef567614f70..696d335be5f 100644 --- a/lib/wasi/src/os/command/builtins/cmd_wasmer.rs +++ b/lib/wasi/src/os/command/builtins/cmd_wasmer.rs @@ -64,7 +64,7 @@ impl CmdWasmer { mut args: Vec, ) -> Result { // 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(); } diff --git a/lib/wasi/tests/runners.rs b/lib/wasi/tests/runners.rs index 713ab862e16..6e9cd6b7323 100644 --- a/lib/wasi/tests/runners.rs +++ b/lib/wasi/tests/runners.rs @@ -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] @@ -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); } } diff --git a/tests/integration/cli/tests/snapshot.rs b/tests/integration/cli/tests/snapshot.rs index 765d6673ada..29e6ef9acf4 100644 --- a/tests/integration/cli/tests/snapshot.rs +++ b/tests/integration/cli/tests/snapshot.rs @@ -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); } @@ -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); } @@ -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); } diff --git a/tests/integration/cli/tests/snapshots/snapshot__snapshot_bash_bash.snap b/tests/integration/cli/tests/snapshots/snapshot__snapshot_bash_bash.snap new file mode 100644 index 00000000000..07cb5976f73 --- /dev/null +++ b/tests/integration/cli/tests/snapshots/snapshot__snapshot_bash_bash.snap @@ -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 + } + } +} diff --git a/tests/integration/cli/tests/snapshots/snapshot__snapshot_bash_dash.snap b/tests/integration/cli/tests/snapshots/snapshot__snapshot_bash_dash.snap new file mode 100644 index 00000000000..2be0183f154 --- /dev/null +++ b/tests/integration/cli/tests/snapshots/snapshot__snapshot_bash_dash.snap @@ -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 + } + } +} diff --git a/tests/integration/cli/tests/snapshots/snapshot__snapshot_dash_bash.snap b/tests/integration/cli/tests/snapshots/snapshot__snapshot_dash_bash.snap new file mode 100644 index 00000000000..fb808153037 --- /dev/null +++ b/tests/integration/cli/tests/snapshots/snapshot__snapshot_dash_bash.snap @@ -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 + } + } +} diff --git a/tests/integration/cli/tests/snapshots/snapshot__snapshot_dash_dash.snap b/tests/integration/cli/tests/snapshots/snapshot__snapshot_dash_dash.snap new file mode 100644 index 00000000000..f736eed8049 --- /dev/null +++ b/tests/integration/cli/tests/snapshots/snapshot__snapshot_dash_dash.snap @@ -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 + } + } +} diff --git a/tests/integration/cli/tests/wasm/web-server.wasm b/tests/integration/cli/tests/wasm/web-server.wasm index ae35be7376b..640a3f48c9e 100755 Binary files a/tests/integration/cli/tests/wasm/web-server.wasm and b/tests/integration/cli/tests/wasm/web-server.wasm differ