From 24cc17ac9ec04bcce5bb9c2dbeb4b371ae1747c3 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Fri, 22 May 2020 13:28:00 -0400 Subject: [PATCH 1/2] update as to 10, add wasi, add sandbox --- package-lock.json | 52 +++++++++++++++++++++--------------------- package.json | 6 ++--- tests/node.js | 20 ++++++++-------- tests/sandbox/test.txt | 0 4 files changed, 40 insertions(+), 38 deletions(-) create mode 100644 tests/sandbox/test.txt diff --git a/package-lock.json b/package-lock.json index 411d808..836d43b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,31 +5,31 @@ "requires": true, "dependencies": { "@as-pect/assembly": { - "version": "3.1.0-beta.3", - "resolved": "https://registry.npmjs.org/@as-pect/assembly/-/assembly-3.1.0-beta.3.tgz", - "integrity": "sha512-NYMzh8c4mloGJHQEyEz7Gw4DFKDjepyuSkojca0agSOVsjJcaTy6DtM42Lq7DTLwNoM4xt+YI7nQNTWcrhhHGw==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/@as-pect/assembly/-/assembly-3.2.1.tgz", + "integrity": "sha512-qok+WPvKV1BLQ+nnpn+hc0PLSZ69Pim4eT72PruA1C+hvMu6HCbNKDFcj4lrL7XNMKuibPf0633SW14asC0//w==", "dev": true }, "@as-pect/core": { - "version": "3.1.0-beta.3", - "resolved": "https://registry.npmjs.org/@as-pect/core/-/core-3.1.0-beta.3.tgz", - "integrity": "sha512-/i3wzOYEvvzECRKLPWm7FGKnPgtD6RdaPFWAT6nA4OHtsHdHz2BvvGdCecheLRG3GoRk00LfCSRB8/L3IJnS/A==", + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/@as-pect/core/-/core-3.2.2.tgz", + "integrity": "sha512-Gr6ha3WGS/omSLvquDC6WPqZt1vP/hxvWovxgUuqNJ1APymMTjbvP2W86pjKLqvSaZj1gETAr5703PxhnnoL4g==", "dev": true, "requires": { - "@as-pect/assembly": "^3.1.0-beta.3", - "@as-pect/snapshots": "^3.1.0-beta.3", - "chalk": "^3.0.0", + "@as-pect/assembly": "^3.2.1", + "@as-pect/snapshots": "^3.2.2", + "chalk": "^4.0.0", "long": "^4.0.0" } }, "@as-pect/snapshots": { - "version": "3.1.0-beta.3", - "resolved": "https://registry.npmjs.org/@as-pect/snapshots/-/snapshots-3.1.0-beta.3.tgz", - "integrity": "sha512-hL+a3/ByQQAhLLVsY9Qtd0eAb9UTZbMeJyh4mKQQS4X9KXhpVHADjoK31PbOlM+E3TUbR/KbZFFPu2Z79T3How==", + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/@as-pect/snapshots/-/snapshots-3.2.2.tgz", + "integrity": "sha512-uJQwwbgX0gGRVD4Au8r3g9TbPCseBuChSDVjfaNAZifaQ0JKrrzB4tga2PVDrWrZHIgYvajTph5tsN3x9pJ5nA==", "dev": true, "requires": { "diff": "^4.0.2", - "nearley": "^2.19.1" + "nearley": "^2.19.3" } }, "@types/color-name": { @@ -49,12 +49,12 @@ } }, "assemblyscript": { - "version": "0.9.3", - "resolved": "https://registry.npmjs.org/assemblyscript/-/assemblyscript-0.9.3.tgz", - "integrity": "sha512-5Mm15oLOi4Uj/N9h2uGuy4U2zFpaOQuP3kcRuFYiTchuvKIpyqqihMm+e7P6VaTLzPnN+oIRwn1KjTyo4aSw1A==", + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/assemblyscript/-/assemblyscript-0.10.0.tgz", + "integrity": "sha512-ErUNhHboD+zsB4oG6X1YICDAIo27Gq7LeNX6jVe+Q0W5cI51/fHwC8yJ68IukqvupmZgYPdp1JqqRXlS+BrUfA==", "dev": true, "requires": { - "binaryen": "91.0.0-nightly.20200310", + "binaryen": "93.0.0-nightly.20200514", "long": "^4.0.0" } }, @@ -65,9 +65,9 @@ "dev": true }, "binaryen": { - "version": "91.0.0-nightly.20200310", - "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-91.0.0-nightly.20200310.tgz", - "integrity": "sha512-MmDzq267aa61HdEQeYiz+7guJlsYk2/6NxWC8I4w1jijqDwoqyZZxi7UYnTH7QvfLrNdMjweEgfT7FHjkvkPmQ==", + "version": "93.0.0-nightly.20200514", + "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-93.0.0-nightly.20200514.tgz", + "integrity": "sha512-SRRItmNvhRVfoWWbRloO4i8IqkKH8rZ7/0QWRgLpM3umupK8gBpo9MY7Zp3pDysRSp+rVoqxvM5x4tFyCSa9zw==", "dev": true }, "brace-expansion": { @@ -81,9 +81,9 @@ } }, "chalk": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", - "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.0.0.tgz", + "integrity": "sha512-N9oWFcegS0sFr9oh1oz2d7Npos6vNoWW9HvtCg5N1KRFpUhaAhvTv5Y58g880fZaEYSNm3qDz8SU1UrGvp+n7A==", "dev": true, "requires": { "ansi-styles": "^4.1.0", @@ -193,9 +193,9 @@ "dev": true }, "nearley": { - "version": "2.19.1", - "resolved": "https://registry.npmjs.org/nearley/-/nearley-2.19.1.tgz", - "integrity": "sha512-xq47GIUGXxU9vQg7g/y1o1xuKnkO7ev4nRWqftmQrLkfnE/FjRqDaGOUakM8XHPn/6pW3bGjU2wgoJyId90rqg==", + "version": "2.19.3", + "resolved": "https://registry.npmjs.org/nearley/-/nearley-2.19.3.tgz", + "integrity": "sha512-FpAy1PmTsUpOtgxr23g4jRNvJHYzZEW2PixXeSzksLR/ykPfwKhAodc2+9wQhY+JneWLcvkDw6q7FJIsIdF/aQ==", "dev": true, "requires": { "commander": "^2.19.0", diff --git a/package.json b/package.json index 0b5ba7b..3265e45 100644 --- a/package.json +++ b/package.json @@ -12,12 +12,12 @@ "url": "https://github.com/AssemblyScript/node/issues" }, "devDependencies": { - "@as-pect/core": "^3.1.0-beta.3", - "assemblyscript": "0.9.3", + "@as-pect/core": "^3.2.2", + "assemblyscript": "0.10.0", "glob": "^7.1.6" }, "scripts": { - "test": "node --experimental-wasi-unstable-preview1 tests/node" + "test": "node --experimental-wasi-unstable-preview1 --experimental-wasm-bigint tests/node" }, "dependencies": {} } diff --git a/tests/node.js b/tests/node.js index 6c9e25f..e1851cd 100644 --- a/tests/node.js +++ b/tests/node.js @@ -40,7 +40,6 @@ const ascOptions = [ relativeFromCwd(require.resolve("@as-pect/assembly/assembly/index.ts")), "--use", "ASC_RTRACE=1", "--explicitStart", - "--validate", "--measure", "--lib", "assembly", "--transform", require.resolve("@as-pect/core/lib/transform/index.js"), @@ -122,24 +121,27 @@ function runTest(fileName, type, binary, wat) { // should not block testing promises.push(fs.writeFile(watPath, wat)); - const context = new TestContext({ - fileName: fileNamePath, // set the fileName - reporter, // use verbose reporter - binary, // pass the binary to get function names - }); const wasi = new WASI({ args: [], - env: {}, + env: process.env, preopens: { - // '/sandbox': '/some/real/path/that/wasm/can/access' + './tests/sandbox': './tests/sandbox' } }); + + const context = new TestContext({ + fileName: fileNamePath, // set the fileName + reporter, // use verbose reporter + binary, // pass the binary to get function names + wasi, + }); + const imports = context.createImports({ wasi_snapshot_preview1: wasi.wasiImport, }); const instance = instantiateSync(binary, imports); - // TODO: wasi.start(instance); + process.stdout.write("\n"); context.run(instance); diff --git a/tests/sandbox/test.txt b/tests/sandbox/test.txt new file mode 100644 index 0000000..e69de29 From 2c529687ecc71763e418a0276611b15f061bd581 Mon Sep 17 00:00:00 2001 From: Joshua Tenner Date: Fri, 22 May 2020 14:01:34 -0400 Subject: [PATCH 2/2] add cli flag preopens, override at {testname}.spec.wasi.js --- tests/fs.spec.ts | 3 +++ tests/fs.spec.wasi.js | 7 +++++++ tests/node.js | 37 +++++++++++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 tests/fs.spec.ts create mode 100644 tests/fs.spec.wasi.js diff --git a/tests/fs.spec.ts b/tests/fs.spec.ts new file mode 100644 index 0000000..84315f6 --- /dev/null +++ b/tests/fs.spec.ts @@ -0,0 +1,3 @@ +test("an empty test", () => { + +}); diff --git a/tests/fs.spec.wasi.js b/tests/fs.spec.wasi.js new file mode 100644 index 0000000..afa6f72 --- /dev/null +++ b/tests/fs.spec.wasi.js @@ -0,0 +1,7 @@ +module.exports = { + env: process.env, + argv: process.argv, + preopens: { + "./tests/sandbox": "./tests/sandbox" + } +}; diff --git a/tests/node.js b/tests/node.js index e1851cd..f6b7e5e 100644 --- a/tests/node.js +++ b/tests/node.js @@ -4,7 +4,8 @@ const { instantiateSync } = require("assemblyscript/lib/loader"); const { main } = require("assemblyscript/cli/asc"); const { parse } = require("assemblyscript/cli/util/options"); const path = require("path"); -const fs = require("fs").promises; +const fssync = require("fs"); +const fs = fssync.promises; const { WASI } = require("wasi"); const promises = []; @@ -21,6 +22,12 @@ const options = parse(process.argv.slice(2), { "type": "b", "alias": "u" }, + "preopens": { + "description": "A set of preopened directories for wasi. Ex. ./dir=./dir", + "type": "S", + "alias": "p", + "default": [], + }, }); if (options.unknown.length > 1) { @@ -28,6 +35,16 @@ if (options.unknown.length > 1) { process.exit(1); } +// calculate default preopens from cli +const preopens = options.options.preopens.reduce( + (obj, value) => { + const [_, dir1, dir2] = /([^=])*=(.*)/.exec(value); + obj[dir1] = dir2; + return obj; + }, + {} +); + const reporter = new VerboseReporter(); reporter.stderr = process.stderr; reporter.stdout = process.stdout; @@ -116,18 +133,22 @@ function runTest(fileName, type, binary, wat) { const basename = path.basename(fileName, ".ts"); const fullName = path.join(dirname, basename) const watPath = `${fullName}.${type}.wat`; + const wasiPath = `${fullName}.wasi.js`; const fileNamePath = `${fullName}.${type}.ts`; + // use either a custom wasi configuration, or the default one + const wasiOptions = fssync.existsSync(wasiPath) + ? require(path.resolve(wasiPath)) + : { + args: process.argv, + env: process.env, + preopens, + }; + // should not block testing promises.push(fs.writeFile(watPath, wat)); - const wasi = new WASI({ - args: [], - env: process.env, - preopens: { - './tests/sandbox': './tests/sandbox' - } - }); + const wasi = new WASI(wasiOptions); const context = new TestContext({ fileName: fileNamePath, // set the fileName