|
1 | 1 | 'use strict'; |
2 | 2 | constcommon=require('../common'); |
3 | | - |
4 | | -functionreturnOnExitEnvToValue(env){ |
5 | | -constenvValue=env.RETURN_ON_EXIT; |
6 | | -if(envValue===undefined){ |
7 | | -returnundefined; |
8 | | -} |
9 | | - |
10 | | -returnenvValue==='true'; |
| 3 | +const{ testWasiPreview1 }=require('../common/wasi'); |
| 4 | + |
| 5 | +// TODO(joyeecheung): tests that don't need special configurations can be ported |
| 6 | +// to a special python test case configuration and get run in parallel. |
| 7 | +// Tests that are currently unsupported on IBM i PASE. |
| 8 | +if(!common.isIBMi){ |
| 9 | +testWasiPreview1(['clock_getres']); |
| 10 | +testWasiPreview1(['getrusage']); |
11 | 11 | } |
12 | 12 |
|
13 | | -if(process.argv[2]==='wasi-child-preview1'){ |
14 | | -// Test version set to preview1 |
15 | | -constassert=require('assert'); |
16 | | -constfixtures=require('../common/fixtures'); |
17 | | -consttmpdir=require('../common/tmpdir'); |
18 | | -constfs=require('fs'); |
19 | | -constpath=require('path'); |
20 | | - |
21 | | -common.expectWarning('ExperimentalWarning', |
22 | | -'WASI is an experimental feature and might change at any time'); |
23 | | - |
24 | | -const{WASI}=require('wasi'); |
25 | | -tmpdir.refresh(); |
26 | | -constwasmDir=path.join(__dirname,'wasm'); |
27 | | -constwasiPreview1=newWASI({ |
28 | | -version: 'preview1', |
29 | | -args: ['foo','-bar','--baz=value'], |
30 | | -env: process.env, |
31 | | -preopens: { |
32 | | -'/sandbox': fixtures.path('wasi'), |
33 | | -'/tmp': tmpdir.path, |
34 | | -}, |
35 | | -returnOnExit: returnOnExitEnvToValue(process.env), |
36 | | -}); |
37 | | - |
38 | | -// Validate the getImportObject helper |
39 | | -assert.strictEqual(wasiPreview1.wasiImport, |
40 | | -wasiPreview1.getImportObject().wasi_snapshot_preview1); |
41 | | -constmodulePathPreview1=path.join(wasmDir,`${process.argv[3]}.wasm`); |
42 | | -constbufferPreview1=fs.readFileSync(modulePathPreview1); |
43 | | - |
44 | | -(async()=>{ |
45 | | -const{instance: instancePreview1}= |
46 | | -awaitWebAssembly.instantiate(bufferPreview1, |
47 | | -wasiPreview1.getImportObject()); |
48 | | - |
49 | | -wasiPreview1.start(instancePreview1); |
50 | | -})().then(common.mustCall()); |
51 | | -}else{ |
52 | | -constassert=require('assert'); |
53 | | -constcp=require('child_process'); |
54 | | -const{ checkoutEOL }=common; |
55 | | - |
56 | | -functioninnerRunWASI(options,args,flavor='preview1'){ |
57 | | -console.log('executing',options.test); |
58 | | -constopts={ |
59 | | -env: { |
60 | | - ...process.env, |
61 | | -NODE_DEBUG_NATIVE: 'wasi', |
62 | | -NODE_PLATFORM: process.platform, |
63 | | -}, |
64 | | -}; |
65 | | - |
66 | | -if(options.stdin!==undefined) |
67 | | -opts.input=options.stdin; |
68 | | - |
69 | | -if('returnOnExit'inoptions){ |
70 | | -opts.env.RETURN_ON_EXIT=options.returnOnExit; |
71 | | -} |
72 | | - |
73 | | -constchild=cp.spawnSync(process.execPath,[ |
74 | | - ...args, |
75 | | -__filename, |
76 | | -'wasi-child-'+flavor, |
77 | | -options.test, |
78 | | -],opts); |
79 | | -console.log(child.stderr.toString()); |
80 | | -assert.strictEqual(child.status,options.exitCode||0); |
81 | | -assert.strictEqual(child.signal,null); |
82 | | -assert.strictEqual(child.stdout.toString(),options.stdout||''); |
83 | | -} |
84 | | - |
85 | | -functionrunWASI(options){ |
86 | | -innerRunWASI(options,['--no-turbo-fast-api-calls']); |
87 | | -innerRunWASI(options,['--turbo-fast-api-calls']); |
88 | | -} |
89 | | - |
90 | | -runWASI({test: 'cant_dotdot'}); |
91 | | - |
92 | | -// Tests that are currently unsupported on IBM i PASE. |
93 | | -if(!common.isIBMi){ |
94 | | -runWASI({test: 'clock_getres'}); |
95 | | -} |
96 | | -runWASI({test: 'exitcode'}); |
97 | | -runWASI({test: 'exitcode',returnOnExit: true}); |
98 | | -runWASI({test: 'exitcode',exitCode: 120,returnOnExit: false}); |
99 | | -runWASI({test: 'fd_prestat_get_refresh'}); |
100 | | -runWASI({test: 'freopen',stdout: `hello from input2.txt${checkoutEOL}`}); |
101 | | -runWASI({test: 'ftruncate'}); |
102 | | -runWASI({test: 'getentropy'}); |
103 | | - |
104 | | -// Tests that are currently unsupported on IBM i PASE. |
105 | | -if(!common.isIBMi){ |
106 | | -runWASI({test: 'getrusage'}); |
107 | | -} |
108 | | -runWASI({test: 'gettimeofday'}); |
109 | | -runWASI({test: 'main_args'}); |
110 | | -runWASI({test: 'notdir'}); |
111 | | -runWASI({test: 'poll'}); |
112 | | -runWASI({test: 'preopen_populates'}); |
113 | | - |
114 | | -if(!common.isWindows&&process.platform!=='android'){ |
115 | | -runWASI({test: 'readdir'}); |
116 | | -} |
117 | | - |
118 | | -runWASI({test: 'read_file',stdout: `hello from input.txt${checkoutEOL}`}); |
119 | | -runWASI({ |
120 | | -test: 'read_file_twice', |
121 | | -stdout: `hello from input.txt${checkoutEOL}hello from input.txt${checkoutEOL}`, |
122 | | -}); |
123 | | -runWASI({test: 'stat'}); |
124 | | -runWASI({test: 'sock'}); |
125 | | -runWASI({test: 'write_file'}); |
126 | | - |
127 | | -// Tests that are currently unsupported on Windows. |
128 | | -if(!common.isWindows){ |
129 | | -runWASI({test: 'stdin',stdin: 'hello world',stdout: 'hello world'}); |
130 | | -} |
| 13 | +// Tests that are currently unsupported on Windows and Android. |
| 14 | +if(!common.isWindows&&process.platform!=='android'){ |
| 15 | +testWasiPreview1(['readdir']); |
131 | 16 | } |
| 17 | + |
| 18 | +testWasiPreview1(['cant_dotdot']); |
| 19 | +testWasiPreview1(['fd_prestat_get_refresh']); |
| 20 | +testWasiPreview1(['ftruncate']); |
| 21 | +testWasiPreview1(['getentropy']); |
| 22 | +testWasiPreview1(['gettimeofday']); |
| 23 | +testWasiPreview1(['main_args']); |
| 24 | +testWasiPreview1(['notdir']); |
| 25 | +testWasiPreview1(['preopen_populates']); |
| 26 | +testWasiPreview1(['stat']); |
| 27 | +testWasiPreview1(['sock']); |
| 28 | +testWasiPreview1(['write_file']); |
0 commit comments