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

Fix wpt #131

Merged
merged 3 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions .scripts/wpt-harness.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Blob } from 'node:buffer';
import EventEmitter from 'node:events';

import path from 'path';
import wptRunner from 'wpt-runner';
Expand All @@ -15,7 +16,7 @@ import { requestAnimationFrame, cancelAnimationFrame } from './wpt-mock/requestA
program
.option('--list', 'List the name of the test files')
.option('--with_crashtests', 'Also run crashtests')
.option('--filter <string...>', 'Filter executed OR listed test files', '.*');
.option('--filter <string...>', 'Filter executed OR listed test files', ['.*']);

program.parse(process.argv);

Expand All @@ -38,15 +39,24 @@ const wptRootPath = path.join('wpt');
const testsPath = path.join('wpt','webaudio');
const rootURL = 'webaudio';

// wpt tests are all run in the same process, but some tests using AudioContext
// do not explicitely call the `close` method. As setup is called before each test
// file we emit a global event so that AudioContext created in previous test file
// can properly close themselves. This prevents them to pile up, continue running
// create all sorts of problems and waste CPU
process.WPT_TEST_RUNNER = new EventEmitter();

// monkey patch `window` with our web audio API
const setup = window => {
process.WPT_TEST_RUNNER.emit('cleanup');

// monkey patch innerText with textContent
Object.defineProperty(window.HTMLScriptElement.prototype, 'innerText', {
get: function() {
return this.textContent;
},
})
// return;

// This is meant to make some idlharness tests pass:
// cf. wpt-runnner/testharness/idlharness.js line 1466-1472
// These tests, which assess the descriptor of the classes according to window,
Expand Down Expand Up @@ -106,18 +116,25 @@ const filterRe = new RegExp(`${options.filter.join('|')}`);

const filter = (name) => {
if (!options.with_crashtests && name.includes('/crashtests/')) {
return false;
return false;
}
if (name.includes('/resources/')) {
return false;
return false;
}

// TODO <https://github.com/ircam-ismm/node-web-audio-api/issues/57>
// these tests make the runner crash
if (
name.includes('the-audiocontext-interface/suspend-with-navigation.html') // timeouts
// timeouts
name.includes('the-audiocontext-interface/suspend-with-navigation.html')
// somehow crahshes the-constantsourcenode-interface/constant-source-basic.html test
// npm run wpt:only -- --filter the-channelmergernode-interface/active-processing.https.html the-constantsourcenode-interface/constant-source-basic.html
|| name.includes('the-channelmergernode-interface/active-processing.https.html')
// timeout, but when test is fixed, trigger a segfault
// should be fixed with https://nodejs.org/api/worker_threads.html#workermarkasuntransferableobject
|| name.includes('the-audioworklet-interface/audioworkletprocessor-process-frozen-array.https.html')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note that these additions are fixed and removed in the next PR

) {
return false;
return false;
}

if (filterRe.test(name)) {
Expand Down
6 changes: 5 additions & 1 deletion js/AudioContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ module.exports = function(jsExport, nativeBinding) {
});
// keep process awake until context is closed
const keepAwakeId = setInterval(() => {}, 10 * 1000);

// clear on close
this.addEventListener('statechange', () => {
if (this.state === 'closed') {
Expand All @@ -126,6 +125,11 @@ module.exports = function(jsExport, nativeBinding) {
clearTimeout(keepAwakeId);
}
});

// for wpt tests, see ./.scripts/wpt_harness.mjs for informations
if (process.WPT_TEST_RUNNER) {
process.WPT_TEST_RUNNER.once('cleanup', () => this.close());
}
}

get baseLatency() {
Expand Down
8 changes: 3 additions & 5 deletions js/AudioWorkletGlobalScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,11 @@ globalThis.registerProcessor = function registerProcessor(name, processorCtor) {
// NOTE: Authors that register an event listener on the "message" event of this
// port should call close on either end of the MessageChannel (either in the
// AudioWorklet or the AudioWorkletGlobalScope side) to allow for resources to be collected.
parentPort.on('exit', () => {
process.stdout.write('closing worklet');
});
// parentPort.on('exit', () => {
// process.stdout.write('closing worklet');
// });

parentPort.on('message', event => {
console.log(event.cmd + '\n');

switch (event.cmd) {
case 'node-web-audio-api:worklet:init': {
const { workletId, processors, promiseId } = event;
Expand Down