Skip to content

Commit 22488a4

Browse files
authored
Add github action for testing (#65)
The full test suite is slow, so we only run wasm tests and 2 gpu tests (1 from tflite and transformers). Enabled for chrome only for now. Fixes #60
1 parent 39b6c19 commit 22488a4

3 files changed

Lines changed: 70 additions & 8 deletions

File tree

.github/workflows/test.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
# TODO enable safari and firefox
19+
browser: [chrome]
20+
steps:
21+
- name: Install Firefox
22+
if: ${{ matrix.browser == 'firefox' }}
23+
run: brew install --cask firefox
24+
25+
- name: Checkout Branch
26+
uses: actions/checkout@v4
27+
28+
- name: Setup Node
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version-file: "package.json"
32+
cache: "npm"
33+
34+
- name: Install Node Packages
35+
run: npm ci
36+
37+
- name: Download Models and Build Benchmarks
38+
run: npm run build
39+
40+
- name: Run Unit Tests
41+
run: |
42+
echo "Running in $BROWSER"
43+
npm run test:${{ matrix.browser }}
44+
45+
- name: Run end2end Tests
46+
run: |
47+
echo "Running in $BROWSER"
48+
npm run test-e2e:${{ matrix.browser }}

resources/default-tests.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const defaultSuites = [
2222
{
2323
name: "Sentence-Similarity-webgpu",
2424
url: "resources/transformers-js/dist/sentence-similarity-gpu.html",
25-
tags: ["default", "sentence-similarity", "webgpu", "transformers-js"],
25+
tags: ["default", "sentence-similarity", "webgpu", "transformers-js", "gpu-test-suite"],
2626
type: "remote",
2727
},
2828
{
@@ -118,7 +118,7 @@ export const defaultSuites = [
118118
{
119119
name: "Image-Classification-LiteRT.js-webgpu",
120120
url: "resources/litert-js/dist/image-classification-gpu.html",
121-
tags: ["default", "image-classification", "webgpu", "litert-js"],
121+
tags: ["default", "image-classification", "webgpu", "litert-js", "gpu-test-suite"],
122122
type: "remote",
123123
},
124124
{

tests/run-end2end.mjs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,23 @@ This script runs end2end tests by invoking the benchmark via the main
99
Speedometer page in /index.html.
1010
`.trim();
1111

12+
const ONE_MINUTE_IN_MS = 60000;
13+
1214
const { driver, PORT, stop } = await testSetup(HELP);
1315

14-
const suites = benchmarkConfigurator.suites;
16+
// Running all of the benchmarks is very slow (especially when the GPU is emulated). To run the
17+
// tests faster we run all of the Wasm benchmarks, and only a few GPU tests to cover most of
18+
// the common code. To run all benchmarks, enable this.
19+
const RUN_FULL_SUITE = false;
20+
let tags = 'wasm,gpu-test-suite';
21+
let suites = benchmarkConfigurator.suites.filter(suite => suite.tags.some((tag) => tag === 'wasm' || tag === 'gpu-test-suite'));
22+
let timeout = 5 * ONE_MINUTE_IN_MS;
23+
24+
if (RUN_FULL_SUITE) {
25+
tags = 'all';
26+
suites = benchmarkConfigurator.suites;
27+
timeout = 20 * ONE_MINUTE_IN_MS;
28+
}
1529

1630
async function testPage(url) {
1731
console.log(`Testing: ${url}`);
@@ -72,7 +86,7 @@ function validateMetric(name, metric) {
7286

7387
async function testIterations() {
7488
const iterationCount = 2;
75-
const metrics = await testPage(`index.html?iterationCount=${iterationCount}`);
89+
const metrics = await testPage(`index.html?iterationCount=${iterationCount}&tags=${tags}`);
7690
suites.forEach((suite) => {
7791
if (suite.enabled) {
7892
const metric = metrics[suite.name];
@@ -87,7 +101,7 @@ async function testIterations() {
87101
}
88102

89103
async function testAll() {
90-
const metrics = await testPage("index.html?iterationCount=1&tags=all");
104+
const metrics = await testPage(`index.html?iterationCount=1&tags=${tags}`);
91105
suites.forEach((suite) => {
92106
assert(suite.name in metrics);
93107
const metric = metrics[suite.name];
@@ -98,10 +112,10 @@ async function testAll() {
98112
}
99113

100114
async function testDeveloperMode() {
101-
const params = ["developerMode", "iterationCount=1", "warmupBeforeSync=2", "waitBeforeSync=2", "shuffleSeed=123", "suites=Perf-Dashboard"];
115+
const params = ["developerMode", "iterationCount=1", "warmupBeforeSync=2", "waitBeforeSync=2", "shuffleSeed=123", "suites=Image-Classification-LiteRT.js-wasm"];
102116
const metrics = await testPage(`index.html?${params.join("&")}`);
103117
suites.forEach((suite) => {
104-
if (suite.name === "Perf-Dashboard") {
118+
if (suite.name === "Image-Classification-LiteRT.js-wasm") {
105119
const metric = metrics[suite.name];
106120
assert(metric.values.length === 1);
107121
} else {
@@ -112,7 +126,7 @@ async function testDeveloperMode() {
112126

113127
async function test() {
114128
try {
115-
await driver.manage().setTimeouts({ script: 60000 });
129+
await driver.manage().setTimeouts({ script: timeout });
116130
await testIterations();
117131
await testAll();
118132
await testDeveloperMode();

0 commit comments

Comments
 (0)