Test / gate (push) Canceled after 0s
The gate first ran on the server that deploys the site: a slow container with no C compiler and no ICU. Ten tests failed there on correct code, and no Mojo program could be built at all. - The workflows ask for a runner labeled heavy, not the deploy server: the gate builds and runs some 300 Mojo programs and fuzzes. docs/ci.md says how to register one. With none registered a run waits. - The pinned environment has a C compiler on Linux (gcc, with its C library pinned to glibc 2.34): mojo build links with the C compiler it finds, and conda-forge's default links against a C library too old for Mojo's runtime. mojo-local reports a program that could not be linked as that, and does not keep the answer. - The pinned Dafny runs without ICU, and dafny-fetch fails when the Dafny it fetched does not start. - A test's time limit is processor time at the machine's pace (tests/helpers/pace.mjs). - The prover's time on the clock is the caller's: provePseudo and Workspace.proofBudgetMs take it, the Prove tab's 3 seconds stay the default, and the command line, library-check and the tests use none, so their answers are the counted budgets' alone. - The library pointer moves to its workflow change (e5ae090).
75 lines
3.8 KiB
JavaScript
75 lines
3.8 KiB
JavaScript
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// Time limits that mean the same thing on every machine. A test that says "this takes under 2 seconds" is there to
|
|
// catch work that grows with the square of its input (seconds become minutes), and its limit was written on one
|
|
// machine. On CI's runner, a small virtual machine that runs eight test files at once, the same correct code took 4
|
|
// to 12 times the limits, and six tests failed with nothing wrong. So a limit here is:
|
|
//
|
|
// - measured in the processor time this process used (process.cpuUsage), not time on the clock, so the other test
|
|
// files that share the processors do not count against it;
|
|
// - multiplied by this machine's pace: how many times longer a fixed piece of work (`work` below) takes here than
|
|
// the REFERENCE_MS it took where the limits were written. The pace is taken before and after what is timed, and
|
|
// the larger counts. It is never below 1, so no limit gets tighter on a faster machine, and on the machine the
|
|
// limits were written on they are what they were.
|
|
//
|
|
// A failure says the time, the limit and the pace. PPLUS_PACE_LOG=1 prints every measurement that passed too.
|
|
import assert from 'node:assert/strict';
|
|
|
|
/** Milliseconds `work()` takes, at its best, on the machine the tests' limits were written on. */
|
|
export const REFERENCE_MS = 2.3;
|
|
|
|
/** A little of what the engines do: cut names out of text, make small objects, count in a Map, sort. */
|
|
function work() {
|
|
let sum = 0;
|
|
const names = new Map();
|
|
for (let i = 0; i < 40000; i++) {
|
|
const word = `v${i % 997}`;
|
|
const node = { kind: 'name', text: word, line: i, at: [i, i + word.length] };
|
|
names.set(word, (names.get(word) ?? 0) + node.at[1] - node.at[0]);
|
|
sum += word.charCodeAt(word.length - 1);
|
|
}
|
|
const list = [...names].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1));
|
|
return sum + list.length;
|
|
}
|
|
|
|
/** Processor time this process has used, in milliseconds (every thread of it: the collector and the compiler too). */
|
|
const cpuMs = () => { const u = process.cpuUsage(); return (u.user + u.system) / 1000; };
|
|
|
|
let warm = false;
|
|
/** How many times longer the fixed work takes here, now, than on the reference machine; at least 1. */
|
|
export function pace() {
|
|
if (!warm) { for (let i = 0; i < 20; i++) work(); warm = true; }
|
|
let best = Infinity;
|
|
for (let i = 0; i < 5; i++) { const t0 = cpuMs(); work(); best = Math.min(best, cpuMs() - t0); }
|
|
return Math.max(1, best / REFERENCE_MS);
|
|
}
|
|
|
|
/** The processor time `fn` takes, in milliseconds, and the pace around it. */
|
|
export function measure(fn) {
|
|
const before = pace();
|
|
const t0 = cpuMs();
|
|
fn();
|
|
const ms = cpuMs() - t0;
|
|
return { ms, pace: Math.max(before, pace()) };
|
|
}
|
|
|
|
/** Whether a measurement is inside a limit written for the reference machine, as a message when it is not. */
|
|
export function over(m, limitMs, what) {
|
|
const line = `${what}: ${m.ms.toFixed(1)} ms of processor time; the limit is ${limitMs} ms${m.pace > 1 ? ` x ${m.pace.toFixed(1)}, this machine's pace (tests/helpers/pace.mjs)` : ''}`;
|
|
if (process.env.PPLUS_PACE_LOG) console.log(`pace: ${line}`);
|
|
return m.ms < limitMs * m.pace ? null : line;
|
|
}
|
|
|
|
/** Run `fn` and fail unless it took under `limitMs` of processor time at this machine's pace. */
|
|
export function within(limitMs, what, fn) {
|
|
const failed = over(measure(fn), limitMs, what);
|
|
assert.ok(!failed, failed ?? '');
|
|
}
|
|
|
|
/**
|
|
* For the prover in a test: no time on the clock for a routine. Its counted budgets then decide alone (docs/limits.md),
|
|
* so what a test finds proved, open or broken is the same on every machine. With the Prove tab's 3 seconds, a slow
|
|
* runner left open what the tests expect proved.
|
|
*/
|
|
export const NO_CLOCK = Object.freeze({ budgetMs: Infinity });
|