-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backfills tests for guest panics (#73)
This backfills tests for guests that panic. Sadly, we don't control the ModuleConfig. Integrators who want to see the data written by TinyGo during a panic need to capture stdout on their own. This is already the case in dapr, which sends stdout to the logger under debug. Signed-off-by: Adrian Cole <[email protected]>
- Loading branch information
1 parent
0368c00
commit 825cfd6
Showing
11 changed files
with
199 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
;; panic_on_handle_request issues an unreachable instruction after writing | ||
;; an error to stdout. This simulates a panic in TinyGo. | ||
(module $panic_on_handle_request | ||
;; Import the fd_write function from wasi, used in TinyGo for println. | ||
(import "wasi_snapshot_preview1" "fd_write" | ||
(func $wasi.fd_write (param $fd i32) (param $iovs i32) (param $iovs_len i32) (param $result.size i32) (result (;errno;) i32))) | ||
|
||
;; Allocate the minimum amount of memory, 1 page (64KB). | ||
(memory (export "memory") 1 1) | ||
|
||
;; Pre-populate memory with the panic message, in iovec format | ||
(data (i32.const 0) "\08") ;; iovs[0].offset | ||
(data (i32.const 4) "\06") ;; iovs[0].length | ||
(data (i32.const 8) "panic!") ;; iovs[0] | ||
|
||
;; On handle_request, write "panic!" to stdout and crash. | ||
(func $handle_request (export "handle_request") (result (; ctx_next ;) i64) | ||
;; Write the panic to stdout via its iovec [offset, len]. | ||
(call $wasi.fd_write | ||
(i32.const 1) ;; stdout | ||
(i32.const 0) ;; where's the iovec | ||
(i32.const 1) ;; only one iovec | ||
(i32.const 0) ;; overwrite the iovec with the ignored result. | ||
) | ||
drop ;; ignore the errno returned | ||
|
||
;; Issue the unreachable instruction instead of returning ctx_next | ||
(unreachable)) | ||
|
||
(func $handle_response (export "handle_response") (param $reqCtx i32) (param $is_error i32)) | ||
) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
;; panic_on_handle_response issues an unreachable instruction after writing | ||
;; an error to stdout. This simulates a panic in TinyGo. | ||
(module $panic_on_handle_response | ||
;; Import the fd_write function from wasi, used in TinyGo for println. | ||
(import "wasi_snapshot_preview1" "fd_write" | ||
(func $wasi.fd_write (param $fd i32) (param $iovs i32) (param $iovs_len i32) (param $result.size i32) (result (;errno;) i32))) | ||
|
||
;; Allocate the minimum amount of memory, 1 page (64KB). | ||
(memory (export "memory") 1 1) | ||
|
||
;; Pre-populate memory with the panic message, in iovec format | ||
(data (i32.const 0) "\08") ;; iovs[0].offset | ||
(data (i32.const 4) "\06") ;; iovs[0].length | ||
(data (i32.const 8) "panic!") ;; iovs[0] | ||
|
||
(func $handle_request (export "handle_request") (result (; ctx_next ;) i64) | ||
(return (i64.const 1))) ;; call the next handler | ||
|
||
;; On handle_response, write "panic!" to stdout and crash. | ||
(func $handle_response (export "handle_response") (param $reqCtx i32) (param $is_error i32) | ||
;; Write the panic to stdout via its iovec [offset, len]. | ||
(call $wasi.fd_write | ||
(i32.const 1) ;; stdout | ||
(i32.const 0) ;; where's the iovec | ||
(i32.const 1) ;; only one iovec | ||
(i32.const 0) ;; overwrite the iovec with the ignored result. | ||
) | ||
drop ;; ignore the errno returned | ||
|
||
;; Issue the unreachable instruction instead of returning. | ||
(unreachable)) | ||
) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
;; panic_on_start is a WASI command which issues an unreachable instruction | ||
;; after writing an error to stdout. This simulates a panic in TinyGo. | ||
(module $panic_on_start | ||
;; Import the fd_write function from wasi, used in TinyGo for println. | ||
(import "wasi_snapshot_preview1" "fd_write" | ||
(func $wasi.fd_write (param $fd i32) (param $iovs i32) (param $iovs_len i32) (param $result.size i32) (result (;errno;) i32))) | ||
|
||
;; Allocate the minimum amount of memory, 1 page (64KB). | ||
(memory (export "memory") 1 1) | ||
|
||
;; Pre-populate memory with the panic message, in iovec format | ||
(data (i32.const 0) "\08") ;; iovs[0].offset | ||
(data (i32.const 4) "\06") ;; iovs[0].length | ||
(data (i32.const 8) "panic!") ;; iovs[0] | ||
|
||
;; On start, write "panic!" to stdout and crash. | ||
(func $main (export "_start") | ||
;; Write the panic to stdout via its iovec [offset, len]. | ||
(call $wasi.fd_write | ||
(i32.const 1) ;; stdout | ||
(i32.const 0) ;; where's the iovec | ||
(i32.const 1) ;; only one iovec | ||
(i32.const 0) ;; overwrite the iovec with the ignored result. | ||
) | ||
drop ;; ignore the errno returned | ||
|
||
;; Issue the unreachable instruction instead of exiting normally | ||
(unreachable)) | ||
|
||
;; Export the required functions for the handler ABI | ||
(func $handle_request (export "handle_request") (result (; ctx_next ;) i64) | ||
(return (i64.const 0))) ;; don't call the next handler | ||
|
||
(func $handle_response (export "handle_response") (param $reqCtx i32) (param $is_error i32)) | ||
) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-368 Bytes
internal/test/testdata/invalid/set_request_header_after_next.wasm
Binary file not shown.