Development mbed library for MAX32630FTHR
Dependents: blinky_max32630fthr
tools/test/examples/examples.py@3:1198227e6421, 2016-12-16 (annotated)
- Committer:
- switches
- Date:
- Fri Dec 16 16:27:57 2016 +0000
- Revision:
- 3:1198227e6421
- Parent:
- 0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:5c4d7b2438d3 | 1 | """ import and bulid a bunch of example programs """ |
switches | 0:5c4d7b2438d3 | 2 | |
switches | 0:5c4d7b2438d3 | 3 | from argparse import ArgumentParser |
switches | 0:5c4d7b2438d3 | 4 | import os |
switches | 0:5c4d7b2438d3 | 5 | from os.path import dirname, abspath, basename |
switches | 0:5c4d7b2438d3 | 6 | import os.path |
switches | 0:5c4d7b2438d3 | 7 | import sys |
switches | 0:5c4d7b2438d3 | 8 | import subprocess |
switches | 0:5c4d7b2438d3 | 9 | import json |
switches | 0:5c4d7b2438d3 | 10 | |
switches | 0:5c4d7b2438d3 | 11 | ROOT = abspath(dirname(dirname(dirname(dirname(__file__))))) |
switches | 0:5c4d7b2438d3 | 12 | sys.path.insert(0, ROOT) |
switches | 0:5c4d7b2438d3 | 13 | |
switches | 0:5c4d7b2438d3 | 14 | from tools.utils import argparse_force_uppercase_type |
switches | 0:5c4d7b2438d3 | 15 | from tools.utils import argparse_many |
switches | 0:5c4d7b2438d3 | 16 | from tools.build_api import get_mbed_official_release |
switches | 0:5c4d7b2438d3 | 17 | import examples_lib as lib |
switches | 0:5c4d7b2438d3 | 18 | from examples_lib import SUPPORTED_TOOLCHAINS, SUPPORTED_IDES |
switches | 0:5c4d7b2438d3 | 19 | |
switches | 0:5c4d7b2438d3 | 20 | def main(): |
switches | 0:5c4d7b2438d3 | 21 | """Entry point""" |
switches | 0:5c4d7b2438d3 | 22 | |
switches | 0:5c4d7b2438d3 | 23 | official_targets = get_mbed_official_release("5") |
switches | 0:5c4d7b2438d3 | 24 | official_target_names = [x[0] for x in official_targets] |
switches | 0:5c4d7b2438d3 | 25 | |
switches | 0:5c4d7b2438d3 | 26 | |
switches | 0:5c4d7b2438d3 | 27 | parser = ArgumentParser() |
switches | 0:5c4d7b2438d3 | 28 | parser.add_argument("-c", dest="config", default="examples.json") |
switches | 0:5c4d7b2438d3 | 29 | parser.add_argument("-e", "--example", |
switches | 0:5c4d7b2438d3 | 30 | help=("filter the examples used in the script"), |
switches | 0:5c4d7b2438d3 | 31 | type=argparse_many(lambda x: x), |
switches | 0:5c4d7b2438d3 | 32 | default=[]) |
switches | 0:5c4d7b2438d3 | 33 | subparsers = parser.add_subparsers() |
switches | 0:5c4d7b2438d3 | 34 | import_cmd = subparsers.add_parser("import") |
switches | 0:5c4d7b2438d3 | 35 | import_cmd.set_defaults(fn=do_import) |
switches | 0:5c4d7b2438d3 | 36 | clone_cmd = subparsers.add_parser("clone") |
switches | 0:5c4d7b2438d3 | 37 | clone_cmd.set_defaults(fn=do_clone) |
switches | 0:5c4d7b2438d3 | 38 | deploy_cmd = subparsers.add_parser("deploy") |
switches | 0:5c4d7b2438d3 | 39 | deploy_cmd.set_defaults(fn=do_deploy) |
switches | 0:5c4d7b2438d3 | 40 | version_cmd = subparsers.add_parser("tag") |
switches | 0:5c4d7b2438d3 | 41 | version_cmd.add_argument("tag") |
switches | 0:5c4d7b2438d3 | 42 | version_cmd.set_defaults(fn=do_versionning) |
switches | 0:5c4d7b2438d3 | 43 | compile_cmd = subparsers.add_parser("compile") |
switches | 0:5c4d7b2438d3 | 44 | compile_cmd.set_defaults(fn=do_compile), |
switches | 0:5c4d7b2438d3 | 45 | compile_cmd.add_argument( |
switches | 0:5c4d7b2438d3 | 46 | "toolchains", nargs="*", default=SUPPORTED_TOOLCHAINS, |
switches | 0:5c4d7b2438d3 | 47 | type=argparse_force_uppercase_type(SUPPORTED_TOOLCHAINS, |
switches | 0:5c4d7b2438d3 | 48 | "toolchain")), |
switches | 0:5c4d7b2438d3 | 49 | compile_cmd.add_argument("-m", "--mcu", |
switches | 0:5c4d7b2438d3 | 50 | help=("build for the given MCU (%s)" % |
switches | 0:5c4d7b2438d3 | 51 | ', '.join(official_target_names)), |
switches | 0:5c4d7b2438d3 | 52 | metavar="MCU", |
switches | 0:5c4d7b2438d3 | 53 | type=argparse_many( |
switches | 0:5c4d7b2438d3 | 54 | argparse_force_uppercase_type( |
switches | 0:5c4d7b2438d3 | 55 | official_target_names, "MCU")), |
switches | 0:5c4d7b2438d3 | 56 | default=official_target_names) |
switches | 0:5c4d7b2438d3 | 57 | export_cmd = subparsers.add_parser("export") |
switches | 0:5c4d7b2438d3 | 58 | export_cmd.set_defaults(fn=do_export), |
switches | 0:5c4d7b2438d3 | 59 | export_cmd.add_argument( |
switches | 0:5c4d7b2438d3 | 60 | "ide", nargs="*", default=SUPPORTED_IDES, |
switches | 0:5c4d7b2438d3 | 61 | type=argparse_force_uppercase_type(SUPPORTED_IDES, |
switches | 0:5c4d7b2438d3 | 62 | "ide")) |
switches | 0:5c4d7b2438d3 | 63 | export_cmd.add_argument("-m", "--mcu", |
switches | 0:5c4d7b2438d3 | 64 | help=("build for the given MCU (%s)" % |
switches | 0:5c4d7b2438d3 | 65 | ', '.join(official_target_names)), |
switches | 0:5c4d7b2438d3 | 66 | metavar="MCU", |
switches | 0:5c4d7b2438d3 | 67 | type=argparse_many( |
switches | 0:5c4d7b2438d3 | 68 | argparse_force_uppercase_type( |
switches | 0:5c4d7b2438d3 | 69 | official_target_names, "MCU")), |
switches | 0:5c4d7b2438d3 | 70 | default=official_target_names) |
switches | 0:5c4d7b2438d3 | 71 | args = parser.parse_args() |
switches | 0:5c4d7b2438d3 | 72 | config = json.load(open(os.path.join(os.path.dirname(__file__), |
switches | 0:5c4d7b2438d3 | 73 | args.config))) |
switches | 0:5c4d7b2438d3 | 74 | |
switches | 0:5c4d7b2438d3 | 75 | all_examples = [] |
switches | 0:5c4d7b2438d3 | 76 | for example in config['examples']: |
switches | 0:5c4d7b2438d3 | 77 | all_examples = all_examples + [basename(x['repo']) for x in lib.get_repo_list(example)] |
switches | 0:5c4d7b2438d3 | 78 | examples = [x for x in all_examples if x in args.example] if args.example else all_examples |
switches | 0:5c4d7b2438d3 | 79 | return args.fn(args, config, examples) |
switches | 0:5c4d7b2438d3 | 80 | |
switches | 0:5c4d7b2438d3 | 81 | |
switches | 0:5c4d7b2438d3 | 82 | def do_export(args, config, examples): |
switches | 0:5c4d7b2438d3 | 83 | """Do export and build step""" |
switches | 0:5c4d7b2438d3 | 84 | results = {} |
switches | 0:5c4d7b2438d3 | 85 | results = lib.export_repos(config, args.ide, args.mcu, examples) |
switches | 0:5c4d7b2438d3 | 86 | |
switches | 0:5c4d7b2438d3 | 87 | lib.print_summary(results, export=True) |
switches | 0:5c4d7b2438d3 | 88 | failures = lib.get_num_failures(results, export=True) |
switches | 0:5c4d7b2438d3 | 89 | print("Number of failures = %d" % failures) |
switches | 0:5c4d7b2438d3 | 90 | return failures |
switches | 0:5c4d7b2438d3 | 91 | |
switches | 0:5c4d7b2438d3 | 92 | |
switches | 0:5c4d7b2438d3 | 93 | def do_import(_, config, examples): |
switches | 0:5c4d7b2438d3 | 94 | """Do the import step of this process""" |
switches | 0:5c4d7b2438d3 | 95 | lib.source_repos(config, examples) |
switches | 0:5c4d7b2438d3 | 96 | return 0 |
switches | 0:5c4d7b2438d3 | 97 | |
switches | 0:5c4d7b2438d3 | 98 | |
switches | 0:5c4d7b2438d3 | 99 | def do_clone(_, config, examples): |
switches | 0:5c4d7b2438d3 | 100 | """Do the clone step of this process""" |
switches | 0:5c4d7b2438d3 | 101 | lib.clone_repos(config, examples) |
switches | 0:5c4d7b2438d3 | 102 | return 0 |
switches | 0:5c4d7b2438d3 | 103 | |
switches | 0:5c4d7b2438d3 | 104 | |
switches | 0:5c4d7b2438d3 | 105 | def do_deploy(_, config, examples): |
switches | 0:5c4d7b2438d3 | 106 | """Do the deploy step of this process""" |
switches | 0:5c4d7b2438d3 | 107 | lib.deploy_repos(config, examples) |
switches | 0:5c4d7b2438d3 | 108 | return 0 |
switches | 0:5c4d7b2438d3 | 109 | |
switches | 0:5c4d7b2438d3 | 110 | |
switches | 0:5c4d7b2438d3 | 111 | def do_compile(args, config, examples): |
switches | 0:5c4d7b2438d3 | 112 | """Do the compile step""" |
switches | 0:5c4d7b2438d3 | 113 | results = {} |
switches | 0:5c4d7b2438d3 | 114 | results = lib.compile_repos(config, args.toolchains, args.mcu, examples) |
switches | 0:5c4d7b2438d3 | 115 | |
switches | 0:5c4d7b2438d3 | 116 | lib.print_summary(results) |
switches | 0:5c4d7b2438d3 | 117 | failures = lib.get_num_failures(results) |
switches | 0:5c4d7b2438d3 | 118 | print("Number of failures = %d" % failures) |
switches | 0:5c4d7b2438d3 | 119 | return failures |
switches | 0:5c4d7b2438d3 | 120 | |
switches | 0:5c4d7b2438d3 | 121 | def do_versionning(args, config, examples): |
switches | 0:5c4d7b2438d3 | 122 | """ Test update the mbed-os to the version specified by the tag """ |
switches | 0:5c4d7b2438d3 | 123 | lib.update_mbedos_version(config, args.tag, examples) |
switches | 0:5c4d7b2438d3 | 124 | return 0 |
switches | 0:5c4d7b2438d3 | 125 | |
switches | 0:5c4d7b2438d3 | 126 | |
switches | 0:5c4d7b2438d3 | 127 | if __name__ == "__main__": |
switches | 0:5c4d7b2438d3 | 128 | sys.exit(main()) |