From df38da592412c7bc079f12fb4b2f5b7666c3995a Mon Sep 17 00:00:00 2001 From: Vishvananda Abrams Date: Mon, 16 Nov 2026 00:24:01 +0000 Subject: [PATCH 1/2] Find Intel dispatches by unique runner identity when gh returns no URL --- scripts/run_intel_benchmarks_once.py | 34 +++++++++++++++++++++++++- scripts/tests/test_intel_benchmarks.py | 31 +++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/scripts/run_intel_benchmarks_once.py b/scripts/run_intel_benchmarks_once.py index f57651a05..f22d14c65 100644 --- a/scripts/run_intel_benchmarks_once.py +++ b/scripts/run_intel_benchmarks_once.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 """Run trusted Intel benchmarks sequentially, with one temporary runner per job.""" import argparse +from datetime import datetime, timezone import hashlib import json import os @@ -12,6 +13,8 @@ import sys import tarfile import tempfile +import time +from urllib.parse import urlencode import urllib.request SUITES = { @@ -51,6 +54,30 @@ def dispatch_command(args, revision, label): return command +def dispatched_run(repo, workflow, label, since, attempts=12): + """Find this runner's job when older gh versions dispatch without a URL.""" + query = urlencode(dict(event='workflow_dispatch', created='>=' + since, per_page=100)) + for attempt in range(attempts): + matches = set() + page = 1 + while True: + runs = github(f'repos/{repo}/actions/workflows/{workflow}/runs?{query}&page={page}')['workflow_runs'] + for run in runs: + jobs = github(f'repos/{repo}/actions/runs/{run["id"]}/jobs?per_page=100')['jobs'] + if any(label in job.get('labels', []) and job.get('runner_name') == label for job in jobs): + matches.add(str(run['id'])) + if len(runs) < 100: + break + page += 1 + if len(matches) > 1: + raise RuntimeError('multiple workflow runs used this supposedly unique runner') + if matches: + return matches.pop() + if attempt + 1 < attempts: + time.sleep(5) + raise RuntimeError('could not identify the dispatched run by its unique runner; check Actions') + + def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--repo', default='vishvananda/cppgm') @@ -97,6 +124,7 @@ def main(): print(f'Runner files and logs: {directory}', flush=True) registered = False run_id = None + queued_at = None try: token = github('--method', 'POST', f'repos/{args.repo}/actions/runners/registration-token')['token'] with (directory / 'configure.log').open('wb') as log: @@ -109,6 +137,7 @@ def main(): registered = True if not args.listen: # Queue the job for this runner's unique label, not any other runner. + queued_at = datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ') output = subprocess.check_output(dispatch_command(args, revision, label), text=True) print(output, end='', flush=True) match = re.search(r'/actions/runs/(\d+)', output) @@ -134,7 +163,10 @@ def main(): raise RuntimeError(f'runner exited {status}; see {directory / "runner.log"}') if not args.listen: if run_id is None: - raise RuntimeError('gh did not return the run URL; check Actions before starting another suite') + run_id = dispatched_run(args.repo, SUITES[args.suite], label, queued_at) + print(f'CI run: https://github.com/{args.repo}/actions/runs/{run_id}', flush=True) + (directory / 'run.json').write_text(json.dumps(dict(run_id=run_id, revision=revision, + workflow_ref=args.ref, runner_label=label), indent=2) + '\n') # A healthy runner process does not imply a successful benchmark. # Wait for validation and badge publication before the next suite. subprocess.run(['gh', 'run', 'watch', run_id, '--repo', args.repo, '--exit-status'], check=True) diff --git a/scripts/tests/test_intel_benchmarks.py b/scripts/tests/test_intel_benchmarks.py index 227eb0541..d697b5fc8 100644 --- a/scripts/tests/test_intel_benchmarks.py +++ b/scripts/tests/test_intel_benchmarks.py @@ -17,6 +17,37 @@ class IntelBenchmarkTests(unittest.TestCase): + def test_missing_dispatch_url_uses_exact_job_labels_and_runner_identity(self): + label='cppgm-intel-unique' + def api(endpoint): + if '/workflows/' in endpoint: + return {'workflow_runs': [{'id': 11}, {'id': 12}, {'id': 13}]} + if '/11/' in endpoint: + return {'jobs': [{'labels': ['self-hosted', label], 'runner_name': 'someone-else'}]} + if '/12/' in endpoint: + return {'jobs': [{'labels': ['self-hosted', label], 'runner_name': label}]} + return {'jobs': [{'labels': ['self-hosted', 'different'], 'runner_name': label}]} + with patch.object(launcher, 'github', side_effect=api): + self.assertEqual(launcher.dispatched_run('owner/repo','suite.yml',label,'2026-11-16T00:00:00Z'), '12') + + def test_discovery_waits_for_job_visibility_and_rejects_ambiguous_matches(self): + response=[{'workflow_runs': []}, {'workflow_runs': [{'id': 12}]}, + {'jobs': [{'labels': ['unique'], 'runner_name': 'unique'}]}] + with patch.object(launcher, 'github', side_effect=response), patch.object(launcher.time,'sleep') as sleep: + self.assertEqual(launcher.dispatched_run('owner/repo','suite.yml','unique','since',attempts=2),'12') + sleep.assert_called_once_with(5) + response=[{'workflow_runs':[{'id':11},{'id':12}]}, + {'jobs':[{'labels':['unique'],'runner_name':'unique'}]}, + {'jobs':[{'labels':['unique'],'runner_name':'unique'}]}] + with patch.object(launcher,'github',side_effect=response): + with self.assertRaisesRegex(RuntimeError,'multiple workflow runs'): + launcher.dispatched_run('owner/repo','suite.yml','unique','since') + + def test_discovery_never_guesses_the_latest_unrelated_run(self): + with patch.object(launcher,'github',return_value={'workflow_runs':[]}), patch.object(launcher.time,'sleep'): + with self.assertRaisesRegex(RuntimeError,'could not identify'): + launcher.dispatched_run('owner/repo','suite.yml','unique','since',attempts=1) + def test_plan_pins_all_suites_without_registering_or_dispatching(self): with patch.object(sys, 'argv', ['runner', '--plan', '--ref', 'feature', '--revision', 'main']), \ patch.object(launcher, 'github', return_value={'sha': 'a' * 40}) as api, \ From 5be0a147f875662dd5e22651e564f036896188f1 Mon Sep 17 00:00:00 2001 From: Vishvananda Abrams Date: Mon, 16 Nov 2026 21:25:04 +0000 Subject: [PATCH 2/2] Run and publish the full WASI self-build on dedicated Intel --- .../workflows/intel-library-benchmarks.yml | 7 +++- .github/workflows/wasm.yml | 9 +++- docs/performance/intel-benchmarks.md | 12 +++++- scripts/experimental/wasi_inception.py | 24 ++++++----- scripts/intel_library_benchmarks.py | 22 +++++++++- scripts/run_intel_benchmarks_once.py | 5 ++- scripts/tests/test_intel_benchmarks.py | 34 ++++++++++++++- scripts/tests/test_public_benchmarks.py | 3 +- scripts/tests/test_wasi_inception.py | 42 +++++++++++++++++++ scripts/tests/test_wasm_benchmarks.py | 17 +++++++- scripts/wasm_benchmark_results.py | 3 +- scripts/wasm_selfbuild_benchmarks.py | 8 +++- 12 files changed, 163 insertions(+), 23 deletions(-) diff --git a/.github/workflows/intel-library-benchmarks.yml b/.github/workflows/intel-library-benchmarks.yml index 69d542be7..eea777131 100644 --- a/.github/workflows/intel-library-benchmarks.yml +++ b/.github/workflows/intel-library-benchmarks.yml @@ -65,14 +65,18 @@ jobs: apt-get install -y --no-install-recommends bzip2 gdb ;; wasm) apt-get install -y --no-install-recommends curl xz-utils perl util-linux ;; + wasm-selfbuild) + apt-get install -y --no-install-recommends curl xz-utils perl nodejs npm ;; index-cpp|simdjson|internal) ;; *) exit 2 ;; esac git config --global --add safe.directory /work/source git config --global --add safe.directory /work/tools make -C dev cppgm -j16 + jobs=16 + if [ "$SUITE" = wasm-selfbuild ]; then jobs=2; fi python3 -u ../tools/scripts/intel_library_benchmarks.py run \ - --suite "$SUITE" --source /work/source --jobs 16 + --suite "$SUITE" --source /work/source --jobs "$jobs" ' - name: Report if: always() @@ -80,6 +84,7 @@ jobs: SUITE: ${{ inputs.suite }} run: | report="source/obj/$SUITE/details.md" + if [ "$SUITE" = wasm-selfbuild ]; then report="source/obj/$SUITE/summary.md"; fi if [ -f "$report" ]; then cat "$report" >> "$GITHUB_STEP_SUMMARY"; fi - name: Collect results and diagnostics if: always() diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index 08a8fd4e4..6e4d93419 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -27,12 +27,17 @@ on: description: Intel runner label supplied by the temporary-runner helper type: string default: cppgm-intel + intel_suite: + description: Dedicated Intel measurement to run + type: choice + options: [wasm, wasm-selfbuild] + default: wasm permissions: contents: read concurrency: - group: wasm-benchmarks-${{ github.ref }}-${{ inputs.platform || 'github' }} + group: wasm-benchmarks-${{ github.ref }}-${{ inputs.platform || 'github' }}-${{ inputs.intel_suite || 'wasm' }} cancel-in-progress: true jobs: @@ -258,6 +263,6 @@ jobs: contents: write uses: ./.github/workflows/intel-library-benchmarks.yml with: - suite: wasm + suite: ${{ inputs.intel_suite || 'wasm' }} revision: ${{ inputs.revision || github.sha }} runner_label: ${{ inputs.runner_label }} diff --git a/docs/performance/intel-benchmarks.md b/docs/performance/intel-benchmarks.md index d06cfd194..5884903b2 100644 --- a/docs/performance/intel-benchmarks.md +++ b/docs/performance/intel-benchmarks.md @@ -12,11 +12,21 @@ python3 scripts/run_intel_benchmarks_once.py --plan \ Remove `--plan` to start. The suites run sequentially: public programs, self-build/inception timing, index-cpp, simdjson scalar and SSE, Godot, Boost O3, -the internal C++ source subset, and Wasm O0/O3 kernels. Each suite gets a fresh temporary runner and Ubuntu 26.04 container. The +the internal C++ source subset, Wasm O0/O3 kernels, and the complete WASI compiler +self-build. Each suite gets a fresh temporary runner and Ubuntu 26.04 container. The launcher waits for the suite and publication to pass before starting the next; runner logs and measurements remain in the printed directory. Use `--suite NAME` to refresh just one suite. +The WASI self-build is a separate suite (`--suite wasm-selfbuild`); kernel +measurements do not include it. It uses the same two workers, frozen inputs, +byte checks and paired timing blocks as the hosted comparison. Its results +populate the dedicated Intel row under `wasm-selfbuild`. To run it before merging +workflow changes, use `--ref BRANCH --revision COMPILER_COMMIT`; the WASI package, +source lists and recorded revision all come from that compiler checkout. +The launcher also supports older GitHub CLI versions that omit the dispatch URL, +identifying the completed job by its unique runner label and name. + The internal suite pins both archive checksums from before and after the `cppgm-extended` to `cppgm` rename: only the archive's directory prefix changed. It records the hash actually used, verifies every cohort source unit, and diff --git a/scripts/experimental/wasi_inception.py b/scripts/experimental/wasi_inception.py index 60c0e4254..b0a6b0efb 100644 --- a/scripts/experimental/wasi_inception.py +++ b/scripts/experimental/wasi_inception.py @@ -71,13 +71,13 @@ def next_word(): return "\n".join(lines) + "\n" -def source_sets(tools): +def source_sets(tools, repo_root=REPO): """Use the compiler's owning source lists, including each tool's entry point.""" makefile = "include dev/frontend_source_sets.mk\nlist:\n" for name in tools: makefile += "\t@printf '%s\\n' '" + name + "' $(FRONTEND_OBJ_BASENAMES_" + name + ") END\n" lines = subprocess.check_output(["make", "-s", "-f", "-", "list"], - input=makefile.encode(), cwd=REPO).decode().splitlines() + input=makefile.encode(), cwd=repo_root).decode().splitlines() result = {} while lines: name = lines.pop(0) @@ -90,17 +90,18 @@ def source_sets(tools): def prepare(args): package = args.directory.resolve() package.mkdir() # Never replace an existing experiment or its observations. + repo_root = getattr(args, 'repo_root', REPO).resolve(strict=True) inputs = package / "inputs" inputs.mkdir() - copy_tree(REPO / "dev/src", inputs / "dev/src") + copy_tree(repo_root / "dev/src", inputs / "dev/src") tools = getattr(args, "reference_tools", ["cppgm"]) for name in tools: - shutil.copyfile(REPO / ("dev/" + name + ".cpp"), inputs / ("dev/" + name + ".cpp")) + shutil.copyfile(repo_root / ("dev/" + name + ".cpp"), inputs / ("dev/" + name + ".cpp")) for name in ['LICENSE', 'NOTICE']: - shutil.copyfile(REPO / name, inputs / name) - shutil.copyfile(HERE / "wasi_host.h", inputs / "wasi_host.h") - shutil.copyfile(HERE / "wasi_stack.S", inputs / "wasi_stack.S") - tool_sources = source_sets(tools) + shutil.copyfile(repo_root / name, inputs / name) + shutil.copyfile(repo_root / "scripts/experimental/wasi_host.h", inputs / "wasi_host.h") + shutil.copyfile(repo_root / "scripts/experimental/wasi_stack.S", inputs / "wasi_stack.S") + tool_sources = source_sets(tools, repo_root) x86_sources = list(tool_sources["cppgm"]) # These are supplied WASI command-host sources, shared by every exported # tool. Native builds keep their owning frontend source sets unchanged. @@ -109,7 +110,7 @@ def prepare(args): sources.insert(-1, "dev/src/support/wasi_heap.cpp") sources.insert(-1, "wasi_stack.S") sources = tool_sources["cppgm"] - config = (REPO / "obj/generated/cppgm_builtin_host_config.h").read_text() + config = (repo_root / "obj/generated/cppgm_builtin_host_config.h").read_text() paths = re.search(r"kStandardIncludePaths\[\] = \{(.*?)\};", config, re.S) if paths is None: raise RuntimeError("generated host configuration has no include path table") @@ -184,9 +185,9 @@ def prepare(args): for p in sorted((package / "shim").rglob("*")) if p.is_file()}, "runner_files": {name: digest((package / name).read_bytes()) for name in runners}, "sdk_version": (args.sdk / "VERSION").read_text(), - "revision": subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=REPO).decode().strip(), + "revision": subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=repo_root).decode().strip(), "tool_sources": tool_sources, - "dirty": bool(subprocess.check_output(["git", "status", "--porcelain"], cwd=REPO)), + "dirty": bool(subprocess.check_output(["git", "status", "--porcelain"], cwd=repo_root)), "source_sha256": digest(json.dumps([(f['path'], f['sha256']) for f in files if f['path'].startswith('dev/')]).encode())} save(package / "manifest.json", manifest) @@ -344,6 +345,7 @@ def main(): commands = parser.add_subparsers(dest="command", required=True) pack = commands.add_parser("prepare") pack.add_argument("--directory", required=True, type=Path) + pack.add_argument("--repo-root", type=Path, default=REPO) pack.add_argument("--sdk", required=True, type=Path) pack.add_argument("--compiler", type=Path, default=REPO / "dev/cppgm") pack.add_argument("--shim", required=True, type=Path) diff --git a/scripts/intel_library_benchmarks.py b/scripts/intel_library_benchmarks.py index 0c4b352aa..98af78c13 100644 --- a/scripts/intel_library_benchmarks.py +++ b/scripts/intel_library_benchmarks.py @@ -15,11 +15,18 @@ 'boost': 'boost_benchmarks.py', 'internal': 'internal_cpp_benchmarks.py', 'wasm': 'wasm_benchmarks.pl', + 'wasm-selfbuild': 'wasm_selfbuild_benchmarks.py', } DIRECTORY = Path(__file__).resolve().parent def run_command(suite, source, jobs): + if suite == 'wasm-selfbuild': + return [sys.executable, str(DIRECTORY / SCRIPTS[suite]), + '--compiler', str(source / 'dev/cppgm'), '--repo-root', str(source), + '--output', str(source / 'obj' / suite), '--tools', str(source / 'obj/wasm-tools'), + '--shim', str(DIRECTORY / 'experimental/node_modules/@bjorn3/browser_wasi_shim'), + '--jobs', str(jobs)] if suite == 'wasm': return ['perl', str(DIRECTORY / SCRIPTS[suite]), '--compiler', str(source / 'dev/cppgm'), '--repo-root', str(source), '--output', str(source / 'obj' / suite)] @@ -31,6 +38,13 @@ def run_command(suite, source, jobs): def run(args): command = run_command(args.suite, args.source.resolve(strict=True), args.jobs) + if args.suite == 'wasm-selfbuild': + subprocess.run(['perl', str(DIRECTORY / 'install_wasm_tools.pl'), '--prefix', + str(args.source / 'obj/wasm-tools')], check=True) + subprocess.run(['npm', 'ci', '--ignore-scripts', '--prefix', + str(DIRECTORY / 'experimental')], check=True) + subprocess.run(command, check=True) + return if args.suite == 'wasm': tools = args.source / 'obj/wasm-tools' subprocess.run(['perl', str(DIRECTORY / 'install_wasm_tools.pl'), '--prefix', str(tools), @@ -61,7 +75,8 @@ def collect(source, target): for path in source.rglob('*'): relative = path.relative_to(source) if ({'build', 'source'}.intersection(relative.parts) or not path.is_file() - or not (path.suffix in suffixes or path.suffix == '.stdin' or path.name in ('stdout', 'stderr') + or (relative.parts[:2] == ('package', 'inputs') and path.suffix != '.log') + or not (path.suffix in suffixes or path.suffix == '.stdin' or path.name in ('stdout', 'stderr', 'manifest.sha256') or path.name.endswith('probe'))): continue destination = target / relative @@ -93,6 +108,11 @@ def main(): elif args.command == 'collect': collect(args.source, args.target) else: + if args.suite == 'wasm-selfbuild': + subprocess.run([sys.executable, str(DIRECTORY / 'wasm_benchmark_results.py'), 'publish-selfbuild', + str(args.artifact), '--target', str(args.target), '--revision', args.revision, + '--run-url', args.run_url, '--platform', 'intel'], check=True) + return if args.suite == 'wasm': subprocess.run([sys.executable, str(DIRECTORY / 'wasm_benchmark_results.py'), 'publish', str(args.artifact / 'O0'), str(args.artifact / 'O3'), '--target', str(args.target), diff --git a/scripts/run_intel_benchmarks_once.py b/scripts/run_intel_benchmarks_once.py index f22d14c65..d033f9df0 100644 --- a/scripts/run_intel_benchmarks_once.py +++ b/scripts/run_intel_benchmarks_once.py @@ -26,6 +26,7 @@ 'boost': 'boost.yml', 'internal': 'internal-cpp.yml', 'wasm': 'wasm.yml', + 'wasm-selfbuild': 'wasm.yml', } @@ -51,6 +52,8 @@ def dispatch_command(args, revision, label): '-f', f'runner_label={label}'] if args.course_quality and args.suite == 'public': command += ['-f', 'course_quality=true'] + if args.suite == 'wasm-selfbuild': + command += ['-f', 'intel_suite=wasm-selfbuild'] return command @@ -87,7 +90,7 @@ def main(): parser.add_argument('--listen', action='store_true', help='accept one manually queued job instead of dispatching') parser.add_argument('--course-quality', action='store_true', help='also measure the optional course exercises') parser.add_argument('--suite', choices=['all', *SUITES], default='all', - help='run all seven suites sequentially (default), or just one') + help='run all suites sequentially (default), or just one') parser.add_argument('--plan', action='store_true', help='show the pinned campaign without registering runners or starting jobs') args = parser.parse_args() revision = github(f'repos/{args.repo}/commits/{args.revision}')['sha'] diff --git a/scripts/tests/test_intel_benchmarks.py b/scripts/tests/test_intel_benchmarks.py index d697b5fc8..076b1bf6a 100644 --- a/scripts/tests/test_intel_benchmarks.py +++ b/scripts/tests/test_intel_benchmarks.py @@ -7,6 +7,7 @@ import subprocess import sys import tempfile +from types import SimpleNamespace import unittest from unittest.mock import patch @@ -68,9 +69,38 @@ def test_library_commands_measure_source_instead_of_workflow_checkout(self): self.assertEqual(command[command.index('--repo-root') + 1], str(source)) self.assertEqual(command[command.index('--compiler') + 1], str(source / 'dev/cppgm')) self.assertEqual(command[command.index('--output') + 1], str(source / 'obj' / suite)) - self.assertEqual('--jobs' in command, suite in ('godot', 'boost', 'internal')) + self.assertEqual('--jobs' in command, suite in ('godot', 'boost', 'internal', 'wasm-selfbuild')) self.assertEqual(Path(command[1]).name, library.SCRIPTS[suite]) + def test_wasi_selfbuild_dispatch_selects_only_its_suite(self): + args = SimpleNamespace(suite='wasm-selfbuild', repo='owner/repo', ref='tooling', course_quality=False) + command = launcher.dispatch_command(args, 'a' * 40, 'unique') + self.assertEqual(command[3], 'wasm.yml') + self.assertIn('intel_suite=wasm-selfbuild', command) + self.assertIn('revision=' + 'a' * 40, command) + self.assertIn('runner_label=unique', command) + args.suite = 'wasm' + self.assertNotIn('intel_suite=wasm-selfbuild', launcher.dispatch_command(args, 'a' * 40, 'unique')) + + def test_wasi_selfbuild_installs_pinned_tools_and_routes_publication(self): + with tempfile.TemporaryDirectory() as temporary: + source = Path(temporary) + args = SimpleNamespace(suite='wasm-selfbuild', source=source, jobs=2) + with patch.object(library.subprocess, 'run') as run: + library.run(args) + calls = [call.args[0] for call in run.call_args_list] + self.assertEqual(len(calls), 3) + self.assertEqual(calls[0][-2:], ['--prefix', str(source / 'obj/wasm-tools')]) + self.assertEqual(calls[1][:3], ['npm', 'ci', '--ignore-scripts']) + self.assertEqual(calls[2], library.run_command('wasm-selfbuild', source, 2)) + with patch.object(sys, 'argv', ['adapter', 'publish', '--suite', 'wasm-selfbuild', + '--artifact', 'artifact', '--target', 'badges', '--revision', 'a' * 40, + '--run-url', 'https://example.org/run']), patch.object(library.subprocess, 'run') as run: + library.main() + command = run.call_args.args[0] + self.assertEqual(command[2:4], ['publish-selfbuild', 'artifact']) + self.assertEqual(command[-2:], ['--platform', 'intel']) + def test_source_metadata_reads_the_selected_clean_checkout(self): with tempfile.TemporaryDirectory() as temporary: root = Path(temporary) @@ -97,10 +127,12 @@ def test_collection_retains_nested_observations_without_build_trees(self): root = Path(temporary) source, target = root / 'run', root / 'artifact' keep = ['results.json', 'compile.stdout', 'compile.stderr', 'counter-probe', + 'package/manifest.json', 'package/manifest.sha256', 'package/inputs/AB-0-0/a.log', 'raw/requests.stdin', 'runtime/observations.jsonl', 'runtime/000/stdout', 'runtime/000/stderr', 'cppgm/libs-json-test/invocations.jsonl', 'cppgm/libs-json-test/b2.log'] discard = ['compiler', 'output.o', 'source/input.json', 'source/tests/result.stdout', + 'package/inputs/dev/header.hpp', 'package/inputs/sysroot/large.json', 'cppgm/build/large.json', 'binary'] for name in keep + discard: path = source / name diff --git a/scripts/tests/test_public_benchmarks.py b/scripts/tests/test_public_benchmarks.py index 067a4c322..45591ea80 100644 --- a/scripts/tests/test_public_benchmarks.py +++ b/scripts/tests/test_public_benchmarks.py @@ -815,7 +815,8 @@ def run(command, check): with mock.patch.object(intel_runner.subprocess, 'run', side_effect=run): intel_runner.run_suites(args, 'a' * 40, Path('/tmp/runners')) - self.assertEqual(calls, ['public', 'self-build', 'index-cpp', 'simdjson', 'godot', 'boost', 'internal', 'wasm']) + self.assertEqual(calls, ['public', 'self-build', 'index-cpp', 'simdjson', 'godot', 'boost', 'internal', + 'wasm', 'wasm-selfbuild']) def test_suites_dispatch_distinct_workflows(self): args = SimpleNamespace(repo='owner/repo', ref='main', course_quality=True, suite='public') diff --git a/scripts/tests/test_wasi_inception.py b/scripts/tests/test_wasi_inception.py index 92aba3615..ebe611d3c 100644 --- a/scripts/tests/test_wasi_inception.py +++ b/scripts/tests/test_wasi_inception.py @@ -3,6 +3,7 @@ import json from pathlib import Path import tempfile +import subprocess import sys from types import SimpleNamespace import unittest @@ -23,6 +24,47 @@ def module(name): class WasiInception(unittest.TestCase): + def test_freeze_uses_selected_checkout_for_sources_lists_and_revision(self): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + source, sdk, shim = root / 'source', root / 'sdk', root / 'shim' + files = { + 'source/dev/frontend_source_sets.mk': 'FRONTEND_OBJ_BASENAMES_cppgm = selected\n', + 'source/dev/src/selected.cpp': 'selected source', + 'source/dev/cppgm.cpp': 'selected entry point', + 'source/LICENSE': 'license', 'source/NOTICE': 'notice', + 'source/scripts/experimental/wasi_host.h': 'selected host', + 'source/scripts/experimental/wasi_stack.S': 'selected stack', + 'source/obj/generated/cppgm_builtin_host_config.h': 'kStandardIncludePaths[] = {nullptr};', + 'source/.gitignore': 'obj/\n', 'compiler': 'binary', + 'shim/dist/index.js': 'shim', + 'shim/package.json': '{"name":"@bjorn3/browser_wasi_shim","version":"0.4.2"}', + 'sdk/VERSION': 'pinned SDK', + 'sdk/lib/clang/23/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a': 'archive', + } + for name in ('crt1-command.o', 'libc.a', 'libc-printscan-long-double.a', + 'eh/libc++.a', 'eh/libc++abi.a', 'eh/libunwind.a'): + files['sdk/share/wasi-sysroot/lib/wasm32-wasip1/' + name] = 'archive' + for name, contents in files.items(): + path = root / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(contents) + subprocess.run(['git', 'init', '-q', str(source)], check=True) + subprocess.run(['git', '-C', str(source), 'add', '.'], check=True) + subprocess.run(['git', '-C', str(source), '-c', 'user.name=Test', '-c', 'user.email=test@example.org', + 'commit', '-qm', 'selected sources'], check=True) + expected = subprocess.check_output(['git', '-C', str(source), 'rev-parse', 'HEAD'], text=True).strip() + package = root / 'package' + frozen.prepare(SimpleNamespace(directory=package, repo_root=source, sdk=sdk, + compiler=root / 'compiler', shim=shim, x86_headers=False, optimization=3)) + manifest = json.loads((package / 'manifest.json').read_text()) + self.assertEqual(manifest['revision'], expected) + self.assertFalse(manifest['dirty']) + self.assertEqual(manifest['x86_sources'][:-1], ['dev/src/selected.cpp', 'dev/cppgm.cpp']) + self.assertEqual((package / 'inputs/dev/src/selected.cpp').read_text(), 'selected source') + self.assertEqual((package / 'inputs/wasi_host.h').read_text(), 'selected host') + frozen.verify(package, manifest) + def test_lane_requires_all_fixed_points_and_x86_levels(self): args = lane.arguments([]) phases = lane.plan(args, Path('/new-package')) diff --git a/scripts/tests/test_wasm_benchmarks.py b/scripts/tests/test_wasm_benchmarks.py index 1a8dde4b2..f3b2fcf50 100644 --- a/scripts/tests/test_wasm_benchmarks.py +++ b/scripts/tests/test_wasm_benchmarks.py @@ -151,7 +151,7 @@ def row(name, cpu): (artifact / 'observations.json').write_text(json.dumps([row('cppgm-producer', 10.), row('clang-producer', 75.)])) args = argparse.Namespace(artifact=artifact, target=target, revision='a' * 40, - run_url='https://example.org/run') + run_url='https://example.org/run', platform='github') producer.publish_selfbuild(args) directory = target / producer.SELFBUILD self.assertIn('7.50', (directory / 'epyc-compile-clang.svg').read_text()) @@ -161,6 +161,21 @@ def row(name, cpu): self.assertNotIn('commands', published['producers']['cppgm-producer']) self.assertIn('[Results](epyc/report.md)', (directory / 'report.md').read_text()) benchmark_publication.prepare(target) + args.platform = 'intel' + with self.assertRaisesRegex(ValueError, 'Intel hardware'): + producer.publish_selfbuild(args) + metadata['cpu'] = 'Intel Xeon Platinum 8581C' + (artifact / 'results.json').write_text(json.dumps(dict(schema=1, status='complete', metadata=metadata, + phases=phases, warnings=[]))) + producer.publish_selfbuild(args) + self.assertIn('7.50', (directory / 'intel-compile-clang.svg').read_text()) + self.assertIn('0.90', (directory / 'intel-runtime-clang.svg').read_text()) + self.assertIn('7.50', (directory / 'epyc-compile-clang.svg').read_text()) + self.assertIn('n/m', (directory / 'github-intel-runtime-clang.svg').read_text()) + self.assertTrue((directory / 'history' / ('a' * 40) / 'intel/results.json').exists()) + args.platform = 'github' + producer.publish_selfbuild(args) + self.assertIn('0.90', (directory / 'github-intel-runtime-clang.svg').read_text()) args.revision = 'b' * 40 with self.assertRaisesRegex(ValueError, 'clean measured'): producer.publish_selfbuild(args) diff --git a/scripts/wasm_benchmark_results.py b/scripts/wasm_benchmark_results.py index 9e8e688b4..0051d686f 100644 --- a/scripts/wasm_benchmark_results.py +++ b/scripts/wasm_benchmark_results.py @@ -242,7 +242,7 @@ def publish_selfbuild(args): metadata = document['metadata'] if metadata['dirty'] or metadata['revision'] != args.revision: raise ValueError('publication requires the clean measured compiler revision') - platform = benchmark_hosts.publication_platform(metadata['cpu'], 'github') + platform = benchmark_hosts.publication_platform(metadata['cpu'], args.platform) directory = args.target / SELFBUILD for destination in (directory / platform, directory / 'history' / args.revision / platform): destination.mkdir(parents=True, exist_ok=True) @@ -303,6 +303,7 @@ def main(): selfbuild.add_argument('--target', type=Path, required=True) selfbuild.add_argument('--revision', required=True) selfbuild.add_argument('--run-url', required=True) + selfbuild.add_argument('--platform', choices=['github', 'intel'], default='github') for command in ('report', 'publish'): sub = commands.add_parser(command) sub.add_argument('artifacts', type=Path, nargs='+') diff --git a/scripts/wasm_selfbuild_benchmarks.py b/scripts/wasm_selfbuild_benchmarks.py index 547a3de1a..7fd7d9259 100644 --- a/scripts/wasm_selfbuild_benchmarks.py +++ b/scripts/wasm_selfbuild_benchmarks.py @@ -138,6 +138,7 @@ def run(args): args.output = args.output.resolve() args.tools = args.tools.resolve() args.compiler = args.compiler.resolve() + args.repo_root = args.repo_root.resolve(strict=True) if hasattr(os, 'sched_getaffinity'): cpus = sorted(os.sched_getaffinity(0))[:args.jobs] os.sched_setaffinity(0, cpus) @@ -145,7 +146,8 @@ def run(args): cpus = [] package = args.output / 'package' inception.prepare(argparse.Namespace(directory=package, sdk=args.tools / 'wasi-sdk', - compiler=args.compiler, shim=args.shim.resolve(), x86_headers=False, optimization=3)) + compiler=args.compiler, shim=args.shim.resolve(), x86_headers=False, optimization=3, + repo_root=args.repo_root)) manifest = json.loads((package / 'manifest.json').read_text()) inception.verify(package, manifest) campaign = Campaign(args, package, manifest) @@ -180,7 +182,8 @@ def run(args): 'link_seconds', 'link_cpu_seconds']} inception.verify(package, manifest) metadata = dict(revision=manifest['revision'], - dirty=bool(subprocess.check_output(['git', 'status', '--porcelain'], cwd=ROOT)), + dirty=manifest['dirty'] or bool(subprocess.check_output( + ['git', 'status', '--porcelain'], cwd=args.repo_root)), sources=len(manifest['sources']), cpu=public_benchmarks.cpu_model(), affinity=cpus, jobs=args.jobs, manifest_sha256=digest(package / 'manifest.json'), candidate_sha256=digest(candidate), reference_sha256=digest(reference), @@ -212,6 +215,7 @@ def run(args): def arguments(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--output', type=Path, required=True) + parser.add_argument('--repo-root', type=Path, default=ROOT, help='compiler source checkout to freeze') parser.add_argument('--tools', type=Path, default=ROOT / 'obj/wasm-tools') parser.add_argument('--compiler', type=Path, default=ROOT / 'dev/cppgm') parser.add_argument('--shim', type=Path, default=ROOT / 'scripts/experimental/node_modules/@bjorn3/browser_wasi_shim')