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 browser test harness #563

Conversation

kateinoigakukun
Copy link
Contributor

This commit adds a browser test harness to run the tests in the browser.

Motivation

We are heavily using wasi-libc on browsers but we don't have any test for the case in wasi-libc. In theory, there should be no behavioral difference between wasmtime and browsers (as long as WASI implementations are correct) but browsers have their own limitations in their Wasm engines. For example, memory.atomic.wait32 is not permitted on the main thread.

We are working on adding some mitigation for such browser-specific issues (#562) and this test harness will help to validate the fix.

Copy link
Collaborator

@abrown abrown left a comment

Choose a reason for hiding this comment

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

I ran all of this locally to understand what is going on and I think this makes sense. It does increase the amount of code to maintain but it seems worth it in order to check this in the browser. Let's hope the CDN artifacts don't cause an issue during CI (they shouldn't, right?) but if they do we could figure out workarounds.

Thanks @kateinoigakukun for working on this!

ConsoleStdout.lineBuffered((stderr) => {
console.error(stderr);
}),
new PreopenDirectory("/", new Map()),
Copy link
Collaborator

@abrown abrown Jan 28, 2025

Choose a reason for hiding this comment

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

Shouldn't there be some way to use the preopens we pass along in the --dir CLI args... or no?

How do the tests that need special access work?! Or maybe that's just the fts.c test that we skip in browser?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. The preopen is unnecessary and I don't think it's even worth adding --dir emulation support to the harness. File system emulation is not part of wasi-libc's responsibility and it's not the main focus here, so I just skipped tests using --dir for now.

@kateinoigakukun kateinoigakukun force-pushed the pr-8b2c52b750dfe1d1529003eff104cb9cefdffc19 branch from 244388f to 424d3a1 Compare January 28, 2025 03:52
This commit adds a browser test harness to run the tests in the browser.
@kateinoigakukun kateinoigakukun force-pushed the pr-8b2c52b750dfe1d1529003eff104cb9cefdffc19 branch from 424d3a1 to 5048494 Compare January 28, 2025 04:14
@abrown abrown merged commit b34d681 into WebAssembly:main Feb 3, 2025
8 checks passed
* This script is served by `harness.mjs` and runs in the browser.
*/
import { WASI, File, OpenFile, ConsoleStdout, PreopenDirectory } from 'https://cdn.jsdelivr.net/npm/@bjorn3/browser_wasi_shim@0.3.0/+esm'
import { polyfill } from 'https://cdn.jsdelivr.net/npm/wasm-imports-parser@1.0.4/polyfill.js/+esm';
Copy link
Member

Choose a reason for hiding this comment

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

It seems like we are taking a dependency here this WASI implementation. Maybe this should be documented somewhere? What happens if this breaks? Who maintains this WASI implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a sentence about the dependency to test/README.md: #576
If the dependency breaks, wasi-libc's CI can fail, but nothing affects the users of wasi-libc. Although it's maintained under a personal namespace, the implementation is the most reliable one on browser today as far as I know.

Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW, I see this browser testing infrastructure as useful but experimental. If we were to run into many problems consistently, I think it would make sense to rip it out. (and I reviewed it with that in mind). But I'm hopeful that things are stable enough at this point that that won't be a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants