Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Thu Oct 11 02:27:46 2018 +0000
Revision:
3:f3764f852aa8
Parent:
0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kadonotakashi 0:8fdf9a60065b 1 """
kadonotakashi 0:8fdf9a60065b 2 Copyright (c) 2018, Arm Limited
kadonotakashi 0:8fdf9a60065b 3 SPDX-License-Identifier: Apache-2.0
kadonotakashi 0:8fdf9a60065b 4
kadonotakashi 0:8fdf9a60065b 5 Licensed under the Apache License, Version 2.0 (the "License");
kadonotakashi 0:8fdf9a60065b 6 you may not use this file except in compliance with the License.
kadonotakashi 0:8fdf9a60065b 7 You may obtain a copy of the License at
kadonotakashi 0:8fdf9a60065b 8
kadonotakashi 0:8fdf9a60065b 9 http://www.apache.org/licenses/LICENSE-2.0
kadonotakashi 0:8fdf9a60065b 10
kadonotakashi 0:8fdf9a60065b 11 Unless required by applicable law or agreed to in writing, software
kadonotakashi 0:8fdf9a60065b 12 distributed under the License is distributed on an "AS IS" BASIS,
kadonotakashi 0:8fdf9a60065b 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kadonotakashi 0:8fdf9a60065b 14 See the License for the specific language governing permissions and
kadonotakashi 0:8fdf9a60065b 15 limitations under the License.
kadonotakashi 0:8fdf9a60065b 16
kadonotakashi 0:8fdf9a60065b 17
kadonotakashi 0:8fdf9a60065b 18 UNIT TEST BUILD & RUN
kadonotakashi 0:8fdf9a60065b 19 """
kadonotakashi 0:8fdf9a60065b 20
kadonotakashi 0:8fdf9a60065b 21 import os
kadonotakashi 0:8fdf9a60065b 22 import logging
kadonotakashi 0:8fdf9a60065b 23 import sys
kadonotakashi 0:8fdf9a60065b 24 from shutil import copy
kadonotakashi 0:8fdf9a60065b 25
kadonotakashi 0:8fdf9a60065b 26 from .utils import execute_program
kadonotakashi 0:8fdf9a60065b 27 from .get_tools import get_make_tool, \
kadonotakashi 0:8fdf9a60065b 28 get_cmake_tool, \
kadonotakashi 0:8fdf9a60065b 29 get_cxx_tool, \
kadonotakashi 0:8fdf9a60065b 30 get_c_tool
kadonotakashi 0:8fdf9a60065b 31 from .settings import DEFAULT_CMAKE_GENERATORS
kadonotakashi 0:8fdf9a60065b 32
kadonotakashi 0:8fdf9a60065b 33 class UnitTestTool(object):
kadonotakashi 0:8fdf9a60065b 34 """
kadonotakashi 0:8fdf9a60065b 35 Unit test tool to:
kadonotakashi 0:8fdf9a60065b 36 - prepare build directory
kadonotakashi 0:8fdf9a60065b 37 - create makefiles
kadonotakashi 0:8fdf9a60065b 38 - build unit tests
kadonotakashi 0:8fdf9a60065b 39 - run unit tests
kadonotakashi 0:8fdf9a60065b 40 - generate code coverage reports
kadonotakashi 0:8fdf9a60065b 41 """
kadonotakashi 0:8fdf9a60065b 42
kadonotakashi 0:8fdf9a60065b 43 def __init__(self,
kadonotakashi 0:8fdf9a60065b 44 make_program=None):
kadonotakashi 0:8fdf9a60065b 45 """
kadonotakashi 0:8fdf9a60065b 46 Constructor
kadonotakashi 0:8fdf9a60065b 47
kadonotakashi 0:8fdf9a60065b 48 Keyword arguments:
kadonotakashi 0:8fdf9a60065b 49 make_program - Make tool to use
kadonotakashi 0:8fdf9a60065b 50 """
kadonotakashi 0:8fdf9a60065b 51
kadonotakashi 0:8fdf9a60065b 52 self.make_program = make_program
kadonotakashi 0:8fdf9a60065b 53
kadonotakashi 0:8fdf9a60065b 54 if self.make_program is None:
kadonotakashi 0:8fdf9a60065b 55 self.make_program = get_make_tool()
kadonotakashi 0:8fdf9a60065b 56
kadonotakashi 0:8fdf9a60065b 57 def create_makefiles(self,
kadonotakashi 0:8fdf9a60065b 58 path_to_src=None,
kadonotakashi 0:8fdf9a60065b 59 generator=None,
kadonotakashi 0:8fdf9a60065b 60 coverage_output_type=None,
kadonotakashi 0:8fdf9a60065b 61 debug=False):
kadonotakashi 0:8fdf9a60065b 62 """
kadonotakashi 0:8fdf9a60065b 63 Create Makefiles and prepare targets with CMake.
kadonotakashi 0:8fdf9a60065b 64
kadonotakashi 0:8fdf9a60065b 65 Keyword arguments:
kadonotakashi 0:8fdf9a60065b 66 path_to_src - Path to source directory
kadonotakashi 0:8fdf9a60065b 67 generator - Type of Makefiles to generate
kadonotakashi 0:8fdf9a60065b 68 coverage_output_type - Generate HTML, XML or both reports
kadonotakashi 0:8fdf9a60065b 69 debug - Target debug or release build
kadonotakashi 0:8fdf9a60065b 70 """
kadonotakashi 0:8fdf9a60065b 71
kadonotakashi 0:8fdf9a60065b 72 if generator is None:
kadonotakashi 0:8fdf9a60065b 73 generator = DEFAULT_CMAKE_GENERATORS.get(self.make_program,
kadonotakashi 0:8fdf9a60065b 74 "Unix Makefiles")
kadonotakashi 0:8fdf9a60065b 75
kadonotakashi 0:8fdf9a60065b 76 cmake = get_cmake_tool()
kadonotakashi 0:8fdf9a60065b 77
kadonotakashi 0:8fdf9a60065b 78 if cmake is None:
kadonotakashi 0:8fdf9a60065b 79 logging.error(
kadonotakashi 0:8fdf9a60065b 80 "No CMake found in Path. Install all the required tools.")
kadonotakashi 0:8fdf9a60065b 81 sys.exit(1)
kadonotakashi 0:8fdf9a60065b 82
kadonotakashi 0:8fdf9a60065b 83 args = [cmake,
kadonotakashi 0:8fdf9a60065b 84 "-G",
kadonotakashi 0:8fdf9a60065b 85 generator,
kadonotakashi 0:8fdf9a60065b 86 "-DCMAKE_MAKE_PROGRAM=%s" % self.make_program,
kadonotakashi 0:8fdf9a60065b 87 "-DCMAKE_CXX_COMPILER=%s" % get_cxx_tool(),
kadonotakashi 0:8fdf9a60065b 88 "-DCMAKE_C_COMPILER=%s" % get_c_tool()]
kadonotakashi 0:8fdf9a60065b 89
kadonotakashi 0:8fdf9a60065b 90 if debug:
kadonotakashi 0:8fdf9a60065b 91 args.append("-DCMAKE_BUILD_TYPE=Debug")
kadonotakashi 0:8fdf9a60065b 92
kadonotakashi 0:8fdf9a60065b 93 if coverage_output_type:
kadonotakashi 0:8fdf9a60065b 94 args.append("-DCOVERAGE:STRING=%s" % coverage_output_type)
kadonotakashi 0:8fdf9a60065b 95
kadonotakashi 0:8fdf9a60065b 96 if path_to_src is not None:
kadonotakashi 0:8fdf9a60065b 97 args.append(path_to_src)
kadonotakashi 0:8fdf9a60065b 98
kadonotakashi 0:8fdf9a60065b 99 execute_program(args,
kadonotakashi 0:8fdf9a60065b 100 "CMake failed to run successfully. See error message.")
kadonotakashi 0:8fdf9a60065b 101
kadonotakashi 0:8fdf9a60065b 102 def build_tests(self):
kadonotakashi 0:8fdf9a60065b 103 """
kadonotakashi 0:8fdf9a60065b 104 Build unit tests and libraries to be tested.
kadonotakashi 0:8fdf9a60065b 105 """
kadonotakashi 0:8fdf9a60065b 106
kadonotakashi 0:8fdf9a60065b 107 args = [self.make_program]
kadonotakashi 0:8fdf9a60065b 108
kadonotakashi 0:8fdf9a60065b 109 if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
kadonotakashi 0:8fdf9a60065b 110 args.append("VERBOSE=1")
kadonotakashi 0:8fdf9a60065b 111
kadonotakashi 0:8fdf9a60065b 112 execute_program(args,
kadonotakashi 0:8fdf9a60065b 113 "Building unit tests failed.",
kadonotakashi 0:8fdf9a60065b 114 "Unit tests built successfully.")
kadonotakashi 0:8fdf9a60065b 115
kadonotakashi 0:8fdf9a60065b 116 def run_tests(self, filter_regex=None):
kadonotakashi 0:8fdf9a60065b 117 """
kadonotakashi 0:8fdf9a60065b 118 Run unit tests.
kadonotakashi 0:8fdf9a60065b 119
kadonotakashi 0:8fdf9a60065b 120 Keyword arguments:
kadonotakashi 0:8fdf9a60065b 121 filter_regex - Regular expression to select which tests to run
kadonotakashi 0:8fdf9a60065b 122 """
kadonotakashi 0:8fdf9a60065b 123
kadonotakashi 0:8fdf9a60065b 124 args = [self.make_program, "test"]
kadonotakashi 0:8fdf9a60065b 125
kadonotakashi 0:8fdf9a60065b 126 if filter_regex:
kadonotakashi 0:8fdf9a60065b 127 args.append("ARGS=-R %s -V -D ExperimentalTest" % filter_regex)
kadonotakashi 0:8fdf9a60065b 128 else:
kadonotakashi 0:8fdf9a60065b 129 args.append("ARGS=-V -D ExperimentalTest")
kadonotakashi 0:8fdf9a60065b 130
kadonotakashi 0:8fdf9a60065b 131 if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
kadonotakashi 0:8fdf9a60065b 132 args.append("VERBOSE=1")
kadonotakashi 0:8fdf9a60065b 133
kadonotakashi 0:8fdf9a60065b 134 execute_program(args, "Unit test run failed.")
kadonotakashi 0:8fdf9a60065b 135
kadonotakashi 0:8fdf9a60065b 136 def prepare_build_directory(self,
kadonotakashi 0:8fdf9a60065b 137 path_to_src=None,
kadonotakashi 0:8fdf9a60065b 138 build_path=None,
kadonotakashi 0:8fdf9a60065b 139 clean=False):
kadonotakashi 0:8fdf9a60065b 140 """
kadonotakashi 0:8fdf9a60065b 141 Create build directory if not exist and
kadonotakashi 0:8fdf9a60065b 142 change current working directory to it
kadonotakashi 0:8fdf9a60065b 143
kadonotakashi 0:8fdf9a60065b 144 Keyword arguments:
kadonotakashi 0:8fdf9a60065b 145 path_to_src - Path to source directory
kadonotakashi 0:8fdf9a60065b 146 build_path - Path to build directory
kadonotakashi 0:8fdf9a60065b 147 clean - Clean build directory
kadonotakashi 0:8fdf9a60065b 148 """
kadonotakashi 0:8fdf9a60065b 149
kadonotakashi 0:8fdf9a60065b 150 if build_path is None:
kadonotakashi 0:8fdf9a60065b 151 build_path = os.getcwd()
kadonotakashi 0:8fdf9a60065b 152
kadonotakashi 0:8fdf9a60065b 153 # Clean CMake data if exists.
kadonotakashi 0:8fdf9a60065b 154 if clean:
kadonotakashi 0:8fdf9a60065b 155 self._clean_build(build_path)
kadonotakashi 0:8fdf9a60065b 156
kadonotakashi 0:8fdf9a60065b 157 # Create build directory if not exist.
kadonotakashi 0:8fdf9a60065b 158 if not os.path.exists(build_path):
kadonotakashi 0:8fdf9a60065b 159 os.makedirs(build_path)
kadonotakashi 0:8fdf9a60065b 160 filename = ".mbedignore"
kadonotakashi 0:8fdf9a60065b 161 inputfile = os.path.join(path_to_src, filename)
kadonotakashi 0:8fdf9a60065b 162 outputfile = os.path.join(build_path, filename)
kadonotakashi 0:8fdf9a60065b 163 copy(inputfile, outputfile)
kadonotakashi 0:8fdf9a60065b 164
kadonotakashi 0:8fdf9a60065b 165 # Change current working directory to build directory.
kadonotakashi 0:8fdf9a60065b 166 os.chdir(build_path)
kadonotakashi 0:8fdf9a60065b 167
kadonotakashi 0:8fdf9a60065b 168 def _clean_build(self, build_path=None):
kadonotakashi 0:8fdf9a60065b 169 """
kadonotakashi 0:8fdf9a60065b 170 Try clean build directory
kadonotakashi 0:8fdf9a60065b 171
kadonotakashi 0:8fdf9a60065b 172 Keyword arguments:
kadonotakashi 0:8fdf9a60065b 173 build_path - Path to build directory
kadonotakashi 0:8fdf9a60065b 174 """
kadonotakashi 0:8fdf9a60065b 175
kadonotakashi 0:8fdf9a60065b 176 logging.info("Cleaning build directory...")
kadonotakashi 0:8fdf9a60065b 177
kadonotakashi 0:8fdf9a60065b 178 if os.path.exists(os.path.join(build_path, "CMakeCache.txt")):
kadonotakashi 0:8fdf9a60065b 179 args = [self.make_program,
kadonotakashi 0:8fdf9a60065b 180 "-C",
kadonotakashi 0:8fdf9a60065b 181 build_path,
kadonotakashi 0:8fdf9a60065b 182 "--no-print-directory",
kadonotakashi 0:8fdf9a60065b 183 "clean"]
kadonotakashi 0:8fdf9a60065b 184
kadonotakashi 0:8fdf9a60065b 185 # Remove coverage files
kadonotakashi 0:8fdf9a60065b 186 for root, _, files in os.walk(build_path):
kadonotakashi 0:8fdf9a60065b 187 for current_file in files:
kadonotakashi 0:8fdf9a60065b 188 if current_file.endswith((".gcno", ".gcda")):
kadonotakashi 0:8fdf9a60065b 189 os.remove(os.path.join(root, current_file))
kadonotakashi 0:8fdf9a60065b 190
kadonotakashi 0:8fdf9a60065b 191 execute_program(args,
kadonotakashi 0:8fdf9a60065b 192 "Clean step failed.",
kadonotakashi 0:8fdf9a60065b 193 "Clean done.")
kadonotakashi 0:8fdf9a60065b 194
kadonotakashi 0:8fdf9a60065b 195 else:
kadonotakashi 0:8fdf9a60065b 196 logging.warning("%s does not exist or \
kadonotakashi 0:8fdf9a60065b 197 does not contain previous build data.", build_path)