From d8cff92470a7bcd8e2c13f725397d8dce302084b Mon Sep 17 00:00:00 2001 From: Yongqin Liu Date: Wed, 21 Mar 2012 23:01:09 +0800 Subject: add support for lava-android-test run-custom command --- build-scripts/post-build-lava.py | 116 ++++++++++++++++++++++++++++++++------- 1 file changed, 95 insertions(+), 21 deletions(-) (limited to 'build-scripts/post-build-lava.py') diff --git a/build-scripts/post-build-lava.py b/build-scripts/post-build-lava.py index db933c0..97f84e4 100755 --- a/build-scripts/post-build-lava.py +++ b/build-scripts/post-build-lava.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import os import json +import urllib2 import xmlrpclib # Map a TARGET_PRODUCT to LAVA parameters. @@ -17,25 +18,25 @@ PRODUCT_MAP = { "image_path": "%s%s" % ( "target/product/", "panda")}, - "beagleboard" : { + "beagleboard": { "test_target": "beaglexm", "test_stream": "/anonymous/android-daily/", "image_path": "%s%s" % ( "target/product/", "beagleboard")}, - "snowball" : { + "snowball": { "test_target": "snowball_sd", "test_stream": "/anonymous/android-daily/", "image_path": "%s%s" % ( "target/product/", "snowball")}, - "iMX53" : { + "iMX53": { "test_target": "mx53loco", "test_stream": "/anonymous/android-daily/", "image_path": "%s%s" % ( "target/product/", "iMX53")}, - "origen" : { + "origen": { "test_target": "origen", "test_stream": "/anonymous/android-daily/", "image_path": "%s%s" % ( @@ -44,7 +45,6 @@ PRODUCT_MAP = { } - def gen_lava_android_test_actions(tests=[]): actions = [] if len(tests) == 0: @@ -69,9 +69,95 @@ def gen_lava_android_test_actions(tests=[]): return actions +def lava_android_test_custom_actions(commands=[], cmd_file=None, parser=None): + parameters = None + if commands: + parameters = {'commands': commands} + elif cmd_file: + parameters = {'command_file': cmd_file} + + if parameters and parser: + parameters = {'parser': parser} + + action = {"command": "lava_android_test_run_custom", + "parameters": parameters} + return action + + +def gen_test_plan_action(): + test_plan = os.environ.get("LAVA_TEST_PLAN") + if test_plan == None: + test_plan = '0xbench, glmark2, monkey' + test_plans = test_plan.split(',') + for index in range(len(test_plans)): + test_plans[index] = test_plans[index].strip() + if test_plans[index] == "test_android_0xbench": + test_plans[index] = "0xbench" + return gen_lava_android_test_actions(test_plans) + + +def gen_test_actions(): + test_actions = [] + lava_tests_str = os.environ.get("LAVA_TESTS") + if lava_tests_str is not None: + lava_tests_ary = lava_tests_str.split(',') + for lava_test in lava_tests_ary: + lava_test = lava_test.strip().upper() + if lava_test == 'LAVA_TEST_PLAN': + test_actions.extend(gen_test_plan_action()) + elif lava_test.startswith('LT_CS_CMD_'): + commands = [os.environ.get(lava_test)] + parser = os.environ.get('%s_PARSER' % lava_test) + test_actions.append( + lava_android_test_custom_actions(commands=commands, + parser=parser)) + elif lava_test.startswith('LT_CMD_FILE_'): + cmd_file = os.environ.get(lava_test) + parser = os.environ.get('%s_PARSER' % lava_test) + test_actions.append( + lava_android_test_custom_actions(cmd_file=cmd_file, + parser=parser)) + elif lava_test.startswith('LT_CMDS_'): + parser = os.environ.get('%s_PARSER' % lava_test) + test_cmds_names_str = os.environ.get(lava_test) + test_cmds_names_ary = test_cmds_names_str.split(',') + commands = [] + for test_cmd_var_name in test_cmds_names_ary: + test_cmd = os.environ.get(test_cmd_var_name) + if test_cmd: + commands.append(test_cmd) + test_actions.append( + lava_android_test_custom_actions(commands=commands, + parser=parser)) + elif lava_test.startswith('LT_CMDS_FILE_'): + commands = [] + file_url = os.environ.get(lava_test) + try: + fd = urllib2.urlopen(file_url.strip()) + except: + print "File to get command list file(%s) for %s." % ( + file_url, lava_test) + continue + for line in fd.readlines(): + test_cmd = line.strip() + if test_cmd and (test_cmd != ''): + commands.append(test_cmd) + if commands: + parser = os.environ.get('%s_PARSER' % lava_test) + test_actions.append(lava_android_test_custom_actions( + commands=commands, parser=parser)) + else: + continue + else: + #keep compatibility + test_actions.extend(gen_test_plan_action()) + + return test_actions + + def main(): """Script entry point: return some JSON based on calling args. - We should be called from Jenkins and expect the following to + We should be called from Jenkins and expect the following to be defined: $TARGET_PRODUCT $JOB_NAME $BUILD_NUMBER $BUILD_URL""" # Target product name, user defined, e.g. pandaboard @@ -81,29 +167,18 @@ def main(): frontend_job_name = "~" + job_name.replace("_", "/", 1) # Build number, defined by android-build, e.g. 61 build_number = os.environ.get("BUILD_NUMBER") - # Build url, defined by android-build, e.g. + # Build url, defined by android-build, e.g. # https://android-build.linaro.org/jenkins/job/linaro-android_leb-panda/61/ build_url = os.environ.get("BUILD_URL") # download base URL, this may differ from job URL if we don't host downloads in Jenkins any more download_url = "http://snapshots.linaro.org/android/%s/%s/" % (frontend_job_name, build_number) - test_plan = os.environ.get("LAVA_TEST_PLAN") - if test_plan == None: - test_plan = '0xbench, glmark2, monkey' - test_plans = test_plan.split(',') - for index in range(len(test_plans)): - test_plans[index] = test_plans[index].strip() - if test_plans[index] == "test_android_0xbench": - test_plans[index] = "0xbench" - # Board-specific parameters if target_product not in PRODUCT_MAP: # We don't know how to test this job, so skip testing. print "Don't know how to test this board. Skip testing." return - - android_test_actions = gen_lava_android_test_actions(test_plans) actions = [ { "command": "deploy_linaro_android_image", @@ -128,7 +203,7 @@ def main(): }, ] - actions.extend(android_test_actions) + actions.extend(gen_test_actions()) actions.append( { @@ -144,7 +219,7 @@ def main(): "image_type": 'android', "device_type": PRODUCT_MAP[target_product]["test_target"], "timeout": 18000, - "actions":actions + "actions": actions }, indent=4) @@ -180,4 +255,3 @@ def main(): if __name__ == "__main__": main() - -- cgit v1.2.3