278
281
def register_arguments(cls, parser):
279
282
super(run, cls).register_arguments(parser)
283
parser.add_argument('-O', '--run-option',
284
help=("Specified in the job file for using in "
285
"the real test action, so that we can customize"
286
" some test when need"))
280
287
group = parser.add_argument_group("specify the bundle output file")
281
288
group.add_argument("-o", "--output",
299
306
% self.args.test_id)
309
result_id = test.run(quiet=self.args.quiet,
310
run_options=self.args.run_option)
312
output_dir = os.path.dirname(self.args.output)
313
if not os.path.exists(output_dir):
314
os.makedirs(output_dir)
315
bundle = generate_bundle(self.args.serial, result_id)
316
with open(self.args.output, "wt") as stream:
317
DocumentIO.dump(stream, bundle)
319
except Exception as strerror:
320
raise LavaCommandError("Test execution error: %s" % strerror)
322
self.say_end(tip_msg)
325
class run_custom(AndroidCommand):
327
Run the command(s) that specified by the -c option in the command line
328
program:: lava-android-test run-custom -c 'command1' -c 'command2'
330
program:: lava-android-test run test-id -s device_serial
331
program:: lava-android-test run test-id -s device_serial -o outputfile
335
def register_arguments(cls, parser):
336
super(run_custom, cls).register_arguments(parser)
337
parser.add_argument('-c', '--android-command', action='append',
338
help=("Specified in the job file for using"
339
" in the real test action, so that "
340
"we can customize some test when need"))
341
parser.add_argument('-p', '--parse-regex',
342
help=("Specified the regular expression used"
343
" for analyzing command output"))
344
group = parser.add_argument_group("specify the bundle output file")
345
group.add_argument("-o", "--output",
348
help=("After running the test parse the result"
349
" artefacts, fuse them with the initial"
350
" bundle and finally save the complete bundle"
351
" to the specified FILE."))
354
self.adb = ADB(self.args.serial)
357
if self.args.android_command:
358
ADB_SHELL_STEPS = self.args.android_command
360
if self.args.parse_regex:
361
PATTERN = self.args.parse_regex
365
tip_msg = "Run following custom test(s) on device(%s):\n\t\t%s" % (
366
self.args.serial, '\n\t\t'.join(ADB_SHELL_STEPS))
368
tip_msg = "Run following custom test(s):\n\t\t%s" % (
369
'\n\t\t'.join(ADB_SHELL_STEPS))
370
self.say_begin(tip_msg)
372
inst = AndroidTestInstaller()
373
run = AndroidTestRunner(adbshell_steps=ADB_SHELL_STEPS)
374
parser = AndroidTestParser(pattern=PATTERN)
375
test = AndroidTest(testname=test_name, installer=inst,
376
runner=run, parser=parser)
377
test.parser.results = {'test_results': []}
378
test.setadb(self.adb)
380
if not self.test_installed(test.testname):
302
384
result_id = test.run(quiet=self.args.quiet)
303
385
if self.args.output:
304
386
output_dir = os.path.dirname(self.args.output)
305
387
if not os.path.exists(output_dir):
306
388
os.makedirs(output_dir)
307
bundle = generate_bundle(self.args.serial, result_id)
389
bundle = generate_bundle(self.args.serial,
390
result_id, test=test)
308
391
with open(self.args.output, "wt") as stream:
309
392
DocumentIO.dump(stream, bundle)
311
394
except Exception as strerror:
312
395
raise LavaCommandError("Test execution error: %s" % strerror)
314
396
self.say_end(tip_msg)
331
def generate_combined_bundle(serial=None, result_ids=None):
413
class parse_custom(AndroidResultsCommand):
415
Parse the results of previous test that run with run-custom command
416
on the specified device
417
program:: lava-android-test parse-custom test-result-id -P
420
def register_arguments(cls, parser):
421
super(parse_custom, cls).register_arguments(parser)
422
parser.add_argument('-p', '--parse-regex',
423
help=("Specified the regular expression used"
424
" for analyzing command output"))
428
if self.args.parse_regex:
429
PATTERN = self.args.parse_regex
431
inst = AndroidTestInstaller()
432
run = AndroidTestRunner()
433
parser = AndroidTestParser(pattern=PATTERN)
434
test = AndroidTest(testname=test_name, installer=inst,
435
runner=run, parser=parser)
436
test.parser.results = {'test_results': []}
437
test.setadb(ADB(self.args.serial))
439
bundle = generate_combined_bundle(self.args.serial,
440
self.args.result_id, test=test)
442
print DocumentIO.dumps(bundle)
447
def generate_combined_bundle(serial=None, result_ids=None, test=None):
332
448
if result_ids is None:
337
453
for rid in result_ids:
338
b = generate_bundle(serial, rid)
454
b = generate_bundle(serial, rid, test=None)
339
455
if rid == result_ids[0]:
356
472
bundle_text = adb.read_file(os.path.join(resultdir, "testdata.json"))
357
473
bundle = DocumentIO.loads(bundle_text)[1]
358
test = testloader(bundle['test_runs'][0]['test_id'], serial)
475
if bundle['test_runs'][0]['test_id'] == 'custom':
478
test_tmp = testloader(bundle['test_runs'][0]['test_id'], serial)
360
test.parse(result_id)
480
test_tmp.parse(result_id)
361
481
stdout_text = adb.read_file(os.path.join(resultdir,
362
482
os.path.basename(test.org_ouput_file)))
363
483
if stdout_text is None: