2019-06-14 18:23:03 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""Run the Mbed TLS demo scripts.
|
|
|
|
"""
|
2020-04-26 22:51:05 +02:00
|
|
|
import argparse
|
2019-06-14 18:23:03 +02:00
|
|
|
import glob
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
2020-04-26 22:51:05 +02:00
|
|
|
def run_demo(demo, quiet=False):
|
2019-06-14 18:23:03 +02:00
|
|
|
"""Run the specified demo script. Return True if it succeeds."""
|
2020-04-26 22:51:05 +02:00
|
|
|
args = {}
|
|
|
|
if quiet:
|
|
|
|
args['stdout'] = subprocess.DEVNULL
|
|
|
|
args['stderr'] = subprocess.DEVNULL
|
|
|
|
returncode = subprocess.call([demo], **args)
|
2019-06-14 18:23:03 +02:00
|
|
|
return returncode == 0
|
|
|
|
|
2020-04-26 22:51:05 +02:00
|
|
|
def run_demos(demos, quiet=False):
|
2019-06-14 18:23:03 +02:00
|
|
|
"""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:
|
2020-04-26 22:51:05 +02:00
|
|
|
if not quiet:
|
|
|
|
print('#### {} ####'.format(demo))
|
|
|
|
success = run_demo(demo, quiet=quiet)
|
2020-04-26 22:33:48 +02:00
|
|
|
if not success:
|
2019-06-14 18:23:03 +02:00
|
|
|
failures.append(demo)
|
2020-04-26 22:51:05 +02:00
|
|
|
if not quiet:
|
|
|
|
print('{}: FAIL'.format(demo))
|
2020-04-27 11:00:59 +02:00
|
|
|
if quiet:
|
|
|
|
print('{}: {}'.format(demo, 'PASS' if success else 'FAIL'))
|
|
|
|
else:
|
2020-04-26 22:51:05 +02:00
|
|
|
print('')
|
2019-06-14 18:23:03 +02:00
|
|
|
successes = len(demos) - len(failures)
|
|
|
|
print('{}/{} demos passed'.format(successes, len(demos)))
|
2020-04-27 11:00:59 +02:00
|
|
|
if failures and not quiet:
|
2019-06-14 18:23:03 +02:00
|
|
|
print('Failures:', *failures)
|
|
|
|
return not failures
|
|
|
|
|
2020-04-26 22:51:05 +02:00
|
|
|
def run_all_demos(quiet=False):
|
2019-06-14 18:23:03 +02:00
|
|
|
"""Run all the available demos.
|
|
|
|
|
|
|
|
Return True if all demos passed and False if a demo fails.
|
|
|
|
"""
|
|
|
|
all_demos = glob.glob('programs/*/*_demo.sh')
|
2020-04-27 10:39:20 +02:00
|
|
|
if not all_demos:
|
2020-04-27 14:34:38 +02:00
|
|
|
# Keep the message on one line. pylint: disable=line-too-long
|
2020-04-27 10:39:20 +02:00
|
|
|
raise Exception('No demos found. run_demos needs to operate from the Mbed TLS toplevel directory.')
|
2020-04-26 22:51:05 +02:00
|
|
|
return run_demos(all_demos, quiet=quiet)
|
2019-06-14 18:23:03 +02:00
|
|
|
|
2020-04-26 22:33:48 +02:00
|
|
|
def main():
|
2020-04-26 22:51:05 +02:00
|
|
|
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)
|
2020-04-26 22:33:48 +02:00
|
|
|
sys.exit(0 if success else 1)
|
|
|
|
|
2019-06-14 18:23:03 +02:00
|
|
|
if __name__ == '__main__':
|
2020-04-26 22:33:48 +02:00
|
|
|
main()
|