mbed os with nrf51 internal bandgap enabled to read battery level
Dependents: BLE_file_test BLE_Blink ExternalEncoder
tools/test/config_test/config_test.py@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | """ |
elessair | 0:f269e3021894 | 2 | mbed SDK |
elessair | 0:f269e3021894 | 3 | Copyright (c) 2011-2016 ARM Limited |
elessair | 0:f269e3021894 | 4 | |
elessair | 0:f269e3021894 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
elessair | 0:f269e3021894 | 6 | you may not use this file except in compliance with the License. |
elessair | 0:f269e3021894 | 7 | You may obtain a copy of the License at |
elessair | 0:f269e3021894 | 8 | |
elessair | 0:f269e3021894 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
elessair | 0:f269e3021894 | 10 | |
elessair | 0:f269e3021894 | 11 | Unless required by applicable law or agreed to in writing, software |
elessair | 0:f269e3021894 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
elessair | 0:f269e3021894 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
elessair | 0:f269e3021894 | 14 | See the License for the specific language governing permissions and |
elessair | 0:f269e3021894 | 15 | limitations under the License. |
elessair | 0:f269e3021894 | 16 | """ |
elessair | 0:f269e3021894 | 17 | |
elessair | 0:f269e3021894 | 18 | from tools.build_api import get_config |
elessair | 0:f269e3021894 | 19 | from tools.targets import set_targets_json_location, Target |
elessair | 0:f269e3021894 | 20 | from tools.config import ConfigException, Config |
elessair | 0:f269e3021894 | 21 | import os, sys |
elessair | 0:f269e3021894 | 22 | |
elessair | 0:f269e3021894 | 23 | # Compare the output of config against a dictionary of known good results |
elessair | 0:f269e3021894 | 24 | def compare_config(cfg, expected): |
elessair | 0:f269e3021894 | 25 | try: |
elessair | 0:f269e3021894 | 26 | for k in cfg: |
elessair | 0:f269e3021894 | 27 | if cfg[k].value != expected[k]: |
elessair | 0:f269e3021894 | 28 | return "'%s': expected '%s', got '%s'" % (k, expected[k], cfg[k].value) |
elessair | 0:f269e3021894 | 29 | except KeyError: |
elessair | 0:f269e3021894 | 30 | raise |
elessair | 0:f269e3021894 | 31 | return "Unexpected key '%s' in configuration data" % k |
elessair | 0:f269e3021894 | 32 | for k in expected: |
elessair | 0:f269e3021894 | 33 | if k not in ["desc", "expected_macros", "expected_features"] + cfg.keys(): |
elessair | 0:f269e3021894 | 34 | return "Expected key '%s' was not found in configuration data" % k |
elessair | 0:f269e3021894 | 35 | return "" |
elessair | 0:f269e3021894 | 36 | |
elessair | 0:f269e3021894 | 37 | def test_tree(full_name, name): |
elessair | 0:f269e3021894 | 38 | failed = 0 |
elessair | 0:f269e3021894 | 39 | sys.path.append(full_name) |
elessair | 0:f269e3021894 | 40 | if "test_data" in sys.modules: |
elessair | 0:f269e3021894 | 41 | del sys.modules["test_data"] |
elessair | 0:f269e3021894 | 42 | import test_data |
elessair | 0:f269e3021894 | 43 | # If the test defines custom targets, they must exist in a file called |
elessair | 0:f269e3021894 | 44 | # "targets.json" in the test's directory. |
elessair | 0:f269e3021894 | 45 | if os.path.isfile(os.path.join(full_name, "targets.json")): |
elessair | 0:f269e3021894 | 46 | set_targets_json_location(os.path.join(full_name, "targets.json")) |
elessair | 0:f269e3021894 | 47 | else: # uset the regular set of targets |
elessair | 0:f269e3021894 | 48 | set_targets_json_location() |
elessair | 0:f269e3021894 | 49 | for target, expected in test_data.expected_results.items(): |
elessair | 0:f269e3021894 | 50 | sys.stdout.write("%s:'%s'(%s) " % (name, expected["desc"], target)) |
elessair | 0:f269e3021894 | 51 | sys.stdout.flush() |
elessair | 0:f269e3021894 | 52 | err_msg = None |
elessair | 0:f269e3021894 | 53 | try: |
elessair | 0:f269e3021894 | 54 | cfg, macros, features = get_config(full_name, target, "GCC_ARM") |
elessair | 0:f269e3021894 | 55 | macros = Config.config_macros_to_macros(macros) |
elessair | 0:f269e3021894 | 56 | except ConfigException as e: |
elessair | 0:f269e3021894 | 57 | err_msg = e.message |
elessair | 0:f269e3021894 | 58 | if err_msg: |
elessair | 0:f269e3021894 | 59 | if expected.has_key("exception_msg"): |
elessair | 0:f269e3021894 | 60 | if err_msg.find(expected["exception_msg"]) == -1: |
elessair | 0:f269e3021894 | 61 | print "FAILED!" |
elessair | 0:f269e3021894 | 62 | sys.stderr.write(" Unexpected error message!\n") |
elessair | 0:f269e3021894 | 63 | sys.stderr.write(" Expected: '%s'\n" % expected["exception_msg"]) |
elessair | 0:f269e3021894 | 64 | sys.stderr.write(" Got: '%s'\n" % err_msg) |
elessair | 0:f269e3021894 | 65 | failed += 1 |
elessair | 0:f269e3021894 | 66 | else: |
elessair | 0:f269e3021894 | 67 | print "OK" |
elessair | 0:f269e3021894 | 68 | else: |
elessair | 0:f269e3021894 | 69 | print "FAILED!" |
elessair | 0:f269e3021894 | 70 | sys.stderr.write(" Error while getting configuration!\n") |
elessair | 0:f269e3021894 | 71 | sys.stderr.write(" " + err_msg + "\n") |
elessair | 0:f269e3021894 | 72 | failed += 1 |
elessair | 0:f269e3021894 | 73 | else: |
elessair | 0:f269e3021894 | 74 | res = compare_config(cfg, expected) |
elessair | 0:f269e3021894 | 75 | expected_macros = expected.get("expected_macros", None) |
elessair | 0:f269e3021894 | 76 | expected_features = expected.get("expected_features", None) |
elessair | 0:f269e3021894 | 77 | |
elessair | 0:f269e3021894 | 78 | if res: |
elessair | 0:f269e3021894 | 79 | print "FAILED!" |
elessair | 0:f269e3021894 | 80 | sys.stdout.write(" " + res + "\n") |
elessair | 0:f269e3021894 | 81 | failed += 1 |
elessair | 0:f269e3021894 | 82 | elif expected_macros is not None: |
elessair | 0:f269e3021894 | 83 | if sorted(expected_macros) != sorted(macros): |
elessair | 0:f269e3021894 | 84 | print "FAILED!" |
elessair | 0:f269e3021894 | 85 | sys.stderr.write(" List of macros doesn't match\n") |
elessair | 0:f269e3021894 | 86 | sys.stderr.write(" Expected: '%s'\n" % ",".join(sorted(expected_macros))) |
elessair | 0:f269e3021894 | 87 | sys.stderr.write(" Got: '%s'\n" % ",".join(sorted(expected_macros))) |
elessair | 0:f269e3021894 | 88 | failed += 1 |
elessair | 0:f269e3021894 | 89 | else: |
elessair | 0:f269e3021894 | 90 | print "OK" |
elessair | 0:f269e3021894 | 91 | elif expected_features is not None: |
elessair | 0:f269e3021894 | 92 | if sorted(expected_features) != sorted(features): |
elessair | 0:f269e3021894 | 93 | print "FAILED!" |
elessair | 0:f269e3021894 | 94 | sys.stderr.write(" List of features doesn't match\n") |
elessair | 0:f269e3021894 | 95 | sys.stderr.write(" Expected: '%s'\n" % ",".join(sorted(expected_features))) |
elessair | 0:f269e3021894 | 96 | sys.stderr.write(" Got: '%s'\n" % ",".join(sorted(expected_features))) |
elessair | 0:f269e3021894 | 97 | failed += 1 |
elessair | 0:f269e3021894 | 98 | else: |
elessair | 0:f269e3021894 | 99 | print "OK" |
elessair | 0:f269e3021894 | 100 | else: |
elessair | 0:f269e3021894 | 101 | print "OK" |
elessair | 0:f269e3021894 | 102 | sys.path.remove(full_name) |
elessair | 0:f269e3021894 | 103 | return failed |
elessair | 0:f269e3021894 | 104 | |
elessair | 0:f269e3021894 | 105 | failed = 0 |
elessair | 0:f269e3021894 | 106 | root_dir = os.path.abspath(os.path.dirname(__file__)) |
elessair | 0:f269e3021894 | 107 | tlist = sorted(os.listdir(root_dir), key = lambda e: int(e[4:]) if e.startswith('test') else -1) |
elessair | 0:f269e3021894 | 108 | for test_name in tlist: |
elessair | 0:f269e3021894 | 109 | full_name = os.path.join(root_dir, test_name) |
elessair | 0:f269e3021894 | 110 | if os.path.isdir(full_name) and test_name.startswith('test'): |
elessair | 0:f269e3021894 | 111 | failed += test_tree(full_name, test_name) |
elessair | 0:f269e3021894 | 112 | sys.exit(failed) |
elessair | 0:f269e3021894 | 113 |