Add --quiet option to suppress demos' output
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/tests/scripts/run_demos.py b/tests/scripts/run_demos.py
index c8e3996..fcf13cd 100755
--- a/tests/scripts/run_demos.py
+++ b/tests/scripts/run_demos.py
@@ -1,44 +1,57 @@
#!/usr/bin/env python3
"""Run the Mbed TLS demo scripts.
"""
+import argparse
import glob
import subprocess
import sys
-def run_demo(demo):
+def run_demo(demo, quiet=False):
"""Run the specified demo script. Return True if it succeeds."""
- returncode = subprocess.call([demo])
+ args = {}
+ if quiet:
+ args['stdout'] = subprocess.DEVNULL
+ args['stderr'] = subprocess.DEVNULL
+ returncode = subprocess.call([demo], **args)
return returncode == 0
-def run_demos(demos):
+def run_demos(demos, quiet=False):
"""Run the specified demos and print summary information about failures.
Return True if all demos passed and False if a demo fails.
"""
failures = []
for demo in demos:
- print('#### {} ####'.format(demo))
- success = run_demo(demo)
+ if not quiet:
+ print('#### {} ####'.format(demo))
+ success = run_demo(demo, quiet=quiet)
if not success:
failures.append(demo)
- print('{}: FAIL'.format(demo))
- print('')
+ if not quiet:
+ print('{}: FAIL'.format(demo))
+ if not quiet:
+ print('')
successes = len(demos) - len(failures)
print('{}/{} demos passed'.format(successes, len(demos)))
if failures:
print('Failures:', *failures)
return not failures
-def run_all_demos():
+def run_all_demos(quiet=False):
"""Run all the available demos.
Return True if all demos passed and False if a demo fails.
"""
all_demos = glob.glob('programs/*/*_demo.sh')
- return run_demos(all_demos)
+ return run_demos(all_demos, quiet=quiet)
def main():
- success = run_all_demos()
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--quiet', '-q',
+ action='store_true',
+ help="suppress the output of demos")
+ options = parser.parse_args()
+ success = run_all_demos(quiet=options.quiet)
sys.exit(0 if success else 1)
if __name__ == '__main__':