| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3fe59ba commit dd708d3
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,43 @@ | |||
| 1 | + // Test version set to preview1 | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const { spawnSyncAndExitWithoutError } = require('./child_process'); | ||
| 5 | + const fixtures = require('./fixtures'); | ||
| 6 | + const childPath = fixtures.path('wasi-preview-1.js'); | ||
| 7 | + | ||
| 8 | + function testWasiPreview1(args, spawnArgs = {}, expectations = {}) { | ||
| 9 | + const newEnv = { | ||
| 10 | + ...process.env, | ||
| 11 | + NODE_DEBUG_NATIVE: 'wasi', | ||
| 12 | + NODE_PLATFORM: process.platform, | ||
| 13 | + ...spawnArgs.env, | ||
| 14 | + }; | ||
| 15 | + spawnArgs.env = newEnv; | ||
| 16 | + | ||
| 17 | + console.log('Testing with --turbo-fast-api-calls:', ...args); | ||
| 18 | + spawnSyncAndExitWithoutError( | ||
| 19 | + process.execPath, [ | ||
| 20 | + '--turbo-fast-api-calls', | ||
| 21 | + childPath, | ||
| 22 | + ...args, | ||
| 23 | + ], | ||
| 24 | + spawnArgs, | ||
| 25 | + expectations, | ||
| 26 | + ); | ||
| 27 | + | ||
| 28 | + console.log('Testing with --no-turbo-fast-api-calls:', ...args); | ||
| 29 | + spawnSyncAndExitWithoutError( | ||
| 30 | + process.execPath, | ||
| 31 | + [ | ||
| 32 | + '--no-turbo-fast-api-calls', | ||
| 33 | + childPath, | ||
| 34 | + ...args, | ||
| 35 | + ], | ||
| 36 | + spawnArgs, | ||
| 37 | + expectations, | ||
| 38 | + ); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + module.exports = { | ||
| 42 | + testWasiPreview1, | ||
| 43 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,48 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const fixtures = require('../common/fixtures'); | ||
| 5 | + const tmpdir = require('../common/tmpdir'); | ||
| 6 | + const fs = require('fs'); | ||
| 7 | + const path = require('path'); | ||
| 8 | + const common = require('../common'); | ||
| 9 | + const { WASI } = require('wasi'); | ||
| 10 | + | ||
| 11 | + function returnOnExitEnvToValue(env) { | ||
| 12 | + const envValue = env.RETURN_ON_EXIT; | ||
| 13 | + if (envValue === undefined) { | ||
| 14 | + return undefined; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + return envValue === 'true'; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + common.expectWarning('ExperimentalWarning', | ||
| 21 | + 'WASI is an experimental feature and might change at any time'); | ||
| 22 | + | ||
| 23 | + tmpdir.refresh(); | ||
| 24 | + const wasmDir = path.join(__dirname, '..', 'wasi', 'wasm'); | ||
| 25 | + const wasiPreview1 = new WASI({ | ||
| 26 | + version: 'preview1', | ||
| 27 | + args: ['foo', '-bar', '--baz=value'], | ||
| 28 | + env: process.env, | ||
| 29 | + preopens: { | ||
| 30 | + '/sandbox': fixtures.path('wasi'), | ||
| 31 | + '/tmp': tmpdir.path, | ||
| 32 | + }, | ||
| 33 | + returnOnExit: returnOnExitEnvToValue(process.env), | ||
| 34 | + }); | ||
| 35 | + | ||
| 36 | + // Validate the getImportObject helper | ||
| 37 | + assert.strictEqual(wasiPreview1.wasiImport, | ||
| 38 | + wasiPreview1.getImportObject().wasi_snapshot_preview1); | ||
| 39 | + const modulePathPreview1 = path.join(wasmDir, `${process.argv[2]}.wasm`); | ||
| 40 | + const bufferPreview1 = fs.readFileSync(modulePathPreview1); | ||
| 41 | + | ||
| 42 | + (async () => { | ||
| 43 | + const { instance: instancePreview1 } = | ||
| 44 | + await WebAssembly.instantiate(bufferPreview1, | ||
| 45 | + wasiPreview1.getImportObject()); | ||
| 46 | + | ||
| 47 | + wasiPreview1.start(instancePreview1); | ||
| 48 | + })().then(common.mustCall()); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,7 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + const { testWasiPreview1 } = require('../common/wasi'); | ||
| 4 | + | ||
| 5 | + testWasiPreview1(['exitcode']); | ||
| 6 | + testWasiPreview1(['exitcode'], { env: { RETURN_ON_EXIT: true } }); | ||
| 7 | + testWasiPreview1(['exitcode'], { env: { RETURN_ON_EXIT: false } }, { status: 120 }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,14 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const { checkoutEOL } = common; | ||
| 4 | + const { testWasiPreview1 } = require('../common/wasi'); | ||
| 5 | + | ||
| 6 | + testWasiPreview1(['freopen'], {}, { stdout: `hello from input2.txt${checkoutEOL}` }); | ||
| 7 | + testWasiPreview1(['read_file'], {}, { stdout: `hello from input.txt${checkoutEOL}` }); | ||
| 8 | + testWasiPreview1(['read_file_twice'], {}, { | ||
| 9 | + stdout: `hello from input.txt${checkoutEOL}hello from input.txt${checkoutEOL}`, | ||
| 10 | + }); | ||
| 11 | + // Tests that are currently unsupported on Windows. | ||
| 12 | + if (!common.isWindows) { | ||
| 13 | + testWasiPreview1(['stdin'], { input: 'hello world' }, { stdout: 'hello world' }); | ||
| 14 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + const { testWasiPreview1 } = require('../common/wasi'); | ||
| 4 | + | ||
| 5 | + testWasiPreview1(['poll']); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,131 +1,28 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const common = require('../common'); | |
| 3 | - | ||
| 4 | - function returnOnExitEnvToValue(env) { | ||
| 5 | - const envValue = env.RETURN_ON_EXIT; | ||
| 6 | - if (envValue === undefined) { | ||
| 7 | - return undefined; | ||
| 8 | - } | ||
| 9 | - | ||
| 10 | - return envValue === '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 | - const assert = require('assert'); | ||
| 16 | - const fixtures = require('../common/fixtures'); | ||
| 17 | - const tmpdir = require('../common/tmpdir'); | ||
| 18 | - const fs = require('fs'); | ||
| 19 | - const path = 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 | - const wasmDir = path.join(__dirname, 'wasm'); | ||
| 27 | - const wasiPreview1 = new WASI({ | ||
| 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 | - const modulePathPreview1 = path.join(wasmDir, `${process.argv[3]}.wasm`); | ||
| 42 | - const bufferPreview1 = fs.readFileSync(modulePathPreview1); | ||
| 43 | - | ||
| 44 | - (async () => { | ||
| 45 | - const { instance: instancePreview1 } = | ||
| 46 | - await WebAssembly.instantiate(bufferPreview1, | ||
| 47 | - wasiPreview1.getImportObject()); | ||
| 48 | - | ||
| 49 | - wasiPreview1.start(instancePreview1); | ||
| 50 | - })().then(common.mustCall()); | ||
| 51 | - } else { | ||
| 52 | - const assert = require('assert'); | ||
| 53 | - const cp = require('child_process'); | ||
| 54 | - const { checkoutEOL } = common; | ||
| 55 | - | ||
| 56 | - function innerRunWASI(options, args, flavor = 'preview1') { | ||
| 57 | - console.log('executing', options.test); | ||
| 58 | - const opts = { | ||
| 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' in options) { | ||
| 70 | - opts.env.RETURN_ON_EXIT = options.returnOnExit; | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - const child = 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 | - function runWASI(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']); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,4 +9,4 @@ prefix wasi | |||
| 9 | 9 | # Windows on ARM | |
| 10 | 10 | [$system==win32 && $arch==arm64] | |
| 11 | 11 | # https://github.com/nodejs/node/issues/51822 | |
| 12 | - test-wasi: PASS, FLAKY | ||
| 12 | + test-wasi-poll: PASS, FLAKY | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments