mirror of
https://github.com/openstf/stf
synced 2025-10-04 18:29:17 +02:00
Make absolutely sure that we kill old procs.
This commit is contained in:
parent
a8914297ad
commit
315418d790
1 changed files with 33 additions and 12 deletions
|
@ -57,12 +57,12 @@ devutil.waitForPort = function(adb, serial, port) {
|
|||
})
|
||||
}
|
||||
|
||||
devutil.killProcsByComm = function(adb, serial, comm, bin) {
|
||||
devutil.listPidsByComm = function(adb, serial, comm, bin) {
|
||||
return adb.shellAsync(serial, ['ps', comm])
|
||||
.then(function(out) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var header = false
|
||||
, killables = []
|
||||
, pids = []
|
||||
out.pipe(split())
|
||||
.on('data', function(chunk) {
|
||||
if (header) {
|
||||
|
@ -71,27 +71,48 @@ devutil.killProcsByComm = function(adb, serial, comm, bin) {
|
|||
else {
|
||||
var cols = chunk.toString().split(/\s+/)
|
||||
if (cols.pop() === bin) {
|
||||
killables.push(cols[1])
|
||||
pids.push(+cols[1])
|
||||
}
|
||||
}
|
||||
})
|
||||
.on('end', function() {
|
||||
resolve(killables)
|
||||
resolve(pids)
|
||||
})
|
||||
})
|
||||
})
|
||||
.then(function(killables) {
|
||||
if (killables.length) {
|
||||
return adb.shellAsync(serial, ['kill'].concat(killables))
|
||||
.then(function(out) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
out.on('end', resolve)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
devutil.waitForProcsToDie = function(adb, serial, comm, bin) {
|
||||
return devutil.listPidsByComm(adb, serial, comm, bin)
|
||||
.then(function(pids) {
|
||||
if (pids.length) {
|
||||
return devutil.waitForProcsToDie(adb, serial, comm, bin)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
devutil.killProcsByComm = function(adb, serial, comm, bin, mode) {
|
||||
return devutil.listPidsByComm(adb, serial, comm, bin, mode)
|
||||
.then(function(pids) {
|
||||
if (!pids.length) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
return adb.shellAsync(serial, ['kill', mode || -15].concat(pids))
|
||||
.then(function(out) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
out.on('end', resolve)
|
||||
})
|
||||
})
|
||||
.then(function() {
|
||||
return devutil.waitForProcsToDie(adb, serial, comm, bin)
|
||||
})
|
||||
.timeout(1000)
|
||||
.then(function() {
|
||||
return devutil.killProcsByComm(adb, serial, comm, bin, -9)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
devutil.startProp = function(adb, serial, cmd) {
|
||||
return adb.openTcpAsync(options.serial, port)
|
||||
.then(function(conn) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue