Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add basic WebAssembly test #16760

Closed
wants to merge 1 commit into from

Conversation

stevekinney
Copy link
Contributor

@stevekinney stevekinney commented Nov 4, 2017

Tests a basic WebAssembly module that adds two numbers.

wasm example from the WebAssembly/wabt repo licensed Apache 2.0.

Not sure if there are licensing concerns. Please let me know if we need to add anything else.

Refs: https://github.com/WebAssembly/wabt/blob/master/demo/wat2wasm/examples.js#L27-L32

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

test

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Nov 4, 2017
@MylesBorins
Copy link
Contributor

ci: https://ci.nodejs.org/job/node-test-pull-request/11194/

/cc @nodejs/tsc what is the best practice for the licensing on this one? the WASM is generated from WAT code that came from an APACHE 2.0 project... we could potentially just write some new code for this but the base function is fairly straight forward.

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

assert.ok(WebAssembly.validate(buffer), 'Buffer should be valid WebAssembly');

WebAssembly.instantiate(buffer, {}).then((results) => {
assert.equal(results.instance.exports.addTwo(10, 20), 30, 'Exported function should add two numbers.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this pass make lint? I think we have a rule against assert.equal (in favour of assert.strictEqual)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to fix lint

@mscdex
Copy link
Contributor

mscdex commented Nov 4, 2017

Isn't this just testing a strictly V8 feature? Wouldn't it be best to leave this to the V8 test suite?

@addaleax
Copy link
Member

addaleax commented Nov 4, 2017

@mscdex It will also be testing NodePlatform code once async WASM compilation is enabled by default in V8, so this will act as a test for both NodePlatform and for the WASM code in V8.

const fixtures = require('../common/fixtures');
const fs = require('fs');

const buffer = fs.readFileSync(fixtures.path('simple.wasm'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixtures.readSync('simple.wasm') and then drop the fs module from the test?

Tests a basic WebAssembly module that adds two numbers.
wasm example from the WebAssembly/wabt repo licensed
Apache 2.0.

Refs: https://github.com/WebAssembly/wabt/blob/master/demo/wat2wasm/examples.js#L27-L32
@MylesBorins
Copy link
Contributor

Copy link
Contributor

@MylesBorins MylesBorins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


assert.ok(WebAssembly.validate(buffer), 'Buffer should be valid WebAssembly');

WebAssembly.instantiate(buffer, {}).then((results) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: common.mustCall around the then would be better.

Copy link
Member

@addaleax addaleax Nov 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, right … we might also want common.crashOnUnhandledRejection() to make sure it really crashes when the promise gets rejected

edit: this test might be trickier than first thought 😄

assert.strictEqual(
results.instance.exports.addTwo(10, 20),
30,
'Exported function should add two numbers.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: it would likely be better to either omit the message here or include the expected and actual values in the message.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this worth blocking on or should we land and fix in a follow up?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, we should just land this

@addaleax
Copy link
Member

Landed in 74e7a4a, thanks for the PR & congratulations to being a Node contributor now! 🎉

@addaleax addaleax closed this Nov 15, 2017
addaleax pushed a commit that referenced this pull request Nov 15, 2017
Tests a basic WebAssembly module that adds two numbers.
wasm example from the WebAssembly/wabt repo licensed
Apache 2.0.

Refs: https://github.com/WebAssembly/wabt/blob/49b7984544ddaf14d5e2f1ad9115dad7e9a2b299/demo/wat2wasm/examples.js#L27-L32
PR-URL: #16760
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
MylesBorins pushed a commit that referenced this pull request Dec 11, 2017
Tests a basic WebAssembly module that adds two numbers.
wasm example from the WebAssembly/wabt repo licensed
Apache 2.0.

Refs: https://github.com/WebAssembly/wabt/blob/49b7984544ddaf14d5e2f1ad9115dad7e9a2b299/demo/wat2wasm/examples.js#L27-L32
PR-URL: #16760
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
@MylesBorins MylesBorins mentioned this pull request Dec 12, 2017
gibfahn pushed a commit that referenced this pull request Dec 19, 2017
Tests a basic WebAssembly module that adds two numbers.
wasm example from the WebAssembly/wabt repo licensed
Apache 2.0.

Refs: https://github.com/WebAssembly/wabt/blob/49b7984544ddaf14d5e2f1ad9115dad7e9a2b299/demo/wat2wasm/examples.js#L27-L32
PR-URL: #16760
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
@gibfahn gibfahn mentioned this pull request Dec 20, 2017
gibfahn pushed a commit that referenced this pull request Dec 20, 2017
Tests a basic WebAssembly module that adds two numbers.
wasm example from the WebAssembly/wabt repo licensed
Apache 2.0.

Refs: https://github.com/WebAssembly/wabt/blob/49b7984544ddaf14d5e2f1ad9115dad7e9a2b299/demo/wat2wasm/examples.js#L27-L32
PR-URL: #16760
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
@gibfahn gibfahn mentioned this pull request Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants