Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
config_test.py
00001 """ 00002 mbed SDK 00003 Copyright (c) 2011-2016 ARM Limited 00004 00005 Licensed under the Apache License, Version 2.0 (the "License"); 00006 you may not use this file except in compliance with the License. 00007 You may obtain a copy of the License at 00008 00009 http://www.apache.org/licenses/LICENSE-2.0 00010 00011 Unless required by applicable law or agreed to in writing, software 00012 distributed under the License is distributed on an "AS IS" BASIS, 00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 See the License for the specific language governing permissions and 00015 limitations under the License. 00016 """ 00017 00018 from tools.build_api import get_config 00019 from tools.targets import set_targets_json_location, Target 00020 from tools.config import ConfigException, Config 00021 import os, sys 00022 00023 # Compare the output of config against a dictionary of known good results 00024 def compare_config(cfg, expected): 00025 try: 00026 for k in cfg: 00027 if cfg[k].value != expected[k]: 00028 return "'%s': expected '%s', got '%s'" % (k, expected[k], cfg[k].value) 00029 except KeyError: 00030 return "Unexpected key '%s' in configuration data" % k 00031 for k in expected: 00032 if k not in ["desc", "expected_macros", "expected_features"] + cfg.keys(): 00033 return "Expected key '%s' was not found in configuration data" % k 00034 return "" 00035 00036 def test_tree(full_name, name): 00037 failed = 0 00038 sys.path.append(full_name) 00039 if "test_data" in sys.modules: 00040 del sys.modules["test_data"] 00041 import test_data 00042 for target, expected in test_data.expected_results.items(): 00043 sys.stdout.write("%s:'%s'(%s) " % (name, expected["desc"], target)) 00044 sys.stdout.flush() 00045 err_msg = None 00046 try: 00047 # Use 'set_targets_json_location' to remove the previous custom targets from the target list 00048 set_targets_json_location(Target._Target__targets_json_location) 00049 cfg, macros, features = get_config(full_name, target, "GCC_ARM") 00050 macros = Config.config_macros_to_macros(macros) 00051 except ConfigException as e: 00052 err_msg = e.message 00053 if err_msg: 00054 if expected.has_key("exception_msg"): 00055 if err_msg.find(expected["exception_msg"]) == -1: 00056 print "FAILED!" 00057 sys.stderr.write(" Unexpected error message!\n") 00058 sys.stderr.write(" Expected: '%s'\n" % expected["exception_msg"]) 00059 sys.stderr.write(" Got: '%s'\n" % err_msg) 00060 failed += 1 00061 else: 00062 print "OK" 00063 else: 00064 print "FAILED!" 00065 sys.stderr.write(" Error while getting configuration!\n") 00066 sys.stderr.write(" " + err_msg + "\n") 00067 failed += 1 00068 else: 00069 res = compare_config(cfg, expected) 00070 expected_macros = expected.get("expected_macros", None) 00071 expected_features = expected.get("expected_features", None) 00072 00073 if res: 00074 print "FAILED!" 00075 sys.stdout.write(" " + res + "\n") 00076 failed += 1 00077 elif expected_macros is not None: 00078 if sorted(expected_macros) != sorted(macros): 00079 print "FAILED!" 00080 sys.stderr.write(" List of macros doesn't match\n") 00081 sys.stderr.write(" Expected: '%s'\n" % ",".join(sorted(expected_macros))) 00082 sys.stderr.write(" Got: '%s'\n" % ",".join(sorted(expected_macros))) 00083 failed += 1 00084 else: 00085 print "OK" 00086 elif expected_features is not None: 00087 if sorted(expected_features) != sorted(features): 00088 print "FAILED!" 00089 sys.stderr.write(" List of features doesn't match\n") 00090 sys.stderr.write(" Expected: '%s'\n" % ",".join(sorted(expected_features))) 00091 sys.stderr.write(" Got: '%s'\n" % ",".join(sorted(expected_features))) 00092 failed += 1 00093 else: 00094 print "OK" 00095 else: 00096 print "OK" 00097 sys.path.remove(full_name) 00098 return failed 00099 00100 failed = 0 00101 root_dir = os.path.abspath(os.path.dirname(__file__)) 00102 tlist = sorted(os.listdir(root_dir), key = lambda e: int(e[4:]) if e.startswith('test') else -1) 00103 for test_name in tlist: 00104 full_name = os.path.join(root_dir, test_name) 00105 if os.path.isdir(full_name) and test_name.startswith('test'): 00106 failed += test_tree(full_name, test_name) 00107 sys.exit(failed) 00108
Generated on Tue Jul 12 2022 12:28:28 by
1.7.2
