mirror of
https://github.com/openstf/stf
synced 2025-10-04 10:19:30 +02:00
Keep better track of vital streams. Add monkey.
This commit is contained in:
parent
6c350d0068
commit
ae4e4d3075
3 changed files with 146 additions and 4 deletions
|
@ -11,6 +11,7 @@ var wireutil = require('../util/wireutil')(wire)
|
||||||
var devutil = require('../util/devutil')
|
var devutil = require('../util/devutil')
|
||||||
var pathutil = require('../util/pathutil')
|
var pathutil = require('../util/pathutil')
|
||||||
var promiseutil = require('../util/promiseutil')
|
var promiseutil = require('../util/promiseutil')
|
||||||
|
var Vitals = require('../util/vitals')
|
||||||
var ChannelManager = require('../wire/channelmanager')
|
var ChannelManager = require('../wire/channelmanager')
|
||||||
|
|
||||||
module.exports = function(options) {
|
module.exports = function(options) {
|
||||||
|
@ -19,6 +20,17 @@ module.exports = function(options) {
|
||||||
var vendor = Object.create(null)
|
var vendor = Object.create(null)
|
||||||
var solo = wireutil.makePrivateChannel()
|
var solo = wireutil.makePrivateChannel()
|
||||||
var channels = new ChannelManager()
|
var channels = new ChannelManager()
|
||||||
|
var vitals = new Vitals()
|
||||||
|
var ports = {
|
||||||
|
http: 2870
|
||||||
|
, input: 2820
|
||||||
|
, stats: 2830
|
||||||
|
, forward: 2810
|
||||||
|
}
|
||||||
|
var services = {
|
||||||
|
input: null
|
||||||
|
, monkey: null
|
||||||
|
}
|
||||||
|
|
||||||
// Show serial number in logs
|
// Show serial number in logs
|
||||||
logger.setGlobalIdentifier(options.serial)
|
logger.setGlobalIdentifier(options.serial)
|
||||||
|
@ -47,6 +59,18 @@ module.exports = function(options) {
|
||||||
push.send([channel, wireutil.makeLeaveGroupMessage(options.serial)])
|
push.send([channel, wireutil.makeLeaveGroupMessage(options.serial)])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Closure of vital functionality
|
||||||
|
vitals.on('end', function(name) {
|
||||||
|
log.fatal(util.format('Vital utility "%s" has ended', name))
|
||||||
|
selfDestruct()
|
||||||
|
})
|
||||||
|
|
||||||
|
// Error in vital utility
|
||||||
|
vitals.on('error', function(name, err) {
|
||||||
|
log.fatal(util.format('Vital utility "%s" had an error', er))
|
||||||
|
selfDestruct()
|
||||||
|
})
|
||||||
|
|
||||||
promiseutil.periodicNotify(adb.waitBootCompleteAsync(options.serial), 1000)
|
promiseutil.periodicNotify(adb.waitBootCompleteAsync(options.serial), 1000)
|
||||||
.progressed(function() {
|
.progressed(function() {
|
||||||
log.info('Waiting for boot to complete')
|
log.info('Waiting for boot to complete')
|
||||||
|
@ -90,21 +114,98 @@ module.exports = function(options) {
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
|
log.info('Launching HTTP API')
|
||||||
return devutil.ensureUnusedPort(adb, options.serial, 2870)
|
return devutil.ensureUnusedPort(adb, options.serial, 2870)
|
||||||
.then(function(port) {
|
.then(function(port) {
|
||||||
|
var log = logger.createLogger('device:remote:http')
|
||||||
return adb.shellAsync(options.serial, [
|
return adb.shellAsync(options.serial, [
|
||||||
vendor.bin.dest
|
vendor.bin.dest
|
||||||
, '--lib', vendor.lib.dest
|
, '--lib', vendor.lib.dest
|
||||||
, '--listen-http', port
|
, '--listen-http', port
|
||||||
])
|
])
|
||||||
.then(function(out) {
|
.then(function(out) {
|
||||||
|
vitals.register('device:remote:http:shell', out)
|
||||||
out.pipe(require('split')())
|
out.pipe(require('split')())
|
||||||
.on('data', function(chunk) {
|
.on('data', function(chunk) {
|
||||||
log.info('remote: "%s"', chunk)
|
log.info(chunk)
|
||||||
})
|
})
|
||||||
.on('end', function() {
|
})
|
||||||
log.fatal('remote: Connection closed')
|
})
|
||||||
selfDestruct()
|
})
|
||||||
|
.then(function() {
|
||||||
|
log.info('Launching monkey service')
|
||||||
|
return devutil.ensureUnusedPort(adb, options.serial, 1080)
|
||||||
|
.then(function(port) {
|
||||||
|
var log = logger.createLogger('device:remote:monkey')
|
||||||
|
return adb.shellAsync(options.serial, [
|
||||||
|
'monkey'
|
||||||
|
, '--port', port
|
||||||
|
])
|
||||||
|
.then(function(out) {
|
||||||
|
vitals.register('device:remote:monkey:shell', out)
|
||||||
|
out.pipe(require('split')())
|
||||||
|
.on('data', function(chunk) {
|
||||||
|
log.info(chunk)
|
||||||
|
})
|
||||||
|
return port
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(function(port) {
|
||||||
|
return devutil.waitForPort(adb, options.serial, port)
|
||||||
|
})
|
||||||
|
.then(function(port) {
|
||||||
|
return adb.openMonkeyAsync(options.serial, port)
|
||||||
|
})
|
||||||
|
.then(function(monkey) {
|
||||||
|
services.monkey =
|
||||||
|
vitals.register('device:remote:monkey:monkey', monkey)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(function() {
|
||||||
|
log.info('Launching input service')
|
||||||
|
return devutil.ensureUnusedPort(adb, options.serial, 2820)
|
||||||
|
.then(function(port) {
|
||||||
|
var log = logger.createLogger('device:remote:input')
|
||||||
|
return adb.shellAsync(options.serial, [
|
||||||
|
vendor.bin.dest
|
||||||
|
, '--lib', vendor.lib.dest
|
||||||
|
, '--listen-input', port
|
||||||
|
])
|
||||||
|
.then(function(out) {
|
||||||
|
vitals.register('device:remote:input:shell', out)
|
||||||
|
out.pipe(require('split')())
|
||||||
|
.on('data', function(chunk) {
|
||||||
|
log.info(chunk)
|
||||||
|
})
|
||||||
|
return port
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(function(port) {
|
||||||
|
return devutil.waitForPort(adb, options.serial, port)
|
||||||
|
})
|
||||||
|
.then(function(port) {
|
||||||
|
return adb.openMonkeyAsync(options.serial, port)
|
||||||
|
})
|
||||||
|
.then(function(monkey) {
|
||||||
|
services.input =
|
||||||
|
vitals.register('device:remote:input:monkey', monkey)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(function() {
|
||||||
|
log.info('Launching stats service')
|
||||||
|
return devutil.ensureUnusedPort(adb, options.serial, 2830)
|
||||||
|
.then(function(port) {
|
||||||
|
var log = logger.createLogger('device:remote:stats')
|
||||||
|
return adb.shellAsync(options.serial, [
|
||||||
|
vendor.bin.dest
|
||||||
|
, '--lib', vendor.lib.dest
|
||||||
|
, '--listen-stats', port
|
||||||
|
])
|
||||||
|
.then(function(out) {
|
||||||
|
vitals.register('device:remote:stats:shell', out)
|
||||||
|
out.pipe(require('split')())
|
||||||
|
.on('data', function(chunk) {
|
||||||
|
log.info(chunk)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -40,6 +40,23 @@ devutil.ensureUnusedPort = function(adb, serial, port) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
devutil.waitForPort = function(adb, serial, port) {
|
||||||
|
function closedError(err) {
|
||||||
|
return err.message === 'closed'
|
||||||
|
}
|
||||||
|
return adb.openTcpAsync(serial, port)
|
||||||
|
.then(function(conn) {
|
||||||
|
conn.end()
|
||||||
|
return port
|
||||||
|
})
|
||||||
|
.catch(closedError, function(err) {
|
||||||
|
return Promise.delay(100)
|
||||||
|
.then(function() {
|
||||||
|
return devutil.waitForPort(adb, serial, port)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
devutil.killProcsByComm = function(adb, serial, comm, bin) {
|
devutil.killProcsByComm = function(adb, serial, comm, bin) {
|
||||||
return adb.shellAsync(serial, ['ps', comm])
|
return adb.shellAsync(serial, ['ps', comm])
|
||||||
.then(function(out) {
|
.then(function(out) {
|
||||||
|
|
24
lib/util/vitals.js
Normal file
24
lib/util/vitals.js
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
var events = require('events')
|
||||||
|
var util = require('util')
|
||||||
|
|
||||||
|
function Vitals() {
|
||||||
|
events.EventEmitter.call(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
util.inherits(Vitals, events.EventEmitter)
|
||||||
|
|
||||||
|
Vitals.prototype.register = function(name, stream) {
|
||||||
|
var that = this
|
||||||
|
|
||||||
|
stream.on('end', function() {
|
||||||
|
that.emit('end', name)
|
||||||
|
})
|
||||||
|
|
||||||
|
stream.on('error', function(err) {
|
||||||
|
that.emit('error', name, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
return stream
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Vitals
|
Loading…
Add table
Add a link
Reference in a new issue