mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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