Skip to content

Commit 60c1025

Browse files
authored
Add UTF16 sources test (WebKit#162)
- Add explicit plan.allowUtf16 setting - Add unittest that checks that no js/mjs files or preloads accidentally contain two-byte characters - Fix workloads where with two-byte comments: - Use dash instead of em-dash for segmentation / async-tasks URL comment - Fix copied bigint-noble license header and use simple double quotes - Replace "•" with " dot " in sunspider comments
1 parent 0780cc6 commit 60c1025

File tree

9 files changed

+57
-12
lines changed

9 files changed

+57
-12
lines changed

JetStreamDriver.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ class Benchmark {
711711
this.tags = this.processTags(plan.tags)
712712
this.iterations = getIterationCount(plan);
713713
this.isAsync = !!plan.isAsync;
714+
this.allowUtf16 = !!plan.allowUtf16;
714715
this.scripts = null;
715716
this.preloads = null;
716717
this.results = [];
@@ -1663,6 +1664,7 @@ let BENCHMARKS = [
16631664
babylonBlob: "./ARES-6/Babylon/babylon-blob.js",
16641665
},
16651666
tags: ["Default", "ARES"],
1667+
allowUtf16: true,
16661668
}),
16671669
// CDJS
16681670
new DefaultBenchmark({
@@ -2229,6 +2231,7 @@ let BENCHMARKS = [
22292231
async: true,
22302232
deterministicRandom: true,
22312233
exposeBrowserTest: true,
2234+
allowUtf16: true,
22322235
tags: ["Wasm"],
22332236
}),
22342237
new WasmLegacyBenchmark({
@@ -2250,6 +2253,7 @@ let BENCHMARKS = [
22502253
async: true,
22512254
deterministicRandom: true,
22522255
exposeBrowserTest: true,
2256+
allowUtf16: true,
22532257
tags: ["Wasm"],
22542258
}),
22552259
new WasmEMCCBenchmark({
@@ -2264,6 +2268,7 @@ let BENCHMARKS = [
22642268
iterations: 30,
22652269
worstCaseCount: 3,
22662270
deterministicRandom: true,
2271+
allowUtf16: true,
22672272
tags: ["Default", "Wasm"],
22682273
}),
22692274
// WorkerTests
@@ -2577,6 +2582,7 @@ for (const name of WTB_TESTS) {
25772582
],
25782583
iterations: 5,
25792584
worstCaseCount: 1,
2585+
allowUtf16: true,
25802586
tags: ["Default", "WTB"],
25812587
}));
25822588
}

