From a7c777d5c1d50e22edd0fec18e7b6c4b8e7a80a3 Mon Sep 17 00:00:00 2001 From: adbridge Date: Wed, 31 Oct 2018 17:40:15 +0000 Subject: [PATCH 1/2] Make examples commands return a failure Currently the following commands in examples.py, do_import() do_deploy() do_versionning() do_clone() all return a success status (ie 0) irrespective of any errors originating from their sub-functions. This PR fixes this. Now these commands will return one of: 0 - success 1 - general failure x - failure returned by a subprocess.call function --- tools/test/examples/examples.py | 12 ++++-------- tools/test/examples/examples_lib.py | 23 +++++++++++++++++++---- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/tools/test/examples/examples.py b/tools/test/examples/examples.py index fcc3485baf2..3fbeaa3acc6 100644 --- a/tools/test/examples/examples.py +++ b/tools/test/examples/examples.py @@ -97,20 +97,17 @@ def do_export(args, config, examples): def do_import(_, config, examples): """Do the import step of this process""" - lib.source_repos(config, examples) - return 0 + return lib.source_repos(config, examples) def do_clone(_, config, examples): """Do the clone step of this process""" - lib.clone_repos(config, examples) - return 0 + return lib.clone_repos(config, examples) def do_deploy(_, config, examples): """Do the deploy step of this process""" - lib.deploy_repos(config, examples) - return 0 + return lib.deploy_repos(config, examples) def do_compile(args, config, examples): @@ -125,8 +122,7 @@ def do_compile(args, config, examples): def do_versionning(args, config, examples): """ Test update the mbed-os to the version specified by the tag """ - lib.update_mbedos_version(config, args.tag, examples) - return 0 + return lib.update_mbedos_version(config, args.tag, examples) if __name__ == "__main__": diff --git a/tools/test/examples/examples_lib.py b/tools/test/examples/examples_lib.py index 51cf970223f..18d3e4d8810 100644 --- a/tools/test/examples/examples_lib.py +++ b/tools/test/examples/examples_lib.py @@ -169,7 +169,11 @@ def source_repos(config, examples): print("'%s' example directory already exists. Deleting..." % name) rmtree(name) - subprocess.call(["mbed-cli", "import", repo_info['repo']]) + result = subprocess.call(["mbed-cli", "import", repo_info['repo']]) + if result: + return result + + return 0 def clone_repos(config, examples , retry = 3): """ Clones each of the repos associated with the specific examples name from the @@ -192,6 +196,8 @@ def clone_repos(config, examples , retry = 3): break else: print("ERROR : unable to clone the repo {}".format(name)) + return 1 + return 0 def deploy_repos(config, examples): """ If the example directory exists as provided by the json config file, @@ -207,11 +213,15 @@ def deploy_repos(config, examples): if name in examples: if os.path.exists(name): os.chdir(name) - subprocess.call(["mbed-cli", "deploy"]) + result = subprocess.call(["mbed-cli", "deploy"]) os.chdir("..") + if result: + print("mbed-cli deploy command failed for '%s'" % name) + return result else: print("'%s' example directory doesn't exist. Skipping..." % name) - + return 1 + return 0 def get_num_failures(results, export=False): """ Returns the number of failed compilations from the results summary @@ -405,5 +415,10 @@ def update_mbedos_version(config, tag, examples): update_dir = basename(repo_info['repo']) + "/mbed-os" print("\nChanging dir to %s\n" % update_dir) os.chdir(update_dir) - subprocess.call(["mbed-cli", "update", tag, "--clean"]) + result = subprocess.call(["mbed-cli", "update", tag, "--clean"]) os.chdir("../..") + if result: + return result: + + return 0 + \ No newline at end of file From b28d0811dff5b220518d13006beac398181304c9 Mon Sep 17 00:00:00 2001 From: adbridge Date: Thu, 1 Nov 2018 13:07:16 +0000 Subject: [PATCH 2/2] Fix up subprocess calls subprocess.call() does not by default return a status value. Update the commands to add shell=True which forces a return value. Also convert the commands to a single string rather than a list as this plays more nicely with both linux and windows. Also fix a spurious : --- tools/test/examples/examples_lib.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/test/examples/examples_lib.py b/tools/test/examples/examples_lib.py index 18d3e4d8810..308fb87c754 100644 --- a/tools/test/examples/examples_lib.py +++ b/tools/test/examples/examples_lib.py @@ -168,8 +168,10 @@ def source_repos(config, examples): if os.path.exists(name): print("'%s' example directory already exists. Deleting..." % name) rmtree(name) + + cmd = "mbed-cli import %s" %repo_info['repo'] + result = subprocess.call(cmd, shell=True) - result = subprocess.call(["mbed-cli", "import", repo_info['repo']]) if result: return result @@ -191,8 +193,9 @@ def clone_repos(config, examples , retry = 3): if os.path.exists(name): print("'%s' example directory already exists. Deleting..." % name) rmtree(name) + cmd = "%s clone %s" %(repo_info['type'], repo_info['repo']) for i in range(0, retry): - if subprocess.call([repo_info['type'], "clone", repo_info['repo']]) == 0: + if not subprocess.call(cmd, shell=True): break else: print("ERROR : unable to clone the repo {}".format(name)) @@ -213,7 +216,7 @@ def deploy_repos(config, examples): if name in examples: if os.path.exists(name): os.chdir(name) - result = subprocess.call(["mbed-cli", "deploy"]) + result = subprocess.call("mbed-cli deploy", shell=True) os.chdir("..") if result: print("mbed-cli deploy command failed for '%s'" % name) @@ -415,10 +418,11 @@ def update_mbedos_version(config, tag, examples): update_dir = basename(repo_info['repo']) + "/mbed-os" print("\nChanging dir to %s\n" % update_dir) os.chdir(update_dir) - result = subprocess.call(["mbed-cli", "update", tag, "--clean"]) + cmd = "mbed-cli update %s --clean" %tag + result = subprocess.call(cmd, shell=True) os.chdir("../..") if result: - return result: + return result return 0 \ No newline at end of file