Skip to content

Commit aed409a

Browse files
authored
Merge pull request #11 from camillobruni/2024-11-26_github_actions
Implement end2end tests
2 parents 9f15b81 + 50af620 commit aed409a

File tree

15 files changed

+4876
-31
lines changed

15 files changed

+4876
-31
lines changed

.github/workflows/test.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
name: Build
15+
runs-on: macos-latest
16+
strategy:
17+
matrix:
18+
browser: [chrome, firefox, safari]
19+
steps:
20+
- name: Install Firefox
21+
if: ${{ matrix.browser == 'firefox' }}
22+
run: brew install --cask firefox
23+
- name: Checkout Branch
24+
uses: actions/checkout@v3
25+
- name: Setup Node
26+
uses: actions/setup-node@v3
27+
with:
28+
node-version: 18.13.0
29+
- name: Install
30+
run: npm install
31+
- name: Run tests
32+
run: |
33+
echo "Running in $BROWSER"
34+
npm run test:${{ matrix.browser }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.directory
3+
/node_modules
34

45
# Ignore auto-generated files by VS & VSCode.
56
/.vs/

JetStreamDriver.js

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,47 @@
2727

2828
const measureTotalTimeAsSubtest = false; // Once we move to preloading all resources, it would be good to turn this on.
2929

30+
const defaultIterationCount = 120;
31+
const defaultWorstCaseCount = 4;
32+
3033
globalThis.performance ??= Date;
3134
globalThis.RAMification ??= false;
3235
globalThis.testIterationCount ??= undefined;
3336
globalThis.testIterationCountMap ??= new Map();
37+
globalThis.testWorstCaseCount ??= undefined;
3438
globalThis.testWorstCaseCountMap ??= new Map();
3539
globalThis.dumpJSONResults ??= false;
3640
globalThis.customTestList ??= [];
41+
globalThis.startDelay ??= undefined;
3742

3843
let shouldReport = false;
39-
let startDelay;
44+
45+
function getIntParam(urlParams, key) {
46+
if (!urlParams.has(key))
47+
return undefined
48+
const rawValue = urlParams.get(key);
49+
const value = parseInt(rawValue);
50+
if (value <= 0)
51+
throw new Error(`Expected positive value for ${key}, but got ${rawValue}`)
52+
return value
53+
}
54+
4055
if (typeof(URLSearchParams) !== "undefined") {
4156
const urlParameters = new URLSearchParams(window.location.search);
4257
shouldReport = urlParameters.has('report') && urlParameters.get('report').toLowerCase() == 'true';
43-
if (shouldReport)
44-
startDelay = 4000;
45-
if (urlParameters.has('startDelay'))
46-
startDelay = urlParameters.get('startDelay');
58+
globalThis.startDelay = getIntParam(urlParameters, "startDelay");
59+
if (shouldReport && !globalThis.startDelay)
60+
globalThis.startDelay = 4000;
4761
if (urlParameters.has('test'))
4862
customTestList = urlParameters.getAll("test");
49-
63+
globalThis.testIterationCount = getIntParam(urlParameters, "iterationCount");
64+
globalThis.testWorstCaseCount = getIntParam(urlParameters, "worstCaseCount");
5065
}
5166

5267
// Used for the promise representing the current benchmark run.
5368
this.currentResolve = null;
5469
this.currentReject = null;
5570

56-
const defaultIterationCount = 120;
57-
const defaultWorstCaseCount = 4;
58-
5971
let showScoreDetails = false;
6072
let categoryScores = null;
6173

@@ -83,6 +95,8 @@ function getIterationCount(plan) {
8395
function getWorstCaseCount(plan) {
8496
if (testWorstCaseCountMap.has(plan.name))
8597
return testWorstCaseCountMap.get(plan.name);
98+
if (testWorstCaseCount)
99+
return testWorstCaseCount;
86100
if (plan.worstCaseCount)
87101
return plan.worstCaseCount;
88102
return defaultWorstCaseCount;
@@ -224,6 +238,7 @@ const fileLoader = (function() {
224238

225239
class Driver {
226240
constructor() {
241+
this.isReady = false;
227242
this.benchmarks = [];
228243
this.blobDataCache = { };
229244
this.loadCache = { };
@@ -318,6 +333,11 @@ class Driver {
318333

319334
this.reportScoreToRunBenchmarkRunner();
320335
this.dumpJSONResultsIfNeeded();
336+
if (isInBrowser) {
337+
globalThis.dispatchEvent(new CustomEvent("JetStreamDone", {
338+
detail: this.resultsObject()
339+
}));
340+
}
321341
}
322342

323343
runCode(string)
@@ -430,8 +450,12 @@ class Driver {
430450
await this.prefetchResourcesForBrowser();
431451
await this.fetchResources();
432452
this.prepareToRun();
433-
if (isInBrowser && startDelay !== undefined) {
434-
setTimeout(() => this.start(), startDelay);
453+
this.isReady = true;
454+
if (isInBrowser) {
455+
globalThis.dispatchEvent(new Event("JetStreamReady"));
456+
if (shouldReport) {
457+
setTimeout(() => this.start(), globalThis.startDelay);
458+
}
435459
}
436460
}
437461

@@ -483,7 +507,7 @@ class Driver {
483507
}
484508
}
485509

486-
resultsJSON()
510+
resultsObject()
487511
{
488512
let results = {};
489513
for (const benchmark of this.benchmarks) {
@@ -502,8 +526,13 @@ class Driver {
502526
}
503527

504528
results = {"JetStream3.0": {"metrics" : {"Score" : ["Geometric"]}, "tests" : results}};
529+
return results;
530+
531+
}
505532

506-
return JSON.stringify(results);
533+
resultsJSON()
534+
{
535+
return JSON.stringify(this.resultsObject());
507536
}
508537

509538
dumpJSONResultsIfNeeded()
@@ -577,7 +606,7 @@ class Benchmark {
577606
results.push(Math.max(1, end - start));
578607
}
579608
if (__benchmark.validate)
580-
__benchmark.validate();
609+
__benchmark.validate(${this.iterations});
581610
top.currentResolve(results);`;
582611
}
583612

@@ -1052,7 +1081,7 @@ class AsyncBenchmark extends DefaultBenchmark {
10521081
results.push(Math.max(1, end - start));
10531082
}
10541083
if (__benchmark.validate)
1055-
__benchmark.validate();
1084+
__benchmark.validate(${this.iterations});
10561085
top.currentResolve(results);
10571086
}
10581087
doRun().catch((error) => { top.currentReject(error); });`

RexBench/FlightPlanner/benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Benchmark {
3737
}
3838
}
3939

40-
validate()
40+
validate(iterations)
4141
{
4242
for (let flightPlan of expectedFlightPlans) {
4343
flightPlan.calculate();

RexBench/OfflineAssembler/benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Benchmark {
3636
this.ast = parse("LowLevelInterpreter.asm");
3737
}
3838

39-
validate()
39+
validate(iterations)
4040
{
4141
let astDumpedAsLines = this.ast.dump().split("\n");
4242

RexBench/UniPoker/benchmark.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ class Benchmark {
3939
playHands(this._players);
4040
}
4141

42-
validate()
42+
validate(iterations)
4343
{
44+
if (!iterations)
45+
throw "Invalid iterations"
46+
const playerExpectations = getPlayerExpectations(iterations)
4447
if (this._players.length != playerExpectations.length)
4548
throw "Expect " + playerExpectations.length + ", but actually have " + this._players.length;
4649
if (isInBrowser) {

RexBench/UniPoker/expected.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
*/
2525
"use strict";
2626

27+
const defaultIterationCount = 120;
28+
2729
class PlayerExpectation
2830
{
29-
constructor(wins, handTypeCounts)
31+
constructor(iterations, wins, handTypeCounts)
3032
{
31-
this._wins = wins;
32-
this._handTypeCounts = handTypeCounts;
33+
const factor = iterations / defaultIterationCount;
34+
this._wins = wins * factor;
35+
this._handTypeCounts = handTypeCounts.map(each => each * factor);
3336
}
3437

3538
validate(player)
@@ -62,10 +65,13 @@ PlayerExpectation._handTypes = [
6265
"Straight Flushes",
6366
"Royal Flushes"
6467
];
65-
66-
var playerExpectations = [];
6768

68-
playerExpectations.push(new PlayerExpectation(60120, [120600, 102000, 10080, 5040, 1440, 360, 480, 0, 0, 0]));
69-
playerExpectations.push(new PlayerExpectation(60480, [120360, 99600, 11760, 6120, 1200, 360, 480, 120, 0, 0]));
70-
playerExpectations.push(new PlayerExpectation(61440, [121200, 99720, 11040, 6120, 1080, 480, 360, 0, 0, 0]));
71-
playerExpectations.push(new PlayerExpectation(57960, [121320, 100440, 11040, 5760, 840, 480, 120, 0, 0, 0]));
69+
70+
function getPlayerExpectations(iterations) {
71+
const playerExpectations = [];
72+
playerExpectations.push(new PlayerExpectation(iterations, 60120, [120600, 102000, 10080, 5040, 1440, 360, 480, 0, 0, 0]));
73+
playerExpectations.push(new PlayerExpectation(iterations, 60480, [120360, 99600, 11760, 6120, 1200, 360, 480, 120, 0, 0]));
74+
playerExpectations.push(new PlayerExpectation(iterations, 61440, [121200, 99720, 11040, 6120, 1080, 480, 360, 0, 0, 0]));
75+
playerExpectations.push(new PlayerExpectation(iterations, 57960, [121320, 100440, 11040, 5760, 840, 480, 120, 0, 0, 0]));
76+
return playerExpectations;
77+
}

bigint/bigdenary-benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Benchmark {
5353
areFirstAndLastResultsEqual(() => bd1.dividedBy(bd2));
5454
}
5555

56-
validate() {
56+
validate(iterations) {
5757
if (!this._allFirstAndLastResultsAreEqual)
5858
throw new Error("Expected all first and last results to be equal, but they aren't.");
5959
}

bigint/paillier-benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Benchmark {
5252
this._decryptedMulIsCorrect &&= decryptedMul === 123456789012345678900n;
5353
}
5454

55-
validate() {
55+
validate(iterations) {
5656
if (!this._c1DecryptedIsCorrect)
5757
throw new Error("Bad value: c1Decrypted!");
5858

generators/js-tokens.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ class Benchmark {
451451
}
452452
}
453453

454-
validate() {
454+
validate(iterations) {
455455
if (this.tokenCount !== 113975)
456456
throw new Error(`this.tokenCount of ${this.tokenCount} is invalid!`);
457457
}

0 commit comments

Comments
 (0)