Skip to content

Commit

Permalink
Merge pull request #64 from dlifshitz-maca/TIMOB-8944_02
Browse files Browse the repository at this point in the history
TIMOB-8944: BlackBerry: BlackBerry: Connect drillbit to BB simulator or device
  • Loading branch information
dlifshitz-maca committed May 31, 2012
2 parents 76de9a7 + 2b5f35e commit 05f5605
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
36 changes: 30 additions & 6 deletions drillbit/modules/drillbit/0.1.0/blackberry.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,15 @@ BlackBerrySimulator.prototype.fillTiAppData = function(data) {
};

BlackBerrySimulator.prototype.run = function(readLineCb) {
var blackberrySimulatorProcess = null;

var emulatorRunning = this.isEmulatorRunning();
if (emulatorRunning || this.device.indexOf('emulator') != 0) {
// TODO Mac
blackberrySimulatorProcess = this.createDeviceManagementProcess('log');
this.testHarnessRunning = this.isTestHarnessRunning();
} else {
// launch the (si|e)mulator async
// TODO Mac
}

blackberrySimulatorProcess.setOnReadLine(readLineCb);
blackberrySimulatorProcess.launch();
this.readLineCb = readLineCb;

if (this.device == 'emulator' && !emulatorRunning) {
// TODO Mac
Expand All @@ -118,6 +113,12 @@ BlackBerrySimulator.prototype.run = function(readLineCb) {
}
};

BlackBerrySimulator.prototype.handleCompleteBlackBerryEvent = function(event)
{
// TODO Mac
ti.api.error("Not implemented: handleCompleteBlackBerryEvent");
};

BlackBerrySimulator.prototype.removeTestJS = function(testScript) {
// TODO Mac
ti.api.error("Not implemented: removeTestJS");
Expand Down Expand Up @@ -181,6 +182,29 @@ BlackBerrySimulator.prototype.launchTestHarness = function(suite) {
}
self.testHarnessRunning = true;
self.needsBuild = false;
var logProcess = self.createDeviceManagementProcess('appLog');
logProcess.setOnReadLine(self.readLineCb);
logProcess.setOnExit(function(e) {
if (logProcess.getExitCode() !== 0) {
self.drillbit.handleTestError(suite, 'blackberry');
return;
}

var exitCodeProcess = self.createDeviceManagementProcess('printExitCode');
var lastLine = "";
exitCodeProcess.setOnReadLine(function(data) {
var lines = data.split("\n");
lastLine = lines[lines.length - 1];
});
exitCodeProcess.setOnExit(function(e) {
if (exitCodeProcess.getExitCode() !== 0 || lastLine !== "0") {
self.drillbit.handleTestError(suite, 'blackberry');
return;
}
});
exitCodeProcess.launch();
});
logProcess.launch();
});
process.launch();
};
Expand Down
21 changes: 21 additions & 0 deletions support/blackberry/blackberryndk.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ def isAppRunning(self, deviceIP, package):
command = [self.deployProgram, '-isAppRunning', '-device', deviceIP, '-package', package]
return self._run(command, echoCommand = False)

def printExitCode(self, deviceIP, package):
command = [self.deployProgram, '-printExitCode', '-device', deviceIP, '-package', package]
return self._run(command, echoCommand = False)

def getFile(self, deviceIP, package, hostFile, deviceFile):
command = [self.deployProgram, '-getFile', deviceFile, hostFile, '-device', deviceIP, '-package', package]
return self._run(command)
Expand All @@ -208,6 +212,23 @@ def putFile(self, deviceIP, package, hostFile, deviceFile):
command = [self.deployProgram, '-putFile', hostFile, deviceFile, '-device', deviceIP, '-package', package]
return self._run(command)

def _isAppRunning(self, deviceIP, package):
command = [self.deployProgram, '-isAppRunning', '-device', deviceIP, '-package', package]
output = subprocess.check_output(command)
return output.find("result::true") != -1

def _printAppLog(self, deviceIP, package):
hostFile = "-"
deviceFile = "logs/log"
command = [self.deployProgram, '-getFile', deviceFile, hostFile, '-device', deviceIP, '-package', package]
return self._run(command)

def appLog(self, deviceIP, package):
import time
while self._isAppRunning(deviceIP, package):
time.sleep(2)
self._printAppLog(deviceIP, package)

def buildTibb(self, tibbPath, buildType):
assert os.path.exists(tibbPath)
oldPath = os.getcwd()
Expand Down
18 changes: 15 additions & 3 deletions support/blackberry/devicemanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ def terminateApp(self):
def isAppRunning(self):
return self.ndk.isAppRunning(self.getDevice(), self.getPackage())

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

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

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

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

if __name__ == "__main__":

# Setup script usage
Expand All @@ -67,12 +73,14 @@ def putFile(self, hostFile, deviceFile):
subparser.add_parser('getDevice')
subparser.add_parser('terminateApp')
subparser.add_parser('isAppRunning')
putFileParser = subparser.add_parser('getFile')
putFileParser.add_argument('hostFile')
putFileParser.add_argument('deviceFile')
subparser.add_parser('printExitCode')
getFileParser = subparser.add_parser('getFile')
getFileParser.add_argument('hostFile')
getFileParser.add_argument('deviceFile')
putFileParser = subparser.add_parser('putFile')
putFileParser.add_argument('hostFile')
putFileParser.add_argument('deviceFile')
subparser.add_parser('appLog')

# Parse input and call apropriate function
args = parser.parse_args()
Expand All @@ -93,10 +101,14 @@ def putFile(self, hostFile, deviceFile):
retCode = deviceManagement.terminateApp()
elif (args.subparser_name == 'isAppRunning'):
retCode = deviceManagement.isAppRunning()
elif (args.subparser_name == 'printExitCode'):
retCode = deviceManagement.printExitCode()
elif (args.subparser_name == 'getFile'):
retCode = deviceManagement.getFile(args.hostFile.decode('utf-8'), args.deviceFile.decode('utf-8'))
elif (args.subparser_name == 'putFile'):
retCode = deviceManagement.putFile(args.hostFile.decode('utf-8'), args.deviceFile.decode('utf-8'))
elif (args.subparser_name == 'appLog'):
retCode = deviceManagement.appLog()
sys.exit(retCode)
except Exception, e:
print >>sys.stderr, e
Expand Down

0 comments on commit 05f5605

Please sign in to comment.