takashi kadono
/
Nucleo446_SSD1331
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/UNITTESTS/mbed_unittest.py@0:8fdf9a60065b, 2018-10-10 (annotated)
- Committer:
- kadonotakashi
- Date:
- Wed Oct 10 00:33:53 2018 +0000
- Revision:
- 0:8fdf9a60065b
how to make mbed librry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | #!/usr/bin/env python |
kadonotakashi | 0:8fdf9a60065b | 2 | |
kadonotakashi | 0:8fdf9a60065b | 3 | """ |
kadonotakashi | 0:8fdf9a60065b | 4 | Copyright (c) 2018, Arm Limited |
kadonotakashi | 0:8fdf9a60065b | 5 | SPDX-License-Identifier: Apache-2.0 |
kadonotakashi | 0:8fdf9a60065b | 6 | |
kadonotakashi | 0:8fdf9a60065b | 7 | Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 8 | you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 9 | You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 10 | |
kadonotakashi | 0:8fdf9a60065b | 11 | http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 12 | |
kadonotakashi | 0:8fdf9a60065b | 13 | Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 14 | distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 16 | See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 17 | limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 18 | |
kadonotakashi | 0:8fdf9a60065b | 19 | |
kadonotakashi | 0:8fdf9a60065b | 20 | UNIT TEST BUILD & RUN |
kadonotakashi | 0:8fdf9a60065b | 21 | """ |
kadonotakashi | 0:8fdf9a60065b | 22 | |
kadonotakashi | 0:8fdf9a60065b | 23 | from __future__ import print_function |
kadonotakashi | 0:8fdf9a60065b | 24 | import os |
kadonotakashi | 0:8fdf9a60065b | 25 | import logging |
kadonotakashi | 0:8fdf9a60065b | 26 | import re |
kadonotakashi | 0:8fdf9a60065b | 27 | |
kadonotakashi | 0:8fdf9a60065b | 28 | from unit_test.options import get_options_parser, \ |
kadonotakashi | 0:8fdf9a60065b | 29 | pretty_print_test_options |
kadonotakashi | 0:8fdf9a60065b | 30 | from unit_test.settings import DEFAULT_CMAKE_GENERATORS |
kadonotakashi | 0:8fdf9a60065b | 31 | from unit_test.test import UnitTestTool |
kadonotakashi | 0:8fdf9a60065b | 32 | from unit_test.new import UnitTestGeneratorTool |
kadonotakashi | 0:8fdf9a60065b | 33 | from unit_test.coverage import CoverageAPI |
kadonotakashi | 0:8fdf9a60065b | 34 | |
kadonotakashi | 0:8fdf9a60065b | 35 | def _mbed_unittest_test(options, cwd, pwd): |
kadonotakashi | 0:8fdf9a60065b | 36 | if options is None: |
kadonotakashi | 0:8fdf9a60065b | 37 | return |
kadonotakashi | 0:8fdf9a60065b | 38 | |
kadonotakashi | 0:8fdf9a60065b | 39 | if options.coverage: |
kadonotakashi | 0:8fdf9a60065b | 40 | options.debug_build = True |
kadonotakashi | 0:8fdf9a60065b | 41 | |
kadonotakashi | 0:8fdf9a60065b | 42 | if options.cmake_generator is None: |
kadonotakashi | 0:8fdf9a60065b | 43 | options.cmake_generator = DEFAULT_CMAKE_GENERATORS.get( |
kadonotakashi | 0:8fdf9a60065b | 44 | options.make_program, |
kadonotakashi | 0:8fdf9a60065b | 45 | "Unix Makefiles") |
kadonotakashi | 0:8fdf9a60065b | 46 | |
kadonotakashi | 0:8fdf9a60065b | 47 | # Do not clean directory if only run. |
kadonotakashi | 0:8fdf9a60065b | 48 | if options.clean and options.run_only and not options.compile_only: |
kadonotakashi | 0:8fdf9a60065b | 49 | options.clean = False |
kadonotakashi | 0:8fdf9a60065b | 50 | |
kadonotakashi | 0:8fdf9a60065b | 51 | # Build and run by default |
kadonotakashi | 0:8fdf9a60065b | 52 | if (not options.compile_only and |
kadonotakashi | 0:8fdf9a60065b | 53 | not options.run_only and |
kadonotakashi | 0:8fdf9a60065b | 54 | not options.clean): |
kadonotakashi | 0:8fdf9a60065b | 55 | options.compile_only = True |
kadonotakashi | 0:8fdf9a60065b | 56 | options.run_only = True |
kadonotakashi | 0:8fdf9a60065b | 57 | |
kadonotakashi | 0:8fdf9a60065b | 58 | # Set build path |
kadonotakashi | 0:8fdf9a60065b | 59 | if not os.path.isabs(options.build): |
kadonotakashi | 0:8fdf9a60065b | 60 | options.build = os.path.normpath( |
kadonotakashi | 0:8fdf9a60065b | 61 | os.path.join(cwd, options.build)) |
kadonotakashi | 0:8fdf9a60065b | 62 | |
kadonotakashi | 0:8fdf9a60065b | 63 | pretty_print_test_options(options) |
kadonotakashi | 0:8fdf9a60065b | 64 | |
kadonotakashi | 0:8fdf9a60065b | 65 | # Create test tool |
kadonotakashi | 0:8fdf9a60065b | 66 | tool = UnitTestTool(make_program=options.make_program) |
kadonotakashi | 0:8fdf9a60065b | 67 | |
kadonotakashi | 0:8fdf9a60065b | 68 | # Prepare build directory |
kadonotakashi | 0:8fdf9a60065b | 69 | tool.prepare_build_directory(path_to_src=pwd, |
kadonotakashi | 0:8fdf9a60065b | 70 | build_path=options.build, |
kadonotakashi | 0:8fdf9a60065b | 71 | clean=options.clean) |
kadonotakashi | 0:8fdf9a60065b | 72 | |
kadonotakashi | 0:8fdf9a60065b | 73 | if options.compile_only: |
kadonotakashi | 0:8fdf9a60065b | 74 | # Create makefiles |
kadonotakashi | 0:8fdf9a60065b | 75 | src_path = os.path.relpath(pwd, options.build) |
kadonotakashi | 0:8fdf9a60065b | 76 | tool.create_makefiles(path_to_src=src_path, |
kadonotakashi | 0:8fdf9a60065b | 77 | generator=options.cmake_generator, |
kadonotakashi | 0:8fdf9a60065b | 78 | coverage_output_type=options.coverage, |
kadonotakashi | 0:8fdf9a60065b | 79 | debug=options.debug_build) |
kadonotakashi | 0:8fdf9a60065b | 80 | |
kadonotakashi | 0:8fdf9a60065b | 81 | # Build tests |
kadonotakashi | 0:8fdf9a60065b | 82 | tool.build_tests() |
kadonotakashi | 0:8fdf9a60065b | 83 | |
kadonotakashi | 0:8fdf9a60065b | 84 | if options.run_only: |
kadonotakashi | 0:8fdf9a60065b | 85 | tool.run_tests(filter_regex=options.test_regex) |
kadonotakashi | 0:8fdf9a60065b | 86 | |
kadonotakashi | 0:8fdf9a60065b | 87 | # If code coverage generation: |
kadonotakashi | 0:8fdf9a60065b | 88 | if options.coverage: |
kadonotakashi | 0:8fdf9a60065b | 89 | cov_api = CoverageAPI( |
kadonotakashi | 0:8fdf9a60065b | 90 | mbed_os_root=os.path.normpath(os.path.join(pwd, "..")), |
kadonotakashi | 0:8fdf9a60065b | 91 | build_dir=options.build) |
kadonotakashi | 0:8fdf9a60065b | 92 | |
kadonotakashi | 0:8fdf9a60065b | 93 | # Generate reports |
kadonotakashi | 0:8fdf9a60065b | 94 | outputs = [options.coverage] |
kadonotakashi | 0:8fdf9a60065b | 95 | if options.coverage == "both": |
kadonotakashi | 0:8fdf9a60065b | 96 | outputs = ["html", "xml"] |
kadonotakashi | 0:8fdf9a60065b | 97 | |
kadonotakashi | 0:8fdf9a60065b | 98 | excludes = [pwd, options.build] |
kadonotakashi | 0:8fdf9a60065b | 99 | |
kadonotakashi | 0:8fdf9a60065b | 100 | if not options.include_headers: |
kadonotakashi | 0:8fdf9a60065b | 101 | excludes.append(re.compile(".*\\.h")) |
kadonotakashi | 0:8fdf9a60065b | 102 | |
kadonotakashi | 0:8fdf9a60065b | 103 | cov_api.generate_reports(outputs=outputs, |
kadonotakashi | 0:8fdf9a60065b | 104 | excludes=excludes, |
kadonotakashi | 0:8fdf9a60065b | 105 | filter_regex=options.test_regex, |
kadonotakashi | 0:8fdf9a60065b | 106 | build_path=options.build) |
kadonotakashi | 0:8fdf9a60065b | 107 | |
kadonotakashi | 0:8fdf9a60065b | 108 | def _mbed_unittest_new(options, pwd): |
kadonotakashi | 0:8fdf9a60065b | 109 | if options is None: |
kadonotakashi | 0:8fdf9a60065b | 110 | return |
kadonotakashi | 0:8fdf9a60065b | 111 | |
kadonotakashi | 0:8fdf9a60065b | 112 | generator = UnitTestGeneratorTool() |
kadonotakashi | 0:8fdf9a60065b | 113 | |
kadonotakashi | 0:8fdf9a60065b | 114 | mbed_os_root = os.path.normpath( |
kadonotakashi | 0:8fdf9a60065b | 115 | os.path.join(pwd, "..") |
kadonotakashi | 0:8fdf9a60065b | 116 | ) |
kadonotakashi | 0:8fdf9a60065b | 117 | |
kadonotakashi | 0:8fdf9a60065b | 118 | for filepath in options.new_files: |
kadonotakashi | 0:8fdf9a60065b | 119 | generator.create( |
kadonotakashi | 0:8fdf9a60065b | 120 | mbed_os_root=mbed_os_root, |
kadonotakashi | 0:8fdf9a60065b | 121 | filepath=filepath) |
kadonotakashi | 0:8fdf9a60065b | 122 | |
kadonotakashi | 0:8fdf9a60065b | 123 | def mbed_unittest(options=None): |
kadonotakashi | 0:8fdf9a60065b | 124 | """ |
kadonotakashi | 0:8fdf9a60065b | 125 | Create, build and run unit tests |
kadonotakashi | 0:8fdf9a60065b | 126 | """ |
kadonotakashi | 0:8fdf9a60065b | 127 | |
kadonotakashi | 0:8fdf9a60065b | 128 | if options is None: |
kadonotakashi | 0:8fdf9a60065b | 129 | return |
kadonotakashi | 0:8fdf9a60065b | 130 | |
kadonotakashi | 0:8fdf9a60065b | 131 | cwd = os.getcwd() |
kadonotakashi | 0:8fdf9a60065b | 132 | |
kadonotakashi | 0:8fdf9a60065b | 133 | # Change current working directory to script location |
kadonotakashi | 0:8fdf9a60065b | 134 | unittest_dir = os.path.dirname(os.path.realpath(__file__)) |
kadonotakashi | 0:8fdf9a60065b | 135 | os.chdir(unittest_dir) |
kadonotakashi | 0:8fdf9a60065b | 136 | |
kadonotakashi | 0:8fdf9a60065b | 137 | if options.new_files: |
kadonotakashi | 0:8fdf9a60065b | 138 | _mbed_unittest_new(options, unittest_dir) |
kadonotakashi | 0:8fdf9a60065b | 139 | else: |
kadonotakashi | 0:8fdf9a60065b | 140 | _mbed_unittest_test(options, cwd, unittest_dir) |
kadonotakashi | 0:8fdf9a60065b | 141 | |
kadonotakashi | 0:8fdf9a60065b | 142 | def mbed_unittest_main(): |
kadonotakashi | 0:8fdf9a60065b | 143 | """ |
kadonotakashi | 0:8fdf9a60065b | 144 | Create, build and run unit tests - main |
kadonotakashi | 0:8fdf9a60065b | 145 | """ |
kadonotakashi | 0:8fdf9a60065b | 146 | |
kadonotakashi | 0:8fdf9a60065b | 147 | # Get parser and parse command line arguments |
kadonotakashi | 0:8fdf9a60065b | 148 | parser = get_options_parser() |
kadonotakashi | 0:8fdf9a60065b | 149 | options = parser.parse_args() |
kadonotakashi | 0:8fdf9a60065b | 150 | |
kadonotakashi | 0:8fdf9a60065b | 151 | # Setup logger |
kadonotakashi | 0:8fdf9a60065b | 152 | if options.log_level: |
kadonotakashi | 0:8fdf9a60065b | 153 | logging.basicConfig(level=getattr(logging, options.log_level), |
kadonotakashi | 0:8fdf9a60065b | 154 | format="%(message)s") |
kadonotakashi | 0:8fdf9a60065b | 155 | else: |
kadonotakashi | 0:8fdf9a60065b | 156 | logging.basicConfig(level=logging.INFO, |
kadonotakashi | 0:8fdf9a60065b | 157 | format="%(message)s") |
kadonotakashi | 0:8fdf9a60065b | 158 | |
kadonotakashi | 0:8fdf9a60065b | 159 | mbed_unittest(options) |
kadonotakashi | 0:8fdf9a60065b | 160 | |
kadonotakashi | 0:8fdf9a60065b | 161 | if __name__ == "__main__": |
kadonotakashi | 0:8fdf9a60065b | 162 | mbed_unittest_main() |