Fix out-of-order subcase logs (#4396)

- First commit fixes a bug where we were capturing a variable too late which prevented the subcase logs from actually being re-sorted the way they were supposed to be
- Second commit simplifies the code a bunch and moves the prefix to the beginning of the log line
This commit is contained in:
Kai Ninomiya 2025-05-27 19:48:51 -07:00 committed by GitHub
parent be765eb463
commit 00bbf5422c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 174 additions and 161 deletions

View file

@ -181,4 +181,43 @@ export class TestCaseRecorder {
this.logs.push(logMessage);
}
/**
* Make a recorder that will defer all calls until `deferUntilPromise` resolves.
* This is used for running subcases, which run concurrently, to ensure that
* logs from all the previous subcases have been flushed before flushing new logs,
* so all logs are in order as if the subcases had not been concurrent.
*/
makeDeferredSubRecorder(prefix: string, deferUntilPromise: Promise<void>) {
return new Proxy(this, {
get: (target, k) => {
switch (k) {
case 'logImpl':
return function (level: LogSeverity, name: string, baseException: unknown) {
globalTestConfig.testHeartbeatCallback();
void deferUntilPromise.then(() => {
target.logImpl(level, prefix + name, baseException);
});
};
case 'beginSubCase':
return function () {
globalTestConfig.testHeartbeatCallback();
void deferUntilPromise.then(() => {
target.beginSubCase();
});
};
case 'endSubCase':
return function (expectedStatus: Expectation) {
globalTestConfig.testHeartbeatCallback();
void deferUntilPromise.then(() => {
target.endSubCase(expectedStatus);
});
};
default:
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
return (target as any)[k];
}
},
});
}
}

View file

