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.
Fork of mbed-os 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 raise 00031 return "Unexpected key '%s' in configuration data" % k 00032 for k in expected: 00033 if k not in ["desc", "expected_macros", "expected_features"] + cfg.keys(): 00034 return "Expected key '%s' was not found in configuration data" % k 00035 return "" 00036 00037 def test_tree(full_name, name): 00038 failed = 0 00039 sys.path.append(full_name) 00040 if "test_data" in sys.modules: 00041 del sys.modules["test_data"] 00042 import test_data 00043 # If the test defines custom targets, they must exist in a file called 00044 # "targets.json" in the test's directory. 00045 if os.path.isfile(os.path.join(full_name, "targets.json")): 00046 set_targets_json_location(os.path.join(full_name, "targets.json")) 00047 else: # uset the regular set of targets 00048 set_targets_json_location() 00049 for target, expected in test_data.expected_results.items(): 00050 sys.stdout.write("%s:'%s'(%s) " % (name, expected["desc"], target)) 00051 sys.stdout.flush() 00052 err_msg = None 00053 try: 00054 cfg, macros, features = get_config(full_name, target, "GCC_ARM") 00055 macros = Config.config_macros_to_macros(macros) 00056 except ConfigException as e: 00057 err_msg = e.message 00058 if err_msg: 00059 if expected.has_key("exception_msg"): 00060 if err_msg.find(expected["exception_msg"]) == -1: 00061 print "FAILED!" 00062 sys.stderr.write(" Unexpected error message!\n") 00063 sys.stderr.write(" Expected: '%s'\n" % expected["exception_msg"]) 00064 sys.stderr.write(" Got: '%s'\n" % err_msg) 00065 failed += 1 00066 else: 00067 print "OK" 00068 else: 00069 print "FAILED!" 00070 sys.stderr.write(" Error while getting configuration!\n") 00071 sys.stderr.write(" " + err_msg + "\n") 00072 failed += 1 00073 else: 00074 res = compare_config(cfg, expected) 00075 expected_macros = expected.get("expected_macros", None) 00076 expected_features = expected.get("expected_features", None) 00077 00078 if res: 00079 print "FAILED!" 00080 sys.stdout.write(" " + res + "\n") 00081 failed += 1 00082 elif expected_macros is not None: 00083 if sorted(expected_macros) != sorted(macros): 00084 print "FAILED!" 00085 sys.stderr.write(" List of macros doesn't match\n") 00086 sys.stderr.write(" Expected: '%s'\n" % ",".join(sorted(expected_macros))) 00087 sys.stderr.write(" Got: '%s'\n" % ",".join(sorted(expected_macros))) 00088 failed += 1 00089 else: 00090 print "OK" 00091 elif expected_features is not None: 00092 if sorted(expected_features) != sorted(features): 00093 print "FAILED!" 00094 sys.stderr.write(" List of features doesn't match\n") 00095 sys.stderr.write(" Expected: '%s'\n" % ",".join(sorted(expected_features))) 00096 sys.stderr.write(" Got: '%s'\n" % ",".join(sorted(expected_features))) 00097 failed += 1 00098 else: 00099 print "OK" 00100 else: 00101 print "OK" 00102 sys.path.remove(full_name) 00103 return failed 00104 00105 failed = 0 00106 root_dir = os.path.abspath(os.path.dirname(__file__)) 00107 tlist = sorted(os.listdir(root_dir), key = lambda e: int(e[4:]) if e.startswith('test') else -1) 00108 for test_name in tlist: 00109 full_name = os.path.join(root_dir, test_name) 00110 if os.path.isdir(full_name) and test_name.startswith('test'): 00111 failed += test_tree(full_name, test_name) 00112 sys.exit(failed) 00113
Generated on Tue Jul 12 2022 13:15:39 by
