1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 19:42:01 +02:00

Add an alternate install location for binary resources. Fixes devices where /data/local/tmp is mounted as noexec, like ZUK Z1. Closes #436.

This commit is contained in:
Simo Kinnunen 2017-02-10 04:45:14 +09:00
parent dc5ed0193f
commit 884c51b9b4
4 changed files with 145 additions and 38 deletions

View file

@ -1,3 +1,4 @@
var fs = require('fs')
var util = require('util')
var Promise = require('bluebird')
@ -7,6 +8,7 @@ var logger = require('../../../util/logger')
var pathutil = require('../../../util/pathutil')
var devutil = require('../../../util/devutil')
var streamutil = require('../../../util/streamutil')
var Resource = require('./util/resource')
module.exports = syrup.serial()
.dependency(require('../support/adb'))
@ -15,16 +17,19 @@ module.exports = syrup.serial()
var log = logger.createLogger('device:resources:minirev')
var resources = {
bin: {
bin: new Resource({
src: pathutil.vendor(util.format(
'minirev/%s/minirev%s'
, properties['ro.product.cpu.abi']
, properties['ro.build.version.sdk'] < 16 ? '-nopie' : ''
))
, dest: '/data/local/tmp/minirev'
, dest: [
'/data/local/tmp/minirev'
, '/data/data/com.android.shell/minirev'
]
, comm: 'minirev'
, mode: 0755
}
})
}
function removeResource(res) {
@ -36,7 +41,7 @@ module.exports = syrup.serial()
.return(res)
}
function installResource(res) {
function pushResource(res) {
return adb.push(options.serial, res.src, res.dest, res.mode)
.timeout(10000)
.then(function(transfer) {
@ -48,29 +53,38 @@ module.exports = syrup.serial()
.return(res)
}
function ensureNotBusy(res) {
return adb.shell(options.serial, [res.dest, '-h'])
.timeout(10000)
.then(function(out) {
// Can be "Text is busy", "text busy"
return streamutil.findLine(out, (/busy/i))
.timeout(10000)
.then(function() {
log.info('Binary is busy, will retry')
return Promise.delay(1000)
})
.then(function() {
return ensureNotBusy(res)
})
.catch(streamutil.NoSuchLineError, function() {
return res
})
function installResource(res) {
log.info('Installing "%s" as "%s"', res.comm, res.dest)
function checkExecutable(res) {
return adb.stat(options.serial, res.dest)
.timeout(5000)
.then(function(stats) {
return (stats.mode & fs.constants.S_IXUSR) === fs.constants.S_IXUSR
})
}
return removeResource(res)
.then(pushResource)
.then(function(res) {
return checkExecutable(res).then(function(ok) {
if (!ok) {
log.info(
'Pushed "%s" not executable, attempting fallback location'
, res.comm
)
res.shift()
return installResource(res)
}
return res
})
})
.return(res)
}
function installAll() {
return Promise.all([
removeResource(resources.bin).then(installResource).then(ensureNotBusy)
installResource(resources.bin)
])
}