Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIMOB-9279: BlackBerry: Add --blackberry-device and --blackberry-password to drillbit #78

Merged
merged 2 commits into from
Jun 15, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion drillbit/drillbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def usage():
--android-runtime=RUNTIME The Android runtime to run tests with (default: v8)

BlackBerry Specific Arguments
TODO Mac
--blackberry-device=DEVICE The hostname or the IP address of the target simulator (mandatory)
--blackberry-password=PASSWORD The password for the simulator (if password-protected)
""" % sys.argv[0]
sys.exit(1)

Expand Down
25 changes: 14 additions & 11 deletions drillbit/modules/drillbit/0.1.0/blackberry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ function BlackBerrySimulator(drillbit, blackberryNdk) {
this.blackberryNdk = blackberryNdk;

this.device = 'emulator';
if ('blackberryDevice' in drillbit.argv) {
this.device = drillbit.argv.blackberryDevice;
this.blackberryDevice = drillbit.argv.blackberryDevice;
this.blackberryDeviceCommandArgs = ['--ip_address', this.blackberryDevice];
if ('blackberryPassword' in drillbit.argv) {
this.blackberryPassword = drillbit.argv.blackberryPassword;
this.blackberryDeviceCommandArgs = this.blackberryDeviceCommandArgs.concat(['--device_password', this.blackberryPassword]);
}

this.runtime = 'v8';
Expand All @@ -26,11 +29,10 @@ BlackBerrySimulator.prototype.createDeviceManagementProcess = function(command,
var procArgs =
[
this.blackberryDeviceManagement,
'-t', 'simulator', // FIXME: need the actual type
'-d', this.drillbit.testHarnessDir,
'-p', this.blackberryNdk,
command,
'-p', this.blackberryNdk,
];
procArgs = procArgs.concat(this.blackberryDeviceCommandArgs);

if (args) {
procArgs = procArgs.concat(args);
Expand All @@ -57,7 +59,7 @@ BlackBerrySimulator.prototype.createTestHarnessBuilderProcess = function(command
BlackBerrySimulator.prototype.isTestHarnessRunning = function() {
var retVal = false;
var command = 'isAppRunning';
var process = this.createDeviceManagementProcess(command);
var process = this.createTestHarnessBuilderProcess(command, this.blackberryDeviceCommandArgs);

var self = this;
process.setOnReadLine(function(data) {
Expand Down Expand Up @@ -135,7 +137,8 @@ BlackBerrySimulator.prototype.pushTestJS = function(testScript) {
// TODO Mac: check
var deviceFile = 'app/native/assets/test.js';
var commandArgs = [testJSFile.nativePath(), deviceFile];
var process = this.createDeviceManagementProcess(command, commandArgs);
commandArgs = commandArgs.concat(this.blackberryDeviceCommandArgs);
var process = this.createTestHarnessBuilderProcess(command, commandArgs);

var self = this;
process.setOnReadLine(function(data) {
Expand Down Expand Up @@ -166,7 +169,7 @@ BlackBerrySimulator.prototype.installTestHarness = function(launch, suite) {
BlackBerrySimulator.prototype.launchTestHarness = function(suite) {
// TODO Mac: need to separate install from launch
var command = 'run';
var process = this.createTestHarnessBuilderProcess(command);
var process = this.createTestHarnessBuilderProcess(command, this.blackberryDeviceCommandArgs);

var self = this;
process.setOnReadLine(function(data) {
Expand All @@ -182,15 +185,15 @@ BlackBerrySimulator.prototype.launchTestHarness = function(suite) {
}
self.testHarnessRunning = true;
self.needsBuild = false;
var logProcess = self.createDeviceManagementProcess('appLog');
var logProcess = self.createTestHarnessBuilderProcess('appLog', self.blackberryDeviceCommandArgs);
logProcess.setOnReadLine(self.readLineCb);
logProcess.setOnExit(function(e) {
if (logProcess.getExitCode() !== 0) {
self.drillbit.handleTestError(suite, 'blackberry');
return;
}

var exitCodeProcess = self.createDeviceManagementProcess('printExitCode');
var exitCodeProcess = self.createTestHarnessBuilderProcess('printExitCode', self.blackberryDeviceCommandArgs);
var lastLine = "";
exitCodeProcess.setOnReadLine(function(data) {
var lines = data.split("\n");
Expand All @@ -212,7 +215,7 @@ BlackBerrySimulator.prototype.launchTestHarness = function(suite) {
BlackBerrySimulator.prototype.killTestHarness = function() {
var retVal = false;
var command = 'terminateApp';
var process = this.createDeviceManagementProcess(command);
var process = this.createTestHarnessBuilderProcess(command, this.blackberryDeviceCommandArgs);

var self = this;
process.setOnReadLine(function(data) {
Expand Down
110 changes: 95 additions & 15 deletions support/blackberry/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,38 @@ class Builder(object):
'device' : ('o.le-v7-g', 'arm'),
'deploy' : ('o.le-v7', 'arm')}

def __init__(self, project_dir, type, ndk):
def __init__(self, project_dir, type, ndk, useLogFile = False):
self.top_dir = project_dir.rstrip(os.sep)
self.type = type
(self.variant, self.cpu) = Builder.type2variantCpu[type]
self.ndk = ndk
project_tiappxml = os.path.join(self.top_dir, 'tiapp.xml')
tiappxml = TiAppXML(project_tiappxml)
if useLogFile:
tiappxml = TiAppXML(project_tiappxml)
else:
# hide property output
with open(os.devnull, 'w') as nul:
oldStdout = sys.stdout
sys.stdout = nul
tiappxml = TiAppXML(project_tiappxml)
sys.stdout = oldStdout
self.name = tiappxml.properties['name']
self.buildDir = os.path.join(self.top_dir, 'build', 'blackberry', self.name)


def getPackage(self):
return os.path.join(self.buildDir, self.cpu, self.variant, '%s.bar' % self.name)

def run(self, ipAddress, password = None, debugToken = None):
# TODO Mac: V8 runtime should be added and possibly a lot of other stuff

retCode = self.build()
if retCode != 0:
return retCode
info('Running')

# Change current directory to do relative operations
os.chdir("%s" % self.buildDir)
barPath = os.path.join(self.buildDir, self.cpu, self.variant, '%s.bar' % self.name)
barPath = self.getPackage()
savePath = os.path.join(self.buildDir, self.cpu, self.variant, self.name)
retCode = self.ndk.package(barPath, savePath, self.name, self.type, debugToken)
if retCode != 0:
Expand All @@ -58,6 +69,24 @@ def build(self):
info('Building')
return self.ndk.build(self.buildDir, self.cpu)

def terminateApp(self, ipAddress):
return self.ndk.terminateApp(ipAddress, self.getPackage())

def isAppRunning(self, ipAddress):
return self.ndk.isAppRunning(ipAddress, self.getPackage())

def printExitCode(self, ipAddress):
return self.ndk.printExitCode(ipAddress, self.getPackage())

def getFile(self, ipAddress, hostFile, deviceFile):
return self.ndk.getFile(ipAddress, self.getPackage(), hostFile, deviceFile)

def putFile(self, ipAddress, hostFile, deviceFile):
return self.ndk.putFile(ipAddress, self.getPackage(), hostFile, deviceFile)

def appLog(self, ipAddress):
return self.ndk.appLog(ipAddress, self.getPackage())

def info(msg):
log.info(msg)

Expand All @@ -76,59 +105,110 @@ def error(msg):
if __name__ == "__main__":

# Setup script usage using optparse
parser = OptionParser(usage='<command: build | run> -t TYPE -d PROJECT_PATH [-p NDK_PATH] [-i IP_ADDRESS] [-s DEVICE_PASSWORD]')
parser = OptionParser(usage='<command: build | run | terminateApp | isAppRunning | printExitCode | getFile | putFile | appLog> -t TYPE -d PROJECT_PATH [-p NDK_PATH] [-i IP_ADDRESS] [-s DEVICE_PASSWORD] [--host_file HOST_FILE] [--device_file DEVICE_FILE]')

commonGroup = parser.add_option_group('Common options')
commonGroup.add_option('-t', '--type', choices=['simulator', 'device', 'deploy'], help='simulator | device | deploy', dest='type')
commonGroup.add_option('-d', '--project_path', help='project directory path', dest='project_path')
commonGroup.add_option('-p', '--ndk_path', help='blackberry ndk path', dest='ndk_path')

runGroup = parser.add_option_group('Run/Deploy options')
runGroup.add_option('-i', '--ip_address', help='(simulator | device) ip address', dest='ip_address')
runGroup.add_option('-s', '--device_password', help='(simulator | device) protection password', dest='device_password')

runEtcGroup = parser.add_option_group('run, terminateApp, isAppRunning, printExitCode, getFile, putFile, appLog options')
runEtcGroup.add_option('-i', '--ip_address', help='(simulator | device) ip address', dest='ip_address')
runEtcGroup.add_option('-s', '--device_password', help='(simulator | device) protection password', dest='device_password')

runGroup = parser.add_option_group('Run options')
runGroup.add_option('--debug_token', help='path to debug token file (required for --type device)')

getPutFileGroup = parser.add_option_group('getFile, putFile options')
getPutFileGroup.add_option('--host_file', help='file location on host')
getPutFileGroup.add_option('--device_file', help='file location on device')

(options, args) = parser.parse_args()
if len(args) != 1:
print parser.get_usage()
sys.exit(1)

buildUsage = 'Usage: %s build -t TYPE -d PROJECT_PATH [-p NDK_PATH]' %os.path.basename(sys.argv[0])
runUsage = 'Usage: %s run -t TYPE -d PROJECT_PATH [-p NDK_PATH] -i IP_ADDRESS [-s DEVICE_PASSWORD] [--debug_token DEBUG_TOKEN]' %os.path.basename(sys.argv[0])
terminateAppUsage = 'Usage: %s terminateApp -t TYPE -d PROJECT_PATH [-p NDK_PATH] -i IP_ADDRESS [-s DEVICE_PASSWORD]' %os.path.basename(sys.argv[0])
isAppRunningUsage = 'Usage: %s isAppRunning -t TYPE -d PROJECT_PATH [-p NDK_PATH] -i IP_ADDRESS [-s DEVICE_PASSWORD]' %os.path.basename(sys.argv[0])
printExitCodeUsage = 'Usage: %s printExitCode -t TYPE -d PROJECT_PATH [-p NDK_PATH] -i IP_ADDRESS [-s DEVICE_PASSWORD]' %os.path.basename(sys.argv[0])
getFileUsage = 'Usage: %s getFile -t TYPE -d PROJECT_PATH [-p NDK_PATH] -i IP_ADDRESS [-s DEVICE_PASSWORD] --host_file HOST_FILE --device_file DEVICE_FILE' %os.path.basename(sys.argv[0])
putFileUsage = 'Usage: %s putFile -t TYPE -d PROJECT_PATH [-p NDK_PATH] -i IP_ADDRESS [-s DEVICE_PASSWORD] --host_file HOST_FILE --device_file DEVICE_FILE' %os.path.basename(sys.argv[0])
appLogUsage = 'Usage: %s appLog -t TYPE -d PROJECT_PATH [-p NDK_PATH] -i IP_ADDRESS [-s DEVICE_PASSWORD]' %os.path.basename(sys.argv[0])

type = options.type and options.type.decode('utf-8')
projectPath = options.project_path and options.project_path.decode('utf-8')
ndkPath = options.ndk_path and options.ndk_path.decode('utf-8')
ipAddress = options.ip_address and options.ip_address.decode('utf-8')
devicePassword = options.device_password and options.device_password.decode('utf-8')
debugToken = options.debug_token and options.debug_token.decode('utf-8')
hostFile = options.host_file and options.host_file.decode('utf-8')
deviceFile = options.device_file and options.device_file.decode('utf-8')

useLogFile = False
if args[0] == 'build':
if options.type == None or options.project_path == None:
if type == None or projectPath == None:
parser.error(buildUsage)
sys.exit(1)
useLogFile = True
elif args[0] == 'run':
if options.type == None or options.project_path == None or options.ip_address == None or (type == 'device' and debugToken == None):
if type == None or projectPath == None or ipAddress == None or (type == 'device' and debugToken == None):
if type == 'device' and debugToken == None:
print "--debug_token is required for --type device"
parser.error(runUsage)
sys.exit(1)
useLogFile = True
elif args[0] in ['terminateApp', 'isAppRunning', 'printExitCode', 'appLog']:
if type == None or projectPath == None or ipAddress == None:
if args[0] == 'terminateApp':
parser.error(terminateAppUsage)
elif args[0] == 'isAppRunning':
parser.error(isAppRunningUsage)
elif args[0] == 'printExitCode':
parser.error(printExitCodeUsage)
elif args[0] == 'appLog':
parser.error(appLogUsage)
sys.exit(1)
elif args[0] in ['getFile', 'putFile']:
if type == None or projectPath == None or ipAddress == None or hostFile == None or deviceFile == None:
if args[0] == 'getFile':
parser.error(getFileUsage)
elif args[0] == 'putFile':
parser.error(putFileUsage)
sys.exit(1)
else:
print parser.get_usage()
sys.exit(1)

log = TiLogger(os.path.join(os.path.abspath(os.path.expanduser(projectPath)), 'build_blackberry.log'))
if useLogFile:
log = TiLogger(os.path.join(os.path.abspath(os.path.expanduser(projectPath)), 'build_blackberry.log'))
else:
log = TiLogger(None, level = TiLogger.INFO)
log.debug(" ".join(sys.argv))
try:
bbndk = BlackberryNDK(ndkPath, log = log)
except Exception, e:
print >>sys.stderr, e
sys.exit(1)

builder = Builder(projectPath, type, bbndk)
builder = Builder(projectPath, type, bbndk, useLogFile = useLogFile)

retCode = 1
if (args[0] == 'build'):
retCode = builder.build()
elif (args[0] == 'run'):
retCode = builder.run(ipAddress, devicePassword, debugToken)
elif (args[0] == 'terminateApp'):
retCode = builder.terminateApp(ipAddress)
elif (args[0] == 'isAppRunning'):
retCode = builder.isAppRunning(ipAddress)
elif (args[0] == 'printExitCode'):
retCode = builder.printExitCode(ipAddress)
elif (args[0] == 'getFile'):
retCode = builder.getFile(ipAddress, hostFile, deviceFile)
elif (args[0] == 'putFile'):
retCode = builder.putFile(ipAddress, hostFile, deviceFile)
elif (args[0] == 'appLog'):
retCode = builder.appLog(ipAddress)
sys.exit(retCode)