SunSpider/crypto-aes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ function ShiftRows(s, Nb) { // shift row r of state S left by r bytes [§5.1.
5757
function MixColumns(s, Nb) { // combine bytes of each col of state S [§5.1.3]
5858
for (var c=0; c<4; c++) {
5959
var a = new Array(4); // 'a' is a copy of the current column from 's'
60-
var b = new Array(4); // 'b' is a{02} in GF(2^8)
60+
var b = new Array(4); // 'b' is a dot {02} in GF(2^8)
6161
for (var i=0; i<4; i++) {
6262
a[i] = s[i][c];
6363
b[i] = s[i][c]&0x80 ? s[i][c]<<1 ^ 0x011b : s[i][c]<<1;
6464
}
65-
// a[n] ^ b[n] is a{03} in GF(2^8)
65+
// a[n] ^ b[n] is a dot {03} in GF(2^8)
6666
s[0][c] = b[0] ^ a[1] ^ b[1] ^ a[2] ^ a[3]; // 2*a0 + 3*a1 + a2 + a3
6767
s[1][c] = a[0] ^ b[1] ^ a[2] ^ b[2] ^ a[3]; // a0 * 2*a1 + 3*a2 + a3
6868
s[2][c] = a[0] ^ a[1] ^ b[2] ^ a[3] ^ b[3]; // a0 + a1 + 2*a2 + 3*a3

bigint/noble-bls12-381-bundle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Copyright (c) 2019 Paul Miller (https://paulmillr.com)
44

55
// Permission is hereby granted, free of charge, to any person obtaining a copy
6-
// of this software and associated documentation files (the Software), to deal
6+
// of this software and associated documentation files (the "Software"), to deal
77
// in the Software without restriction, including without limitation the rights
88
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
// copies of the Software, and to permit persons to whom the Software is
@@ -12,7 +12,7 @@
1212
// The above copyright notice and this permission notice shall be included in
1313
// all copies or substantial portions of the Software.
1414

15-
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

bigint/noble-ed25519-bundle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Copyright (c) 2019 Paul Miller (https://paulmillr.com)
44

55
// Permission is hereby granted, free of charge, to any person obtaining a copy
6-
// of this software and associated documentation files (the Software), to deal
6+
// of this software and associated documentation files (the "Software"), to deal
77
// in the Software without restriction, including without limitation the rights
88
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
// copies of the Software, and to permit persons to whom the Software is
@@ -12,7 +12,7 @@
1212
// The above copyright notice and this permission notice shall be included in
1313
// all copies or substantial portions of the Software.
1414

15-
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

bigint/noble-secp256k1-bundle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Copyright (c) 2019 Paul Miller (https://paulmillr.com)
44

55
// Permission is hereby granted, free of charge, to any person obtaining a copy
6-
// of this software and associated documentation files (the Software), to deal
6+
// of this software and associated documentation files (the "Software"), to deal
77
// in the Software without restriction, including without limitation the rights
88
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
// copies of the Software, and to permit persons to whom the Software is
@@ -12,7 +12,7 @@
1212
// The above copyright notice and this permission notice shall be included in
1313
// all copies or substantial portions of the Software.
1414

15-
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

tests/unit-tests.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,45 @@ function assertThrows(message, func) {
114114
}
115115
})();
116116

117+
(function checkUtf16Sources() {
118+
// Test that only explicitly UTF16-enabled benchmarks can have sources
119+
// with non-8-byte characters.
120+
const twoByteCharsRegex = /[^\x00-\xFF]/g;
121+
const jsFileRegex = /\.(js|mjs)$/;
122+
123+
function checkFile(benchmarkName, file, type) {
124+
if (!jsFileRegex.test(file))
125+
return;
126+
const content = read(file);
127+
const match = content.match(twoByteCharsRegex);
128+
if (!match)
129+
return;
130+
const uniqueMatches = Array.from(new Set(match));
131+
const offendingChars = uniqueMatches.map(char => {
132+
const hex = char.charCodeAt(0).toString(16).padStart(4, "0");
133+
return `\n - \\u${hex}: '${char}'`;
134+
}).join("");
135+
throw new Error(
136+
`Benchmark '${benchmarkName}' has two-byte characters in ${type} '${file}':\n` +
137+
` Offending characters: ${offendingChars}`);
138+
}
139+
140+
for (const benchmark of BENCHMARKS) {
141+
if (benchmark.allowUtf16)
142+
continue;
143+
144+
for (const file of benchmark.files) {
145+
checkFile(benchmark.name, file, "file");
146+
}
147+
148+
if (benchmark.plan.preload) {
149+
for (const [name, file] of Object.entries(benchmark.plan.preload)) {
150+
checkFile(benchmark.name, file, `preload.${name}`);
151+
}
152+
}
153+
}
154+
})();
155+
117156
function validateIterationSources(sources) {
118157
for (const source of sources) {
119158
assertTrue(typeof source == "string");

worker/async-task.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ var Statistics = new (function () {
123123
var sumOfSampleVarianceOverSampleSize = stat1.variance / stat1.size + stat2.variance / stat2.size;
124124
var t = Math.abs((stat1.mean - stat2.mean) / Math.sqrt(sumOfSampleVarianceOverSampleSize));
125125

126-
// http://en.wikipedia.org/wiki/WelchSatterthwaite_equation
126+
// http://en.wikipedia.org/wiki/Welch-Satterthwaite_equation
127127
var degreesOfFreedom = sumOfSampleVarianceOverSampleSize * sumOfSampleVarianceOverSampleSize
128128
/ (stat1.variance * stat1.variance / stat1.size / stat1.size / stat1.degreesOfFreedom
129129
+ stat2.variance * stat2.variance / stat2.size / stat2.size / stat2.degreesOfFreedom);

worker/bomb-subtests/crypto-aes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ function ShiftRows(s, Nb) { // shift row r of state S left by r bytes [§5.1.
5757
function MixColumns(s, Nb) { // combine bytes of each col of state S [§5.1.3]
5858
for (var c=0; c<4; c++) {
5959
var a = new Array(4); // 'a' is a copy of the current column from 's'
60-
var b = new Array(4); // 'b' is a{02} in GF(2^8)
60+
var b = new Array(4); // 'b' is a dot {02} in GF(2^8)
6161
for (var i=0; i<4; i++) {
6262
a[i] = s[i][c];
6363
b[i] = s[i][c]&0x80 ? s[i][c]<<1 ^ 0x011b : s[i][c]<<1;
6464
}
65-
// a[n] ^ b[n] is a{03} in GF(2^8)
65+
// a[n] ^ b[n] is a dot {03} in GF(2^8)
6666
s[0][c] = b[0] ^ a[1] ^ b[1] ^ a[2] ^ a[3]; // 2*a0 + 3*a1 + a2 + a3
6767
s[1][c] = a[0] ^ b[1] ^ a[2] ^ b[2] ^ a[3]; // a0 * 2*a1 + 3*a2 + a3
6868
s[2][c] = a[0] ^ a[1] ^ b[2] ^ a[3] ^ b[3]; // a0 + a1 + 2*a2 + 3*a3

worker/segmentation.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)