replace tabs with spaces (indent 2)
use real commandline flag to control install vs. run benchmark
This commit is contained in:
Bill Walker 2015-05-18 17:13:24 -07:00
Родитель 99d22326b5
Коммит d321ab9d09
1 изменённых файлов: 91 добавлений и 86 удалений

Просмотреть файл

@ -2,7 +2,7 @@
// prerequisites: // prerequisites:
// set the pref security.turn_off_all_security_so_that_viruses_can_take_over_this_computer // on your phone, set the pref security.turn_off_all_security_so_that_viruses_can_take_over_this_computer
// see https://wiki.mozilla.org/B2G/QA/Tips_And_Tricks#For_changing_the_preference: // see https://wiki.mozilla.org/B2G/QA/Tips_And_Tricks#For_changing_the_preference:
// make clean && BENCHMARK=1 make package // make clean && BENCHMARK=1 make package
@ -25,10 +25,15 @@ var gBenchRunner = {};
gBenchRunner.deviceClient = null; gBenchRunner.deviceClient = null;
gBenchRunner.emulatorWebApp = null; gBenchRunner.emulatorWebApp = null;
gBenchRunner.pathToPackagedApp = args[2]; gBenchRunner.pathToPackagedApp = args[2];
gBenchRunner.install = false;
if (gBenchRunner.pathToPackagedApp == null) { if (gBenchRunner.pathToPackagedApp == null) {
console.log('usage: node benchrunner.js /path/to/packaged/app'); console.log('usage: node benchrunner.js /path/to/packaged/app [install]');
process.exit(1); process.exit(1);
}
if (args[3] && args[3] == 'install') {
gBenchRunner.install = true;
} }
console.log('app package:', gBenchRunner.pathToPackagedApp); console.log('app package:', gBenchRunner.pathToPackagedApp);
@ -42,122 +47,122 @@ gBenchRunner.manifest = JSON.parse(manifestString);
// find the device, uninstall the old packaged app, install the new packaged app // find the device, uninstall the old packaged app, install the new packaged app
function reinstallEmulatorApp(apps) { function reinstallEmulatorApp(apps) {
console.log('Found', apps.length, 'existing apps'); console.log('Found', apps.length, 'existing apps');
return Promise.all(apps.map(function(app) { return Promise.all(apps.map(function(app) {
console.log('Uninstalling', app.manifestURL); console.log('Uninstalling', app.manifestURL);
return uninstallApp({ manifestURL: app.manifestURL, client: gBenchRunner.deviceClient }) return uninstallApp({ manifestURL: app.manifestURL, client: gBenchRunner.deviceClient })
})) }))
.then(function installEmulatorApp() { .then(function installEmulatorApp() {
console.log('Installing'); console.log('Installing');
return installApp({ return installApp({
// 3. install the new version // 3. install the new version
appPath: gBenchRunner.pathToPackagedApp, appPath: gBenchRunner.pathToPackagedApp,
client: gBenchRunner.deviceClient client: gBenchRunner.deviceClient
}) })
}) })
.then(function finishInstallEmulatorApp(appId) { .then(function finishInstallEmulatorApp(appId) {
// 4. find the new version // 4. find the new version
console.log('App installed', appId); console.log('App installed', appId);
// TODO: this is rude from a Promises point of view. // TODO: this is rude from a Promises point of view.
process.exit(0); process.exit(0);
}); });
} }
// find the device, find, launch, and connect to the j2me app, connect to the console, run the benchmark // find the device, find, launch, and connect to the j2me app, connect to the console, run the benchmark
function benchmarkEmulatorApp(apps) { function benchmarkEmulatorApp(apps) {
gBenchRunner.emulatorWebApp = apps[0]; gBenchRunner.emulatorWebApp = apps[0];
console.log('Found', gBenchRunner.emulatorWebApp.name, gBenchRunner.emulatorWebApp.manifestURL); console.log('Found', gBenchRunner.emulatorWebApp.name, gBenchRunner.emulatorWebApp.manifestURL);
return launchApp({ return launchApp({
client: gBenchRunner.deviceClient, client: gBenchRunner.deviceClient,
manifestURL: gBenchRunner.emulatorWebApp.manifestURL manifestURL: gBenchRunner.emulatorWebApp.manifestURL
}) })
.then(function connectToAppConsoleAndRunTest(result) { .then(function connectToAppConsoleAndRunTest(result) {
console.log('Launched app', result); console.log('Launched app', result);
gBenchRunner.deviceClient.getWebapps(function(err, webapps) { gBenchRunner.deviceClient.getWebapps(function(err, webapps) {
console.log('Getting webapp', gBenchRunner.emulatorWebApp.manifestURL); console.log('Getting webapp', gBenchRunner.emulatorWebApp.manifestURL);
if (err) { if (err) {
console.log(err); console.log(err);
} }
webapps.getApp(gBenchRunner.emulatorWebApp.manifestURL, function (err, app) { webapps.getApp(gBenchRunner.emulatorWebApp.manifestURL, function (err, app) {
if (err) { if (err) {
console.log(err); console.log(err);
} }
app.Console.addListener('console-api-call', function(e) { app.Console.addListener('console-api-call', function(e) {
var consoleLine = e.arguments[0]; var consoleLine = e.arguments[0];
if (consoleLine.indexOf('bench: ') >= 0) { if (consoleLine.indexOf('bench: ') >= 0) {
console.log(consoleLine); console.log(consoleLine);
if (consoleLine.indexOf('bench: done') >= 0) { if (consoleLine.indexOf('bench: done') >= 0) {
// TODO: this is rude from a Promises point of view. // TODO: this is rude from a Promises point of view.
process.exit(0); process.exit(0);
} }
} }
}); });
app.Console.startListening(); app.Console.startListening();
console.log('Listening to console'); console.log('Listening to console');
setTimeout(function () { setTimeout(function () {
app.Console.evaluateJS("cd(frames[0])", function(err, resp) { app.Console.evaluateJS("cd(frames[0])", function(err, resp) {
console.log('cd(frames[0])', err, resp); console.log('cd(frames[0])', err, resp);
app.Console.evaluateJS("Benchmark.start()", function(err, resp) { app.Console.evaluateJS("Benchmark.start()", function(err, resp) {
console.log('Started Benchmark', err, resp); console.log('Started Benchmark', err, resp);
}); });
}); });
}, 30000); }, 30000);
}); });
}); });
}); });
} }
// Start process // Start process
Promise.resolve().then(function() { Promise.resolve().then(function() {
findPorts() findPorts()
.then(function connectToDevice(results) { .then(function connectToDevice(results) {
console.log('findPorts', results); console.log('findPorts', results);
return connect(results[0].port); return connect(results[0].port);
}) })
.then(function connected(client) { .then(function connected(client) {
console.log('Connected'); console.log('Connected');
gBenchRunner.deviceClient = client; gBenchRunner.deviceClient = client;
return client; return client;
}) })
.then(function findEmulatorApp(client) { .then(function findEmulatorApp(client) {
// find the old version of this app // find the old version of this app
return findApp({ return findApp({
manifest: gBenchRunner.manifest, manifest: gBenchRunner.manifest,
client: gBenchRunner.deviceClient client: gBenchRunner.deviceClient
}) })
}) })
.then(function doTheThing(apps) { .then(function installOrRunBenchmark(apps) {
if (false) { if (gBenchRunner.install) {
return reinstallEmulatorApp(apps); return reinstallEmulatorApp(apps);
} else { } else {
return benchmarkEmulatorApp(apps); return benchmarkEmulatorApp(apps);
} }
}) })
}) })