Skip to content

Commit b25ea9b

Browse files
cjihrigcodebytere
authored andcommitted
test: add tests for main() argument handling
This test provides missing coverage for __wasi_args_get() and __wasi_args_sizes_get(), which translate to argc and argv in WASI applications. PR-URL: #31426 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent e9462b4 commit b25ea9b

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

test/wasi/c/main_args.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <assert.h>
2+
#include <string.h>
3+
4+
int main(int argc, char** argv) {
5+
assert(argc == 3);
6+
assert(0 == strcmp(argv[0], "foo"));
7+
assert(0 == strcmp(argv[1], "-bar"));
8+
assert(0 == strcmp(argv[2], "--baz=value"));
9+
return 0;
10+
}

test/wasi/test-wasi.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if (process.argv[2] === 'wasi-child') {
1515
tmpdir.refresh();
1616
const wasmDir = path.join(__dirname, 'wasm');
1717
const wasi = new WASI({
18-
args: [],
18+
args: ['foo', '-bar', '--baz=value'],
1919
env: process.env,
2020
preopens: {
2121
'/sandbox': fixtures.path('wasi'),
@@ -64,6 +64,7 @@ if (process.argv[2] === 'wasi-child') {
6464
runWASI({ test: 'getentropy' });
6565
runWASI({ test: 'getrusage' });
6666
runWASI({ test: 'gettimeofday' });
67+
runWASI({ test: 'main_args' });
6768
runWASI({ test: 'notdir' });
6869
// runWASI({ test: 'poll' });
6970
runWASI({ test: 'preopen_populates' });

test/wasi/wasm/main_args.wasm

29.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)