Skip to content

Commit a7c777d

Browse files
committed
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
1 parent 56293af commit a7c777d

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

tools/test/examples/examples.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,17 @@ def do_export(args, config, examples):
9797

9898
def do_import(_, config, examples):
9999
"""Do the import step of this process"""
100-
lib.source_repos(config, examples)
101-
return 0
100+
return lib.source_repos(config, examples)
102101

103102

104103
def do_clone(_, config, examples):
105104
"""Do the clone step of this process"""
106-
lib.clone_repos(config, examples)
107-
return 0
105+
return lib.clone_repos(config, examples)
108106

109107

110108
def do_deploy(_, config, examples):
111109
"""Do the deploy step of this process"""
112-
lib.deploy_repos(config, examples)
113-
return 0
110+
return lib.deploy_repos(config, examples)
114111

115112

116113
def do_compile(args, config, examples):
@@ -125,8 +122,7 @@ def do_compile(args, config, examples):
125122

126123
def do_versionning(args, config, examples):
127124
""" Test update the mbed-os to the version specified by the tag """
128-
lib.update_mbedos_version(config, args.tag, examples)
129-
return 0
125+
return lib.update_mbedos_version(config, args.tag, examples)
130126

131127

132128
if __name__ == "__main__":

tools/test/examples/examples_lib.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ def source_repos(config, examples):
169169
print("'%s' example directory already exists. Deleting..." % name)
170170
rmtree(name)
171171

172-
subprocess.call(["mbed-cli", "import", repo_info['repo']])
172+
result = subprocess.call(["mbed-cli", "import", repo_info['repo']])
173+
if result:
174+
return result
175+
176+
return 0
173177

174178
def clone_repos(config, examples , retry = 3):
175179
""" Clones each of the repos associated with the specific examples name from the
@@ -192,6 +196,8 @@ def clone_repos(config, examples , retry = 3):
192196
break
193197
else:
194198
print("ERROR : unable to clone the repo {}".format(name))
199+
return 1
200+
return 0
195201

196202
def deploy_repos(config, examples):
197203
""" If the example directory exists as provided by the json config file,
@@ -207,11 +213,15 @@ def deploy_repos(config, examples):
207213
if name in examples:
208214
if os.path.exists(name):
209215
os.chdir(name)
210-
subprocess.call(["mbed-cli", "deploy"])
216+
result = subprocess.call(["mbed-cli", "deploy"])
211217
os.chdir("..")
218+
if result:
219+
print("mbed-cli deploy command failed for '%s'" % name)
220+
return result
212221
else:
213222
print("'%s' example directory doesn't exist. Skipping..." % name)
214-
223+
return 1
224+
return 0
215225

216226
def get_num_failures(results, export=False):
217227
""" Returns the number of failed compilations from the results summary
@@ -405,5 +415,10 @@ def update_mbedos_version(config, tag, examples):
405415
update_dir = basename(repo_info['repo']) + "/mbed-os"
406416
print("\nChanging dir to %s\n" % update_dir)
407417
os.chdir(update_dir)
408-
subprocess.call(["mbed-cli", "update", tag, "--clean"])
418+
result = subprocess.call(["mbed-cli", "update", tag, "--clean"])
409419
os.chdir("../..")
420+
if result:
421+
return result:
422+
423+
return 0
424+

0 commit comments

Comments
 (0)