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

Generate Web Worker script for every test file #3415

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 5 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ module.exports = function (grunt) {
cmd: 'node',
args: ['tools/gen_version'],
},
'generate-listings': {
'generate-listings-and-webworkers': {
cmd: 'node',
args: ['tools/gen_listings', 'gen/', ...kAllSuites.map(s => 'src/' + s)],
args: ['tools/gen_listings_and_webworkers', 'gen/', ...kAllSuites.map(s => 'src/' + s)],
},
validate: {
cmd: 'node',
Expand Down Expand Up @@ -159,14 +159,14 @@ module.exports = function (grunt) {
// Must run after generate-common and run:build-out.
files: [
{ expand: true, dest: 'out/', cwd: 'gen', src: 'common/internal/version.js' },
{ expand: true, dest: 'out/', cwd: 'gen', src: '*/listing.js' },
{ expand: true, dest: 'out/', cwd: 'gen', src: '*/**/*.js' },
],
},
'gen-to-out-wpt': {
// Must run after generate-common and run:build-out-wpt.
files: [
{ expand: true, dest: 'out-wpt/', cwd: 'gen', src: 'common/internal/version.js' },
{ expand: true, dest: 'out-wpt/', cwd: 'gen', src: 'webgpu/listing.js' },
{ expand: true, dest: 'out-wpt/', cwd: 'gen', src: 'webgpu/**/*.js' },
],
},
'htmlfiles-to-out': {
Expand Down Expand Up @@ -243,7 +243,7 @@ module.exports = function (grunt) {

grunt.registerTask('generate-common', 'Generate files into gen/ and src/', [
'run:generate-version',
'run:generate-listings',
'run:generate-listings-and-webworkers',
'run:generate-cache',
]);
grunt.registerTask('build-standalone', 'Build out/ (no checks; run after generate-common)', [
Expand Down
56 changes: 0 additions & 56 deletions src/common/tools/gen_listings.ts

This file was deleted.

91 changes: 91 additions & 0 deletions src/common/tools/gen_listings_and_webworkers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import * as fs from 'fs';
import * as path from 'path';
import * as process from 'process';

import { crawl } from './crawl.js';

function usage(rc: number): void {
console.error(`Usage: tools/gen_listings [options] [OUT_DIR] [SUITE_DIRS...]

For each suite in SUITE_DIRS, generate listings into OUT_DIR/{suite}/listing.js,
and generate Web Worker proxies in OUT_DIR/{suite}/webworker/**/*.worker.js for
every .spec.js file. (Note {suite}/webworker/ is reserved for this purpose.)

Example:
tools/gen_listings gen/ src/unittests/ src/webgpu/

Options:
--help Print this message and exit.
`);
process.exit(rc);
}

const argv = process.argv;
if (argv.indexOf('--help') !== -1) {
usage(0);
}

{
// Ignore old argument that is now the default
const i = argv.indexOf('--no-validate');
if (i !== -1) {
argv.splice(i, 1);
}
}

if (argv.length < 4) {
usage(0);
}

const myself = 'src/common/tools/gen_listings.ts';

const outDir = argv[2];

for (const suiteDir of argv.slice(3)) {
// Run concurrently for each suite (might be a tiny bit more efficient)
void crawl(suiteDir, false).then(listing => {
const suite = path.basename(suiteDir);

// Write listing.js
const outFile = path.normalize(path.join(outDir, `${suite}/listing.js`));
fs.mkdirSync(path.join(outDir, suite), { recursive: true });
fs.writeFileSync(
outFile,
`\
// AUTO-GENERATED - DO NOT EDIT. See ${myself}.

export const listing = ${JSON.stringify(listing, undefined, 2)};
`
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All the code above this point is the same as the old gen_listings.ts. Git didn't detect it as a rename because I added too much code.


// Write suite/webworker/**/*.worker.js
for (const entry of listing) {
if ('readme' in entry) continue;

const outFileDir = path.join(
outDir,
suite,
'webworker',
...entry.file.slice(0, entry.file.length - 1)
);
const outFile = path.join(outDir, suite, 'webworker', ...entry.file) + '.worker.js';

const relPathToSuiteRoot = Array<string>(entry.file.length).fill('..').join('/');

fs.mkdirSync(outFileDir, { recursive: true });
fs.writeFileSync(
outFile,
`\
// AUTO-GENERATED - DO NOT EDIT. See ${myself}.

// oldG is a TestGroup<Fixture> object (defined in common/internal/test_group.ts).
import { g as oldG } from '${relPathToSuiteRoot}/${entry.file.join('/')}.spec.js';

// FIXME: Expose a proxied test interface. I think this can completely replace test_worker-worker.js
// (using this instead of that), but if not then hopefully it can at least share code with it.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It may or may not replace test_worker-worker.js. It would be nice to avoid the duplicated functionality. But that one is a lot more flexible - it just creates one worker and runs tests on it, instead of having to manage one worker for every test file. But since we need to do that for Service Workers anyway, it's probably simplest to use the same setup and logic for all types of workers.

console.log(oldG.iterate());
`
);
}
});
}
2 changes: 2 additions & 0 deletions src/demo/webworker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DIRECTORY RESERVED FOR GENERATED FILES. See gen_listings_and_webworkers.
*
2 changes: 2 additions & 0 deletions src/manual/webworker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DIRECTORY RESERVED FOR GENERATED FILES. See gen_listings_and_webworkers.
*
2 changes: 2 additions & 0 deletions src/stress/webworker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DIRECTORY RESERVED FOR GENERATED FILES. See gen_listings_and_webworkers.
*
2 changes: 2 additions & 0 deletions src/unittests/webworker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DIRECTORY RESERVED FOR GENERATED FILES. See gen_listings_and_webworkers.
*
2 changes: 2 additions & 0 deletions src/webgpu/webworker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DIRECTORY RESERVED FOR GENERATED FILES. See gen_listings_and_webworkers.
*
7 changes: 0 additions & 7 deletions tools/gen_listings

This file was deleted.

8 changes: 8 additions & 0 deletions tools/gen_listings_and_webworkers
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env node

// Crawl a suite directory (e.g. src/webgpu/) to generate a listing.js containing
// the listing of test files in the suite, and some generated test files
// (like suite/serviceworker/**/*.spec.js).

require('../src/common/tools/setup-ts-in-node.js');
require('../src/common/tools/gen_listings_and_webworkers.ts');
Loading