diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2024-03-06 12:39:07 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2024-03-11 09:36:35 -0700 |
| commit | 7141379559e2ef17e48dfbadc898581cd34bef6f (patch) | |
| tree | 626bcaef1d4ed48bb18c8ebb63851ba2e4db6be9 /tests/run-make/wasm-custom-section | |
| parent | d255c6a57c393db6221b1ff700daea478436f1cd (diff) | |
Convert some WebAssembly run-make tests to Rust
This commit rewrites a number of `run-make` tests centered around wasm to instead use `rmake.rs` and additionally use the `wasm32-wasip1` target instead of `wasm32-unknown-unknown`. Testing no longer requires Node.js and additionally uses the `wasmparser` crate from crates.io to parse outputs and power assertions.
Diffstat (limited to 'tests/run-make/wasm-custom-section')
| -rw-r--r-- | tests/run-make/wasm-custom-section/Makefile | 8 | ||||
| -rw-r--r-- | tests/run-make/wasm-custom-section/foo.js | 36 | ||||
| -rw-r--r-- | tests/run-make/wasm-custom-section/rmake.rs | 28 |
3 files changed, 28 insertions, 44 deletions
diff --git a/tests/run-make/wasm-custom-section/Makefile b/tests/run-make/wasm-custom-section/Makefile deleted file mode 100644 index 2f7d38c2736..00000000000 --- a/tests/run-make/wasm-custom-section/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -include ../tools.mk - -# only-wasm32-bare - -all: - $(RUSTC) foo.rs --target wasm32-unknown-unknown - $(RUSTC) bar.rs -C lto -O --target wasm32-unknown-unknown - $(NODE) foo.js $(TMPDIR)/bar.wasm diff --git a/tests/run-make/wasm-custom-section/foo.js b/tests/run-make/wasm-custom-section/foo.js deleted file mode 100644 index 57a0f50732d..00000000000 --- a/tests/run-make/wasm-custom-section/foo.js +++ /dev/null @@ -1,36 +0,0 @@ -const fs = require('fs'); -const process = require('process'); -const assert = require('assert'); -const buffer = fs.readFileSync(process.argv[2]); - -let m = new WebAssembly.Module(buffer); -let sections = WebAssembly.Module.customSections(m, "baz"); -console.log('section baz', sections); -assert.strictEqual(sections.length, 1); -let section = new Uint8Array(sections[0]); -console.log('contents', section); -assert.strictEqual(section.length, 2); -assert.strictEqual(section[0], 7); -assert.strictEqual(section[1], 8); - -sections = WebAssembly.Module.customSections(m, "bar"); -console.log('section bar', sections); -assert.strictEqual(sections.length, 1, "didn't pick up `bar` section from dependency"); -section = new Uint8Array(sections[0]); -console.log('contents', section); -assert.strictEqual(section.length, 2); -assert.strictEqual(section[0], 3); -assert.strictEqual(section[1], 4); - -sections = WebAssembly.Module.customSections(m, "foo"); -console.log('section foo', sections); -assert.strictEqual(sections.length, 1, "didn't create `foo` section"); -section = new Uint8Array(sections[0]); -console.log('contents', section); -assert.strictEqual(section.length, 4, "didn't concatenate `foo` sections"); -assert.strictEqual(section[0], 5); -assert.strictEqual(section[1], 6); -assert.strictEqual(section[2], 1); -assert.strictEqual(section[3], 2); - -process.exit(0); diff --git a/tests/run-make/wasm-custom-section/rmake.rs b/tests/run-make/wasm-custom-section/rmake.rs new file mode 100644 index 00000000000..9ad152695ec --- /dev/null +++ b/tests/run-make/wasm-custom-section/rmake.rs @@ -0,0 +1,28 @@ +extern crate run_make_support; + +use run_make_support::{out_dir, rustc, wasmparser}; +use std::collections::HashMap; + +fn main() { + if std::env::var("TARGET").unwrap() != "wasm32-wasip1" { + return; + } + + rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run(); + rustc().arg("bar.rs").arg("--target=wasm32-wasip1").arg("-Clto").arg("-O").run(); + + let file = std::fs::read(&out_dir().join("bar.wasm")).unwrap(); + + let mut custom = HashMap::new(); + for payload in wasmparser::Parser::new(0).parse_all(&file) { + let payload = payload.unwrap(); + if let wasmparser::Payload::CustomSection(s) = payload { + let prev = custom.insert(s.name(), s.data()); + assert!(prev.is_none()); + } + } + + assert_eq!(custom.remove("foo"), Some(&[5, 6, 1, 2][..])); + assert_eq!(custom.remove("bar"), Some(&[3, 4][..])); + assert_eq!(custom.remove("baz"), Some(&[7, 8][..])); +} |
