- Adding AndroidDeviceManager to botManager.js to help in selecting devices, in case running test on Android devices.
- Select BotType using nodeJs terminal command. - ping_pong.js test added. R=andresp@webrtc.org Review URL: https://webrtc-codereview.appspot.com/19159004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7099 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@@ -12,12 +12,16 @@ The host runs in node.js, but the test code is run in an isolated context with
|
|||||||
no access to node.js specifics other than the exposed api via a test variable.
|
no access to node.js specifics other than the exposed api via a test variable.
|
||||||
|
|
||||||
Part of the exposed api (test.spawnBot) allows a test to spawn a bot and
|
Part of the exposed api (test.spawnBot) allows a test to spawn a bot and
|
||||||
access its exposed API. Details are in BotManager.js.
|
access its exposed API. Details are in botmanager.js.
|
||||||
|
|
||||||
== How to run the test ==
|
== How to run the test ==
|
||||||
$ cd trunk/webrtc/tool/rtcbot
|
$ cd trunk/webrtc/tool/rtcbot
|
||||||
$ npm install express browserify ws websocket-stream dnode
|
$ npm install express browserify ws websocket-stream dnode
|
||||||
$ node test.js
|
$ node test.js <bot_type> <test_file_path>
|
||||||
|
|
||||||
|
<bot_type> — the type of the running bot. For example:
|
||||||
|
- chrome: chrome on host machine.
|
||||||
|
- android: android device. Details in "Android" Section.
|
||||||
|
|
||||||
== Example on how to install nodejs ==
|
== Example on how to install nodejs ==
|
||||||
$ cd /work/tools/
|
$ cd /work/tools/
|
||||||
@@ -25,3 +29,11 @@ access its exposed API. Details are in BotManager.js.
|
|||||||
$ export NVM_DIR=/work/tools/nvm; source $NVM_DIR/nvm.sh
|
$ export NVM_DIR=/work/tools/nvm; source $NVM_DIR/nvm.sh
|
||||||
$ nvm install 0.10
|
$ nvm install 0.10
|
||||||
$ nvm use 0.10
|
$ nvm use 0.10
|
||||||
|
|
||||||
|
== Android ==
|
||||||
|
Before running test with Android one MUST forward the device port 8080 to the
|
||||||
|
host machine. That is easy to achieve with chrome port forwarding tools.
|
||||||
|
- Visit chrome://inspect/devices on the host machine.
|
||||||
|
- Configure and enable port forwarding 8080 -> localhost:8080
|
||||||
|
- Leave chrome running in the background on your Android device till
|
||||||
|
the test is done.
|
||||||
@@ -28,10 +28,24 @@ BotManager = function () {
|
|||||||
this.pendingConnections_ = [];
|
this.pendingConnections_ = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BotManager.BotTypes = {
|
||||||
|
CHROME : 'chrome',
|
||||||
|
};
|
||||||
|
|
||||||
BotManager.prototype = {
|
BotManager.prototype = {
|
||||||
spawnNewBot: function (name, callback) {
|
createBot_: function (name, botType, callback) {
|
||||||
|
switch(botType) {
|
||||||
|
case BotManager.BotTypes.CHROME:
|
||||||
|
return new BrowserBot(name, callback);
|
||||||
|
default:
|
||||||
|
console.log('Error: Type ' + botType + ' not supported by rtc-Bot!');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
spawnNewBot: function (name, botType, callback) {
|
||||||
this.startWebSocketServer_();
|
this.startWebSocketServer_();
|
||||||
var bot = new BrowserBot(name, callback);
|
var bot = this.createBot_(name, botType, callback);
|
||||||
this.bots_.push(bot);
|
this.bots_.push(bot);
|
||||||
this.pendingConnections_.push(bot.onBotConnected.bind(bot));
|
this.pendingConnections_.push(bot.onBotConnected.bind(bot));
|
||||||
},
|
},
|
||||||
@@ -115,4 +129,49 @@ BrowserBot.prototype = {
|
|||||||
__proto__: Bot.prototype
|
__proto__: Bot.prototype
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AndroidDeviceManager = function () {
|
||||||
|
this.connectedDevices_ = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
AndroidDeviceManager.prototype = {
|
||||||
|
getNewDevice: function (callback) {
|
||||||
|
this.listDevices_(function (devices) {
|
||||||
|
for (var i = 0; i < devices.length; i++) {
|
||||||
|
if (!this.connectedDevices_[devices[i]]) {
|
||||||
|
this.connectedDevices_[devices[i]] = devices[i];
|
||||||
|
callback(this.connectedDevices_[devices[i]]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (devices.length == 0) {
|
||||||
|
console.log('Error: No connected devices!');
|
||||||
|
} else {
|
||||||
|
console.log('Error: There is no enough connected devices.');
|
||||||
|
}
|
||||||
|
process.exit(1);
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
|
listDevices_: function (callback) {
|
||||||
|
child.exec('adb devices' , function (error, stdout, stderr) {
|
||||||
|
var devices = [];
|
||||||
|
if (error || stderr) {
|
||||||
|
console.log('' + (error || stderr));
|
||||||
|
}
|
||||||
|
if (stdout) {
|
||||||
|
// The first line is "List of devices attached"
|
||||||
|
// and the following lines:
|
||||||
|
// <serial number> <device/emulator>
|
||||||
|
var tempList = ('' + stdout).split("\n").slice(1);
|
||||||
|
for (var i = 0; i < tempList.length; i++) {
|
||||||
|
if (tempList[i] == "") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
devices.push(tempList[i].split("\t")[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callback(devices);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}
|
||||||
module.exports = BotManager;
|
module.exports = BotManager;
|
||||||
|
|||||||
@@ -16,11 +16,12 @@ var fs = require('fs');
|
|||||||
var vm = require('vm');
|
var vm = require('vm');
|
||||||
var BotManager = require('./botmanager.js');
|
var BotManager = require('./botmanager.js');
|
||||||
|
|
||||||
function Test() {
|
function Test(botType) {
|
||||||
// Make the test fail if not completed in 3 seconds.
|
// Make the test fail if not completed in 3 seconds.
|
||||||
this.timeout_ = setTimeout(
|
this.timeout_ = setTimeout(
|
||||||
this.fail.bind(this, "Test timeout!"),
|
this.fail.bind(this, "Test timeout!"),
|
||||||
3000);
|
5000);
|
||||||
|
this.botType_ = botType;
|
||||||
}
|
}
|
||||||
|
|
||||||
Test.prototype = {
|
Test.prototype = {
|
||||||
@@ -71,14 +72,14 @@ Test.prototype = {
|
|||||||
// Lazy initialization of botmanager.
|
// Lazy initialization of botmanager.
|
||||||
if (!this.botManager_)
|
if (!this.botManager_)
|
||||||
this.botManager_ = new BotManager();
|
this.botManager_ = new BotManager();
|
||||||
this.botManager_.spawnNewBot(name, doneCallback);
|
this.botManager_.spawnNewBot(name, this.botType_, doneCallback);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function runTest(testfile) {
|
function runTest(testfile) {
|
||||||
console.log("Running test: " + testfile);
|
console.log("Running test: " + testfile);
|
||||||
var script = vm.createScript(fs.readFileSync(testfile), testfile);
|
var script = vm.createScript(fs.readFileSync(testfile), testfile);
|
||||||
script.runInNewContext({ test: new Test() });
|
script.runInNewContext({ test: new Test(process.argv[2]) });
|
||||||
}
|
}
|
||||||
|
|
||||||
runTest("./test/simple_offer_answer.js");
|
runTest("./test/simple_offer_answer.js");
|
||||||
|
|||||||
19
webrtc/tools/rtcbot/test/ping_pong.js
Normal file
19
webrtc/tools/rtcbot/test/ping_pong.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Use of this source code is governed by a BSD-style license
|
||||||
|
// that can be found in the LICENSE file in the root of the source
|
||||||
|
// tree. An additional intellectual property rights grant can be found
|
||||||
|
// in the file PATENTS. All contributing project authors may
|
||||||
|
// be found in the AUTHORS file in the root of the source tree.
|
||||||
|
//
|
||||||
|
function testPingPong(bot) {
|
||||||
|
test.log('bot:alice > Sending Ping to bot');
|
||||||
|
bot.ping(gotAnswer);
|
||||||
|
|
||||||
|
function gotAnswer(answer) {
|
||||||
|
test.log('bot > ' + answer);
|
||||||
|
test.done();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test.spawnBot("alice", testPingPong);
|
||||||
Reference in New Issue
Block a user