Includes library modifications to allow access to AIN_4 (AIN_0 / 5)
mbd_os/tools/test/examples/examples.py@0:eafc3fd41f75, 2016-09-20 (annotated)
- Committer:
- bryantaylor
- Date:
- Tue Sep 20 21:26:12 2016 +0000
- Revision:
- 0:eafc3fd41f75
hackathon
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bryantaylor | 0:eafc3fd41f75 | 1 | """ import and bulid a bunch of example programs """ |
bryantaylor | 0:eafc3fd41f75 | 2 | |
bryantaylor | 0:eafc3fd41f75 | 3 | from argparse import ArgumentParser |
bryantaylor | 0:eafc3fd41f75 | 4 | import os |
bryantaylor | 0:eafc3fd41f75 | 5 | from os.path import dirname, abspath, basename |
bryantaylor | 0:eafc3fd41f75 | 6 | import os.path |
bryantaylor | 0:eafc3fd41f75 | 7 | import sys |
bryantaylor | 0:eafc3fd41f75 | 8 | import subprocess |
bryantaylor | 0:eafc3fd41f75 | 9 | import json |
bryantaylor | 0:eafc3fd41f75 | 10 | |
bryantaylor | 0:eafc3fd41f75 | 11 | ROOT = abspath(dirname(dirname(dirname(dirname(__file__))))) |
bryantaylor | 0:eafc3fd41f75 | 12 | sys.path.insert(0, ROOT) |
bryantaylor | 0:eafc3fd41f75 | 13 | |
bryantaylor | 0:eafc3fd41f75 | 14 | from tools.build_api import get_mbed_official_release |
bryantaylor | 0:eafc3fd41f75 | 15 | from tools.targets import TARGET_MAP |
bryantaylor | 0:eafc3fd41f75 | 16 | from tools.utils import argparse_force_uppercase_type |
bryantaylor | 0:eafc3fd41f75 | 17 | |
bryantaylor | 0:eafc3fd41f75 | 18 | |
bryantaylor | 0:eafc3fd41f75 | 19 | EXAMPLES = json.load(open(os.path.join(os.path.dirname(__file__), |
bryantaylor | 0:eafc3fd41f75 | 20 | "examples.json"))) |
bryantaylor | 0:eafc3fd41f75 | 21 | |
bryantaylor | 0:eafc3fd41f75 | 22 | def print_stuff(name, lst): |
bryantaylor | 0:eafc3fd41f75 | 23 | if lst: |
bryantaylor | 0:eafc3fd41f75 | 24 | print("#"*80) |
bryantaylor | 0:eafc3fd41f75 | 25 | print("# {} example combinations".format(name)) |
bryantaylor | 0:eafc3fd41f75 | 26 | print("#") |
bryantaylor | 0:eafc3fd41f75 | 27 | for thing in lst: |
bryantaylor | 0:eafc3fd41f75 | 28 | print(thing) |
bryantaylor | 0:eafc3fd41f75 | 29 | |
bryantaylor | 0:eafc3fd41f75 | 30 | |
bryantaylor | 0:eafc3fd41f75 | 31 | SUPPORTED_TOOLCHAINS = ["ARM", "IAR", "GCC_ARM"] |
bryantaylor | 0:eafc3fd41f75 | 32 | |
bryantaylor | 0:eafc3fd41f75 | 33 | |
bryantaylor | 0:eafc3fd41f75 | 34 | def target_cross_toolchain(allowed_toolchains, |
bryantaylor | 0:eafc3fd41f75 | 35 | features=[], targets=TARGET_MAP.keys()): |
bryantaylor | 0:eafc3fd41f75 | 36 | """Generate pairs of target and toolchains |
bryantaylor | 0:eafc3fd41f75 | 37 | |
bryantaylor | 0:eafc3fd41f75 | 38 | Args: |
bryantaylor | 0:eafc3fd41f75 | 39 | allowed_toolchains - a list of all possible toolchains |
bryantaylor | 0:eafc3fd41f75 | 40 | |
bryantaylor | 0:eafc3fd41f75 | 41 | Kwargs: |
bryantaylor | 0:eafc3fd41f75 | 42 | features - the features that must be in the features array of a |
bryantaylor | 0:eafc3fd41f75 | 43 | target |
bryantaylor | 0:eafc3fd41f75 | 44 | targets - a list of available targets |
bryantaylor | 0:eafc3fd41f75 | 45 | """ |
bryantaylor | 0:eafc3fd41f75 | 46 | for target, toolchains in get_mbed_official_release("5"): |
bryantaylor | 0:eafc3fd41f75 | 47 | for toolchain in toolchains: |
bryantaylor | 0:eafc3fd41f75 | 48 | if (toolchain in allowed_toolchains and |
bryantaylor | 0:eafc3fd41f75 | 49 | target in targets and |
bryantaylor | 0:eafc3fd41f75 | 50 | all(feature in TARGET_MAP[target].features |
bryantaylor | 0:eafc3fd41f75 | 51 | for feature in features)): |
bryantaylor | 0:eafc3fd41f75 | 52 | yield target, toolchain |
bryantaylor | 0:eafc3fd41f75 | 53 | |
bryantaylor | 0:eafc3fd41f75 | 54 | |
bryantaylor | 0:eafc3fd41f75 | 55 | def main(): |
bryantaylor | 0:eafc3fd41f75 | 56 | """Entry point""" |
bryantaylor | 0:eafc3fd41f75 | 57 | parser = ArgumentParser() |
bryantaylor | 0:eafc3fd41f75 | 58 | subparsers = parser.add_subparsers() |
bryantaylor | 0:eafc3fd41f75 | 59 | import_cmd = subparsers.add_parser("import") |
bryantaylor | 0:eafc3fd41f75 | 60 | import_cmd.set_defaults(fn=do_import) |
bryantaylor | 0:eafc3fd41f75 | 61 | compile_cmd = subparsers.add_parser("compile") |
bryantaylor | 0:eafc3fd41f75 | 62 | compile_cmd.set_defaults(fn=do_compile) |
bryantaylor | 0:eafc3fd41f75 | 63 | compile_cmd.add_argument( |
bryantaylor | 0:eafc3fd41f75 | 64 | "toolchains", nargs="*", default=SUPPORTED_TOOLCHAINS, |
bryantaylor | 0:eafc3fd41f75 | 65 | type=argparse_force_uppercase_type(SUPPORTED_TOOLCHAINS, |
bryantaylor | 0:eafc3fd41f75 | 66 | "toolchain")) |
bryantaylor | 0:eafc3fd41f75 | 67 | args = parser.parse_args() |
bryantaylor | 0:eafc3fd41f75 | 68 | return args.fn(args) |
bryantaylor | 0:eafc3fd41f75 | 69 | |
bryantaylor | 0:eafc3fd41f75 | 70 | |
bryantaylor | 0:eafc3fd41f75 | 71 | def do_import(_): |
bryantaylor | 0:eafc3fd41f75 | 72 | """Do the import step of this process""" |
bryantaylor | 0:eafc3fd41f75 | 73 | for example, _ in EXAMPLES.iteritems(): |
bryantaylor | 0:eafc3fd41f75 | 74 | subprocess.call(["mbed-cli", "import", example]) |
bryantaylor | 0:eafc3fd41f75 | 75 | return 0 |
bryantaylor | 0:eafc3fd41f75 | 76 | |
bryantaylor | 0:eafc3fd41f75 | 77 | |
bryantaylor | 0:eafc3fd41f75 | 78 | def do_compile(args): |
bryantaylor | 0:eafc3fd41f75 | 79 | """Do the compile step""" |
bryantaylor | 0:eafc3fd41f75 | 80 | failures = [] |
bryantaylor | 0:eafc3fd41f75 | 81 | sucesses = [] |
bryantaylor | 0:eafc3fd41f75 | 82 | for example, requirements in EXAMPLES.iteritems(): |
bryantaylor | 0:eafc3fd41f75 | 83 | os.chdir(basename(example)) |
bryantaylor | 0:eafc3fd41f75 | 84 | for target, toolchain in target_cross_toolchain(args.toolchains, |
bryantaylor | 0:eafc3fd41f75 | 85 | **requirements): |
bryantaylor | 0:eafc3fd41f75 | 86 | proc = subprocess.Popen(["mbed-cli", "compile", "-t", toolchain, |
bryantaylor | 0:eafc3fd41f75 | 87 | "-m", target, "--silent"]) |
bryantaylor | 0:eafc3fd41f75 | 88 | proc.wait() |
bryantaylor | 0:eafc3fd41f75 | 89 | example_name = "{} {} {}".format(basename(example), target, |
bryantaylor | 0:eafc3fd41f75 | 90 | toolchain) |
bryantaylor | 0:eafc3fd41f75 | 91 | if proc.returncode: |
bryantaylor | 0:eafc3fd41f75 | 92 | failures.append(example_name) |
bryantaylor | 0:eafc3fd41f75 | 93 | else: |
bryantaylor | 0:eafc3fd41f75 | 94 | sucesses.append(example_name) |
bryantaylor | 0:eafc3fd41f75 | 95 | os.chdir("..") |
bryantaylor | 0:eafc3fd41f75 | 96 | |
bryantaylor | 0:eafc3fd41f75 | 97 | print_stuff("Passed", sucesses) |
bryantaylor | 0:eafc3fd41f75 | 98 | print_stuff("Failed", failures) |
bryantaylor | 0:eafc3fd41f75 | 99 | return len(failures) |
bryantaylor | 0:eafc3fd41f75 | 100 | |
bryantaylor | 0:eafc3fd41f75 | 101 | if __name__ == "__main__": |
bryantaylor | 0:eafc3fd41f75 | 102 | sys.exit(main()) |