Skip to content

Commit 810ba80

Browse files
authored
Support multiple backends (#37)
1 parent 98e99bd commit 810ba80

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ out/
44
.vscode/
55
env.json
66
package-lock.json
7-
config.json
7+
config*.json

generate-config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ program
301301
.default(["cpu", "gpu", "npu"])
302302
)
303303
.addOption(new Option("-e, --backend <backend>", "The backend to use").choices(["ort", "tflite"]).default("ort"))
304-
.action(async ({ devices, browser, backend }) => {
304+
.option("-o, --output <path>", "The output config file path", "config.json")
305+
.action(async ({ devices, browser, backend, output }) => {
305306
if (process.platform === "linux" && browser === "edge_canary") {
306307
console.error("edge_canary is not available on linux.");
307308
return;
@@ -313,7 +314,7 @@ program
313314
devices.splice(devices.indexOf("npu"), 1);
314315
}
315316

316-
const config = { browser, ...filterSamplesWithDevices(ORIGINAL_CONFIG, devices) };
317+
const config = { backend, browser, ...filterSamplesWithDevices(ORIGINAL_CONFIG, devices) };
317318
if (backend === "ort") {
318319
config.browserArgs.push("--enable-features=WebMachineLearningNeuralNetwork,WebNNOnnxRuntime");
319320
} else if (backend === "tflite") {
@@ -323,7 +324,7 @@ program
323324
);
324325
}
325326

326-
fs.writeFileSync("config.json", JSON.stringify(config, null, 2));
327-
console.log(`Generated config.json for ${browser} with ${backend} backend on ${devices.join("-")}`);
327+
fs.writeFileSync(output, JSON.stringify(config, null, 2));
328+
console.log(`Generated ${output} for ${browser} with ${backend} backend on ${devices.join("-")}`);
328329
})
329330
.parse();

src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ program
4444
program.action(async ({ config: configPath, filters, browserDir, userDataDir }) => {
4545
try {
4646
const config = require(path.resolve(process.cwd(), configPath));
47+
console.log(`Using config file: ${configPath}`);
4748

4849
if (filters === true) {
4950
console.log("Available filters:");

src/utils/report.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ async function report(results) {
132132
}
133133
const hostname = env.hostname || os.hostname();
134134
const reportTime = util.getTimestamp(true);
135-
let subject = `[Sample Test][${results.deviceInfo.browser}] ${hostname} ${reportTime}`;
135+
let subject = `[Sample Test][${results.deviceInfo.browser}][${results.deviceInfo.backend}] ${hostname} ${reportTime}`;
136136

137137
try {
138138
await sendMail(subject, await renderResultsAsHTML(results), [

src/utils/util.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,15 @@ async function getNPUInfo() {
334334

335335
// get device info
336336
async function getDeviceInfo(config) {
337-
let deviceInfo = {};
338-
deviceInfo["hostname"] = config["hostname"] ? config["hostname"] : os.hostname();
339-
deviceInfo.platform = os.platform();
340-
deviceInfo["samplesUrl"] = config["samplesBasicUrl"];
341-
deviceInfo["developerPreviewUrl"] = config["developerPreviewBasicUrl"];
342-
deviceInfo["browser"] = config["browser"];
343-
deviceInfo["browserArgs"] = config["browserArgs"];
337+
let deviceInfo = {
338+
hostname: config.hostname || os.hostname(),
339+
platform: os.platform(),
340+
samplesUrl: config.samplesBasicUrl,
341+
developerPreviewUrl: config.developerPreviewBasicUrl,
342+
backend: config.backend,
343+
browser: config.browser,
344+
browserArgs: config.browserArgs
345+
};
344346
const { browserPath, userDataDir } = getBrowserPath(config);
345347
deviceInfo["browserPath"] = browserPath;
346348

0 commit comments

Comments
 (0)