@ -615,46 +615,11 @@ class RunCaseSpecific implements RunCase {
};
for (const subParams of this.subcases) {
// Make a recorder that will defer all calls until `allPreviousSubcasesFinalizedPromise`
// resolves. Waiting on `allPreviousSubcasesFinalizedPromise` ensures that
// logs from all the previous subcases have been flushed before flushing new logs.
const subcasePrefix = 'subcase: ' + stringifyPublicParams(subParams);
const subRec = new Proxy(rec, {
get: (target, k: keyof TestCaseRecorder) => {
const prop = rec[k] ?? TestCaseRecorder.prototype[k];
if (typeof prop === 'function') {
testHeartbeatCallback();
return function (...args: Parameters<typeof prop>) {
void allPreviousSubcasesFinalizedPromise.then(() => {
// Prepend the subcase name to all error messages.
for (const arg of args) {
if (arg instanceof Error) {
try {
arg.message = subcasePrefix + '\n' + arg.message;
} catch {
// If that fails (e.g. on DOMException), try to put it in the stack:
let stack = subcasePrefix;
if (arg.stack) stack += '\n' + arg.stack;
try {
arg.stack = stack;
} catch {
// If that fails too, just silence it.
}
}
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const rv = (prop as any).apply(target, args);
// Because this proxy executes functions in a deferred manner,
// it should never be used for functions that need to return a value.
assert(rv === undefined);
});
};
}
return prop;
},
});
// Defer subcase logs so that they appear in the correct order.
const subRec = rec.makeDeferredSubRecorder(
`(in subcase: ${stringifyPublicParams(subParams)}) `,
allPreviousSubcasesFinalizedPromise
);
const params = mergeParams(this.params, subParams);
const subcaseQuery = new TestQuerySingleCase(
@ -684,16 +649,16 @@ class RunCaseSpecific implements RunCase {
getExpectedStatus(subcaseQuery)
)
.then(() => {
subRec.info(new Error('OK'));
subRec.info(new Error('subcase ran'));
})
.catch(ex => {
if (ex instanceof SkipTestCase) {
// Convert SkipTestCase to info messages
// Convert SkipTestCase to an info message so it won't skip the whole test
ex.message = 'subcase skipped: ' + ex.message;
subRec.info(ex);
subRec.info(new Error('subcase skipped'));
++skipCount;
} else {
// Since we are catching all error inside runTest(), this should never happen
// We are catching all other errors inside runTest(), so this should never happen
subRec.threw(ex);
}
})

View file

@ -5,19 +5,28 @@ import { UnitTest } from '../unittests/unit_test.js';
export const g = makeTestGroup(UnitTest);
g.test('pass_warn_fail')
g.test('skip')
.paramsSubcasesOnly(u => u.combine('y', [1, 2]))
.fn(t => {
t.skip('I skip!');
});
g.test('pass_warn_fail_skip')
.params(u =>
u
.combine('x', [1, 2, 3]) //
.combine('x', [0, 1, 2, 3]) //
.beginSubcases()
.combine('y', [1, 2, 3])
)
.fn(t => {
const { x, y } = t.params;
if (x + y > 5) {
t.fail();
} else if (x + y > 4) {
t.warn();
if (x + y >= 5) {
t.fail('I fail!');
} else if (x + y >= 4) {
t.warn('I warn!');
}
if (x + y === 1 || x + y === 6) {
t.skip('I skip!');
}
});

220
src/resources/cache/hashes.json generated vendored
View file

@ -1,112 +1,112 @@
{
"webgpu/shader/execution/binary/af_addition.bin": "69d8c730",
"webgpu/shader/execution/binary/af_logical.bin": "df722626",
"webgpu/shader/execution/binary/af_division.bin": "bb8cc68",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "3d8e4a93",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "47cc1496",
"webgpu/shader/execution/binary/af_multiplication.bin": "f16b33d5",
"webgpu/shader/execution/binary/af_remainder.bin": "9471ee16",
"webgpu/shader/execution/binary/af_subtraction.bin": "f959d87d",
"webgpu/shader/execution/binary/f16_addition.bin": "166f1be0",
"webgpu/shader/execution/binary/f16_logical.bin": "dc857762",
"webgpu/shader/execution/binary/f16_division.bin": "13ae9b61",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "6c0426af",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "a6a68d2",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "5ef8fbb2",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "eb94a142",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "407650ba",
"webgpu/shader/execution/binary/f16_multiplication.bin": "6535a6ea",
"webgpu/shader/execution/binary/f16_remainder.bin": "a6e7ef56",
"webgpu/shader/execution/binary/f16_subtraction.bin": "83e390b3",
"webgpu/shader/execution/binary/f32_addition.bin": "6cd6cb88",
"webgpu/shader/execution/binary/f32_logical.bin": "22f76cb8",
"webgpu/shader/execution/binary/f32_division.bin": "47c954a4",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "8fa5dac4",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "73db2123",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "e96f5ffb",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "68c8dfb3",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "a714b183",
"webgpu/shader/execution/binary/f32_multiplication.bin": "fcd276a5",
"webgpu/shader/execution/binary/f32_remainder.bin": "5243579c",
"webgpu/shader/execution/binary/f32_subtraction.bin": "abc20140",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "ca8fce81",
"webgpu/shader/execution/binary/i32_comparison.bin": "adafa117",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "46f25ff3",
"webgpu/shader/execution/binary/u32_comparison.bin": "50f01cc2",
"webgpu/shader/execution/abs.bin": "8db6f40c",
"webgpu/shader/execution/acos.bin": "fa9e73e5",
"webgpu/shader/execution/acosh.bin": "2b62e68e",
"webgpu/shader/execution/asin.bin": "a3cc9c0e",
"webgpu/shader/execution/asinh.bin": "b546f2bb",
"webgpu/shader/execution/atan.bin": "dc6818f3",
"webgpu/shader/execution/atan2.bin": "24dd68fc",
"webgpu/shader/execution/atanh.bin": "61d8addc",
"webgpu/shader/execution/bitcast.bin": "1c066623",
"webgpu/shader/execution/ceil.bin": "185f7dd2",
"webgpu/shader/execution/clamp.bin": "25ee9846",
"webgpu/shader/execution/cos.bin": "22c4213a",
"webgpu/shader/execution/cosh.bin": "cc23e635",
"webgpu/shader/execution/cross.bin": "bf8a2d4e",
"webgpu/shader/execution/degrees.bin": "390f244f",
"webgpu/shader/execution/determinant.bin": "51fafd2e",
"webgpu/shader/execution/distance.bin": "4214e5a4",
"webgpu/shader/execution/dot.bin": "6da5b2fa",
"webgpu/shader/execution/exp.bin": "63eddb66",
"webgpu/shader/execution/exp2.bin": "2c2f604d",
"webgpu/shader/execution/faceForward.bin": "ab8bfad7",
"webgpu/shader/execution/floor.bin": "1fac4b05",
"webgpu/shader/execution/fma.bin": "da16950c",
"webgpu/shader/execution/fract.bin": "9f0572fa",
"webgpu/shader/execution/frexp.bin": "f6f1d740",
"webgpu/shader/execution/inverseSqrt.bin": "9e5a8beb",
"webgpu/shader/execution/ldexp.bin": "72216eb7",
"webgpu/shader/execution/length.bin": "124d0174",
"webgpu/shader/execution/log.bin": "19182b6",
"webgpu/shader/execution/log2.bin": "8b929d95",
"webgpu/shader/execution/max.bin": "c6d6c28c",
"webgpu/shader/execution/min.bin": "b84a715b",
"webgpu/shader/execution/mix.bin": "86fe01be",
"webgpu/shader/execution/modf.bin": "16a8c8b5",
"webgpu/shader/execution/normalize.bin": "ca833050",
"webgpu/shader/execution/pack2x16float.bin": "1d137095",
"webgpu/shader/execution/pow.bin": "e12f4a4f",
"webgpu/shader/execution/quantizeToF16.bin": "1e4003ad",
"webgpu/shader/execution/radians.bin": "e267fd0e",
"webgpu/shader/execution/reflect.bin": "ecc2eed0",
"webgpu/shader/execution/refract.bin": "69a93ec1",
"webgpu/shader/execution/round.bin": "9db6910f",
"webgpu/shader/execution/saturate.bin": "2b3c052c",
"webgpu/shader/execution/sign.bin": "42ee64f8",
"webgpu/shader/execution/sin.bin": "c2ed110b",
"webgpu/shader/execution/sinh.bin": "86c00a07",
"webgpu/shader/execution/smoothstep.bin": "e4da3c5b",
"webgpu/shader/execution/sqrt.bin": "88174318",
"webgpu/shader/execution/step.bin": "c58a6268",
"webgpu/shader/execution/tan.bin": "7f13503b",
"webgpu/shader/execution/tanh.bin": "d5d8eb6d",
"webgpu/shader/execution/transpose.bin": "31e30397",
"webgpu/shader/execution/trunc.bin": "27a2bb9c",
"webgpu/shader/execution/unpack2x16float.bin": "7f1bf4a9",
"webgpu/shader/execution/unpack2x16snorm.bin": "6257a809",
"webgpu/shader/execution/unpack2x16unorm.bin": "ce471e6f",
"webgpu/shader/execution/unpack4x8snorm.bin": "b2ab0540",
"webgpu/shader/execution/unpack4x8unorm.bin": "d771618a",
"webgpu/shader/execution/unary/af_arithmetic.bin": "13a0a14f",
"webgpu/shader/execution/unary/af_assignment.bin": "d33fb282",
"webgpu/shader/execution/unary/bool_conversion.bin": "cf1a3d6a",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "ef04115b",
"webgpu/shader/execution/unary/f16_conversion.bin": "18d541f",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "2b47620c",
"webgpu/shader/execution/unary/f32_conversion.bin": "c451a8ab",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "8907d111",
"webgpu/shader/execution/unary/i32_conversion.bin": "6d4c8066",
"webgpu/shader/execution/unary/u32_conversion.bin": "a113b6b7",
"webgpu/shader/execution/unary/ai_assignment.bin": "bc149f1b",
"webgpu/shader/execution/binary/ai_arithmetic.bin": "f4f9cf7",
"webgpu/shader/execution/unary/ai_arithmetic.bin": "1384ba15",
"webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "b6969739",
"webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "7047d8c1",
"webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "26c7f01c",
"webgpu/shader/execution/derivatives.bin": "f102972a",
"webgpu/shader/execution/fwidth.bin": "448a3813"
"webgpu/shader/execution/binary/af_addition.bin": "4dd765ee",
"webgpu/shader/execution/binary/af_logical.bin": "f05532a6",
"webgpu/shader/execution/binary/af_division.bin": "ad21c1ed",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "fbad9908",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "a1736fe",
"webgpu/shader/execution/binary/af_multiplication.bin": "ede233ce",
"webgpu/shader/execution/binary/af_remainder.bin": "a306bcf5",
"webgpu/shader/execution/binary/af_subtraction.bin": "af70a585",
"webgpu/shader/execution/binary/f16_addition.bin": "994d244e",
"webgpu/shader/execution/binary/f16_logical.bin": "f18456f4",
"webgpu/shader/execution/binary/f16_division.bin": "8d203ceb",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "9cce50c1",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "932b289a",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "15e8a658",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "fa79eec8",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "b22c6790",
"webgpu/shader/execution/binary/f16_multiplication.bin": "7adff421",
"webgpu/shader/execution/binary/f16_remainder.bin": "7e320fd9",
"webgpu/shader/execution/binary/f16_subtraction.bin": "f9db9cf4",
"webgpu/shader/execution/binary/f32_addition.bin": "e5fd0666",
"webgpu/shader/execution/binary/f32_logical.bin": "86621123",
"webgpu/shader/execution/binary/f32_division.bin": "7c5ec6eb",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "59158e5",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "922e560",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "fb500450",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "e261e53f",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "a9f9e18a",
"webgpu/shader/execution/binary/f32_multiplication.bin": "41feefea",
"webgpu/shader/execution/binary/f32_remainder.bin": "b54de7ed",
"webgpu/shader/execution/binary/f32_subtraction.bin": "cff3367b",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "d08b6f60",
"webgpu/shader/execution/binary/i32_comparison.bin": "9f69561a",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "7ee7eb32",
"webgpu/shader/execution/binary/u32_comparison.bin": "8778541",
"webgpu/shader/execution/abs.bin": "94d59c90",
"webgpu/shader/execution/acos.bin": "8ad29a79",
"webgpu/shader/execution/acosh.bin": "b078d453",
"webgpu/shader/execution/asin.bin": "aa6157d2",
"webgpu/shader/execution/asinh.bin": "78daf8ea",
"webgpu/shader/execution/atan.bin": "375dd59c",
"webgpu/shader/execution/atan2.bin": "ff3ee36",
"webgpu/shader/execution/atanh.bin": "c1fcaecc",
"webgpu/shader/execution/bitcast.bin": "21322e2",
"webgpu/shader/execution/ceil.bin": "399d4097",
"webgpu/shader/execution/clamp.bin": "ee8014b4",
"webgpu/shader/execution/cos.bin": "722df76d",
"webgpu/shader/execution/cosh.bin": "eca1051a",
"webgpu/shader/execution/cross.bin": "5db9a9df",
"webgpu/shader/execution/degrees.bin": "c6465b4a",
"webgpu/shader/execution/determinant.bin": "2af5a3e",
"webgpu/shader/execution/distance.bin": "7df35965",
"webgpu/shader/execution/dot.bin": "15f58105",
"webgpu/shader/execution/exp.bin": "9eadb1ae",
"webgpu/shader/execution/exp2.bin": "e00d8b50",
"webgpu/shader/execution/faceForward.bin": "b27fad56",
"webgpu/shader/execution/floor.bin": "46686077",
"webgpu/shader/execution/fma.bin": "f91cdfdf",
"webgpu/shader/execution/fract.bin": "db7d3667",
"webgpu/shader/execution/frexp.bin": "4ea45247",
"webgpu/shader/execution/inverseSqrt.bin": "bcaf282b",
"webgpu/shader/execution/ldexp.bin": "24e4c8d8",
"webgpu/shader/execution/length.bin": "221e04a7",
"webgpu/shader/execution/log.bin": "882da20a",
"webgpu/shader/execution/log2.bin": "9ae28e83",
"webgpu/shader/execution/max.bin": "6d1cad5d",
"webgpu/shader/execution/min.bin": "74aab00f",
"webgpu/shader/execution/mix.bin": "104d6da8",
"webgpu/shader/execution/modf.bin": "9b3eab09",
"webgpu/shader/execution/normalize.bin": "56c1c6",
"webgpu/shader/execution/pack2x16float.bin": "f31e7555",
"webgpu/shader/execution/pow.bin": "a9dbe015",
"webgpu/shader/execution/quantizeToF16.bin": "48a9ef48",
"webgpu/shader/execution/radians.bin": "2f849190",
"webgpu/shader/execution/reflect.bin": "c0c2c4a4",
"webgpu/shader/execution/refract.bin": "ecf918da",
"webgpu/shader/execution/round.bin": "3fa50618",
"webgpu/shader/execution/saturate.bin": "81505ae7",
"webgpu/shader/execution/sign.bin": "8643d988",
"webgpu/shader/execution/sin.bin": "a0bf3549",
"webgpu/shader/execution/sinh.bin": "38b38c74",
"webgpu/shader/execution/smoothstep.bin": "5ec3ef8b",
"webgpu/shader/execution/sqrt.bin": "8f252e99",
"webgpu/shader/execution/step.bin": "c106da0e",
"webgpu/shader/execution/tan.bin": "7c522645",
"webgpu/shader/execution/tanh.bin": "defdcf9d",
"webgpu/shader/execution/transpose.bin": "32456502",
"webgpu/shader/execution/trunc.bin": "632941bf",
"webgpu/shader/execution/unpack2x16float.bin": "9ef5f098",
"webgpu/shader/execution/unpack2x16snorm.bin": "ca94395f",
"webgpu/shader/execution/unpack2x16unorm.bin": "6dfe63f",
"webgpu/shader/execution/unpack4x8snorm.bin": "28d36036",
"webgpu/shader/execution/unpack4x8unorm.bin": "6299217e",
"webgpu/shader/execution/unary/af_arithmetic.bin": "207d9942",
"webgpu/shader/execution/unary/af_assignment.bin": "e48ee5ef",
"webgpu/shader/execution/unary/bool_conversion.bin": "65287f04",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "c4d325cd",
"webgpu/shader/execution/unary/f16_conversion.bin": "798dfcba",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "f5e7070c",
"webgpu/shader/execution/unary/f32_conversion.bin": "90637f97",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "37f67041",
"webgpu/shader/execution/unary/i32_conversion.bin": "25561640",
"webgpu/shader/execution/unary/u32_conversion.bin": "97025648",
"webgpu/shader/execution/unary/ai_assignment.bin": "b30866f8",
"webgpu/shader/execution/binary/ai_arithmetic.bin": "e9c0b7b2",
"webgpu/shader/execution/unary/ai_arithmetic.bin": "c27ca726",
"webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "29b268ff",
"webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "7a7f44c0",
"webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "6d248213",
"webgpu/shader/execution/derivatives.bin": "9c856427",
"webgpu/shader/execution/fwidth.bin": "4be019e8"
}

View file

@ -343,7 +343,7 @@ g.test('subcases,skip')
const expectedStatus = allSkip ? 'skip' : 'pass';
t0.expect(
values[0].status === expectedStatus,
`expect: ${values[0].status} === ${expectedStatus}}, allSkip: ${allSkip}`
`expect: ${values[0].status} === ${expectedStatus}, allSkip: ${allSkip}`
);
});