1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-06 03:50:04 +02:00
OpenSTF/lib/roles/device/plugins/stats.js
2014-03-19 20:36:46 +09:00

61 lines
1.8 KiB
JavaScript

var syrup = require('syrup')
var split = require('split')
var logger = require('../../../util/logger')
var devutil = require('../../../util/devutil')
module.exports = syrup.serial()
.dependency(require('../support/adb'))
.dependency(require('../support/quit'))
.dependency(require('../resources/remote'))
.define(function(options, adb, quit, remote) {
var log = logger.createLogger('device:plugins:stats')
var service = {
port: 2830
}
function openService() {
return devutil.ensureUnusedPort(adb, options.serial, service.port)
.then(function() {
return adb.shell(options.serial, [
remote.bin
, '--lib', remote.lib
, '--listen-stats', service.port
])
.then(function(out) {
out.pipe(split())
.on('data', function(chunk) {
log.info('Remote says: "%s"', chunk)
})
.on('error', function(err) {
log.fatal('Remote shell had an error', err.stack)
quit.fatal()
})
.on('end', function() {
log.fatal('Remote shell ended')
quit.fatal()
})
})
})
.then(function() {
return devutil.waitForPort(adb, options.serial, service.port)
})
.then(function(conn) {
conn.pipe(split())
.on('error', function(err) {
log.fatal('Remote had an error', err.stack)
quit.fatal()
})
.on('end', function() {
log.fatal('Remote ended')
quit.fatal()
})
})
}
return openService()
.then(function() {
return {}
})
})