Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 2 | # vim: set syntax=python ts=4 : |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3 | """Zephyr Sanity Tests |
| 4 | |
| 5 | This script scans for the set of unit test applications in the git |
| 6 | repository and attempts to execute them. By default, it tries to |
| 7 | build each test case on one platform per architecture, using a precedence |
Paul Sokolovsky | ff70add | 2017-06-16 01:31:54 +0300 | [diff] [blame] | 8 | list defined in an architecture configuration file, and if possible |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 9 | run the tests in the QEMU emulator. |
| 10 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 11 | Test cases are detected by the presence of a 'testcase.yaml' or a sample.yaml |
| 12 | files in the application's project directory. This file may contain one or more |
| 13 | blocks, each identifying a test scenario. The title of the block is a name for |
| 14 | the test case, which only needs to be unique for the test cases specified in |
| 15 | that testcase meta-data. The full canonical name for each test case is <path to |
| 16 | test case>/<block>. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 17 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 18 | Each test block in the testcase meta data can define the following key/value |
| 19 | pairs: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 20 | |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 21 | tags: <list of tags> (required) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 22 | A set of string tags for the testcase. Usually pertains to |
| 23 | functional domains but can be anything. Command line invocations |
| 24 | of this script can filter the set of tests to run based on tag. |
| 25 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 26 | skip: <True|False> (default False) |
Anas Nashif | 2bd99bc | 2015-10-12 13:10:57 -0400 | [diff] [blame] | 27 | skip testcase unconditionally. This can be used for broken tests. |
| 28 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 29 | slow: <True|False> (default False) |
Andy Ross | dc4151f | 2019-01-03 14:17:43 -0800 | [diff] [blame] | 30 | Don't build or run this test case unless --enable-slow was passed |
| 31 | in on the command line. Intended for time-consuming test cases |
| 32 | that are only run under certain circumstances, like daily |
| 33 | builds. |
Andrew Boie | 6bb087c | 2016-02-10 13:39:00 -0800 | [diff] [blame] | 34 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 35 | extra_args: <list of extra arguments> |
Sebastian Bøe | c218261 | 2017-11-09 12:25:02 +0100 | [diff] [blame] | 36 | Extra cache entries to pass to CMake when building or running the |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 37 | test case. |
| 38 | |
Anas Nashif | ebc329d | 2017-10-17 09:00:33 -0400 | [diff] [blame] | 39 | extra_configs: <list of extra configurations> |
| 40 | Extra configuration options to be merged with a master prj.conf |
| 41 | when building or running the test case. |
| 42 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 43 | build_only: <True|False> (default False) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 44 | If true, don't try to run the test under QEMU even if the |
| 45 | selected platform supports it. |
| 46 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 47 | build_on_all: <True|False> (default False) |
| 48 | If true, attempt to build test on all available platforms. |
| 49 | |
| 50 | depends_on: <list of features> |
| 51 | A board or platform can announce what features it supports, this option |
| 52 | will enable the test only those platforms that provide this feature. |
| 53 | |
| 54 | min_ram: <integer> |
| 55 | minimum amount of RAM needed for this test to build and run. This is |
| 56 | compared with information provided by the board metadata. |
| 57 | |
| 58 | min_flash: <integer> |
| 59 | minimum amount of ROM needed for this test to build and run. This is |
| 60 | compared with information provided by the board metadata. |
| 61 | |
| 62 | timeout: <number of seconds> |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 63 | Length of time to run test in QEMU before automatically killing it. |
| 64 | Default to 60 seconds. |
| 65 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 66 | arch_whitelist: <list of arches, such as x86, arm, arc> |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 67 | Set of architectures that this test case should only be run for. |
| 68 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 69 | arch_exclude: <list of arches, such as x86, arm, arc> |
Anas Nashif | 30d1387 | 2015-10-05 10:02:45 -0400 | [diff] [blame] | 70 | Set of architectures that this test case should not run on. |
| 71 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 72 | platform_whitelist: <list of platforms> |
Anas Nashif | 30d1387 | 2015-10-05 10:02:45 -0400 | [diff] [blame] | 73 | Set of platforms that this test case should only be run for. |
| 74 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 75 | platform_exclude: <list of platforms> |
Anas Nashif | 30d1387 | 2015-10-05 10:02:45 -0400 | [diff] [blame] | 76 | Set of platforms that this test case should not run on. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 77 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 78 | extra_sections: <list of extra binary sections> |
Andrew Boie | 52fef67 | 2016-11-29 12:21:59 -0800 | [diff] [blame] | 79 | When computing sizes, sanitycheck will report errors if it finds |
| 80 | extra, unexpected sections in the Zephyr binary unless they are named |
| 81 | here. They will not be included in the size calculation. |
| 82 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 83 | filter: <expression> |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 84 | Filter whether the testcase should be run by evaluating an expression |
| 85 | against an environment containing the following values: |
| 86 | |
| 87 | { ARCH : <architecture>, |
| 88 | PLATFORM : <platform>, |
Javier B Perez | 7941454 | 2016-08-08 12:24:59 -0500 | [diff] [blame] | 89 | <all CONFIG_* key/value pairs in the test's generated defconfig>, |
Anas Nashif | 45a9786 | 2019-01-09 08:46:42 -0500 | [diff] [blame] | 90 | <all DT_* key/value pairs in the test's generated device tree file>, |
| 91 | <all CMake key/value pairs in the test's generated CMakeCache.txt file>, |
Javier B Perez | 7941454 | 2016-08-08 12:24:59 -0500 | [diff] [blame] | 92 | *<env>: any environment variable available |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | The grammar for the expression language is as follows: |
| 96 | |
| 97 | expression ::= expression "and" expression |
| 98 | | expression "or" expression |
| 99 | | "not" expression |
| 100 | | "(" expression ")" |
| 101 | | symbol "==" constant |
| 102 | | symbol "!=" constant |
| 103 | | symbol "<" number |
| 104 | | symbol ">" number |
| 105 | | symbol ">=" number |
| 106 | | symbol "<=" number |
| 107 | | symbol "in" list |
Andrew Boie | 7a87f9f | 2016-06-02 12:27:54 -0700 | [diff] [blame] | 108 | | symbol ":" string |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 109 | | symbol |
| 110 | |
| 111 | list ::= "[" list_contents "]" |
| 112 | |
| 113 | list_contents ::= constant |
| 114 | | list_contents "," constant |
| 115 | |
| 116 | constant ::= number |
| 117 | | string |
| 118 | |
| 119 | |
| 120 | For the case where expression ::= symbol, it evaluates to true |
| 121 | if the symbol is defined to a non-empty string. |
| 122 | |
| 123 | Operator precedence, starting from lowest to highest: |
| 124 | |
| 125 | or (left associative) |
| 126 | and (left associative) |
| 127 | not (right associative) |
| 128 | all comparison operators (non-associative) |
| 129 | |
| 130 | arch_whitelist, arch_exclude, platform_whitelist, platform_exclude |
| 131 | are all syntactic sugar for these expressions. For instance |
| 132 | |
| 133 | arch_exclude = x86 arc |
| 134 | |
| 135 | Is the same as: |
| 136 | |
| 137 | filter = not ARCH in ["x86", "arc"] |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 138 | |
Andrew Boie | 7a87f9f | 2016-06-02 12:27:54 -0700 | [diff] [blame] | 139 | The ':' operator compiles the string argument as a regular expression, |
| 140 | and then returns a true value only if the symbol's value in the environment |
| 141 | matches. For example, if CONFIG_SOC="quark_se" then |
| 142 | |
| 143 | filter = CONFIG_SOC : "quark.*" |
| 144 | |
| 145 | Would match it. |
| 146 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 147 | The set of test cases that actually run depends on directives in the testcase |
| 148 | filed and options passed in on the command line. If there is any confusion, |
| 149 | running with -v or --discard-report can help show why particular test cases |
| 150 | were skipped. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 151 | |
| 152 | Metrics (such as pass/fail state and binary size) for the last code |
| 153 | release are stored in scripts/sanity_chk/sanity_last_release.csv. |
| 154 | To update this, pass the --all --release options. |
| 155 | |
Genaro Saucedo Tejada | 28bba92 | 2016-10-24 18:00:58 -0500 | [diff] [blame] | 156 | To load arguments from a file, write '+' before the file name, e.g., |
| 157 | +file_name. File content must be one or more valid arguments separated by |
| 158 | line break instead of white spaces. |
| 159 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 160 | Most everyday users will run with no arguments. |
Andy Ross | dc4151f | 2019-01-03 14:17:43 -0800 | [diff] [blame] | 161 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 162 | """ |
| 163 | |
Sebastian Bøe | 56d7471 | 2019-01-21 15:48:46 +0100 | [diff] [blame] | 164 | import os |
| 165 | |
| 166 | if os.name == 'nt': |
| 167 | print("Running sanitycheck on Windows is not supported yet.") |
| 168 | print("https://github.com/zephyrproject-rtos/zephyr/issues/2664") |
| 169 | exit(1) |
| 170 | |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 171 | import contextlib |
Anas Nashif | a4c368e | 2018-10-15 09:45:59 -0400 | [diff] [blame] | 172 | import string |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 173 | import mmap |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 174 | import argparse |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 175 | import sys |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 176 | import re |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 177 | import subprocess |
| 178 | import multiprocessing |
| 179 | import select |
| 180 | import shutil |
| 181 | import signal |
| 182 | import threading |
| 183 | import time |
| 184 | import csv |
Andrew Boie | 5d4eb78 | 2015-10-02 10:04:56 -0700 | [diff] [blame] | 185 | import glob |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 186 | import serial |
Daniel Leung | 6b17007 | 2016-04-07 12:10:25 -0700 | [diff] [blame] | 187 | import concurrent |
| 188 | import concurrent.futures |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 189 | import xml.etree.ElementTree as ET |
Anas Nashif | e6fcc01 | 2017-05-17 09:29:09 -0400 | [diff] [blame] | 190 | from xml.sax.saxutils import escape |
Anas Nashif | 035799f | 2017-05-13 21:31:53 -0400 | [diff] [blame] | 191 | from collections import OrderedDict |
| 192 | from itertools import islice |
Anas Nashif | 1a5bba7 | 2018-01-05 08:07:45 -0500 | [diff] [blame] | 193 | from functools import cmp_to_key |
Anas Nashif | e24350c | 2018-07-11 15:09:22 -0500 | [diff] [blame] | 194 | from pathlib import Path |
| 195 | from distutils.spawn import find_executable |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 196 | |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 197 | import logging |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 198 | from sanity_chk import scl |
| 199 | from sanity_chk import expr_parser |
| 200 | |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 201 | log_format = "%(levelname)s %(name)s::%(module)s.%(funcName)s():%(lineno)d: %(message)s" |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 202 | logging.basicConfig(format=log_format, level=30) |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 203 | |
Oleg Zhurakivskyy | 4282208 | 2018-08-17 14:54:41 +0300 | [diff] [blame] | 204 | ZEPHYR_BASE = os.environ.get("ZEPHYR_BASE") |
| 205 | if not ZEPHYR_BASE: |
Anas Nashif | 427cdd3 | 2015-08-06 07:25:42 -0400 | [diff] [blame] | 206 | sys.stderr.write("$ZEPHYR_BASE environment variable undefined.\n") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 207 | exit(1) |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 208 | |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 209 | sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/")) |
| 210 | |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 211 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 212 | VERBOSE = 0 |
| 213 | LAST_SANITY = os.path.join(ZEPHYR_BASE, "scripts", "sanity_chk", |
| 214 | "last_sanity.csv") |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 215 | LAST_SANITY_XUNIT = os.path.join(ZEPHYR_BASE, "scripts", "sanity_chk", |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 216 | "last_sanity.xml") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 217 | RELEASE_DATA = os.path.join(ZEPHYR_BASE, "scripts", "sanity_chk", |
| 218 | "sanity_last_release.csv") |
Oleg Zhurakivskyy | f3bc967 | 2018-08-17 18:31:38 +0300 | [diff] [blame] | 219 | JOBS = multiprocessing.cpu_count() * 2 |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 220 | |
| 221 | if os.isatty(sys.stdout.fileno()): |
| 222 | TERMINAL = True |
| 223 | COLOR_NORMAL = '\033[0m' |
| 224 | COLOR_RED = '\033[91m' |
| 225 | COLOR_GREEN = '\033[92m' |
| 226 | COLOR_YELLOW = '\033[93m' |
| 227 | else: |
| 228 | TERMINAL = False |
| 229 | COLOR_NORMAL = "" |
| 230 | COLOR_RED = "" |
| 231 | COLOR_GREEN = "" |
| 232 | COLOR_YELLOW = "" |
| 233 | |
Anas Nashif | 45a9786 | 2019-01-09 08:46:42 -0500 | [diff] [blame] | 234 | class CMakeCacheEntry: |
| 235 | '''Represents a CMake cache entry. |
| 236 | |
| 237 | This class understands the type system in a CMakeCache.txt, and |
| 238 | converts the following cache types to Python types: |
| 239 | |
| 240 | Cache Type Python type |
| 241 | ---------- ------------------------------------------- |
| 242 | FILEPATH str |
| 243 | PATH str |
| 244 | STRING str OR list of str (if ';' is in the value) |
| 245 | BOOL bool |
| 246 | INTERNAL str OR list of str (if ';' is in the value) |
| 247 | ---------- ------------------------------------------- |
| 248 | ''' |
| 249 | |
| 250 | # Regular expression for a cache entry. |
| 251 | # |
| 252 | # CMake variable names can include escape characters, allowing a |
| 253 | # wider set of names than is easy to match with a regular |
| 254 | # expression. To be permissive here, use a non-greedy match up to |
| 255 | # the first colon (':'). This breaks if the variable name has a |
| 256 | # colon inside, but it's good enough. |
| 257 | CACHE_ENTRY = re.compile( |
| 258 | r'''(?P<name>.*?) # name |
| 259 | :(?P<type>FILEPATH|PATH|STRING|BOOL|INTERNAL) # type |
| 260 | =(?P<value>.*) # value |
| 261 | ''', re.X) |
| 262 | |
| 263 | @classmethod |
| 264 | def _to_bool(cls, val): |
| 265 | # Convert a CMake BOOL string into a Python bool. |
| 266 | # |
| 267 | # "True if the constant is 1, ON, YES, TRUE, Y, or a |
| 268 | # non-zero number. False if the constant is 0, OFF, NO, |
| 269 | # FALSE, N, IGNORE, NOTFOUND, the empty string, or ends in |
| 270 | # the suffix -NOTFOUND. Named boolean constants are |
| 271 | # case-insensitive. If the argument is not one of these |
| 272 | # constants, it is treated as a variable." |
| 273 | # |
| 274 | # https://cmake.org/cmake/help/v3.0/command/if.html |
| 275 | val = val.upper() |
| 276 | if val in ('ON', 'YES', 'TRUE', 'Y'): |
| 277 | return 1 |
| 278 | elif val in ('OFF', 'NO', 'FALSE', 'N', 'IGNORE', 'NOTFOUND', ''): |
| 279 | return 0 |
| 280 | elif val.endswith('-NOTFOUND'): |
| 281 | return 0 |
| 282 | else: |
| 283 | try: |
| 284 | v = int(val) |
| 285 | return v != 0 |
| 286 | except ValueError as exc: |
| 287 | raise ValueError('invalid bool {}'.format(val)) from exc |
| 288 | |
| 289 | @classmethod |
| 290 | def from_line(cls, line, line_no): |
| 291 | # Comments can only occur at the beginning of a line. |
| 292 | # (The value of an entry could contain a comment character). |
| 293 | if line.startswith('//') or line.startswith('#'): |
| 294 | return None |
| 295 | |
| 296 | # Whitespace-only lines do not contain cache entries. |
| 297 | if not line.strip(): |
| 298 | return None |
| 299 | |
| 300 | m = cls.CACHE_ENTRY.match(line) |
| 301 | if not m: |
| 302 | return None |
| 303 | |
| 304 | name, type_, value = (m.group(g) for g in ('name', 'type', 'value')) |
| 305 | if type_ == 'BOOL': |
| 306 | try: |
| 307 | value = cls._to_bool(value) |
| 308 | except ValueError as exc: |
| 309 | args = exc.args + ('on line {}: {}'.format(line_no, line),) |
| 310 | raise ValueError(args) from exc |
| 311 | elif type_ == 'STRING' or type_ == 'INTERNAL': |
| 312 | # If the value is a CMake list (i.e. is a string which |
| 313 | # contains a ';'), convert to a Python list. |
| 314 | if ';' in value: |
| 315 | value = value.split(';') |
| 316 | |
| 317 | return CMakeCacheEntry(name, value) |
| 318 | |
| 319 | def __init__(self, name, value): |
| 320 | self.name = name |
| 321 | self.value = value |
| 322 | |
| 323 | def __str__(self): |
| 324 | fmt = 'CMakeCacheEntry(name={}, value={})' |
| 325 | return fmt.format(self.name, self.value) |
| 326 | |
| 327 | |
| 328 | class CMakeCache: |
| 329 | '''Parses and represents a CMake cache file.''' |
| 330 | |
| 331 | @staticmethod |
| 332 | def from_file(cache_file): |
| 333 | return CMakeCache(cache_file) |
| 334 | |
| 335 | def __init__(self, cache_file): |
| 336 | self.cache_file = cache_file |
| 337 | self.load(cache_file) |
| 338 | |
| 339 | def load(self, cache_file): |
| 340 | entries = [] |
| 341 | with open(cache_file, 'r') as cache: |
| 342 | for line_no, line in enumerate(cache): |
| 343 | entry = CMakeCacheEntry.from_line(line, line_no) |
| 344 | if entry: |
| 345 | entries.append(entry) |
| 346 | self._entries = OrderedDict((e.name, e) for e in entries) |
| 347 | |
| 348 | def get(self, name, default=None): |
| 349 | entry = self._entries.get(name) |
| 350 | if entry is not None: |
| 351 | return entry.value |
| 352 | else: |
| 353 | return default |
| 354 | |
| 355 | def get_list(self, name, default=None): |
| 356 | if default is None: |
| 357 | default = [] |
| 358 | entry = self._entries.get(name) |
| 359 | if entry is not None: |
| 360 | value = entry.value |
| 361 | if isinstance(value, list): |
| 362 | return value |
| 363 | elif isinstance(value, str): |
| 364 | return [value] if value else [] |
| 365 | else: |
| 366 | msg = 'invalid value {} type {}' |
| 367 | raise RuntimeError(msg.format(value, type(value))) |
| 368 | else: |
| 369 | return default |
| 370 | |
| 371 | def __contains__(self, name): |
| 372 | return name in self._entries |
| 373 | |
| 374 | def __getitem__(self, name): |
| 375 | return self._entries[name].value |
| 376 | |
| 377 | def __setitem__(self, name, entry): |
| 378 | if not isinstance(entry, CMakeCacheEntry): |
| 379 | msg = 'improper type {} for value {}, expecting CMakeCacheEntry' |
| 380 | raise TypeError(msg.format(type(entry), entry)) |
| 381 | self._entries[name] = entry |
| 382 | |
| 383 | def __delitem__(self, name): |
| 384 | del self._entries[name] |
| 385 | |
| 386 | def __iter__(self): |
| 387 | return iter(self._entries.values()) |
| 388 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 389 | class SanityCheckException(Exception): |
| 390 | pass |
| 391 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 392 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 393 | class SanityRuntimeError(SanityCheckException): |
| 394 | pass |
| 395 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 396 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 397 | class ConfigurationError(SanityCheckException): |
| 398 | def __init__(self, cfile, message): |
| 399 | self.cfile = cfile |
| 400 | self.message = message |
| 401 | |
| 402 | def __str__(self): |
| 403 | return repr(self.cfile + ": " + self.message) |
| 404 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 405 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 406 | class MakeError(SanityCheckException): |
| 407 | pass |
| 408 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 409 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 410 | class BuildError(MakeError): |
| 411 | pass |
| 412 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 413 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 414 | class ExecutionError(MakeError): |
| 415 | pass |
| 416 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 417 | |
Inaky Perez-Gonzalez | 9a36cb6 | 2016-11-29 10:43:40 -0800 | [diff] [blame] | 418 | log_file = None |
| 419 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 420 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 421 | # Debug Functions |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 422 | def info(what): |
| 423 | sys.stdout.write(what + "\n") |
Paul Sokolovsky | 3ba0876 | 2017-10-27 14:53:24 +0300 | [diff] [blame] | 424 | sys.stdout.flush() |
Inaky Perez-Gonzalez | 9a36cb6 | 2016-11-29 10:43:40 -0800 | [diff] [blame] | 425 | if log_file: |
| 426 | log_file.write(what + "\n") |
| 427 | log_file.flush() |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 428 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 429 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 430 | def error(what): |
| 431 | sys.stderr.write(COLOR_RED + what + COLOR_NORMAL + "\n") |
Inaky Perez-Gonzalez | 9a36cb6 | 2016-11-29 10:43:40 -0800 | [diff] [blame] | 432 | if log_file: |
| 433 | log_file(what + "\n") |
| 434 | log_file.flush() |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 435 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 436 | |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 437 | def debug(what): |
| 438 | if VERBOSE >= 1: |
| 439 | info(what) |
| 440 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 441 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 442 | def verbose(what): |
| 443 | if VERBOSE >= 2: |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 444 | info(what) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 445 | |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 446 | class HarnessImporter: |
| 447 | |
| 448 | def __init__(self, name): |
| 449 | sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/sanity_chk")) |
| 450 | module = __import__("harness") |
| 451 | if name: |
| 452 | my_class = getattr(module, name) |
| 453 | else: |
| 454 | my_class = getattr(module, "Test") |
| 455 | |
| 456 | self.instance = my_class() |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 457 | |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 458 | class Handler: |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 459 | def __init__(self, instance): |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 460 | """Constructor |
| 461 | |
| 462 | @param name Arbitrary name of the created thread |
Anas Nashif | 66bdb32 | 2017-11-25 17:20:07 -0500 | [diff] [blame] | 463 | @param outdir Working directory, should be where handler pid file (qemu.pid for example) |
| 464 | gets created by the build system |
| 465 | @param log_fn Absolute path to write out handler's log data |
| 466 | @param timeout Kill the handler process if it doesn't finish up within |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 467 | the given number of seconds |
| 468 | """ |
| 469 | self.lock = threading.Lock() |
| 470 | self.state = "waiting" |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 471 | self.run = False |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 472 | self.metrics = {} |
Anas Nashif | c8390f1 | 2017-11-25 17:14:12 -0500 | [diff] [blame] | 473 | self.metrics["handler_time"] = 0 |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 474 | self.metrics["ram_size"] = 0 |
| 475 | self.metrics["rom_size"] = 0 |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 476 | |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 477 | self.binary = None |
Jan Kowalewski | 265895b | 2019-01-07 16:40:24 +0100 | [diff] [blame] | 478 | self.pid_fn = None |
Anas Nashif | 99f5a6c | 2018-07-07 08:45:53 -0500 | [diff] [blame] | 479 | self.call_make_run = False |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 480 | |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 481 | self.name = instance.name |
| 482 | self.instance = instance |
| 483 | self.timeout = instance.test.timeout |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 484 | self.sourcedir = instance.test.test_path |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 485 | self.outdir = instance.outdir |
Anas Nashif | 4a9f3e6 | 2018-07-06 18:58:18 -0500 | [diff] [blame] | 486 | self.log = os.path.join(self.outdir, "handler.log") |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 487 | self.returncode = 0 |
| 488 | self.set_state("running", {}) |
| 489 | |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 490 | def set_state(self, state, metrics): |
| 491 | self.lock.acquire() |
| 492 | self.state = state |
| 493 | self.metrics.update(metrics) |
| 494 | self.lock.release() |
| 495 | |
| 496 | def get_state(self): |
| 497 | self.lock.acquire() |
| 498 | ret = (self.state, self.metrics) |
| 499 | self.lock.release() |
| 500 | return ret |
| 501 | |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 502 | class BinaryHandler(Handler): |
| 503 | def __init__(self, instance): |
| 504 | """Constructor |
| 505 | |
| 506 | @param instance Test Instance |
| 507 | """ |
| 508 | super().__init__(instance) |
| 509 | |
| 510 | self.valgrind = False |
Alberto Escolar Piedras | 661bc82 | 2018-12-11 15:13:05 +0100 | [diff] [blame] | 511 | self.terminated = False |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 512 | |
Jan Kowalewski | 265895b | 2019-01-07 16:40:24 +0100 | [diff] [blame] | 513 | def try_kill_process_by_pid(self): |
| 514 | if self.pid_fn != None: |
| 515 | pid = int(open(self.pid_fn).read()) |
| 516 | os.unlink(self.pid_fn) |
| 517 | self.pid_fn = None # clear so we don't try to kill the binary twice |
| 518 | try: |
| 519 | os.kill(pid, signal.SIGTERM) |
| 520 | except ProcessLookupError: |
| 521 | pass |
| 522 | |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 523 | def _output_reader(self, proc, harness): |
| 524 | log_out_fp = open(self.log, "wt") |
| 525 | for line in iter(proc.stdout.readline, b''): |
| 526 | verbose("OUTPUT: {0}".format(line.decode('utf-8').rstrip())) |
| 527 | log_out_fp.write(line.decode('utf-8')) |
| 528 | log_out_fp.flush() |
| 529 | harness.handle(line.decode('utf-8').rstrip()) |
| 530 | if harness.state: |
Alberto Escolar Piedras | 661bc82 | 2018-12-11 15:13:05 +0100 | [diff] [blame] | 531 | try: |
| 532 | #POSIX arch based ztests end on their own, |
| 533 | #so let's give it up to 100ms to do so |
| 534 | proc.wait(0.1) |
| 535 | except subprocess.TimeoutExpired: |
| 536 | proc.terminate() |
| 537 | self.terminated = True |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 538 | break |
| 539 | |
| 540 | log_out_fp.close() |
| 541 | |
| 542 | def handle(self): |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 543 | |
| 544 | harness_name = self.instance.test.harness.capitalize() |
| 545 | harness_import = HarnessImporter(harness_name) |
| 546 | harness = harness_import.instance |
| 547 | harness.configure(self.instance) |
| 548 | |
Anas Nashif | 99f5a6c | 2018-07-07 08:45:53 -0500 | [diff] [blame] | 549 | if self.call_make_run: |
| 550 | if options.ninja: |
| 551 | generator_cmd = "ninja" |
| 552 | else: |
| 553 | generator_cmd = "make" |
| 554 | command = [generator_cmd, "-C", self.outdir, "run"] |
| 555 | else: |
| 556 | command = [self.binary] |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 557 | |
| 558 | if shutil.which("valgrind") and self.valgrind: |
| 559 | command = ["valgrind", "--error-exitcode=2", |
Alberto Escolar Piedras | 3980e0c | 2018-12-12 17:41:04 +0100 | [diff] [blame] | 560 | "--leak-check=full", |
| 561 | "--suppressions="+ZEPHYR_BASE+"/scripts/valgrind.supp", |
| 562 | "--log-file="+self.outdir+"/valgrind.log" |
| 563 | ] + command |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 564 | |
| 565 | with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc: |
| 566 | t = threading.Thread(target=self._output_reader, args=(proc, harness, )) |
| 567 | t.start() |
| 568 | t.join(self.timeout) |
| 569 | if t.is_alive(): |
Jan Kowalewski | 265895b | 2019-01-07 16:40:24 +0100 | [diff] [blame] | 570 | self.try_kill_process_by_pid() |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 571 | proc.terminate() |
Alberto Escolar Piedras | 661bc82 | 2018-12-11 15:13:05 +0100 | [diff] [blame] | 572 | self.terminated = True |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 573 | t.join() |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 574 | proc.wait() |
| 575 | self.returncode = proc.returncode |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 576 | |
| 577 | if options.enable_coverage: |
| 578 | returncode = subprocess.call(["GCOV_PREFIX=" + self.outdir, |
| 579 | "gcov", self.sourcedir, "-b", "-s", self.outdir], shell=True) |
| 580 | |
Jan Kowalewski | 265895b | 2019-01-07 16:40:24 +0100 | [diff] [blame] | 581 | self.try_kill_process_by_pid() |
| 582 | |
Anas Nashif | 99f5a6c | 2018-07-07 08:45:53 -0500 | [diff] [blame] | 583 | # FIME: This is needed when killing the simulator, the console is |
| 584 | # garbled and needs to be reset. Did not find a better way to do that. |
| 585 | |
| 586 | subprocess.call(["stty", "sane"]) |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 587 | self.instance.results = harness.tests |
Alberto Escolar Piedras | 661bc82 | 2018-12-11 15:13:05 +0100 | [diff] [blame] | 588 | if self.terminated==False and self.returncode != 0: |
| 589 | #When a process is killed, the default handler returns 128 + SIGTERM |
| 590 | #so in that case the return code itself is not meaningful |
| 591 | self.set_state("error", {}) |
| 592 | elif harness.state: |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 593 | self.set_state(harness.state, {}) |
| 594 | else: |
Alberto Escolar Piedras | 661bc82 | 2018-12-11 15:13:05 +0100 | [diff] [blame] | 595 | self.set_state("timeout", {}) |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 596 | |
| 597 | class DeviceHandler(Handler): |
| 598 | |
| 599 | def __init__(self, instance): |
| 600 | """Constructor |
| 601 | |
| 602 | @param instance Test Instance |
| 603 | """ |
| 604 | super().__init__(instance) |
| 605 | |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 606 | def monitor_serial(self, ser, halt_fileno, harness): |
Anas Nashif | 4a9f3e6 | 2018-07-06 18:58:18 -0500 | [diff] [blame] | 607 | log_out_fp = open(self.log, "wt") |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 608 | |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 609 | ser_fileno = ser.fileno() |
| 610 | readlist = [halt_fileno, ser_fileno] |
| 611 | |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 612 | while ser.isOpen(): |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 613 | readable, _, _ = select.select(readlist, [], [], self.timeout) |
| 614 | |
| 615 | if halt_fileno in readable: |
| 616 | verbose('halted') |
| 617 | ser.close() |
| 618 | break |
| 619 | if ser_fileno not in readable: |
| 620 | continue # Timeout. |
| 621 | |
| 622 | serial_line = None |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 623 | try: |
| 624 | serial_line = ser.readline() |
| 625 | except TypeError: |
| 626 | pass |
Anas Nashif | 5923760 | 2019-03-03 10:36:35 -0500 | [diff] [blame] | 627 | except serial.serialutil.SerialException: |
| 628 | ser.close() |
| 629 | break |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 630 | |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 631 | # Just because ser_fileno has data doesn't mean an entire line |
| 632 | # is available yet. |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 633 | if serial_line: |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 634 | sl = serial_line.decode('utf-8', 'ignore') |
| 635 | verbose("DEVICE: {0}".format(sl.rstrip())) |
| 636 | |
| 637 | log_out_fp.write(sl) |
| 638 | log_out_fp.flush() |
| 639 | harness.handle(sl.rstrip()) |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 640 | |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 641 | if harness.state: |
| 642 | ser.close() |
| 643 | break |
| 644 | |
| 645 | log_out_fp.close() |
| 646 | |
| 647 | def handle(self): |
| 648 | out_state = "failed" |
| 649 | |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 650 | if options.ninja: |
| 651 | generator_cmd = "ninja" |
| 652 | else: |
| 653 | generator_cmd = "make" |
| 654 | |
| 655 | command = [generator_cmd, "-C", self.outdir, "flash"] |
| 656 | |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 657 | device = options.device_serial |
| 658 | ser = serial.Serial( |
| 659 | device, |
| 660 | baudrate=115200, |
| 661 | parity=serial.PARITY_NONE, |
| 662 | stopbits=serial.STOPBITS_ONE, |
| 663 | bytesize=serial.EIGHTBITS, |
| 664 | timeout=self.timeout |
| 665 | ) |
| 666 | |
| 667 | ser.flush() |
| 668 | |
| 669 | harness_name = self.instance.test.harness.capitalize() |
| 670 | harness_import = HarnessImporter(harness_name) |
| 671 | harness = harness_import.instance |
| 672 | harness.configure(self.instance) |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 673 | rpipe, wpipe = os.pipe() |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 674 | |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 675 | t = threading.Thread(target=self.monitor_serial, daemon=True, |
| 676 | args=(ser, rpipe, harness)) |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 677 | t.start() |
| 678 | |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 679 | try: |
Marti Bolivar | 303b522 | 2019-02-07 15:50:55 -0700 | [diff] [blame] | 680 | if VERBOSE: |
| 681 | subprocess.check_call(command) |
| 682 | else: |
| 683 | subprocess.check_output(command, stderr=subprocess.PIPE) |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 684 | except subprocess.CalledProcessError: |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 685 | os.write(wpipe, b'x') # halt the thread |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 686 | |
| 687 | t.join(self.timeout) |
| 688 | if t.is_alive(): |
| 689 | out_state = "timeout" |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 690 | |
| 691 | if ser.isOpen(): |
| 692 | ser.close() |
| 693 | |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 694 | if out_state == "timeout": |
| 695 | for c in self.instance.test.cases: |
| 696 | if c not in harness.tests: |
| 697 | harness.tests[c] = "BLOCK" |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 698 | |
| 699 | self.instance.results = harness.tests |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 700 | if harness.state: |
| 701 | self.set_state(harness.state, {}) |
| 702 | else: |
| 703 | self.set_state(out_state, {}) |
| 704 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 705 | |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 706 | class QEMUHandler(Handler): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 707 | """Spawns a thread to monitor QEMU output from pipes |
| 708 | |
Anas Nashif | 3ac7b3a | 2017-08-03 10:03:02 -0400 | [diff] [blame] | 709 | We pass QEMU_PIPE to 'make run' and monitor the pipes for output. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 710 | We need to do this as once qemu starts, it runs forever until killed. |
| 711 | Test cases emit special messages to the console as they run, we check |
| 712 | for these to collect whether the test passed or failed. |
| 713 | """ |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 714 | |
| 715 | @staticmethod |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 716 | def _thread(handler, timeout, outdir, logfile, fifo_fn, pid_fn, results, harness): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 717 | fifo_in = fifo_fn + ".in" |
| 718 | fifo_out = fifo_fn + ".out" |
| 719 | |
| 720 | # These in/out nodes are named from QEMU's perspective, not ours |
| 721 | if os.path.exists(fifo_in): |
| 722 | os.unlink(fifo_in) |
| 723 | os.mkfifo(fifo_in) |
| 724 | if os.path.exists(fifo_out): |
| 725 | os.unlink(fifo_out) |
| 726 | os.mkfifo(fifo_out) |
| 727 | |
| 728 | # We don't do anything with out_fp but we need to open it for |
| 729 | # writing so that QEMU doesn't block, due to the way pipes work |
| 730 | out_fp = open(fifo_in, "wb") |
| 731 | # Disable internal buffering, we don't |
| 732 | # want read() or poll() to ever block if there is data in there |
| 733 | in_fp = open(fifo_out, "rb", buffering=0) |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 734 | log_out_fp = open(logfile, "wt") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 735 | |
| 736 | start_time = time.time() |
| 737 | timeout_time = start_time + timeout |
| 738 | p = select.poll() |
| 739 | p.register(in_fp, select.POLLIN) |
Anas Nashif | 39ae72b | 2018-08-29 01:45:38 -0400 | [diff] [blame] | 740 | out_state = None |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 741 | |
| 742 | metrics = {} |
| 743 | line = "" |
Anas Nashif | 74dbe33 | 2019-01-17 17:11:37 -0500 | [diff] [blame] | 744 | timeout_extended = False |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 745 | while True: |
| 746 | this_timeout = int((timeout_time - time.time()) * 1000) |
| 747 | if this_timeout < 0 or not p.poll(this_timeout): |
Anas Nashif | 39ae72b | 2018-08-29 01:45:38 -0400 | [diff] [blame] | 748 | if not out_state: |
| 749 | out_state = "timeout" |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 750 | break |
| 751 | |
Genaro Saucedo Tejada | 2968b36 | 2016-08-09 15:11:53 -0500 | [diff] [blame] | 752 | try: |
| 753 | c = in_fp.read(1).decode("utf-8") |
| 754 | except UnicodeDecodeError: |
| 755 | # Test is writing something weird, fail |
| 756 | out_state = "unexpected byte" |
| 757 | break |
| 758 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 759 | if c == "": |
| 760 | # EOF, this shouldn't happen unless QEMU crashes |
| 761 | out_state = "unexpected eof" |
| 762 | break |
| 763 | line = line + c |
| 764 | if c != "\n": |
| 765 | continue |
| 766 | |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 767 | # line contains a full line of data output from QEMU |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 768 | log_out_fp.write(line) |
| 769 | log_out_fp.flush() |
| 770 | line = line.strip() |
| 771 | verbose("QEMU: %s" % line) |
| 772 | |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 773 | harness.handle(line) |
| 774 | if harness.state: |
Anas Nashif | 39ae72b | 2018-08-29 01:45:38 -0400 | [diff] [blame] | 775 | # if we have registered a fail make sure the state is not |
| 776 | # overridden by a false success message coming from the |
| 777 | # testsuite |
| 778 | if out_state != 'failed': |
| 779 | out_state = harness.state |
| 780 | |
| 781 | # if we get some state, that means test is doing well, we reset |
Anas Nashif | 74dbe33 | 2019-01-17 17:11:37 -0500 | [diff] [blame] | 782 | # the timeout and wait for 2 more seconds just in case we have |
Anas Nashif | 39ae72b | 2018-08-29 01:45:38 -0400 | [diff] [blame] | 783 | # crashed after test has completed |
Anas Nashif | f29087e | 2019-01-25 09:37:38 -0500 | [diff] [blame] | 784 | if not timeout_extended or harness.capture_coverage: |
| 785 | timeout_extended= True |
| 786 | if harness.capture_coverage: |
| 787 | timeout_time = time.time() + 10 |
| 788 | else: |
Anas Nashif | 74dbe33 | 2019-01-17 17:11:37 -0500 | [diff] [blame] | 789 | timeout_time = time.time() + 2 |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 790 | |
| 791 | # TODO: Add support for getting numerical performance data |
| 792 | # from test cases. Will involve extending test case reporting |
| 793 | # APIs. Add whatever gets reported to the metrics dictionary |
| 794 | line = "" |
| 795 | |
Anas Nashif | c8390f1 | 2017-11-25 17:14:12 -0500 | [diff] [blame] | 796 | metrics["handler_time"] = time.time() - start_time |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 797 | verbose("QEMU complete (%s) after %f seconds" % |
Anas Nashif | c8390f1 | 2017-11-25 17:14:12 -0500 | [diff] [blame] | 798 | (out_state, metrics["handler_time"])) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 799 | handler.set_state(out_state, metrics) |
| 800 | |
| 801 | log_out_fp.close() |
| 802 | out_fp.close() |
| 803 | in_fp.close() |
| 804 | |
| 805 | pid = int(open(pid_fn).read()) |
| 806 | os.unlink(pid_fn) |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 807 | try: |
| 808 | os.kill(pid, signal.SIGTERM) |
| 809 | except ProcessLookupError: |
| 810 | # Oh well, as long as it's dead! User probably sent Ctrl-C |
| 811 | pass |
| 812 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 813 | os.unlink(fifo_in) |
| 814 | os.unlink(fifo_out) |
| 815 | |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 816 | def __init__(self, instance): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 817 | """Constructor |
| 818 | |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 819 | @param instance Test instance |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 820 | """ |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 821 | |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 822 | super().__init__(instance) |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 823 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 824 | self.results = {} |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 825 | self.run = True |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 826 | |
| 827 | # We pass this to QEMU which looks for fifos with .in and .out |
| 828 | # suffixes. |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 829 | self.fifo_fn = os.path.join(instance.outdir, "qemu-fifo") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 830 | |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 831 | self.pid_fn = os.path.join(instance.outdir, "qemu.pid") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 832 | if os.path.exists(self.pid_fn): |
| 833 | os.unlink(self.pid_fn) |
| 834 | |
Anas Nashif | 4a9f3e6 | 2018-07-06 18:58:18 -0500 | [diff] [blame] | 835 | self.log_fn = self.log |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 836 | |
| 837 | harness_import = HarnessImporter(instance.test.harness.capitalize()) |
| 838 | harness = harness_import.instance |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 839 | harness.configure(self.instance) |
| 840 | self.thread = threading.Thread(name=self.name, target=QEMUHandler._thread, |
| 841 | args=(self, self.timeout, self.outdir, |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 842 | self.log_fn, self.fifo_fn, |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 843 | self.pid_fn, self.results, harness)) |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 844 | |
| 845 | self.instance.results = harness.tests |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 846 | self.thread.daemon = True |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 847 | verbose("Spawning QEMU process for %s" % self.name) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 848 | self.thread.start() |
| 849 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 850 | def get_fifo(self): |
| 851 | return self.fifo_fn |
| 852 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 853 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 854 | class SizeCalculator: |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 855 | |
Erwin Rol | cb3d127 | 2018-02-10 11:40:40 +0100 | [diff] [blame] | 856 | alloc_sections = ["bss", "noinit", "app_bss", "app_noinit", "ccm_bss", |
| 857 | "ccm_noinit"] |
Daniel Leung | c8066c5 | 2019-03-09 00:35:40 -0800 | [diff] [blame] | 858 | rw_sections = ["datas", "initlevel", "exceptions", "initshell", |
Andrew Boie | c2e01df | 2018-11-12 15:16:54 -0800 | [diff] [blame] | 859 | "_static_thread_area", "_k_timer_area", |
Andrew Boie | 506f15c | 2018-11-08 14:44:31 -0800 | [diff] [blame] | 860 | "_k_mem_slab_area", "_k_mem_pool_area", "sw_isr_table", |
Andrew Boie | c253a68 | 2019-01-29 12:56:02 -0800 | [diff] [blame] | 861 | "_k_sem_area", "_k_mutex_area", "app_shmem_regions", |
Andrew Boie | 3ef0b56 | 2017-08-31 12:36:45 -0700 | [diff] [blame] | 862 | "_k_fifo_area", "_k_lifo_area", "_k_stack_area", |
| 863 | "_k_msgq_area", "_k_mbox_area", "_k_pipe_area", |
Jukka Rissanen | 6049207 | 2018-02-07 15:00:08 +0200 | [diff] [blame] | 864 | "net_if", "net_if_dev", "net_stack", "net_l2_data", |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 865 | "_k_queue_area", "_net_buf_pool_area", "app_datas", |
Erwin Rol | cb3d127 | 2018-02-10 11:40:40 +0100 | [diff] [blame] | 866 | "kobject_data", "mmu_tables", "app_pad", "priv_stacks", |
Anas Nashif | 0b68560 | 2018-06-29 12:57:47 -0500 | [diff] [blame] | 867 | "ccm_data", "usb_descriptor", "usb_data", "usb_bos_desc", |
| 868 | 'log_backends_sections', 'log_dynamic_sections', |
Johann Fischer | fcffebf | 2018-09-13 00:53:15 +0200 | [diff] [blame] | 869 | 'log_const_sections',"app_smem", 'shell_root_cmds_sections', |
Adithya Baglody | 1fa8cf9 | 2018-10-19 10:15:19 -0700 | [diff] [blame] | 870 | 'log_const_sections',"app_smem", "font_entry_sections", |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 871 | "priv_stacks_noinit", "_TEXT_SECTION_NAME_2", |
Kumar Gala | e6393dd | 2019-02-16 10:08:33 -0600 | [diff] [blame] | 872 | '_GCOV_BSS_SECTION_NAME', 'gcov', 'nocache'] |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 873 | |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 874 | # These get copied into RAM only on non-XIP |
Andrew Boie | 877f82e | 2017-10-17 11:20:22 -0700 | [diff] [blame] | 875 | ro_sections = ["text", "ctors", "init_array", "reset", "object_access", |
Andrew Boie | 506f15c | 2018-11-08 14:44:31 -0800 | [diff] [blame] | 876 | "rodata", "devconfig", "net_l2", "vector", "sw_isr_table", |
| 877 | "_bt_settings_area"] |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 878 | |
Andrew Boie | 52fef67 | 2016-11-29 12:21:59 -0800 | [diff] [blame] | 879 | def __init__(self, filename, extra_sections): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 880 | """Constructor |
| 881 | |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 882 | @param filename Path to the output binary |
| 883 | The <filename> is parsed by objdump to determine section sizes |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 884 | """ |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 885 | # Make sure this is an ELF binary |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 886 | with open(filename, "rb") as f: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 887 | magic = f.read(4) |
| 888 | |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 889 | try: |
| 890 | if (magic != b'\x7fELF'): |
| 891 | raise SanityRuntimeError("%s is not an ELF binary" % filename) |
| 892 | except Exception as e: |
| 893 | print(str(e)) |
| 894 | sys.exit(2) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 895 | |
| 896 | # Search for CONFIG_XIP in the ELF's list of symbols using NM and AWK. |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 897 | # GREP can not be used as it returns an error if the symbol is not |
| 898 | # found. |
| 899 | is_xip_command = "nm " + filename + \ |
| 900 | " | awk '/CONFIG_XIP/ { print $3 }'" |
| 901 | is_xip_output = subprocess.check_output( |
| 902 | is_xip_command, shell=True, stderr=subprocess.STDOUT).decode( |
| 903 | "utf-8").strip() |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 904 | try: |
| 905 | if is_xip_output.endswith("no symbols"): |
| 906 | raise SanityRuntimeError("%s has no symbol information" % filename) |
| 907 | except Exception as e: |
| 908 | print(str(e)) |
| 909 | sys.exit(2) |
| 910 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 911 | self.is_xip = (len(is_xip_output) != 0) |
| 912 | |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 913 | self.filename = filename |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 914 | self.sections = [] |
| 915 | self.rom_size = 0 |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 916 | self.ram_size = 0 |
Andrew Boie | 52fef67 | 2016-11-29 12:21:59 -0800 | [diff] [blame] | 917 | self.extra_sections = extra_sections |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 918 | |
| 919 | self._calculate_sizes() |
| 920 | |
| 921 | def get_ram_size(self): |
| 922 | """Get the amount of RAM the application will use up on the device |
| 923 | |
| 924 | @return amount of RAM, in bytes |
| 925 | """ |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 926 | return self.ram_size |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 927 | |
| 928 | def get_rom_size(self): |
| 929 | """Get the size of the data that this application uses on device's flash |
| 930 | |
| 931 | @return amount of ROM, in bytes |
| 932 | """ |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 933 | return self.rom_size |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 934 | |
| 935 | def unrecognized_sections(self): |
| 936 | """Get a list of sections inside the binary that weren't recognized |
| 937 | |
David B. Kinder | 29963c3 | 2017-06-16 12:32:42 -0700 | [diff] [blame] | 938 | @return list of unrecognized section names |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 939 | """ |
| 940 | slist = [] |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 941 | for v in self.sections: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 942 | if not v["recognized"]: |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 943 | slist.append(v["name"]) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 944 | return slist |
| 945 | |
| 946 | def _calculate_sizes(self): |
| 947 | """ Calculate RAM and ROM usage by section """ |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 948 | objdump_command = "objdump -h " + self.filename |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 949 | objdump_output = subprocess.check_output( |
| 950 | objdump_command, shell=True).decode("utf-8").splitlines() |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 951 | |
| 952 | for line in objdump_output: |
| 953 | words = line.split() |
| 954 | |
| 955 | if (len(words) == 0): # Skip lines that are too short |
| 956 | continue |
| 957 | |
| 958 | index = words[0] |
| 959 | if (not index[0].isdigit()): # Skip lines that do not start |
| 960 | continue # with a digit |
| 961 | |
| 962 | name = words[1] # Skip lines with section names |
| 963 | if (name[0] == '.'): # starting with '.' |
| 964 | continue |
| 965 | |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 966 | # TODO this doesn't actually reflect the size in flash or RAM as |
| 967 | # it doesn't include linker-imposed padding between sections. |
| 968 | # It is close though. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 969 | size = int(words[2], 16) |
Andrew Boie | 9882dcd | 2015-10-07 14:25:51 -0700 | [diff] [blame] | 970 | if size == 0: |
| 971 | continue |
| 972 | |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 973 | load_addr = int(words[4], 16) |
| 974 | virt_addr = int(words[3], 16) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 975 | |
| 976 | # Add section to memory use totals (for both non-XIP and XIP scenarios) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 977 | # Unrecognized section names are not included in the calculations. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 978 | recognized = True |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 979 | if name in SizeCalculator.alloc_sections: |
| 980 | self.ram_size += size |
| 981 | stype = "alloc" |
| 982 | elif name in SizeCalculator.rw_sections: |
| 983 | self.ram_size += size |
| 984 | self.rom_size += size |
| 985 | stype = "rw" |
| 986 | elif name in SizeCalculator.ro_sections: |
| 987 | self.rom_size += size |
| 988 | if not self.is_xip: |
| 989 | self.ram_size += size |
| 990 | stype = "ro" |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 991 | else: |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 992 | stype = "unknown" |
Andrew Boie | 52fef67 | 2016-11-29 12:21:59 -0800 | [diff] [blame] | 993 | if name not in self.extra_sections: |
| 994 | recognized = False |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 995 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 996 | self.sections.append({"name": name, "load_addr": load_addr, |
| 997 | "size": size, "virt_addr": virt_addr, |
| 998 | "type": stype, "recognized": recognized}) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 999 | |
| 1000 | |
| 1001 | class MakeGoal: |
| 1002 | """Metadata class representing one of the sub-makes called by MakeGenerator |
| 1003 | |
David B. Kinder | 29963c3 | 2017-06-16 12:32:42 -0700 | [diff] [blame] | 1004 | MakeGenerator returns a dictionary of these which can then be associated |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1005 | with TestInstances to get a complete picture of what happened during a test. |
| 1006 | MakeGenerator is used for tasks outside of building tests (such as |
| 1007 | defconfigs) which is why MakeGoal is a separate class from TestInstance. |
| 1008 | """ |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1009 | |
Anas Nashif | 4d25b50 | 2017-11-25 17:37:17 -0500 | [diff] [blame] | 1010 | def __init__(self, name, text, handler, make_log, build_log, run_log, handler_log): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1011 | self.name = name |
| 1012 | self.text = text |
Anas Nashif | 4d25b50 | 2017-11-25 17:37:17 -0500 | [diff] [blame] | 1013 | self.handler = handler |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1014 | self.make_log = make_log |
| 1015 | self.build_log = build_log |
| 1016 | self.run_log = run_log |
Anas Nashif | 4d25b50 | 2017-11-25 17:37:17 -0500 | [diff] [blame] | 1017 | self.handler_log = handler_log |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1018 | self.make_state = "waiting" |
| 1019 | self.failed = False |
| 1020 | self.finished = False |
| 1021 | self.reason = None |
| 1022 | self.metrics = {} |
| 1023 | |
| 1024 | def get_error_log(self): |
| 1025 | if self.make_state == "waiting": |
| 1026 | # Shouldn't ever see this; breakage in the main Makefile itself. |
| 1027 | return self.make_log |
| 1028 | elif self.make_state == "building": |
| 1029 | # Failure when calling the sub-make to build the code |
| 1030 | return self.build_log |
| 1031 | elif self.make_state == "running": |
Anas Nashif | 3ac7b3a | 2017-08-03 10:03:02 -0400 | [diff] [blame] | 1032 | # Failure in sub-make for "make run", qemu probably failed to start |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1033 | return self.run_log |
| 1034 | elif self.make_state == "finished": |
Anas Nashif | cc16422 | 2017-12-26 11:02:46 -0500 | [diff] [blame] | 1035 | # Execution handler finished, but timed out or otherwise wasn't successful |
Anas Nashif | 4d25b50 | 2017-11-25 17:37:17 -0500 | [diff] [blame] | 1036 | return self.handler_log |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1037 | |
| 1038 | def fail(self, reason): |
| 1039 | self.failed = True |
| 1040 | self.finished = True |
| 1041 | self.reason = reason |
| 1042 | |
| 1043 | def success(self): |
| 1044 | self.finished = True |
| 1045 | |
| 1046 | def __str__(self): |
| 1047 | if self.finished: |
| 1048 | if self.failed: |
| 1049 | return "[%s] failed (%s: see %s)" % (self.name, self.reason, |
| 1050 | self.get_error_log()) |
| 1051 | else: |
| 1052 | return "[%s] passed" % self.name |
| 1053 | else: |
| 1054 | return "[%s] in progress (%s)" % (self.name, self.make_state) |
| 1055 | |
| 1056 | |
| 1057 | class MakeGenerator: |
| 1058 | """Generates a Makefile which just calls a bunch of sub-make sessions |
| 1059 | |
| 1060 | In any given test suite we may need to build dozens if not hundreds of |
| 1061 | test cases. The cleanest way to parallelize this is to just let Make |
| 1062 | do the parallelization, sharing the jobserver among all the different |
| 1063 | sub-make targets. |
| 1064 | """ |
| 1065 | |
| 1066 | GOAL_HEADER_TMPL = """.PHONY: {goal} |
| 1067 | {goal}: |
| 1068 | """ |
| 1069 | |
| 1070 | MAKE_RULE_TMPL = """\t@echo sanity_test_{phase} {goal} >&2 |
Anas Nashif | fb91ad6 | 2017-10-31 08:33:17 -0400 | [diff] [blame] | 1071 | \tcmake \\ |
Anas Nashif | a8a1388 | 2017-12-30 13:01:06 -0500 | [diff] [blame] | 1072 | \t\t-G"{generator}"\\ |
Anas Nashif | fb91ad6 | 2017-10-31 08:33:17 -0400 | [diff] [blame] | 1073 | \t\t-H{directory}\\ |
| 1074 | \t\t-B{outdir}\\ |
| 1075 | \t\t-DEXTRA_CFLAGS="-Werror {cflags}"\\ |
| 1076 | \t\t-DEXTRA_AFLAGS=-Wa,--fatal-warnings\\ |
Anas Nashif | 262e4a4 | 2017-12-14 08:42:45 -0500 | [diff] [blame] | 1077 | \t\t-DEXTRA_LDFLAGS="{ldflags}"\\ |
Anas Nashif | fb91ad6 | 2017-10-31 08:33:17 -0400 | [diff] [blame] | 1078 | \t\t{args}\\ |
| 1079 | \t\t>{logfile} 2>&1 |
Anas Nashif | a8a1388 | 2017-12-30 13:01:06 -0500 | [diff] [blame] | 1080 | \t{generator_cmd} -C {outdir}\\ |
| 1081 | \t\t{verb} {make_args}\\ |
Anas Nashif | fb91ad6 | 2017-10-31 08:33:17 -0400 | [diff] [blame] | 1082 | \t\t>>{logfile} 2>&1 |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1083 | """ |
Anas Nashif | 20f553f | 2018-03-23 11:26:41 -0500 | [diff] [blame] | 1084 | MAKE_RULE_TMPL_RUN = """\t@echo sanity_test_{phase} {goal} >&2 |
| 1085 | \t{generator_cmd} -C {outdir}\\ |
| 1086 | \t\t{verb} {make_args}\\ |
| 1087 | \t\t>>{logfile} 2>&1 |
| 1088 | """ |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1089 | |
| 1090 | GOAL_FOOTER_TMPL = "\t@echo sanity_test_finished {goal} >&2\n\n" |
| 1091 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1092 | re_make = re.compile( |
| 1093 | "sanity_test_([A-Za-z0-9]+) (.+)|$|make[:] \*\*\* \[(.+:.+: )?(.+)\] Error.+$") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1094 | |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 1095 | def __init__(self, base_outdir): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1096 | """MakeGenerator constructor |
| 1097 | |
| 1098 | @param base_outdir Intended to be the base out directory. A make.log |
| 1099 | file will be created here which contains the output of the |
| 1100 | top-level Make session, as well as the dynamic control Makefile |
| 1101 | @param verbose If true, pass V=1 to all the sub-makes which greatly |
| 1102 | increases their verbosity |
| 1103 | """ |
| 1104 | self.goals = {} |
| 1105 | if not os.path.exists(base_outdir): |
| 1106 | os.makedirs(base_outdir) |
| 1107 | self.logfile = os.path.join(base_outdir, "make.log") |
| 1108 | self.makefile = os.path.join(base_outdir, "Makefile") |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 1109 | self.deprecations = options.error_on_deprecations |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1110 | |
| 1111 | def _get_rule_header(self, name): |
| 1112 | return MakeGenerator.GOAL_HEADER_TMPL.format(goal=name) |
| 1113 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1114 | def _get_sub_make(self, name, phase, workdir, outdir, |
| 1115 | logfile, args, make_args=""): |
Anas Nashif | fb91ad6 | 2017-10-31 08:33:17 -0400 | [diff] [blame] | 1116 | """ |
| 1117 | @param args Arguments given to CMake |
| 1118 | @param make_args Arguments given to the Makefile generated by CMake |
| 1119 | """ |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1120 | args = " ".join(["-D{}".format(a) for a in args]) |
Anas Nashif | 262e4a4 | 2017-12-14 08:42:45 -0500 | [diff] [blame] | 1121 | ldflags = "" |
Andrew Boie | 29599f6 | 2018-05-24 13:33:09 -0700 | [diff] [blame] | 1122 | cflags = "" |
Anas Nashif | e3febe9 | 2016-11-30 14:25:44 -0500 | [diff] [blame] | 1123 | |
| 1124 | if self.deprecations: |
| 1125 | cflags = cflags + " -Wno-deprecated-declarations" |
Andrew Boie | f7a6e28 | 2017-02-02 13:04:57 -0800 | [diff] [blame] | 1126 | |
Alberto Escolar Piedras | 770178b | 2018-05-02 13:49:51 +0200 | [diff] [blame] | 1127 | ldflags="-Wl,--fatal-warnings" |
Anas Nashif | 262e4a4 | 2017-12-14 08:42:45 -0500 | [diff] [blame] | 1128 | |
Anas Nashif | 25f6ab6 | 2018-03-06 07:15:11 -0600 | [diff] [blame] | 1129 | if options.ninja: |
Sebastian Bøe | 0e6689d | 2018-01-18 14:40:07 +0100 | [diff] [blame] | 1130 | generator = "Ninja" |
Andy Ross | dec163f | 2018-05-21 10:12:59 -0700 | [diff] [blame] | 1131 | generator_cmd = "ninja -j1" |
Sebastian Bøe | 0e6689d | 2018-01-18 14:40:07 +0100 | [diff] [blame] | 1132 | verb = "-v" if VERBOSE else "" |
Anas Nashif | 25f6ab6 | 2018-03-06 07:15:11 -0600 | [diff] [blame] | 1133 | else: |
| 1134 | generator = "Unix Makefiles" |
| 1135 | generator_cmd = "$(MAKE)" |
Andrew Boie | 3efd269 | 2018-06-26 10:41:35 -0700 | [diff] [blame] | 1136 | verb = "VERBOSE=1" if VERBOSE else "" |
Anas Nashif | a8a1388 | 2017-12-30 13:01:06 -0500 | [diff] [blame] | 1137 | |
Anas Nashif | 20f553f | 2018-03-23 11:26:41 -0500 | [diff] [blame] | 1138 | if phase == 'running': |
| 1139 | return MakeGenerator.MAKE_RULE_TMPL_RUN.format( |
| 1140 | generator_cmd=generator_cmd, |
| 1141 | phase=phase, |
| 1142 | goal=name, |
| 1143 | outdir=outdir, |
| 1144 | verb=verb, |
| 1145 | logfile=logfile, |
| 1146 | make_args=make_args |
| 1147 | ) |
| 1148 | else: |
| 1149 | return MakeGenerator.MAKE_RULE_TMPL.format( |
| 1150 | generator=generator, |
| 1151 | generator_cmd=generator_cmd, |
| 1152 | phase=phase, |
| 1153 | goal=name, |
| 1154 | outdir=outdir, |
| 1155 | cflags=cflags, |
| 1156 | ldflags=ldflags, |
| 1157 | directory=workdir, |
| 1158 | verb=verb, |
| 1159 | args=args, |
| 1160 | logfile=logfile, |
| 1161 | make_args=make_args |
| 1162 | ) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1163 | |
| 1164 | def _get_rule_footer(self, name): |
| 1165 | return MakeGenerator.GOAL_FOOTER_TMPL.format(goal=name) |
| 1166 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1167 | def add_build_goal(self, name, directory, outdir, |
| 1168 | args, buildlog, make_args=""): |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1169 | """Add a goal to invoke a build session |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1170 | |
| 1171 | @param name A unique string name for this build goal. The results |
| 1172 | dictionary returned by execute() will be keyed by this name. |
| 1173 | @param directory Absolute path to working directory, will be passed |
| 1174 | to make -C |
| 1175 | @param outdir Absolute path to output directory, will be passed to |
Sebastian Bøe | 71d7de0 | 2017-11-09 12:06:04 +0100 | [diff] [blame] | 1176 | cmake via -B=<path> |
| 1177 | @param args Extra command line arguments to pass to 'cmake', typically |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1178 | environment variables or specific Make goals |
| 1179 | """ |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1180 | |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1181 | if not os.path.exists(outdir): |
| 1182 | os.makedirs(outdir) |
| 1183 | |
| 1184 | build_logfile = os.path.join(outdir, buildlog) |
| 1185 | text = self._get_rule_header(name) |
| 1186 | text += self._get_sub_make(name, "building", directory, outdir, build_logfile, |
| 1187 | args, make_args=make_args) |
| 1188 | text += self._get_rule_footer(name) |
| 1189 | |
| 1190 | self.goals[name] = MakeGoal( name, text, None, self.logfile, build_logfile, None, None) |
| 1191 | |
| 1192 | def add_goal(self, instance, type, args, make_args=""): |
Anas Nashif | 4a9f3e6 | 2018-07-06 18:58:18 -0500 | [diff] [blame] | 1193 | |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1194 | """Add a goal to build a Zephyr project and then run it using a handler |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1195 | |
| 1196 | The generated make goal invokes Make twice, the first time it will |
| 1197 | build the default goal, and the second will invoke the 'qemu' goal. |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1198 | The output of the handler session will be monitored, and terminated |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1199 | either upon pass/fail result of the test program, or the timeout |
| 1200 | is reached. |
| 1201 | |
Sebastian Bøe | 71d7de0 | 2017-11-09 12:06:04 +0100 | [diff] [blame] | 1202 | @param args Extra cache entries to define in CMake. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1203 | """ |
| 1204 | |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 1205 | name = instance.name |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 1206 | directory = instance.test.test_path |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 1207 | outdir = instance.outdir |
| 1208 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1209 | build_logfile = os.path.join(outdir, "build.log") |
| 1210 | run_logfile = os.path.join(outdir, "run.log") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1211 | |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1212 | if not os.path.exists(outdir): |
| 1213 | os.makedirs(outdir) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1214 | |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1215 | handler = None |
| 1216 | if type == "qemu": |
| 1217 | handler = QEMUHandler(instance) |
| 1218 | elif type == "native": |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 1219 | handler = BinaryHandler(instance) |
| 1220 | handler.binary = os.path.join(outdir, "zephyr", "zephyr.exe") |
Anas Nashif | a4b5a73 | 2019-01-24 18:15:44 -0500 | [diff] [blame] | 1221 | if options.enable_coverage: |
| 1222 | args += ["EXTRA_LDFLAGS=--coverage"] |
Anas Nashif | 99f5a6c | 2018-07-07 08:45:53 -0500 | [diff] [blame] | 1223 | elif type == "nsim": |
| 1224 | handler = BinaryHandler(instance) |
| 1225 | handler.call_make_run = True |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1226 | elif type == "unit": |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 1227 | handler = BinaryHandler(instance) |
| 1228 | handler.binary = os.path.join(outdir, "testbinary") |
Anas Nashif | a4b5a73 | 2019-01-24 18:15:44 -0500 | [diff] [blame] | 1229 | if options.enable_coverage: |
| 1230 | args += ["EXTRA_LDFLAGS=--coverage"] |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1231 | elif type == "device": |
| 1232 | handler = DeviceHandler(instance) |
Jan Kowalewski | 265895b | 2019-01-07 16:40:24 +0100 | [diff] [blame] | 1233 | elif type == "renode": |
| 1234 | handler = BinaryHandler(instance) |
| 1235 | handler.pid_fn = os.path.join(instance.outdir, "renode.pid") |
| 1236 | handler.call_make_run = True |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 1237 | |
Alberto Escolar Piedras | c026c2e | 2018-06-21 09:30:20 +0200 | [diff] [blame] | 1238 | |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1239 | if type == 'qemu': |
| 1240 | args.append("QEMU_PIPE=%s" % handler.get_fifo()) |
| 1241 | |
Anas Nashif | cc16422 | 2017-12-26 11:02:46 -0500 | [diff] [blame] | 1242 | text = (self._get_rule_header(name) + |
| 1243 | self._get_sub_make(name, "building", directory, |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1244 | outdir, build_logfile, args, make_args=make_args)) |
| 1245 | if handler and handler.run: |
| 1246 | text += self._get_sub_make(name, "running", directory, |
| 1247 | outdir, run_logfile, |
| 1248 | args, make_args="run") |
Anas Nashif | 4d25b50 | 2017-11-25 17:37:17 -0500 | [diff] [blame] | 1249 | |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1250 | text += self._get_rule_footer(name) |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 1251 | |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 1252 | self.goals[name] = MakeGoal(name, text, handler, self.logfile, build_logfile, |
Anas Nashif | 4a9f3e6 | 2018-07-06 18:58:18 -0500 | [diff] [blame] | 1253 | run_logfile, handler.log if handler else None) |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 1254 | |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1255 | |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 1256 | def add_test_instance(self, ti, extra_args=[]): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1257 | """Add a goal to build/test a TestInstance object |
| 1258 | |
| 1259 | @param ti TestInstance object to build. The status dictionary returned |
| 1260 | by execute() will be keyed by its .name field. |
| 1261 | """ |
| 1262 | args = ti.test.extra_args[:] |
Anas Nashif | f9e73c9 | 2019-02-12 13:59:08 -0500 | [diff] [blame] | 1263 | |
| 1264 | # merge overlay files into one variable |
| 1265 | overlays = "" |
| 1266 | idx = 0 |
| 1267 | for a in args: |
| 1268 | m = re.search('OVERLAY_CONFIG="(.*)"', a) |
| 1269 | if m: |
| 1270 | overlays += m.group(1) |
| 1271 | del args[idx] |
| 1272 | idx += 1 |
| 1273 | |
Anas Nashif | 3cbffef | 2018-11-07 23:50:54 -0500 | [diff] [blame] | 1274 | if len(ti.test.extra_configs) > 0 or options.coverage: |
Anas Nashif | f9e73c9 | 2019-02-12 13:59:08 -0500 | [diff] [blame] | 1275 | args.append("OVERLAY_CONFIG=\"%s %s\"" %(overlays, |
| 1276 | os.path.join(ti.outdir, "overlay.conf"))) |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 1277 | |
Anas Nashif | 3cbffef | 2018-11-07 23:50:54 -0500 | [diff] [blame] | 1278 | if ti.test.type == "unit" and options.enable_coverage: |
| 1279 | args.append("COVERAGE=1") |
| 1280 | |
Anas Nashif | fb91ad6 | 2017-10-31 08:33:17 -0400 | [diff] [blame] | 1281 | args.append("BOARD={}".format(ti.platform.name)) |
Andrew Boie | ba61200 | 2016-09-01 10:41:03 -0700 | [diff] [blame] | 1282 | args.extend(extra_args) |
Anas Nashif | 5df8cff | 2018-02-23 08:37:14 -0600 | [diff] [blame] | 1283 | |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 1284 | do_build_only = ti.build_only or options.build_only |
Andy Ross | dc4151f | 2019-01-03 14:17:43 -0800 | [diff] [blame] | 1285 | do_run = not do_build_only |
| 1286 | skip_slow = ti.test.slow and not options.enable_slow |
Anas Nashif | 5df8cff | 2018-02-23 08:37:14 -0600 | [diff] [blame] | 1287 | |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1288 | # FIXME: Need refactoring and cleanup |
| 1289 | type = None |
Anas Nashif | 5df8cff | 2018-02-23 08:37:14 -0600 | [diff] [blame] | 1290 | if ti.platform.qemu_support and do_run: |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1291 | type = "qemu" |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 1292 | elif ti.test.type == "unit": |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1293 | type = "unit" |
Anas Nashif | 5df8cff | 2018-02-23 08:37:14 -0600 | [diff] [blame] | 1294 | elif ti.platform.type == "native" and do_run: |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1295 | type = "native" |
Anas Nashif | 99f5a6c | 2018-07-07 08:45:53 -0500 | [diff] [blame] | 1296 | elif ti.platform.simulation == "nsim" and do_run: |
Anas Nashif | e24350c | 2018-07-11 15:09:22 -0500 | [diff] [blame] | 1297 | if find_executable("nsimdrv"): |
| 1298 | type = "nsim" |
Jan Kowalewski | 265895b | 2019-01-07 16:40:24 +0100 | [diff] [blame] | 1299 | elif ti.platform.simulation == "renode" and do_run: |
| 1300 | if find_executable("renode"): |
| 1301 | type = "renode" |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 1302 | elif options.device_testing and (not ti.build_only) and (not options.build_only): |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 1303 | type = "device" |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 1304 | |
Andy Ross | dc4151f | 2019-01-03 14:17:43 -0800 | [diff] [blame] | 1305 | if not skip_slow: |
| 1306 | self.add_goal(ti, type, args) |
| 1307 | else: |
| 1308 | verbose("Skipping slow test: " + ti.name) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1309 | |
| 1310 | def execute(self, callback_fn=None, context=None): |
| 1311 | """Execute all the registered build goals |
| 1312 | |
| 1313 | @param callback_fn If not None, a callback function will be called |
| 1314 | as individual goals transition between states. This function |
| 1315 | should accept two parameters: a string state and an arbitrary |
| 1316 | context object, supplied here |
| 1317 | @param context Context object to pass to the callback function. |
| 1318 | Type and semantics are specific to that callback function. |
| 1319 | @return A dictionary mapping goal names to final status. |
| 1320 | """ |
| 1321 | |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 1322 | with open(self.makefile, "wt") as tf, \ |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1323 | open(os.devnull, "wb") as devnull, \ |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 1324 | open(self.logfile, "wt") as make_log: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1325 | # Create our dynamic Makefile and execute it. |
| 1326 | # Watch stderr output which is where we will keep |
| 1327 | # track of build state |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 1328 | for name, goal in self.goals.items(): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1329 | tf.write(goal.text) |
| 1330 | tf.write("all: %s\n" % (" ".join(self.goals.keys()))) |
| 1331 | tf.flush() |
| 1332 | |
Oleg Zhurakivskyy | 99aacd9 | 2018-08-17 15:02:28 +0300 | [diff] [blame] | 1333 | cmd = ["make", "-k", "-j", str(JOBS), "-f", tf.name, "all"] |
Andy Ross | dec163f | 2018-05-21 10:12:59 -0700 | [diff] [blame] | 1334 | |
Bobby Noelte | 9cf8b3c | 2018-06-13 06:10:20 +0200 | [diff] [blame] | 1335 | # assure language neutral environemnt |
| 1336 | make_env = os.environ.copy() |
| 1337 | make_env['LC_MESSAGES'] = 'C.UTF-8' |
| 1338 | p = subprocess.Popen(cmd, stderr=subprocess.PIPE, |
| 1339 | stdout=devnull, env=make_env) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1340 | |
| 1341 | for line in iter(p.stderr.readline, b''): |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 1342 | line = line.decode("utf-8") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1343 | make_log.write(line) |
| 1344 | verbose("MAKE: " + repr(line.strip())) |
| 1345 | m = MakeGenerator.re_make.match(line) |
| 1346 | if not m: |
| 1347 | continue |
| 1348 | |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 1349 | state, name, _, error = m.groups() |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1350 | if error: |
| 1351 | goal = self.goals[error] |
Andrew Boie | 822b087 | 2017-01-10 13:32:40 -0800 | [diff] [blame] | 1352 | # Sometimes QEMU will run an image and then crash out, which |
Anas Nashif | 3ac7b3a | 2017-08-03 10:03:02 -0400 | [diff] [blame] | 1353 | # will cause the 'make run' invocation to exit with |
Andrew Boie | 822b087 | 2017-01-10 13:32:40 -0800 | [diff] [blame] | 1354 | # nonzero status. |
| 1355 | # Need to distinguish this case from a compilation failure. |
Anas Nashif | 4d25b50 | 2017-11-25 17:37:17 -0500 | [diff] [blame] | 1356 | if goal.handler: |
Anas Nashif | 9a839df | 2018-01-29 08:42:38 -0500 | [diff] [blame] | 1357 | goal.fail("handler_crash") |
Andrew Boie | 822b087 | 2017-01-10 13:32:40 -0800 | [diff] [blame] | 1358 | else: |
| 1359 | goal.fail("build_error") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1360 | else: |
Anas Nashif | cc16422 | 2017-12-26 11:02:46 -0500 | [diff] [blame] | 1361 | goal = self.goals[name] |
| 1362 | goal.make_state = state |
| 1363 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1364 | if state == "finished": |
Anas Nashif | 4d25b50 | 2017-11-25 17:37:17 -0500 | [diff] [blame] | 1365 | if goal.handler: |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 1366 | if hasattr(goal.handler, "handle"): |
Anas Nashif | 4d25b50 | 2017-11-25 17:37:17 -0500 | [diff] [blame] | 1367 | goal.handler.handle() |
Anas Nashif | 4a9f3e6 | 2018-07-06 18:58:18 -0500 | [diff] [blame] | 1368 | goal.handler_log = goal.handler.log |
Anas Nashif | cc16422 | 2017-12-26 11:02:46 -0500 | [diff] [blame] | 1369 | |
Anas Nashif | 4d25b50 | 2017-11-25 17:37:17 -0500 | [diff] [blame] | 1370 | thread_status, metrics = goal.handler.get_state() |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1371 | goal.metrics.update(metrics) |
| 1372 | if thread_status == "passed": |
| 1373 | goal.success() |
| 1374 | else: |
| 1375 | goal.fail(thread_status) |
| 1376 | else: |
| 1377 | goal.success() |
| 1378 | |
| 1379 | if callback_fn: |
| 1380 | callback_fn(context, self.goals, goal) |
| 1381 | |
| 1382 | p.wait() |
| 1383 | return self.goals |
| 1384 | |
| 1385 | |
| 1386 | # "list" - List of strings |
| 1387 | # "list:<type>" - List of <type> |
| 1388 | # "set" - Set of unordered, unique strings |
| 1389 | # "set:<type>" - Set of <type> |
| 1390 | # "float" - Floating point |
| 1391 | # "int" - Integer |
| 1392 | # "bool" - Boolean |
| 1393 | # "str" - String |
| 1394 | |
| 1395 | # XXX Be sure to update __doc__ if you change any of this!! |
| 1396 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1397 | platform_valid_keys = {"qemu_support": {"type": "bool", "default": False}, |
Anas Nashif | 924a4e7 | 2018-10-18 12:25:55 -0400 | [diff] [blame] | 1398 | "supported_toolchains": {"type": "list", "default": []}, |
| 1399 | "env": {"type": "list", "default": []} |
| 1400 | } |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1401 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1402 | testcase_valid_keys = {"tags": {"type": "set", "required": False}, |
| 1403 | "type": {"type": "str", "default": "integration"}, |
| 1404 | "extra_args": {"type": "list"}, |
| 1405 | "extra_configs": {"type": "list"}, |
| 1406 | "build_only": {"type": "bool", "default": False}, |
| 1407 | "build_on_all": {"type": "bool", "default": False}, |
| 1408 | "skip": {"type": "bool", "default": False}, |
| 1409 | "slow": {"type": "bool", "default": False}, |
| 1410 | "timeout": {"type": "int", "default": 60}, |
| 1411 | "min_ram": {"type": "int", "default": 8}, |
| 1412 | "depends_on": {"type": "set"}, |
| 1413 | "min_flash": {"type": "int", "default": 32}, |
| 1414 | "arch_whitelist": {"type": "set"}, |
| 1415 | "arch_exclude": {"type": "set"}, |
| 1416 | "extra_sections": {"type": "list", "default": []}, |
| 1417 | "platform_exclude": {"type": "set"}, |
| 1418 | "platform_whitelist": {"type": "set"}, |
| 1419 | "toolchain_exclude": {"type": "set"}, |
| 1420 | "toolchain_whitelist": {"type": "set"}, |
Anas Nashif | ab94016 | 2017-12-08 10:17:57 -0500 | [diff] [blame] | 1421 | "filter": {"type": "str"}, |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 1422 | "harness": {"type": "str"}, |
Praful Swarnakar | cf89e28 | 2018-09-13 02:58:28 +0530 | [diff] [blame] | 1423 | "harness_config": {"type": "map", "default": {}} |
Anas Nashif | ab94016 | 2017-12-08 10:17:57 -0500 | [diff] [blame] | 1424 | } |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1425 | |
| 1426 | |
| 1427 | class SanityConfigParser: |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1428 | """Class to read test case files with semantic checking |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1429 | """ |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1430 | |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 1431 | def __init__(self, filename, schema): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1432 | """Instantiate a new SanityConfigParser object |
| 1433 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1434 | @param filename Source .yaml file to read |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1435 | """ |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1436 | self.data = scl.yaml_load_verify(filename, schema) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1437 | self.filename = filename |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1438 | self.tests = {} |
| 1439 | self.common = {} |
| 1440 | if 'tests' in self.data: |
| 1441 | self.tests = self.data['tests'] |
| 1442 | if 'common' in self.data: |
| 1443 | self.common = self.data['common'] |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1444 | |
| 1445 | def _cast_value(self, value, typestr): |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1446 | if isinstance(value, str): |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1447 | v = value.strip() |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1448 | if typestr == "str": |
| 1449 | return v |
| 1450 | |
| 1451 | elif typestr == "float": |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1452 | return float(value) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1453 | |
| 1454 | elif typestr == "int": |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1455 | return int(value) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1456 | |
| 1457 | elif typestr == "bool": |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1458 | return value |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1459 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1460 | elif typestr.startswith("list") and isinstance(value, list): |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 1461 | return value |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1462 | elif typestr.startswith("list") and isinstance(value, str): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1463 | vs = v.split() |
| 1464 | if len(typestr) > 4 and typestr[4] == ":": |
| 1465 | return [self._cast_value(vsi, typestr[5:]) for vsi in vs] |
| 1466 | else: |
| 1467 | return vs |
| 1468 | |
| 1469 | elif typestr.startswith("set"): |
| 1470 | vs = v.split() |
| 1471 | if len(typestr) > 3 and typestr[3] == ":": |
| 1472 | return set([self._cast_value(vsi, typestr[4:]) for vsi in vs]) |
| 1473 | else: |
| 1474 | return set(vs) |
| 1475 | |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 1476 | elif typestr.startswith("map"): |
| 1477 | return value |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1478 | else: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1479 | raise ConfigurationError( |
| 1480 | self.filename, "unknown type '%s'" % value) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1481 | |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1482 | def get_test(self, name, valid_keys): |
| 1483 | """Get a dictionary representing the keys/values within a test |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1484 | |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1485 | @param name The test in the .yaml file to retrieve data from |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1486 | @param valid_keys A dictionary representing the intended semantics |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1487 | for this test. Each key in this dictionary is a key that could |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1488 | be specified, if a key is given in the .yaml file which isn't in |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1489 | here, it will generate an error. Each value in this dictionary |
| 1490 | is another dictionary containing metadata: |
| 1491 | |
| 1492 | "default" - Default value if not given |
| 1493 | "type" - Data type to convert the text value to. Simple types |
| 1494 | supported are "str", "float", "int", "bool" which will get |
| 1495 | converted to respective Python data types. "set" and "list" |
| 1496 | may also be specified which will split the value by |
| 1497 | whitespace (but keep the elements as strings). finally, |
| 1498 | "list:<type>" and "set:<type>" may be given which will |
| 1499 | perform a type conversion after splitting the value up. |
| 1500 | "required" - If true, raise an error if not defined. If false |
| 1501 | and "default" isn't specified, a type conversion will be |
| 1502 | done on an empty string |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1503 | @return A dictionary containing the test key-value pairs with |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1504 | type conversion and default values filled in per valid_keys |
| 1505 | """ |
| 1506 | |
| 1507 | d = {} |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1508 | for k, v in self.common.items(): |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 1509 | d[k] = v |
Anas Nashif | 75547e2 | 2018-02-24 08:32:14 -0600 | [diff] [blame] | 1510 | |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1511 | for k, v in self.tests[name].items(): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1512 | if k not in valid_keys: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1513 | raise ConfigurationError( |
| 1514 | self.filename, |
| 1515 | "Unknown config key '%s' in definition for '%s'" % |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1516 | (k, name)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1517 | |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 1518 | if k in d: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1519 | if isinstance(d[k], str): |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 1520 | d[k] += " " + v |
| 1521 | else: |
| 1522 | d[k] = v |
Anas Nashif | 75547e2 | 2018-02-24 08:32:14 -0600 | [diff] [blame] | 1523 | |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 1524 | for k, kinfo in valid_keys.items(): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1525 | if k not in d: |
| 1526 | if "required" in kinfo: |
| 1527 | required = kinfo["required"] |
| 1528 | else: |
| 1529 | required = False |
| 1530 | |
| 1531 | if required: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1532 | raise ConfigurationError( |
| 1533 | self.filename, |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1534 | "missing required value for '%s' in test '%s'" % |
| 1535 | (k, name)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1536 | else: |
| 1537 | if "default" in kinfo: |
| 1538 | default = kinfo["default"] |
| 1539 | else: |
| 1540 | default = self._cast_value("", kinfo["type"]) |
| 1541 | d[k] = default |
| 1542 | else: |
| 1543 | try: |
| 1544 | d[k] = self._cast_value(d[k], kinfo["type"]) |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 1545 | except ValueError as ve: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1546 | raise ConfigurationError( |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1547 | self.filename, "bad %s value '%s' for key '%s' in name '%s'" % |
| 1548 | (kinfo["type"], d[k], k, name)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1549 | |
| 1550 | return d |
| 1551 | |
| 1552 | |
| 1553 | class Platform: |
| 1554 | """Class representing metadata for a particular platform |
| 1555 | |
Anas Nashif | c740608 | 2015-12-13 15:00:31 -0500 | [diff] [blame] | 1556 | Maps directly to BOARD when building""" |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 1557 | |
| 1558 | yaml_platform_schema = scl.yaml_load( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1559 | os.path.join( |
Oleg Zhurakivskyy | 4282208 | 2018-08-17 14:54:41 +0300 | [diff] [blame] | 1560 | ZEPHYR_BASE, |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1561 | "scripts", |
| 1562 | "sanity_chk", |
| 1563 | "sanitycheck-platform-schema.yaml")) |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 1564 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1565 | def __init__(self, cfile): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1566 | """Constructor. |
| 1567 | |
Anas Nashif | 877d3ca | 2017-12-05 17:39:29 -0500 | [diff] [blame] | 1568 | @param cfile Path to platform configuration file, which gives |
| 1569 | info about the platform to be added. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1570 | """ |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 1571 | scp = SanityConfigParser(cfile, self.yaml_platform_schema) |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1572 | data = scp.data |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1573 | |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1574 | self.name = data['identifier'] |
Anas Nashif | f3d48e1 | 2018-07-24 08:14:42 -0500 | [diff] [blame] | 1575 | self.sanitycheck = data.get("sanitycheck", True) |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1576 | # if no RAM size is specified by the board, take a default of 128K |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1577 | self.ram = data.get("ram", 128) |
| 1578 | testing = data.get("testing", {}) |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1579 | self.ignore_tags = testing.get("ignore_tags", []) |
| 1580 | self.default = testing.get("default", False) |
| 1581 | # if no flash size is specified by the board, take a default of 512K |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1582 | self.flash = data.get("flash", 512) |
Anas Nashif | 9527693 | 2017-07-31 08:47:41 -0400 | [diff] [blame] | 1583 | self.supported = set() |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1584 | for supp_feature in data.get("supported", []): |
Anas Nashif | 9527693 | 2017-07-31 08:47:41 -0400 | [diff] [blame] | 1585 | for item in supp_feature.split(":"): |
| 1586 | self.supported.add(item) |
| 1587 | |
Anas Nashif | 8acdbd7 | 2018-01-04 14:15:22 -0500 | [diff] [blame] | 1588 | self.qemu_support = True if data.get('simulation', "na") == 'qemu' else False |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1589 | self.arch = data['arch'] |
Anas Nashif | cc16422 | 2017-12-26 11:02:46 -0500 | [diff] [blame] | 1590 | self.type = data.get('type', "na") |
Anas Nashif | 8acdbd7 | 2018-01-04 14:15:22 -0500 | [diff] [blame] | 1591 | self.simulation = data.get('simulation', "na") |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1592 | self.supported_toolchains = data.get("toolchain", []) |
Anas Nashif | 924a4e7 | 2018-10-18 12:25:55 -0400 | [diff] [blame] | 1593 | self.env = data.get("env", []) |
| 1594 | self.env_satisfied = True |
| 1595 | for env in self.env: |
| 1596 | if os.environ.get(env, None) == None: |
| 1597 | self.env_satisfied = False |
Andrew Boie | 4187822 | 2016-11-03 11:58:53 -0700 | [diff] [blame] | 1598 | self.defconfig = None |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1599 | pass |
| 1600 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1601 | def __repr__(self): |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1602 | return "<%s on %s>" % (self.name, self.arch) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1603 | |
| 1604 | |
| 1605 | class Architecture: |
| 1606 | """Class representing metadata for a particular architecture |
| 1607 | """ |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1608 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1609 | def __init__(self, name, platforms): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1610 | """Architecture constructor |
| 1611 | |
Anas Nashif | 877d3ca | 2017-12-05 17:39:29 -0500 | [diff] [blame] | 1612 | @param name String name for this architecture |
| 1613 | @param platforms list of platforms belonging to this architecture |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1614 | """ |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1615 | self.platforms = platforms |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1616 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1617 | self.name = name |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1618 | |
| 1619 | def __repr__(self): |
| 1620 | return "<arch %s>" % self.name |
| 1621 | |
| 1622 | |
| 1623 | class TestCase: |
| 1624 | """Class representing a test application |
| 1625 | """ |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1626 | |
Anas Nashif | 7fae29c | 2017-10-09 13:19:12 -0400 | [diff] [blame] | 1627 | def __init__(self, testcase_root, workdir, name, tc_dict, yamlfile): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1628 | """TestCase constructor. |
| 1629 | |
Anas Nashif | 877d3ca | 2017-12-05 17:39:29 -0500 | [diff] [blame] | 1630 | This gets called by TestSuite as it finds and reads test yaml files. |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1631 | Multiple TestCase instances may be generated from a single testcase.yaml, |
Anas Nashif | 877d3ca | 2017-12-05 17:39:29 -0500 | [diff] [blame] | 1632 | each one corresponds to an entry within that file. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1633 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1634 | We need to have a unique name for every single test case. Since |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1635 | a testcase.yaml can define multiple tests, the canonical name for |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1636 | the test case is <workdir>/<name>. |
| 1637 | |
| 1638 | @param testcase_root Absolute path to the root directory where |
| 1639 | all the test cases live |
| 1640 | @param workdir Relative path to the project directory for this |
| 1641 | test application from the test_case root. |
Anas Nashif | 877d3ca | 2017-12-05 17:39:29 -0500 | [diff] [blame] | 1642 | @param name Name of this test case, corresponding to the entry name |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1643 | in the test case configuration file. For many test cases that just |
| 1644 | define one test, can be anything and is usually "test". This is |
| 1645 | really only used to distinguish between different cases when |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1646 | the testcase.yaml defines multiple tests |
Anas Nashif | 877d3ca | 2017-12-05 17:39:29 -0500 | [diff] [blame] | 1647 | @param tc_dict Dictionary with test values for this test case |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1648 | from the testcase.yaml file |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1649 | """ |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 1650 | self.test_path = os.path.join(testcase_root, workdir) |
| 1651 | |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1652 | self.id = name |
| 1653 | self.cases = [] |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 1654 | self.type = tc_dict["type"] |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1655 | self.tags = tc_dict["tags"] |
| 1656 | self.extra_args = tc_dict["extra_args"] |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 1657 | self.extra_configs = tc_dict["extra_configs"] |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1658 | self.arch_whitelist = tc_dict["arch_whitelist"] |
Anas Nashif | 30d1387 | 2015-10-05 10:02:45 -0400 | [diff] [blame] | 1659 | self.arch_exclude = tc_dict["arch_exclude"] |
Anas Nashif | 2bd99bc | 2015-10-12 13:10:57 -0400 | [diff] [blame] | 1660 | self.skip = tc_dict["skip"] |
Anas Nashif | 30d1387 | 2015-10-05 10:02:45 -0400 | [diff] [blame] | 1661 | self.platform_exclude = tc_dict["platform_exclude"] |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1662 | self.platform_whitelist = tc_dict["platform_whitelist"] |
Anas Nashif | b17e1ca | 2017-06-27 18:05:30 -0400 | [diff] [blame] | 1663 | self.toolchain_exclude = tc_dict["toolchain_exclude"] |
| 1664 | self.toolchain_whitelist = tc_dict["toolchain_whitelist"] |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 1665 | self.tc_filter = tc_dict["filter"] |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1666 | self.timeout = tc_dict["timeout"] |
Anas Nashif | b0f3ae0 | 2017-12-08 12:48:39 -0500 | [diff] [blame] | 1667 | self.harness = tc_dict["harness"] |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 1668 | self.harness_config = tc_dict["harness_config"] |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1669 | self.build_only = tc_dict["build_only"] |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1670 | self.build_on_all = tc_dict["build_on_all"] |
Andrew Boie | 6bb087c | 2016-02-10 13:39:00 -0800 | [diff] [blame] | 1671 | self.slow = tc_dict["slow"] |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1672 | self.min_ram = tc_dict["min_ram"] |
| 1673 | self.depends_on = tc_dict["depends_on"] |
| 1674 | self.min_flash = tc_dict["min_flash"] |
Andrew Boie | 52fef67 | 2016-11-29 12:21:59 -0800 | [diff] [blame] | 1675 | self.extra_sections = tc_dict["extra_sections"] |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 1676 | |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 1677 | self.name = self.get_unique(testcase_root, workdir, name) |
Alberto Escolar Piedras | 2151b86 | 2018-01-29 15:09:21 +0100 | [diff] [blame] | 1678 | |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 1679 | self.defconfig = {} |
Anas Nashif | 1c65b6b | 2018-12-02 19:12:21 -0500 | [diff] [blame] | 1680 | self.dt_config = {} |
Anas Nashif | 45a9786 | 2019-01-09 08:46:42 -0500 | [diff] [blame] | 1681 | self.cmake_cache = {} |
Anas Nashif | 7fae29c | 2017-10-09 13:19:12 -0400 | [diff] [blame] | 1682 | self.yamlfile = yamlfile |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1683 | |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 1684 | |
| 1685 | def get_unique(self, testcase_root, workdir, name): |
| 1686 | |
| 1687 | if ZEPHYR_BASE in testcase_root: |
| 1688 | # This is a Zephyr Test, so include path in name for uniqueness |
| 1689 | # FIXME: We should not depend on path of test for unique names. |
| 1690 | |
| 1691 | zephyr_base = os.path.join(os.path.realpath(ZEPHYR_BASE)) |
| 1692 | short_path = os.path.normpath(testcase_root.replace(zephyr_base + "/", "")) |
| 1693 | else: |
| 1694 | short_path = "" |
| 1695 | |
| 1696 | unique = os.path.normpath(os.path.join(short_path, workdir, name)) |
| 1697 | return unique |
| 1698 | |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1699 | def scan_file(self, inf_name): |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1700 | suite_regex = re.compile( |
Inaky Perez-Gonzalez | 75e2d90 | 2018-04-26 00:17:01 -0700 | [diff] [blame] | 1701 | # do not match until end-of-line, otherwise we won't allow |
| 1702 | # stc_regex below to catch the ones that are declared in the same |
| 1703 | # line--as we only search starting the end of this match |
| 1704 | br"^\s*ztest_test_suite\(\s*(?P<suite_name>[a-zA-Z0-9_]+)\s*,", |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1705 | re.MULTILINE) |
| 1706 | stc_regex = re.compile( |
Inaky Perez-Gonzalez | 75e2d90 | 2018-04-26 00:17:01 -0700 | [diff] [blame] | 1707 | br"^\s*" # empy space at the beginning is ok |
| 1708 | # catch the case where it is declared in the same sentence, e.g: |
| 1709 | # |
| 1710 | # ztest_test_suite(mutex_complex, ztest_user_unit_test(TESTNAME)); |
| 1711 | br"(?:ztest_test_suite\([a-zA-Z0-9_]+,\s*)?" |
| 1712 | # Catch ztest[_user]_unit_test-[_setup_teardown](TESTNAME) |
| 1713 | br"ztest_(?:user_)?unit_test(?:_setup_teardown)?" |
| 1714 | # Consume the argument that becomes the extra testcse |
| 1715 | br"\(\s*" |
| 1716 | br"(?P<stc_name>[a-zA-Z0-9_]+)" |
| 1717 | # _setup_teardown() variant has two extra arguments that we ignore |
| 1718 | br"(?:\s*,\s*[a-zA-Z0-9_]+\s*,\s*[a-zA-Z0-9_]+)?" |
| 1719 | br"\s*\)", |
| 1720 | # We don't check how it finishes; we don't care |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1721 | re.MULTILINE) |
| 1722 | suite_run_regex = re.compile( |
| 1723 | br"^\s*ztest_run_test_suite\((?P<suite_name>[a-zA-Z0-9_]+)\)", |
| 1724 | re.MULTILINE) |
| 1725 | achtung_regex = re.compile( |
| 1726 | br"(#ifdef|#endif)", |
| 1727 | re.MULTILINE) |
| 1728 | warnings = None |
| 1729 | |
| 1730 | with open(inf_name) as inf: |
| 1731 | with contextlib.closing(mmap.mmap(inf.fileno(), 0, mmap.MAP_PRIVATE, |
| 1732 | mmap.PROT_READ, 0)) as main_c: |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1733 | suite_regex_match = suite_regex.search(main_c) |
| 1734 | if not suite_regex_match: |
| 1735 | # can't find ztest_test_suite, maybe a client, because |
| 1736 | # it includes ztest.h |
| 1737 | return None, None |
| 1738 | |
| 1739 | suite_run_match = suite_run_regex.search(main_c) |
| 1740 | if not suite_run_match: |
| 1741 | raise ValueError("can't find ztest_run_test_suite") |
| 1742 | |
| 1743 | achtung_matches = re.findall( |
| 1744 | achtung_regex, |
| 1745 | main_c[suite_regex_match.end():suite_run_match.start()]) |
| 1746 | if achtung_matches: |
| 1747 | warnings = "found invalid %s in ztest_test_suite()" \ |
Inaky Perez-Gonzalez | 75e2d90 | 2018-04-26 00:17:01 -0700 | [diff] [blame] | 1748 | % ", ".join(set([ |
| 1749 | match.decode() for match in achtung_matches |
| 1750 | ])) |
| 1751 | _matches = re.findall( |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1752 | stc_regex, |
| 1753 | main_c[suite_regex_match.end():suite_run_match.start()]) |
Inaky Perez-Gonzalez | 75e2d90 | 2018-04-26 00:17:01 -0700 | [diff] [blame] | 1754 | matches = [ match.decode().replace("test_", "") for match in _matches ] |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1755 | return matches, warnings |
| 1756 | |
| 1757 | def scan_path(self, path): |
| 1758 | subcases = [] |
| 1759 | for filename in glob.glob(os.path.join(path, "src", "*.c")): |
| 1760 | try: |
| 1761 | _subcases, warnings = self.scan_file(filename) |
| 1762 | if warnings: |
Inaky Perez-Gonzalez | 75e2d90 | 2018-04-26 00:17:01 -0700 | [diff] [blame] | 1763 | error("%s: %s" % (filename, warnings)) |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1764 | if _subcases: |
| 1765 | subcases += _subcases |
| 1766 | except ValueError as e: |
| 1767 | error("%s: can't find: %s", filename, e) |
| 1768 | return subcases |
| 1769 | |
| 1770 | |
| 1771 | def parse_subcases(self): |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 1772 | results = self.scan_path(self.test_path) |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1773 | for sub in results: |
Inaky Perez-Gonzalez | 75e2d90 | 2018-04-26 00:17:01 -0700 | [diff] [blame] | 1774 | name = "{}.{}".format(self.id, sub) |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1775 | self.cases.append(name) |
| 1776 | |
| 1777 | |
Anas Nashif | 75547e2 | 2018-02-24 08:32:14 -0600 | [diff] [blame] | 1778 | def __str__(self): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1779 | return self.name |
| 1780 | |
| 1781 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1782 | class TestInstance: |
| 1783 | """Class representing the execution of a particular TestCase on a platform |
| 1784 | |
| 1785 | @param test The TestCase object we want to build/execute |
| 1786 | @param platform Platform object that we want to build and run against |
| 1787 | @param base_outdir Base directory for all test results. The actual |
| 1788 | out directory used is <outdir>/<platform>/<test case name> |
| 1789 | """ |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1790 | |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 1791 | def __init__(self, test, platform, base_outdir): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1792 | self.test = test |
| 1793 | self.platform = platform |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 1794 | self.name = os.path.join(platform.name, test.name) |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 1795 | self.outdir = os.path.join(base_outdir, platform.name, test.name) |
Anas Nashif | 7dd19ea | 2018-11-14 08:46:49 -0500 | [diff] [blame] | 1796 | |
| 1797 | self.build_only = options.build_only or test.build_only \ |
| 1798 | or self.check_dependency() |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 1799 | self.results = {} |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1800 | |
Anas Nashif | 7dd19ea | 2018-11-14 08:46:49 -0500 | [diff] [blame] | 1801 | def check_dependency(self): |
| 1802 | build_only = False |
| 1803 | if self.test.harness == 'console': |
| 1804 | if "fixture" in self.test.harness_config: |
| 1805 | fixture = self.test.harness_config['fixture'] |
| 1806 | if fixture not in options.fixture: |
| 1807 | build_only = True |
| 1808 | elif self.test.harness: |
| 1809 | build_only = True |
| 1810 | |
| 1811 | return build_only |
| 1812 | |
Anas Nashif | dbd7649 | 2018-11-23 20:24:19 -0500 | [diff] [blame] | 1813 | def create_overlay(self, platform): |
Anas Nashif | 3cbffef | 2018-11-07 23:50:54 -0500 | [diff] [blame] | 1814 | file = os.path.join(self.outdir, "overlay.conf") |
| 1815 | os.makedirs(self.outdir, exist_ok=True) |
Anas Nashif | f4d8ecc | 2019-03-02 15:43:23 -0500 | [diff] [blame] | 1816 | with open(file, "w") as f: |
| 1817 | content = "" |
Anas Nashif | 3cbffef | 2018-11-07 23:50:54 -0500 | [diff] [blame] | 1818 | |
Anas Nashif | f4d8ecc | 2019-03-02 15:43:23 -0500 | [diff] [blame] | 1819 | if len(self.test.extra_configs) > 0: |
| 1820 | content = "\n".join(self.test.extra_configs) |
Anas Nashif | 3cbffef | 2018-11-07 23:50:54 -0500 | [diff] [blame] | 1821 | |
Anas Nashif | f4d8ecc | 2019-03-02 15:43:23 -0500 | [diff] [blame] | 1822 | if options.enable_coverage: |
| 1823 | if platform in options.coverage_platform: |
| 1824 | content = content + "\nCONFIG_COVERAGE=y" |
| 1825 | |
| 1826 | f.write(content) |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 1827 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1828 | def calculate_sizes(self): |
| 1829 | """Get the RAM/ROM sizes of a test case. |
| 1830 | |
| 1831 | This can only be run after the instance has been executed by |
| 1832 | MakeGenerator, otherwise there won't be any binaries to measure. |
| 1833 | |
| 1834 | @return A SizeCalculator object |
| 1835 | """ |
Anas Nashif | fb91ad6 | 2017-10-31 08:33:17 -0400 | [diff] [blame] | 1836 | fns = glob.glob(os.path.join(self.outdir, "zephyr", "*.elf")) |
Anas Nashif | 2f4e170 | 2017-11-24 08:11:25 -0500 | [diff] [blame] | 1837 | fns.extend(glob.glob(os.path.join(self.outdir, "zephyr", "*.exe"))) |
Anas Nashif | f8dcad4 | 2016-10-27 18:10:08 -0400 | [diff] [blame] | 1838 | fns = [x for x in fns if not x.endswith('_prebuilt.elf')] |
Andrew Boie | 5d4eb78 | 2015-10-02 10:04:56 -0700 | [diff] [blame] | 1839 | if (len(fns) != 1): |
| 1840 | raise BuildError("Missing/multiple output ELF binary") |
Andrew Boie | 52fef67 | 2016-11-29 12:21:59 -0800 | [diff] [blame] | 1841 | return SizeCalculator(fns[0], self.test.extra_sections) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1842 | |
| 1843 | def __repr__(self): |
| 1844 | return "<TestCase %s on %s>" % (self.test.name, self.platform.name) |
| 1845 | |
| 1846 | |
Andrew Boie | 4ef16c5 | 2015-08-28 12:36:03 -0700 | [diff] [blame] | 1847 | def defconfig_cb(context, goals, goal): |
| 1848 | if not goal.failed: |
| 1849 | return |
| 1850 | |
| 1851 | info("%sCould not build defconfig for %s%s" % |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1852 | (COLOR_RED, goal.name, COLOR_NORMAL)) |
Andrew Boie | 4ef16c5 | 2015-08-28 12:36:03 -0700 | [diff] [blame] | 1853 | if INLINE_LOGS: |
| 1854 | with open(goal.get_error_log()) as fp: |
Inaky Perez-Gonzalez | 9a36cb6 | 2016-11-29 10:43:40 -0800 | [diff] [blame] | 1855 | data = fp.read() |
| 1856 | sys.stdout.write(data) |
| 1857 | if log_file: |
| 1858 | log_file.write(data) |
Andrew Boie | 4ef16c5 | 2015-08-28 12:36:03 -0700 | [diff] [blame] | 1859 | else: |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 1860 | info("\tsee: " + COLOR_YELLOW + goal.get_error_log() + COLOR_NORMAL) |
Andrew Boie | 4ef16c5 | 2015-08-28 12:36:03 -0700 | [diff] [blame] | 1861 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1862 | |
| 1863 | class TestSuite: |
Andrew Boie | 60823c2 | 2017-02-10 09:43:07 -0800 | [diff] [blame] | 1864 | config_re = re.compile('(CONFIG_[A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$') |
Anas Nashif | 1c65b6b | 2018-12-02 19:12:21 -0500 | [diff] [blame] | 1865 | dt_re = re.compile('([A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$') |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1866 | |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 1867 | yaml_tc_schema = scl.yaml_load( |
Oleg Zhurakivskyy | 4282208 | 2018-08-17 14:54:41 +0300 | [diff] [blame] | 1868 | os.path.join(ZEPHYR_BASE, |
Anas Nashif | db3d55f | 2017-09-02 06:31:25 -0400 | [diff] [blame] | 1869 | "scripts", "sanity_chk", "sanitycheck-tc-schema.yaml")) |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 1870 | |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 1871 | def __init__(self, board_root_list, testcase_roots, outdir): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1872 | # Keep track of which test cases we've filtered out and why |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1873 | self.arches = {} |
| 1874 | self.testcases = {} |
| 1875 | self.platforms = [] |
Andrew Boie | b391e66 | 2015-08-31 15:25:45 -0700 | [diff] [blame] | 1876 | self.outdir = os.path.abspath(outdir) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1877 | self.instances = {} |
| 1878 | self.goals = None |
| 1879 | self.discards = None |
Kumar Gala | c84235e | 2018-04-10 13:32:51 -0500 | [diff] [blame] | 1880 | self.load_errors = 0 |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1881 | |
Andrew Boie | 3d34871 | 2016-04-08 11:52:13 -0700 | [diff] [blame] | 1882 | for testcase_root in testcase_roots: |
| 1883 | testcase_root = os.path.abspath(testcase_root) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1884 | |
Andrew Boie | 3d34871 | 2016-04-08 11:52:13 -0700 | [diff] [blame] | 1885 | debug("Reading test case configuration files under %s..." % |
| 1886 | testcase_root) |
| 1887 | for dirpath, dirnames, filenames in os.walk(testcase_root, |
| 1888 | topdown=True): |
| 1889 | verbose("scanning %s" % dirpath) |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 1890 | if 'sample.yaml' in filenames: |
| 1891 | filename = 'sample.yaml' |
| 1892 | elif 'testcase.yaml' in filenames: |
| 1893 | filename = 'testcase.yaml' |
| 1894 | else: |
| 1895 | continue |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 1896 | |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 1897 | verbose("Found possible test case in " + dirpath) |
| 1898 | dirnames[:] = [] |
| 1899 | yaml_path = os.path.join(dirpath, filename) |
| 1900 | try: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1901 | parsed_data = SanityConfigParser( |
| 1902 | yaml_path, self.yaml_tc_schema) |
Andrew Boie | 3d34871 | 2016-04-08 11:52:13 -0700 | [diff] [blame] | 1903 | |
Paul Sokolovsky | 100474d | 2018-01-03 17:19:43 +0200 | [diff] [blame] | 1904 | workdir = os.path.relpath(dirpath, testcase_root) |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 1905 | |
Paul Sokolovsky | 100474d | 2018-01-03 17:19:43 +0200 | [diff] [blame] | 1906 | for name in parsed_data.tests.keys(): |
| 1907 | tc_dict = parsed_data.get_test(name, testcase_valid_keys) |
| 1908 | tc = TestCase(testcase_root, workdir, name, tc_dict, |
| 1909 | yaml_path) |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1910 | tc.parse_subcases() |
Paul Sokolovsky | 100474d | 2018-01-03 17:19:43 +0200 | [diff] [blame] | 1911 | self.testcases[tc.name] = tc |
| 1912 | |
| 1913 | except Exception as e: |
| 1914 | error("E: %s: can't load (skipping): %s" % (yaml_path, e)) |
Kumar Gala | c84235e | 2018-04-10 13:32:51 -0500 | [diff] [blame] | 1915 | self.load_errors += 1 |
Paul Sokolovsky | 100474d | 2018-01-03 17:19:43 +0200 | [diff] [blame] | 1916 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1917 | |
Anas Nashif | 86c8e23 | 2017-10-09 13:42:28 -0400 | [diff] [blame] | 1918 | for board_root in board_root_list: |
| 1919 | board_root = os.path.abspath(board_root) |
| 1920 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1921 | debug( |
| 1922 | "Reading platform configuration files under %s..." % |
| 1923 | board_root) |
Anas Nashif | 8b11a1f | 2017-11-26 17:08:47 -0500 | [diff] [blame] | 1924 | for fn in glob.glob(os.path.join(board_root, "*", "*", "*.yaml")): |
| 1925 | verbose("Found plaform configuration " + fn) |
| 1926 | try: |
| 1927 | platform = Platform(fn) |
Anas Nashif | f3d48e1 | 2018-07-24 08:14:42 -0500 | [diff] [blame] | 1928 | if platform.sanitycheck: |
| 1929 | self.platforms.append(platform) |
Anas Nashif | 8b11a1f | 2017-11-26 17:08:47 -0500 | [diff] [blame] | 1930 | except RuntimeError as e: |
| 1931 | error("E: %s: can't load: %s" % (fn, e)) |
Kumar Gala | c84235e | 2018-04-10 13:32:51 -0500 | [diff] [blame] | 1932 | self.load_errors += 1 |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1933 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1934 | arches = [] |
| 1935 | for p in self.platforms: |
| 1936 | arches.append(p.arch) |
| 1937 | for a in list(set(arches)): |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1938 | aplatforms = [p for p in self.platforms if p.arch == a] |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1939 | arch = Architecture(a, aplatforms) |
| 1940 | self.arches[a] = arch |
| 1941 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1942 | self.instances = {} |
| 1943 | |
Anas Nashif | f4d8ecc | 2019-03-02 15:43:23 -0500 | [diff] [blame] | 1944 | def get_platform(self, name): |
| 1945 | selected_platform = None |
| 1946 | for platform in self.platforms: |
| 1947 | if platform.name == name: |
| 1948 | selected_platform = platform |
| 1949 | break |
| 1950 | return selected_platform |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 1951 | |
Anas Nashif | f4d8ecc | 2019-03-02 15:43:23 -0500 | [diff] [blame] | 1952 | def get_last_failed(self): |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 1953 | try: |
| 1954 | if not os.path.exists(LAST_SANITY): |
| 1955 | raise SanityRuntimeError("Couldn't find last sanity run.") |
| 1956 | except Exception as e: |
| 1957 | print(str(e)) |
| 1958 | sys.exit(2) |
| 1959 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1960 | result = [] |
| 1961 | with open(LAST_SANITY, "r") as fp: |
| 1962 | cr = csv.DictReader(fp) |
Anas Nashif | f4d8ecc | 2019-03-02 15:43:23 -0500 | [diff] [blame] | 1963 | instance_list = [] |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1964 | for row in cr: |
| 1965 | if row["passed"] == "True": |
| 1966 | continue |
| 1967 | test = row["test"] |
Anas Nashif | f4d8ecc | 2019-03-02 15:43:23 -0500 | [diff] [blame] | 1968 | platform = self.get_platform(row["platform"]) |
| 1969 | instance = TestInstance(self.testcases[test], platform, self.outdir) |
| 1970 | instance.create_overlay(platform.name) |
| 1971 | instance_list.append(instance) |
| 1972 | self.add_instances(instance_list) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1973 | |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 1974 | def load_from_file(self, file): |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 1975 | try: |
| 1976 | if not os.path.exists(file): |
| 1977 | raise SanityRuntimeError( |
| 1978 | "Couldn't find input file with list of tests.") |
| 1979 | except Exception as e: |
| 1980 | print(str(e)) |
| 1981 | sys.exit(2) |
| 1982 | |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 1983 | with open(file, "r") as fp: |
| 1984 | cr = csv.reader(fp) |
| 1985 | instance_list = [] |
| 1986 | for row in cr: |
| 1987 | name = os.path.join(row[0], row[1]) |
Anas Nashif | f4d8ecc | 2019-03-02 15:43:23 -0500 | [diff] [blame] | 1988 | platform = self.get_platform(row[2]) |
| 1989 | instance = TestInstance(self.testcases[name], platform, self.outdir) |
| 1990 | instance.create_overlay(platform.name) |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 1991 | instance_list.append(instance) |
| 1992 | self.add_instances(instance_list) |
| 1993 | |
Anas Nashif | 4f02888 | 2017-12-30 11:48:43 -0500 | [diff] [blame] | 1994 | def apply_filters(self): |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 1995 | |
Anas Nashif | 7fe35cf | 2018-02-15 07:20:18 -0600 | [diff] [blame] | 1996 | toolchain = os.environ.get("ZEPHYR_TOOLCHAIN_VARIANT", None) or \ |
| 1997 | os.environ.get("ZEPHYR_GCC_VARIANT", None) |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 1998 | |
Sebastian Bøe | 5681f87 | 2018-10-12 16:03:49 +0200 | [diff] [blame] | 1999 | if toolchain == "gccarmemb": |
| 2000 | # Remove this translation when gccarmemb is no longer supported. |
| 2001 | toolchain = "gnuarmemb" |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 2002 | |
| 2003 | try: |
| 2004 | if not toolchain: |
| 2005 | raise SanityRuntimeError("E: Variable ZEPHYR_TOOLCHAIN_VARIANT is not defined") |
| 2006 | except Exception as e: |
| 2007 | print(str(e)) |
| 2008 | sys.exit(2) |
Anas Nashif | 7fe35cf | 2018-02-15 07:20:18 -0600 | [diff] [blame] | 2009 | |
| 2010 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2011 | instances = [] |
| 2012 | discards = {} |
Anas Nashif | 4f02888 | 2017-12-30 11:48:43 -0500 | [diff] [blame] | 2013 | platform_filter = options.platform |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 2014 | testcase_filter = run_individual_tests |
Anas Nashif | 4f02888 | 2017-12-30 11:48:43 -0500 | [diff] [blame] | 2015 | arch_filter = options.arch |
| 2016 | tag_filter = options.tag |
| 2017 | exclude_tag = options.exclude_tag |
| 2018 | config_filter = options.config |
| 2019 | extra_args = options.extra_args |
| 2020 | all_plats = options.all |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 2021 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2022 | verbose("platform filter: " + str(platform_filter)) |
| 2023 | verbose(" arch_filter: " + str(arch_filter)) |
| 2024 | verbose(" tag_filter: " + str(tag_filter)) |
Anas Nashif | dfa86e2 | 2016-10-24 17:08:56 -0400 | [diff] [blame] | 2025 | verbose(" exclude_tag: " + str(exclude_tag)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2026 | verbose(" config_filter: " + str(config_filter)) |
| 2027 | |
Andrew Boie | 821d832 | 2016-03-22 10:08:35 -0700 | [diff] [blame] | 2028 | default_platforms = False |
| 2029 | |
| 2030 | if all_plats: |
| 2031 | info("Selecting all possible platforms per test case") |
| 2032 | # When --all used, any --platform arguments ignored |
| 2033 | platform_filter = [] |
| 2034 | elif not platform_filter: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2035 | info("Selecting default platforms per test case") |
| 2036 | default_platforms = True |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2037 | |
Sebastian Bøe | 781e398 | 2017-11-09 11:43:33 +0100 | [diff] [blame] | 2038 | mg = MakeGenerator(self.outdir) |
Anas Nashif | 1c65b6b | 2018-12-02 19:12:21 -0500 | [diff] [blame] | 2039 | defconfig_list = {} |
| 2040 | dt_list = {} |
Anas Nashif | 45a9786 | 2019-01-09 08:46:42 -0500 | [diff] [blame] | 2041 | cmake_list = {} |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 2042 | for tc_name, tc in self.testcases.items(): |
| 2043 | for arch_name, arch in self.arches.items(): |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2044 | for plat in arch.platforms: |
| 2045 | instance = TestInstance(tc, plat, self.outdir) |
| 2046 | |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 2047 | if (arch_name == "unit") != (tc.type == "unit"): |
| 2048 | continue |
| 2049 | |
Anas Nashif | bfab06b | 2017-06-22 09:22:24 -0400 | [diff] [blame] | 2050 | if tc.build_on_all and not platform_filter: |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 2051 | platform_filter = [] |
| 2052 | |
Anas Nashif | 2bd99bc | 2015-10-12 13:10:57 -0400 | [diff] [blame] | 2053 | if tc.skip: |
| 2054 | continue |
| 2055 | |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2056 | if tag_filter and not tc.tags.intersection(tag_filter): |
| 2057 | continue |
| 2058 | |
Anas Nashif | dfa86e2 | 2016-10-24 17:08:56 -0400 | [diff] [blame] | 2059 | if exclude_tag and tc.tags.intersection(exclude_tag): |
| 2060 | continue |
| 2061 | |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2062 | if testcase_filter and tc_name not in testcase_filter: |
| 2063 | continue |
| 2064 | |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2065 | if arch_filter and arch_name not in arch_filter: |
| 2066 | continue |
| 2067 | |
| 2068 | if tc.arch_whitelist and arch.name not in tc.arch_whitelist: |
| 2069 | continue |
| 2070 | |
| 2071 | if tc.arch_exclude and arch.name in tc.arch_exclude: |
| 2072 | continue |
| 2073 | |
| 2074 | if tc.platform_exclude and plat.name in tc.platform_exclude: |
| 2075 | continue |
| 2076 | |
Anas Nashif | b17e1ca | 2017-06-27 18:05:30 -0400 | [diff] [blame] | 2077 | if tc.toolchain_exclude and toolchain in tc.toolchain_exclude: |
| 2078 | continue |
| 2079 | |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2080 | if platform_filter and plat.name not in platform_filter: |
| 2081 | continue |
| 2082 | |
Anas Nashif | 6222418 | 2017-08-09 23:55:53 -0400 | [diff] [blame] | 2083 | if plat.ram < tc.min_ram: |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 2084 | continue |
| 2085 | |
| 2086 | if set(plat.ignore_tags) & tc.tags: |
| 2087 | continue |
| 2088 | |
Kumar Gala | 5141d52 | 2017-07-07 08:05:48 -0500 | [diff] [blame] | 2089 | if tc.depends_on: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2090 | dep_intersection = tc.depends_on.intersection( |
| 2091 | set(plat.supported)) |
Kumar Gala | 5141d52 | 2017-07-07 08:05:48 -0500 | [diff] [blame] | 2092 | if dep_intersection != set(tc.depends_on): |
| 2093 | continue |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 2094 | |
| 2095 | if plat.flash < tc.min_flash: |
| 2096 | continue |
| 2097 | |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2098 | if tc.platform_whitelist and plat.name not in tc.platform_whitelist: |
| 2099 | continue |
| 2100 | |
Anas Nashif | b17e1ca | 2017-06-27 18:05:30 -0400 | [diff] [blame] | 2101 | if tc.toolchain_whitelist and toolchain not in tc.toolchain_whitelist: |
| 2102 | continue |
| 2103 | |
Anas Nashif | 924a4e7 | 2018-10-18 12:25:55 -0400 | [diff] [blame] | 2104 | if (plat.env_satisfied and tc.tc_filter |
| 2105 | and (plat.default or all_plats or platform_filter) |
Anas Nashif | 07d54c0 | 2018-07-21 19:29:08 -0500 | [diff] [blame] | 2106 | and (toolchain in plat.supported_toolchains or options.force_toolchain)): |
Anas Nashif | 8ea9d02 | 2015-11-10 12:24:20 -0500 | [diff] [blame] | 2107 | args = tc.extra_args[:] |
Anas Nashif | fb91ad6 | 2017-10-31 08:33:17 -0400 | [diff] [blame] | 2108 | args.append("BOARD={}".format(plat.name)) |
Andrew Boie | ba61200 | 2016-09-01 10:41:03 -0700 | [diff] [blame] | 2109 | args.extend(extra_args) |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2110 | # FIXME would be nice to use a common outdir for this so that |
Andrew Boie | 4187822 | 2016-11-03 11:58:53 -0700 | [diff] [blame] | 2111 | # conf, gen_idt, etc aren't rebuilt for every combination, |
David B. Kinder | 29963c3 | 2017-06-16 12:32:42 -0700 | [diff] [blame] | 2112 | # need a way to avoid different Make processes from clobbering |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2113 | # each other since they all try to build them |
| 2114 | # simultaneously |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2115 | |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 2116 | o = os.path.join(self.outdir, plat.name, tc.name) |
Anas Nashif | 45a9786 | 2019-01-09 08:46:42 -0500 | [diff] [blame] | 2117 | cmake_cache_path = os.path.join(o, "CMakeCache.txt") |
Anas Nashif | 1c65b6b | 2018-12-02 19:12:21 -0500 | [diff] [blame] | 2118 | generated_dt_confg = "include/generated/generated_dts_board.conf" |
| 2119 | dt_config_path = os.path.join(o, "zephyr", generated_dt_confg) |
| 2120 | dt_list[tc, plat, tc.name.split("/")[-1]] = dt_config_path |
Anas Nashif | 45a9786 | 2019-01-09 08:46:42 -0500 | [diff] [blame] | 2121 | cmake_list[tc, plat, tc.name.split("/")[-1]] = cmake_cache_path |
Anas Nashif | 1c65b6b | 2018-12-02 19:12:21 -0500 | [diff] [blame] | 2122 | defconfig_list[tc, plat, tc.name.split("/")[-1]] = os.path.join(o, "zephyr", ".config") |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 2123 | goal = "_".join([plat.name, "_".join(tc.name.split("/")), "config-sanitycheck"]) |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 2124 | mg.add_build_goal(goal, os.path.join(ZEPHYR_BASE, tc.test_path), |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 2125 | o, args, "config-sanitycheck.log", make_args="config-sanitycheck") |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2126 | |
| 2127 | info("Building testcase defconfigs...") |
| 2128 | results = mg.execute(defconfig_cb) |
| 2129 | |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 2130 | for name, goal in results.items(): |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 2131 | try: |
| 2132 | if goal.failed: |
| 2133 | raise SanityRuntimeError("Couldn't build some defconfigs") |
| 2134 | except Exception as e: |
| 2135 | error(str(e)) |
| 2136 | sys.exit(2) |
| 2137 | |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2138 | |
Anas Nashif | 1c65b6b | 2018-12-02 19:12:21 -0500 | [diff] [blame] | 2139 | for k, out_config in defconfig_list.items(): |
Andrew Boie | 4187822 | 2016-11-03 11:58:53 -0700 | [diff] [blame] | 2140 | test, plat, name = k |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2141 | defconfig = {} |
| 2142 | with open(out_config, "r") as fp: |
| 2143 | for line in fp.readlines(): |
| 2144 | m = TestSuite.config_re.match(line) |
| 2145 | if not m: |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 2146 | if line.strip() and not line.startswith("#"): |
| 2147 | sys.stderr.write("Unrecognized line %s\n" % line) |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2148 | continue |
| 2149 | defconfig[m.group(1)] = m.group(2).strip() |
Andrew Boie | 4187822 | 2016-11-03 11:58:53 -0700 | [diff] [blame] | 2150 | test.defconfig[plat] = defconfig |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2151 | |
Anas Nashif | 45a9786 | 2019-01-09 08:46:42 -0500 | [diff] [blame] | 2152 | for k, cache_file in cmake_list.items(): |
| 2153 | if not os.path.exists(out_config): |
| 2154 | continue |
| 2155 | |
| 2156 | test, plat, name = k |
| 2157 | cmake_conf = {} |
| 2158 | try: |
| 2159 | cache = CMakeCache.from_file(cache_file) |
| 2160 | except FileNotFoundError: |
| 2161 | cache = {} |
| 2162 | |
| 2163 | for k in iter(cache): |
| 2164 | cmake_conf[k.name] = k.value |
| 2165 | |
| 2166 | test.cmake_cache[plat] = cmake_conf |
| 2167 | |
Anas Nashif | 1c65b6b | 2018-12-02 19:12:21 -0500 | [diff] [blame] | 2168 | for k, out_config in dt_list.items(): |
| 2169 | if not os.path.exists(out_config): |
| 2170 | continue |
| 2171 | |
| 2172 | test, plat, name = k |
| 2173 | dt_conf = {} |
| 2174 | with open(out_config, "r") as fp: |
| 2175 | for line in fp.readlines(): |
| 2176 | m = TestSuite.dt_re.match(line) |
| 2177 | if not m: |
| 2178 | if line.strip() and not line.startswith("#"): |
| 2179 | sys.stderr.write("Unrecognized line %s\n" % line) |
| 2180 | continue |
| 2181 | dt_conf[m.group(1)] = m.group(2).strip() |
| 2182 | test.dt_config[plat] = dt_conf |
| 2183 | |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 2184 | for tc_name, tc in self.testcases.items(): |
| 2185 | for arch_name, arch in self.arches.items(): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2186 | instance_list = [] |
| 2187 | for plat in arch.platforms: |
| 2188 | instance = TestInstance(tc, plat, self.outdir) |
| 2189 | |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 2190 | if (arch_name == "unit") != (tc.type == "unit"): |
| 2191 | # Discard silently |
| 2192 | continue |
| 2193 | |
Anas Nashif | 2bd99bc | 2015-10-12 13:10:57 -0400 | [diff] [blame] | 2194 | if tc.skip: |
| 2195 | discards[instance] = "Skip filter" |
| 2196 | continue |
| 2197 | |
Anas Nashif | bfab06b | 2017-06-22 09:22:24 -0400 | [diff] [blame] | 2198 | if tc.build_on_all and not platform_filter: |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 2199 | platform_filter = [] |
| 2200 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2201 | if tag_filter and not tc.tags.intersection(tag_filter): |
| 2202 | discards[instance] = "Command line testcase tag filter" |
| 2203 | continue |
| 2204 | |
Anas Nashif | dfa86e2 | 2016-10-24 17:08:56 -0400 | [diff] [blame] | 2205 | if exclude_tag and tc.tags.intersection(exclude_tag): |
| 2206 | discards[instance] = "Command line testcase exclude filter" |
| 2207 | continue |
| 2208 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2209 | if testcase_filter and tc_name not in testcase_filter: |
| 2210 | discards[instance] = "Testcase name filter" |
| 2211 | continue |
| 2212 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2213 | if arch_filter and arch_name not in arch_filter: |
| 2214 | discards[instance] = "Command line testcase arch filter" |
| 2215 | continue |
| 2216 | |
| 2217 | if tc.arch_whitelist and arch.name not in tc.arch_whitelist: |
| 2218 | discards[instance] = "Not in test case arch whitelist" |
| 2219 | continue |
| 2220 | |
Anas Nashif | 30d1387 | 2015-10-05 10:02:45 -0400 | [diff] [blame] | 2221 | if tc.arch_exclude and arch.name in tc.arch_exclude: |
| 2222 | discards[instance] = "In test case arch exclude" |
| 2223 | continue |
| 2224 | |
| 2225 | if tc.platform_exclude and plat.name in tc.platform_exclude: |
| 2226 | discards[instance] = "In test case platform exclude" |
| 2227 | continue |
| 2228 | |
Anas Nashif | b17e1ca | 2017-06-27 18:05:30 -0400 | [diff] [blame] | 2229 | if tc.toolchain_exclude and toolchain in tc.toolchain_exclude: |
| 2230 | discards[instance] = "In test case toolchain exclude" |
| 2231 | continue |
| 2232 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2233 | if platform_filter and plat.name not in platform_filter: |
| 2234 | discards[instance] = "Command line platform filter" |
| 2235 | continue |
| 2236 | |
| 2237 | if tc.platform_whitelist and plat.name not in tc.platform_whitelist: |
| 2238 | discards[instance] = "Not in testcase platform whitelist" |
| 2239 | continue |
| 2240 | |
Anas Nashif | b17e1ca | 2017-06-27 18:05:30 -0400 | [diff] [blame] | 2241 | if tc.toolchain_whitelist and toolchain not in tc.toolchain_whitelist: |
| 2242 | discards[instance] = "Not in testcase toolchain whitelist" |
| 2243 | continue |
| 2244 | |
Anas Nashif | 924a4e7 | 2018-10-18 12:25:55 -0400 | [diff] [blame] | 2245 | if not plat.env_satisfied: |
| 2246 | discards[instance] = "Environment ({}) not satisfied".format(", ".join(plat.env)) |
| 2247 | continue |
| 2248 | |
| 2249 | if not options.force_toolchain \ |
| 2250 | and toolchain and (toolchain not in plat.supported_toolchains) \ |
| 2251 | and tc.type != 'unit': |
Javier B Perez | 4b554ba | 2016-08-15 13:25:33 -0500 | [diff] [blame] | 2252 | discards[instance] = "Not supported by the toolchain" |
| 2253 | continue |
| 2254 | |
Anas Nashif | 6222418 | 2017-08-09 23:55:53 -0400 | [diff] [blame] | 2255 | if plat.ram < tc.min_ram: |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 2256 | discards[instance] = "Not enough RAM" |
| 2257 | continue |
| 2258 | |
Kumar Gala | 5141d52 | 2017-07-07 08:05:48 -0500 | [diff] [blame] | 2259 | if tc.depends_on: |
Anas Nashif | 07d54c0 | 2018-07-21 19:29:08 -0500 | [diff] [blame] | 2260 | dep_intersection = tc.depends_on.intersection(set(plat.supported)) |
Kumar Gala | 5141d52 | 2017-07-07 08:05:48 -0500 | [diff] [blame] | 2261 | if dep_intersection != set(tc.depends_on): |
| 2262 | discards[instance] = "No hardware support" |
| 2263 | continue |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 2264 | |
Anas Nashif | 6222418 | 2017-08-09 23:55:53 -0400 | [diff] [blame] | 2265 | if plat.flash < tc.min_flash: |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 2266 | discards[instance] = "Not enough FLASH" |
| 2267 | continue |
| 2268 | |
| 2269 | if set(plat.ignore_tags) & tc.tags: |
| 2270 | discards[instance] = "Excluded tags per platform" |
| 2271 | continue |
| 2272 | |
Anas Nashif | 674bb28 | 2018-01-09 09:12:15 -0500 | [diff] [blame] | 2273 | defconfig = { |
Anas Nashif | 674bb28 | 2018-01-09 09:12:15 -0500 | [diff] [blame] | 2274 | "ARCH": arch.name, |
| 2275 | "PLATFORM": plat.name |
| 2276 | } |
Javier B Perez | 7941454 | 2016-08-08 12:24:59 -0500 | [diff] [blame] | 2277 | defconfig.update(os.environ) |
Andrew Boie | 4187822 | 2016-11-03 11:58:53 -0700 | [diff] [blame] | 2278 | for p, tdefconfig in tc.defconfig.items(): |
| 2279 | if p == plat: |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 2280 | defconfig.update(tdefconfig) |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2281 | break |
| 2282 | |
Anas Nashif | 1c65b6b | 2018-12-02 19:12:21 -0500 | [diff] [blame] | 2283 | for p, tdefconfig in tc.dt_config.items(): |
| 2284 | if p == plat: |
| 2285 | defconfig.update(tdefconfig) |
| 2286 | break |
| 2287 | |
Anas Nashif | 45a9786 | 2019-01-09 08:46:42 -0500 | [diff] [blame] | 2288 | for p, tdefconfig in tc.cmake_cache.items(): |
| 2289 | if p == plat: |
| 2290 | defconfig.update(tdefconfig) |
| 2291 | break |
| 2292 | |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 2293 | if tc.tc_filter: |
| 2294 | try: |
| 2295 | res = expr_parser.parse(tc.tc_filter, defconfig) |
Andrew Boie | c09b4b8 | 2017-04-18 11:46:07 -0700 | [diff] [blame] | 2296 | except (ValueError, SyntaxError) as se: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2297 | sys.stderr.write( |
| 2298 | "Failed processing %s\n" % tc.yamlfile) |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 2299 | raise se |
| 2300 | if not res: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2301 | discards[instance] = ( |
| 2302 | "defconfig doesn't satisfy expression '%s'" % |
| 2303 | tc.tc_filter) |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 2304 | continue |
Anas Nashif | 2cf0df0 | 2015-10-10 09:29:43 -0400 | [diff] [blame] | 2305 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2306 | instance_list.append(instance) |
| 2307 | |
| 2308 | if not instance_list: |
| 2309 | # Every platform in this arch was rejected already |
| 2310 | continue |
| 2311 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 2312 | if default_platforms and not tc.build_on_all: |
| 2313 | if not tc.platform_whitelist: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2314 | instances = list( |
| 2315 | filter( |
| 2316 | lambda tc: tc.platform.default, |
| 2317 | instance_list)) |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 2318 | self.add_instances(instances) |
| 2319 | else: |
Anas Nashif | ab74706 | 2017-12-05 17:59:01 -0500 | [diff] [blame] | 2320 | self.add_instances(instance_list[:1]) |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 2321 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2322 | for instance in list( |
| 2323 | filter(lambda tc: not tc.platform.default, instance_list)): |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 2324 | discards[instance] = "Not a default test platform" |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2325 | else: |
Andrew Boie | 821d832 | 2016-03-22 10:08:35 -0700 | [diff] [blame] | 2326 | self.add_instances(instance_list) |
Anas Nashif | ab351f4 | 2018-04-08 08:57:48 -0500 | [diff] [blame] | 2327 | |
| 2328 | for name, case in self.instances.items(): |
Anas Nashif | dbd7649 | 2018-11-23 20:24:19 -0500 | [diff] [blame] | 2329 | case.create_overlay(case.platform.name) |
Anas Nashif | ab351f4 | 2018-04-08 08:57:48 -0500 | [diff] [blame] | 2330 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2331 | self.discards = discards |
| 2332 | return discards |
| 2333 | |
Andrew Boie | 821d832 | 2016-03-22 10:08:35 -0700 | [diff] [blame] | 2334 | def add_instances(self, ti_list): |
| 2335 | for ti in ti_list: |
| 2336 | self.instances[ti.name] = ti |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2337 | |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 2338 | def execute(self, cb, cb_context): |
Daniel Leung | 6b17007 | 2016-04-07 12:10:25 -0700 | [diff] [blame] | 2339 | |
| 2340 | def calc_one_elf_size(name, goal): |
| 2341 | if not goal.failed: |
Alberto Escolar Piedras | b1045fe | 2018-07-14 13:11:02 +0200 | [diff] [blame] | 2342 | if self.instances[name].platform.type != "native": |
| 2343 | i = self.instances[name] |
| 2344 | sc = i.calculate_sizes() |
| 2345 | goal.metrics["ram_size"] = sc.get_ram_size() |
| 2346 | goal.metrics["rom_size"] = sc.get_rom_size() |
| 2347 | goal.metrics["unrecognized"] = sc.unrecognized_sections() |
| 2348 | else: |
| 2349 | goal.metrics["ram_size"] = 0 |
| 2350 | goal.metrics["rom_size"] = 0 |
| 2351 | goal.metrics["unrecognized"] = [] |
Daniel Leung | 6b17007 | 2016-04-07 12:10:25 -0700 | [diff] [blame] | 2352 | |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 2353 | mg = MakeGenerator(self.outdir) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2354 | for i in self.instances.values(): |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 2355 | mg.add_test_instance(i, options.extra_args) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2356 | self.goals = mg.execute(cb, cb_context) |
Daniel Leung | 6b17007 | 2016-04-07 12:10:25 -0700 | [diff] [blame] | 2357 | |
Andy Ross | 9c9162d | 2019-01-03 10:50:53 -0800 | [diff] [blame] | 2358 | if not options.disable_size_report: |
| 2359 | # Parallelize size calculation |
| 2360 | executor = concurrent.futures.ThreadPoolExecutor(JOBS) |
| 2361 | futures = [executor.submit(calc_one_elf_size, name, goal) |
| 2362 | for name, goal in self.goals.items()] |
| 2363 | concurrent.futures.wait(futures) |
| 2364 | else: |
| 2365 | for goal in self.goals.values(): |
| 2366 | goal.metrics["ram_size"] = 0 |
| 2367 | goal.metrics["rom_size"] = 0 |
| 2368 | goal.metrics["unrecognized"] = [] |
Daniel Leung | 6b17007 | 2016-04-07 12:10:25 -0700 | [diff] [blame] | 2369 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2370 | return self.goals |
| 2371 | |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 2372 | def run_report(self, filename): |
| 2373 | with open(filename, "at") as csvfile: |
| 2374 | fieldnames = ['path', 'test', 'platform', 'arch'] |
| 2375 | cw = csv.DictWriter(csvfile, fieldnames, lineterminator=os.linesep) |
| 2376 | for instance in self.instances.values(): |
| 2377 | rowdict = { |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2378 | "path": os.path.dirname(instance.test.name), |
| 2379 | "test": os.path.basename(instance.test.name), |
| 2380 | "platform": instance.platform.name, |
| 2381 | "arch": instance.platform.arch |
| 2382 | } |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 2383 | cw.writerow(rowdict) |
| 2384 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2385 | def discard_report(self, filename): |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 2386 | |
| 2387 | try: |
| 2388 | if self.discards is None: |
| 2389 | raise SanityRuntimeError("apply_filters() hasn't been run!") |
| 2390 | except Exception as e: |
| 2391 | error(str(e)) |
| 2392 | sys.exit(2) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2393 | |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 2394 | with open(filename, "wt") as csvfile: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2395 | fieldnames = ["test", "arch", "platform", "reason"] |
| 2396 | cw = csv.DictWriter(csvfile, fieldnames, lineterminator=os.linesep) |
| 2397 | cw.writeheader() |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 2398 | for instance, reason in self.discards.items(): |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2399 | rowdict = {"test": instance.test.name, |
| 2400 | "arch": instance.platform.arch, |
| 2401 | "platform": instance.platform.name, |
| 2402 | "reason": reason} |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2403 | cw.writerow(rowdict) |
| 2404 | |
| 2405 | def compare_metrics(self, filename): |
| 2406 | # name, datatype, lower results better |
| 2407 | interesting_metrics = [("ram_size", int, True), |
| 2408 | ("rom_size", int, True)] |
| 2409 | |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 2410 | try: |
| 2411 | if self.goals is None: |
| 2412 | raise SanityRuntimeError("execute() hasn't been run!") |
| 2413 | except Exception as e: |
| 2414 | print(str(e)) |
| 2415 | sys.exit(2) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2416 | |
| 2417 | if not os.path.exists(filename): |
| 2418 | info("Cannot compare metrics, %s not found" % filename) |
| 2419 | return [] |
| 2420 | |
| 2421 | results = [] |
| 2422 | saved_metrics = {} |
| 2423 | with open(filename) as fp: |
| 2424 | cr = csv.DictReader(fp) |
| 2425 | for row in cr: |
| 2426 | d = {} |
| 2427 | for m, _, _ in interesting_metrics: |
| 2428 | d[m] = row[m] |
| 2429 | saved_metrics[(row["test"], row["platform"])] = d |
| 2430 | |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 2431 | for name, goal in self.goals.items(): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2432 | i = self.instances[name] |
| 2433 | mkey = (i.test.name, i.platform.name) |
| 2434 | if mkey not in saved_metrics: |
| 2435 | continue |
| 2436 | sm = saved_metrics[mkey] |
| 2437 | for metric, mtype, lower_better in interesting_metrics: |
| 2438 | if metric not in goal.metrics: |
| 2439 | continue |
| 2440 | if sm[metric] == "": |
| 2441 | continue |
| 2442 | delta = goal.metrics[metric] - mtype(sm[metric]) |
Andrew Boie | ea7928f | 2015-08-14 14:27:38 -0700 | [diff] [blame] | 2443 | if delta == 0: |
| 2444 | continue |
| 2445 | results.append((i, metric, goal.metrics[metric], delta, |
| 2446 | lower_better)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2447 | return results |
| 2448 | |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2449 | |
| 2450 | |
| 2451 | def encode_for_xml(self, unicode_data, encoding='ascii'): |
| 2452 | unicode_data = unicode_data.replace('\x00', '') |
| 2453 | return unicode_data |
| 2454 | |
| 2455 | def testcase_target_report(self, report_file): |
| 2456 | |
| 2457 | run = "Sanitycheck" |
| 2458 | eleTestsuite = None |
| 2459 | append = options.only_failed |
| 2460 | |
| 2461 | errors = 0 |
| 2462 | passes = 0 |
| 2463 | fails = 0 |
| 2464 | duration = 0 |
| 2465 | skips = 0 |
| 2466 | |
| 2467 | for identifier, ti in self.instances.items(): |
| 2468 | for k in ti.results.keys(): |
| 2469 | if ti.results[k] == 'PASS': |
| 2470 | passes += 1 |
| 2471 | elif ti.results[k] == 'BLOCK': |
| 2472 | errors += 1 |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 2473 | elif ti.results[k] == 'SKIP': |
| 2474 | skips += 1 |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2475 | else: |
| 2476 | fails += 1 |
| 2477 | |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2478 | eleTestsuites = ET.Element('testsuites') |
| 2479 | eleTestsuite = ET.SubElement(eleTestsuites, 'testsuite', |
| 2480 | name=run, time="%d" % duration, |
| 2481 | tests="%d" % (errors + passes + fails), |
| 2482 | failures="%d" % fails, |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 2483 | errors="%d" % errors, skipped="%d" %skips) |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2484 | |
| 2485 | handler_time = "0" |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 2486 | |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2487 | # print out test results |
| 2488 | for identifier, ti in self.instances.items(): |
| 2489 | for k in ti.results.keys(): |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2490 | |
| 2491 | eleTestcase = ET.SubElement( |
| 2492 | eleTestsuite, 'testcase', classname="%s:%s" %(ti.platform.name, os.path.basename(ti.test.name)), |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 2493 | name="%s" % (k), time=handler_time) |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2494 | if ti.results[k] in ['FAIL', 'BLOCK']: |
| 2495 | el = None |
| 2496 | |
| 2497 | if ti.results[k] == 'FAIL': |
| 2498 | el = ET.SubElement( |
| 2499 | eleTestcase, |
| 2500 | 'failure', |
| 2501 | type="failure", |
| 2502 | message="failed") |
| 2503 | elif ti.results[k] == 'BLOCK': |
| 2504 | el = ET.SubElement( |
| 2505 | eleTestcase, |
| 2506 | 'error', |
| 2507 | type="failure", |
| 2508 | message="failed") |
| 2509 | p = os.path.join(options.outdir, ti.platform.name, ti.test.name) |
| 2510 | bl = os.path.join(p, "handler.log") |
| 2511 | |
| 2512 | if os.path.exists(bl): |
| 2513 | with open(bl, "rb") as f: |
| 2514 | log = f.read().decode("utf-8") |
| 2515 | el.text = self.encode_for_xml(log) |
| 2516 | |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 2517 | elif ti.results[k] == 'SKIP': |
| 2518 | el = ET.SubElement( |
| 2519 | eleTestcase, |
Anas Nashif | 2c7636b | 2018-09-02 13:11:19 -0400 | [diff] [blame] | 2520 | 'skipped', |
| 2521 | type="skipped", |
| 2522 | message="Skipped") |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 2523 | |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2524 | result = ET.tostring(eleTestsuites) |
| 2525 | f = open(report_file, 'wb') |
| 2526 | f.write(result) |
| 2527 | f.close() |
| 2528 | |
| 2529 | |
Anas Nashif | 4f02888 | 2017-12-30 11:48:43 -0500 | [diff] [blame] | 2530 | def testcase_xunit_report(self, filename, duration): |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 2531 | try: |
| 2532 | if self.goals is None: |
| 2533 | raise SanityRuntimeError("execute() hasn't been run!") |
| 2534 | except Exception as e: |
| 2535 | print(str(e)) |
| 2536 | sys.exit(2) |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2537 | |
| 2538 | fails = 0 |
| 2539 | passes = 0 |
| 2540 | errors = 0 |
| 2541 | |
| 2542 | for name, goal in self.goals.items(): |
| 2543 | if goal.failed: |
Anas Nashif | 9a839df | 2018-01-29 08:42:38 -0500 | [diff] [blame] | 2544 | if goal.reason in ['build_error', 'handler_crash']: |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2545 | errors += 1 |
| 2546 | else: |
| 2547 | fails += 1 |
| 2548 | else: |
| 2549 | passes += 1 |
| 2550 | |
| 2551 | run = "Sanitycheck" |
| 2552 | eleTestsuite = None |
Anas Nashif | 4f02888 | 2017-12-30 11:48:43 -0500 | [diff] [blame] | 2553 | append = options.only_failed |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2554 | |
Anas Nashif | 0605fa3 | 2017-05-07 08:51:02 -0400 | [diff] [blame] | 2555 | if os.path.exists(filename) and append: |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2556 | tree = ET.parse(filename) |
| 2557 | eleTestsuites = tree.getroot() |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2558 | eleTestsuite = tree.findall('testsuite')[0] |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2559 | else: |
| 2560 | eleTestsuites = ET.Element('testsuites') |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2561 | eleTestsuite = ET.SubElement(eleTestsuites, 'testsuite', |
| 2562 | name=run, time="%d" % duration, |
| 2563 | tests="%d" % (errors + passes + fails), |
| 2564 | failures="%d" % fails, |
| 2565 | errors="%d" % errors, skip="0") |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2566 | |
Anas Nashif | c8390f1 | 2017-11-25 17:14:12 -0500 | [diff] [blame] | 2567 | handler_time = "0" |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2568 | for name, goal in self.goals.items(): |
| 2569 | |
| 2570 | i = self.instances[name] |
| 2571 | if append: |
| 2572 | for tc in eleTestsuite.findall('testcase'): |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2573 | if tc.get('classname') == "%s:%s" % ( |
| 2574 | i.platform.name, i.test.name): |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2575 | eleTestsuite.remove(tc) |
| 2576 | |
Anas Nashif | 4d25b50 | 2017-11-25 17:37:17 -0500 | [diff] [blame] | 2577 | if not goal.failed and goal.handler: |
| 2578 | handler_time = "%s" %(goal.metrics["handler_time"]) |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2579 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2580 | eleTestcase = ET.SubElement( |
| 2581 | eleTestsuite, 'testcase', classname="%s:%s" % |
| 2582 | (i.platform.name, i.test.name), name="%s" % |
| 2583 | (name), time=handler_time) |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2584 | if goal.failed: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2585 | failure = ET.SubElement( |
| 2586 | eleTestcase, |
| 2587 | 'failure', |
| 2588 | type="failure", |
| 2589 | message=goal.reason) |
Anas Nashif | 4f02888 | 2017-12-30 11:48:43 -0500 | [diff] [blame] | 2590 | p = ("%s/%s/%s" % (options.outdir, i.platform.name, i.test.name)) |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2591 | bl = os.path.join(p, "build.log") |
Anas Nashif | c96c90a | 2019-02-05 07:38:32 -0500 | [diff] [blame] | 2592 | hl = os.path.join(p, "handler.log") |
| 2593 | log_file = bl |
Anas Nashif | accc8eb | 2017-05-01 16:33:43 -0400 | [diff] [blame] | 2594 | if goal.reason != 'build_error': |
Anas Nashif | c96c90a | 2019-02-05 07:38:32 -0500 | [diff] [blame] | 2595 | if os.path.exists(hl): |
| 2596 | log_file = hl |
| 2597 | else: |
| 2598 | log_file = bl |
Anas Nashif | accc8eb | 2017-05-01 16:33:43 -0400 | [diff] [blame] | 2599 | |
Anas Nashif | c96c90a | 2019-02-05 07:38:32 -0500 | [diff] [blame] | 2600 | if os.path.exists(log_file): |
| 2601 | with open(log_file, "rb") as f: |
Anas Nashif | 712d345 | 2017-12-29 22:09:03 -0500 | [diff] [blame] | 2602 | log = f.read().decode("utf-8") |
Anas Nashif | a4c368e | 2018-10-15 09:45:59 -0400 | [diff] [blame] | 2603 | filtered_string = ''.join(filter(lambda x: x in string.printable, log)) |
| 2604 | failure.text = filtered_string |
Anas Nashif | ba4643b | 2018-09-23 09:41:59 -0500 | [diff] [blame] | 2605 | f.close() |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2606 | |
| 2607 | result = ET.tostring(eleTestsuites) |
| 2608 | f = open(filename, 'wb') |
| 2609 | f.write(result) |
| 2610 | f.close() |
| 2611 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2612 | def testcase_report(self, filename): |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 2613 | try: |
| 2614 | if self.goals is None: |
| 2615 | raise SanityRuntimeError("execute() hasn't been run!") |
| 2616 | except Exception as e: |
| 2617 | print(str(e)) |
| 2618 | sys.exit(2) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2619 | |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 2620 | with open(filename, "wt") as csvfile: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2621 | fieldnames = ["test", "arch", "platform", "passed", "status", |
Anas Nashif | c8390f1 | 2017-11-25 17:14:12 -0500 | [diff] [blame] | 2622 | "extra_args", "qemu", "handler_time", "ram_size", |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2623 | "rom_size"] |
| 2624 | cw = csv.DictWriter(csvfile, fieldnames, lineterminator=os.linesep) |
| 2625 | cw.writeheader() |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 2626 | for name, goal in self.goals.items(): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2627 | i = self.instances[name] |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2628 | rowdict = {"test": i.test.name, |
| 2629 | "arch": i.platform.arch, |
| 2630 | "platform": i.platform.name, |
| 2631 | "extra_args": " ".join(i.test.extra_args), |
| 2632 | "qemu": i.platform.qemu_support} |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2633 | if goal.failed: |
| 2634 | rowdict["passed"] = False |
| 2635 | rowdict["status"] = goal.reason |
| 2636 | else: |
| 2637 | rowdict["passed"] = True |
Anas Nashif | 4d25b50 | 2017-11-25 17:37:17 -0500 | [diff] [blame] | 2638 | if goal.handler: |
Anas Nashif | c8390f1 | 2017-11-25 17:14:12 -0500 | [diff] [blame] | 2639 | rowdict["handler_time"] = goal.metrics["handler_time"] |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2640 | rowdict["ram_size"] = goal.metrics["ram_size"] |
| 2641 | rowdict["rom_size"] = goal.metrics["rom_size"] |
| 2642 | cw.writerow(rowdict) |
| 2643 | |
| 2644 | |
| 2645 | def parse_arguments(): |
| 2646 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2647 | parser = argparse.ArgumentParser( |
| 2648 | description=__doc__, |
| 2649 | formatter_class=argparse.RawDescriptionHelpFormatter) |
Genaro Saucedo Tejada | 28bba92 | 2016-10-24 18:00:58 -0500 | [diff] [blame] | 2650 | parser.fromfile_prefix_chars = "+" |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2651 | |
Marc Herbert | edf1759 | 2019-03-08 12:39:11 -0800 | [diff] [blame] | 2652 | case_select = parser.add_argument_group("Test case selection") |
| 2653 | |
Anas Nashif | 07d54c0 | 2018-07-21 19:29:08 -0500 | [diff] [blame] | 2654 | parser.add_argument("--force-toolchain", action="store_true", |
| 2655 | help="Do not filter based on toolchain, use the set " |
| 2656 | " toolchain unconditionally") |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2657 | parser.add_argument( |
| 2658 | "-p", "--platform", action="append", |
| 2659 | help="Platform filter for testing. This option may be used multiple " |
| 2660 | "times. Testcases will only be built/run on the platforms " |
| 2661 | "specified. If this option is not used, then platforms marked " |
| 2662 | "as default in the platform metadata file will be chosen " |
| 2663 | "to build and test. ") |
| 2664 | parser.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2665 | "-a", "--arch", action="append", |
| 2666 | help="Arch filter for testing. Takes precedence over --platform. " |
| 2667 | "If unspecified, test all arches. Multiple invocations " |
| 2668 | "are treated as a logical 'or' relationship") |
| 2669 | parser.add_argument( |
| 2670 | "-t", "--tag", action="append", |
| 2671 | help="Specify tags to restrict which tests to run by tag value. " |
| 2672 | "Default is to not do any tag filtering. Multiple invocations " |
| 2673 | "are treated as a logical 'or' relationship") |
Anas Nashif | dfa86e2 | 2016-10-24 17:08:56 -0400 | [diff] [blame] | 2674 | parser.add_argument("-e", "--exclude-tag", action="append", |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2675 | help="Specify tags of tests that should not run. " |
| 2676 | "Default is to run all tests with all tags.") |
Marc Herbert | edf1759 | 2019-03-08 12:39:11 -0800 | [diff] [blame] | 2677 | case_select.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2678 | "-f", |
| 2679 | "--only-failed", |
| 2680 | action="store_true", |
| 2681 | help="Run only those tests that failed the previous sanity check " |
| 2682 | "invocation.") |
| 2683 | parser.add_argument( |
| 2684 | "-c", "--config", action="append", |
| 2685 | help="Specify platform configuration values filtering. This can be " |
| 2686 | "specified two ways: <config>=<value> or just <config>. The " |
| 2687 | "defconfig for all platforms will be " |
| 2688 | "checked. For the <config>=<value> case, only match defconfig " |
| 2689 | "that have that value defined. For the <config> case, match " |
| 2690 | "defconfig that have that value assigned to any value. " |
| 2691 | "Prepend a '!' to invert the match.") |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 2692 | |
Marc Herbert | 0c465bb | 2019-03-11 17:28:36 -0700 | [diff] [blame^] | 2693 | test_xor_subtest = case_select.add_mutually_exclusive_group() |
| 2694 | |
| 2695 | test_xor_subtest.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2696 | "-s", "--test", action="append", |
| 2697 | help="Run only the specified test cases. These are named by " |
| 2698 | "<path to test project relative to " |
| 2699 | "--testcase-root>/<testcase.yaml section name>") |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 2700 | |
Marc Herbert | 0c465bb | 2019-03-11 17:28:36 -0700 | [diff] [blame^] | 2701 | test_xor_subtest.add_argument( |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 2702 | "--sub-test", action="append", |
| 2703 | help="Run only the specified sub-test cases and its parent. These are named by " |
| 2704 | "test case name appended by test function, i.e. kernel.mutex.mutex_lock_unlock." |
| 2705 | ) |
| 2706 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2707 | parser.add_argument( |
| 2708 | "-l", "--all", action="store_true", |
| 2709 | help="Build/test on all platforms. Any --platform arguments " |
| 2710 | "ignored.") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2711 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2712 | parser.add_argument( |
| 2713 | "-o", "--testcase-report", |
| 2714 | help="Output a CSV spreadsheet containing results of the test run") |
| 2715 | parser.add_argument( |
| 2716 | "-d", "--discard-report", |
| 2717 | help="Output a CSV spreadsheet showing tests that were skipped " |
| 2718 | "and why") |
Daniel Leung | 7f85010 | 2016-04-08 11:07:32 -0700 | [diff] [blame] | 2719 | parser.add_argument("--compare-report", |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2720 | help="Use this report file for size comparison") |
Daniel Leung | 7f85010 | 2016-04-08 11:07:32 -0700 | [diff] [blame] | 2721 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2722 | parser.add_argument( |
| 2723 | "-B", "--subset", |
| 2724 | help="Only run a subset of the tests, 1/4 for running the first 25%%, " |
| 2725 | "3/5 means run the 3rd fifth of the total. " |
| 2726 | "This option is useful when running a large number of tests on " |
| 2727 | "different hosts to speed up execution time.") |
Anas Nashif | a8a1388 | 2017-12-30 13:01:06 -0500 | [diff] [blame] | 2728 | |
| 2729 | parser.add_argument( |
| 2730 | "-N", "--ninja", action="store_true", |
Anas Nashif | 25f6ab6 | 2018-03-06 07:15:11 -0600 | [diff] [blame] | 2731 | help="Use the Ninja generator with CMake") |
Anas Nashif | a8a1388 | 2017-12-30 13:01:06 -0500 | [diff] [blame] | 2732 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2733 | parser.add_argument( |
| 2734 | "-y", "--dry-run", action="store_true", |
| 2735 | help="Create the filtered list of test cases, but don't actually " |
| 2736 | "run them. Useful if you're just interested in " |
| 2737 | "--discard-report") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2738 | |
Anas Nashif | 75547e2 | 2018-02-24 08:32:14 -0600 | [diff] [blame] | 2739 | parser.add_argument("--list-tags", action="store_true", |
| 2740 | help="list all tags in selected tests") |
| 2741 | |
Marc Herbert | edf1759 | 2019-03-08 12:39:11 -0800 | [diff] [blame] | 2742 | case_select.add_argument("--list-tests", action="store_true", |
Anas Nashif | c0149cc | 2018-04-14 23:12:58 -0500 | [diff] [blame] | 2743 | help="list all tests.") |
| 2744 | |
Anas Nashif | 5d6e7eb | 2018-06-01 09:51:08 -0500 | [diff] [blame] | 2745 | parser.add_argument("--export-tests", action="store", |
| 2746 | metavar="FILENAME", |
| 2747 | help="Export tests case meta-data to a file in CSV format.") |
| 2748 | |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2749 | parser.add_argument("--detailed-report", |
| 2750 | action="store", |
| 2751 | metavar="FILENAME", |
| 2752 | help="Generate a junit report with detailed testcase results.") |
| 2753 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2754 | parser.add_argument( |
| 2755 | "-r", "--release", action="store_true", |
| 2756 | help="Update the benchmark database with the results of this test " |
| 2757 | "run. Intended to be run by CI when tagging an official " |
| 2758 | "release. This database is used as a basis for comparison " |
| 2759 | "when looking for deltas in metrics such as footprint") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2760 | parser.add_argument("-w", "--warnings-as-errors", action="store_true", |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2761 | help="Treat warning conditions as errors") |
| 2762 | parser.add_argument( |
| 2763 | "-v", |
| 2764 | "--verbose", |
| 2765 | action="count", |
| 2766 | default=0, |
| 2767 | help="Emit debugging information, call multiple times to increase " |
| 2768 | "verbosity") |
| 2769 | parser.add_argument( |
| 2770 | "-i", "--inline-logs", action="store_true", |
| 2771 | help="Upon test failure, print relevant log data to stdout " |
| 2772 | "instead of just a path to it") |
Inaky Perez-Gonzalez | 9a36cb6 | 2016-11-29 10:43:40 -0800 | [diff] [blame] | 2773 | parser.add_argument("--log-file", metavar="FILENAME", action="store", |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2774 | help="log also to file") |
| 2775 | parser.add_argument( |
| 2776 | "-m", "--last-metrics", action="store_true", |
| 2777 | help="Instead of comparing metrics from the last --release, " |
| 2778 | "compare with the results of the previous sanity check " |
| 2779 | "invocation") |
| 2780 | parser.add_argument( |
| 2781 | "-u", |
| 2782 | "--no-update", |
| 2783 | action="store_true", |
| 2784 | help="do not update the results of the last run of the sanity " |
| 2785 | "checks") |
Marc Herbert | edf1759 | 2019-03-08 12:39:11 -0800 | [diff] [blame] | 2786 | case_select.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2787 | "-F", |
| 2788 | "--load-tests", |
| 2789 | metavar="FILENAME", |
| 2790 | action="store", |
| 2791 | help="Load list of tests to be run from file.") |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 2792 | |
Marc Herbert | edf1759 | 2019-03-08 12:39:11 -0800 | [diff] [blame] | 2793 | case_select.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2794 | "-E", |
| 2795 | "--save-tests", |
| 2796 | metavar="FILENAME", |
| 2797 | action="store", |
| 2798 | help="Save list of tests to be run to file.") |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 2799 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2800 | parser.add_argument( |
| 2801 | "-b", "--build-only", action="store_true", |
| 2802 | help="Only build the code, do not execute any of it in QEMU") |
| 2803 | parser.add_argument( |
| 2804 | "-j", "--jobs", type=int, |
Oleg Zhurakivskyy | f3bc967 | 2018-08-17 18:31:38 +0300 | [diff] [blame] | 2805 | help="Number of jobs for building, defaults to number of CPU threads " |
| 2806 | "overcommited by factor 2") |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 2807 | |
| 2808 | parser.add_argument( |
| 2809 | "--device-testing", action="store_true", |
Anas Nashif | 333a315 | 2018-05-24 14:35:33 -0500 | [diff] [blame] | 2810 | help="Test on device directly. Specify the serial device to " |
| 2811 | "use with the --device-serial option.") |
Anas Nashif | 7dd19ea | 2018-11-14 08:46:49 -0500 | [diff] [blame] | 2812 | |
| 2813 | parser.add_argument( |
| 2814 | "-X", "--fixture", action="append", default=[], |
| 2815 | help="Specify a fixture that a board might support") |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 2816 | parser.add_argument( |
| 2817 | "--device-serial", |
Anas Nashif | 333a315 | 2018-05-24 14:35:33 -0500 | [diff] [blame] | 2818 | help="Serial device for accessing the board (e.g., /dev/ttyACM0)") |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2819 | parser.add_argument( |
Anas Nashif | 424a3db | 2018-02-20 08:37:24 -0600 | [diff] [blame] | 2820 | "--show-footprint", action="store_true", |
| 2821 | help="Show footprint statistics and deltas since last release." |
| 2822 | ) |
| 2823 | parser.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2824 | "-H", "--footprint-threshold", type=float, default=5, |
| 2825 | help="When checking test case footprint sizes, warn the user if " |
| 2826 | "the new app size is greater then the specified percentage " |
| 2827 | "from the last release. Default is 5. 0 to warn on any " |
| 2828 | "increase on app size") |
| 2829 | parser.add_argument( |
| 2830 | "-D", "--all-deltas", action="store_true", |
| 2831 | help="Show all footprint deltas, positive or negative. Implies " |
| 2832 | "--footprint-threshold=0") |
Håkon Øye Amundsen | de223cc | 2018-04-25 06:24:25 +0000 | [diff] [blame] | 2833 | parser.add_argument( |
| 2834 | "-O", "--outdir", |
Anas Nashif | f114a13 | 2018-11-20 11:51:34 -0500 | [diff] [blame] | 2835 | default="%s/sanity-out" % os.getcwd(), |
Håkon Øye Amundsen | de223cc | 2018-04-25 06:24:25 +0000 | [diff] [blame] | 2836 | help="Output directory for logs and binaries. " |
Anas Nashif | f114a13 | 2018-11-20 11:51:34 -0500 | [diff] [blame] | 2837 | "Default is 'sanity-out' in the current directory. " |
Håkon Øye Amundsen | de223cc | 2018-04-25 06:24:25 +0000 | [diff] [blame] | 2838 | "This directory will be deleted unless '--no-clean' is set.") |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2839 | parser.add_argument( |
| 2840 | "-n", "--no-clean", action="store_true", |
| 2841 | help="Do not delete the outdir before building. Will result in " |
| 2842 | "faster compilation since builds will be incremental") |
Marc Herbert | edf1759 | 2019-03-08 12:39:11 -0800 | [diff] [blame] | 2843 | case_select.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2844 | "-T", "--testcase-root", action="append", default=[], |
| 2845 | help="Base directory to recursively search for test cases. All " |
| 2846 | "testcase.yaml files under here will be processed. May be " |
| 2847 | "called multiple times. Defaults to the 'samples' and " |
| 2848 | "'tests' directories in the Zephyr tree.") |
Anas Nashif | 7dd19ea | 2018-11-14 08:46:49 -0500 | [diff] [blame] | 2849 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2850 | board_root_list = ["%s/boards" % ZEPHYR_BASE, |
| 2851 | "%s/scripts/sanity_chk/boards" % ZEPHYR_BASE] |
Anas Nashif | 7dd19ea | 2018-11-14 08:46:49 -0500 | [diff] [blame] | 2852 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2853 | parser.add_argument( |
| 2854 | "-A", "--board-root", action="append", default=board_root_list, |
| 2855 | help="Directory to search for board configuration files. All .yaml " |
| 2856 | "files in the directory will be processed.") |
| 2857 | parser.add_argument( |
| 2858 | "-z", "--size", action="append", |
| 2859 | help="Don't run sanity checks. Instead, produce a report to " |
| 2860 | "stdout detailing RAM/ROM sizes on the specified filenames. " |
| 2861 | "All other command line arguments ignored.") |
| 2862 | parser.add_argument( |
| 2863 | "-S", "--enable-slow", action="store_true", |
| 2864 | help="Execute time-consuming test cases that have been marked " |
| 2865 | "as 'slow' in testcase.yaml. Normally these are only built.") |
Sebastian Bøe | 03ed095 | 2018-11-13 13:36:19 +0100 | [diff] [blame] | 2866 | parser.add_argument( |
| 2867 | "--disable-unrecognized-section-test", action="store_true", |
| 2868 | default=False, |
| 2869 | help="Skip the 'unrecognized section' test.") |
Andrew Boie | 5512105 | 2016-07-20 11:52:04 -0700 | [diff] [blame] | 2870 | parser.add_argument("-R", "--enable-asserts", action="store_true", |
Kumar Gala | 0d48cbe | 2018-01-26 10:22:20 -0600 | [diff] [blame] | 2871 | default=True, |
Andrew Boie | 29599f6 | 2018-05-24 13:33:09 -0700 | [diff] [blame] | 2872 | help="deprecated, left for compatibility") |
Kumar Gala | 0d48cbe | 2018-01-26 10:22:20 -0600 | [diff] [blame] | 2873 | parser.add_argument("--disable-asserts", action="store_false", |
| 2874 | dest="enable_asserts", |
Andrew Boie | 29599f6 | 2018-05-24 13:33:09 -0700 | [diff] [blame] | 2875 | help="deprecated, left for compatibility") |
Anas Nashif | e3febe9 | 2016-11-30 14:25:44 -0500 | [diff] [blame] | 2876 | parser.add_argument("-Q", "--error-on-deprecations", action="store_false", |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2877 | help="Error on deprecation warnings.") |
Andy Ross | 9c9162d | 2019-01-03 10:50:53 -0800 | [diff] [blame] | 2878 | parser.add_argument("--disable-size-report", action="store_true", |
| 2879 | help="Skip expensive computation of ram/rom segment sizes.") |
Sebastian Bøe | c218261 | 2017-11-09 12:25:02 +0100 | [diff] [blame] | 2880 | |
| 2881 | parser.add_argument( |
| 2882 | "-x", "--extra-args", action="append", default=[], |
Alberto Escolar Piedras | 25e0636 | 2018-02-10 17:40:33 +0100 | [diff] [blame] | 2883 | help="""Extra CMake cache entries to define when building test cases. |
| 2884 | May be called multiple times. The key-value entries will be |
Sebastian Bøe | c218261 | 2017-11-09 12:25:02 +0100 | [diff] [blame] | 2885 | prefixed with -D before being passed to CMake. |
| 2886 | |
| 2887 | E.g |
| 2888 | "sanitycheck -x=USE_CCACHE=0" |
| 2889 | will translate to |
| 2890 | "cmake -DUSE_CCACHE=0" |
| 2891 | |
| 2892 | which will ultimately disable ccache. |
| 2893 | """ |
| 2894 | ) |
Anas Nashif | 47cf4bf | 2019-01-24 21:50:59 -0500 | [diff] [blame] | 2895 | parser.add_argument("--gcov-tool", default="gcov", |
| 2896 | help="Path to the gcov tool. Default is gcov in the path.") |
Sebastian Bøe | c218261 | 2017-11-09 12:25:02 +0100 | [diff] [blame] | 2897 | |
Alberto Escolar Piedras | c026c2e | 2018-06-21 09:30:20 +0200 | [diff] [blame] | 2898 | parser.add_argument("--enable-coverage", action="store_true", |
Anas Nashif | 8d72bb9 | 2018-11-07 23:05:42 -0500 | [diff] [blame] | 2899 | help="Enable code coverage using gcov.") |
Alberto Escolar Piedras | c026c2e | 2018-06-21 09:30:20 +0200 | [diff] [blame] | 2900 | |
Jaakko Hannikainen | 54c90bc | 2016-08-31 14:17:03 +0300 | [diff] [blame] | 2901 | parser.add_argument("-C", "--coverage", action="store_true", |
Anas Nashif | 8d72bb9 | 2018-11-07 23:05:42 -0500 | [diff] [blame] | 2902 | help="Generate coverage reports. Implies --enable_coverage") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2903 | |
Anas Nashif | dbd7649 | 2018-11-23 20:24:19 -0500 | [diff] [blame] | 2904 | coverage_platforms = ["native_posix", "nrf52_bsim"] |
| 2905 | parser.add_argument("--coverage-platform", action="append", default=coverage_platforms, |
| 2906 | help="Plarforms to run coverage reports on. " |
| 2907 | "This option may be used multiple times.") |
| 2908 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2909 | return parser.parse_args() |
| 2910 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2911 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2912 | def log_info(filename): |
Mazen NEIFER | 8f1dd3a | 2017-02-04 14:32:04 +0100 | [diff] [blame] | 2913 | filename = os.path.relpath(os.path.realpath(filename)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2914 | if INLINE_LOGS: |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 2915 | info("{:-^100}".format(filename)) |
Andrew Boie | d01535c | 2017-01-10 13:15:02 -0800 | [diff] [blame] | 2916 | |
| 2917 | try: |
| 2918 | with open(filename) as fp: |
| 2919 | data = fp.read() |
| 2920 | except Exception as e: |
| 2921 | data = "Unable to read log data (%s)\n" % (str(e)) |
| 2922 | |
| 2923 | sys.stdout.write(data) |
| 2924 | if log_file: |
| 2925 | log_file.write(data) |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 2926 | info("{:-^100}".format(filename)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2927 | else: |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 2928 | info("\tsee: " + COLOR_YELLOW + filename + COLOR_NORMAL) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2929 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2930 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2931 | def terse_test_cb(instances, goals, goal): |
| 2932 | total_tests = len(goals) |
| 2933 | total_done = 0 |
| 2934 | total_failed = 0 |
| 2935 | |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 2936 | for k, g in goals.items(): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2937 | if g.finished: |
| 2938 | total_done += 1 |
| 2939 | if g.failed: |
| 2940 | total_failed += 1 |
| 2941 | |
| 2942 | if goal.failed: |
| 2943 | i = instances[goal.name] |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2944 | info( |
| 2945 | "\n\n{:<25} {:<50} {}FAILED{}: {}".format( |
| 2946 | i.platform.name, |
| 2947 | i.test.name, |
| 2948 | COLOR_RED, |
| 2949 | COLOR_NORMAL, |
| 2950 | goal.reason)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2951 | log_info(goal.get_error_log()) |
| 2952 | info("") |
| 2953 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2954 | sys.stdout.write( |
| 2955 | "\rtotal complete: %s%4d/%4d%s %2d%% failed: %s%4d%s" % |
| 2956 | (COLOR_GREEN, total_done, total_tests, COLOR_NORMAL, |
| 2957 | int((float(total_done) / total_tests) * 100), |
| 2958 | COLOR_RED if total_failed > 0 else COLOR_NORMAL, total_failed, |
| 2959 | COLOR_NORMAL)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2960 | sys.stdout.flush() |
| 2961 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 2962 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2963 | def chatty_test_cb(instances, goals, goal): |
| 2964 | i = instances[goal.name] |
| 2965 | |
| 2966 | if VERBOSE < 2 and not goal.finished: |
| 2967 | return |
| 2968 | |
Ruslan Mstoi | 33fa63e | 2018-05-29 14:35:34 +0300 | [diff] [blame] | 2969 | total_tests = len(goals) |
| 2970 | total_tests_width = len(str(total_tests)) |
| 2971 | total_done = 0 |
| 2972 | |
| 2973 | for k, g in goals.items(): |
| 2974 | if g.finished: |
| 2975 | total_done += 1 |
| 2976 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2977 | if goal.failed: |
| 2978 | status = COLOR_RED + "FAILED" + COLOR_NORMAL + ": " + goal.reason |
| 2979 | elif goal.finished: |
| 2980 | status = COLOR_GREEN + "PASSED" + COLOR_NORMAL |
| 2981 | else: |
| 2982 | status = goal.make_state |
| 2983 | |
Ruslan Mstoi | 33fa63e | 2018-05-29 14:35:34 +0300 | [diff] [blame] | 2984 | info("{:>{}}/{} {:<25} {:<50} {}".format( |
| 2985 | total_done, total_tests_width, total_tests, i.platform.name, |
| 2986 | i.test.name, status)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2987 | if goal.failed: |
| 2988 | log_info(goal.get_error_log()) |
| 2989 | |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 2990 | |
| 2991 | def size_report(sc): |
| 2992 | info(sc.filename) |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 2993 | info("SECTION NAME VMA LMA SIZE HEX SZ TYPE") |
Andrew Boie | 9882dcd | 2015-10-07 14:25:51 -0700 | [diff] [blame] | 2994 | for i in range(len(sc.sections)): |
| 2995 | v = sc.sections[i] |
| 2996 | |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 2997 | info("%-17s 0x%08x 0x%08x %8d 0x%05x %-7s" % |
| 2998 | (v["name"], v["virt_addr"], v["load_addr"], v["size"], v["size"], |
| 2999 | v["type"])) |
Andrew Boie | 9882dcd | 2015-10-07 14:25:51 -0700 | [diff] [blame] | 3000 | |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 3001 | info("Totals: %d bytes (ROM), %d bytes (RAM)" % |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3002 | (sc.rom_size, sc.ram_size)) |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 3003 | info("") |
| 3004 | |
Anas Nashif | f29087e | 2019-01-25 09:37:38 -0500 | [diff] [blame] | 3005 | def retrieve_gcov_data(intput_file): |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 3006 | if VERBOSE: |
| 3007 | print("Working on %s" %intput_file) |
| 3008 | extracted_coverage_info = {} |
| 3009 | capture_data = False |
Anas Nashif | f29087e | 2019-01-25 09:37:38 -0500 | [diff] [blame] | 3010 | capture_complete = False |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 3011 | with open(intput_file, 'r') as fp: |
| 3012 | for line in fp.readlines(): |
| 3013 | if re.search("GCOV_COVERAGE_DUMP_START", line): |
| 3014 | capture_data = True |
| 3015 | continue |
| 3016 | if re.search("GCOV_COVERAGE_DUMP_END", line): |
Anas Nashif | f29087e | 2019-01-25 09:37:38 -0500 | [diff] [blame] | 3017 | capture_complete = True |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 3018 | break |
| 3019 | # Loop until the coverage data is found. |
| 3020 | if not capture_data: |
| 3021 | continue |
| 3022 | if line.startswith("*"): |
| 3023 | sp = line.split("<") |
| 3024 | if len(sp) > 1: |
| 3025 | # Remove the leading delimiter "*" |
| 3026 | file_name = sp[0][1:] |
| 3027 | # Remove the trailing new line char |
| 3028 | hex_dump = sp[1][:-1] |
| 3029 | else: |
| 3030 | continue |
| 3031 | else: |
| 3032 | continue |
| 3033 | extracted_coverage_info.update({file_name:hex_dump}) |
Anas Nashif | f29087e | 2019-01-25 09:37:38 -0500 | [diff] [blame] | 3034 | if not capture_data: |
| 3035 | capture_complete = True |
| 3036 | return {'complete': capture_complete, 'data': extracted_coverage_info} |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 3037 | |
| 3038 | def create_gcda_files(extracted_coverage_info): |
| 3039 | if VERBOSE: |
| 3040 | print("Generating gcda files") |
| 3041 | for filename, hexdump_val in extracted_coverage_info.items(): |
| 3042 | # if kobject_hash is given for coverage gcovr fails |
| 3043 | # hence skipping it problem only in gcovr v4.1 |
| 3044 | if "kobject_hash" in filename: |
| 3045 | filename = (filename[:-4]) +"gcno" |
| 3046 | try: |
| 3047 | os.remove(filename) |
| 3048 | except: |
| 3049 | pass |
| 3050 | continue |
| 3051 | |
| 3052 | with open(filename, 'wb') as fp: |
| 3053 | fp.write(bytes.fromhex(hexdump_val)) |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3054 | |
Jaakko Hannikainen | 54c90bc | 2016-08-31 14:17:03 +0300 | [diff] [blame] | 3055 | def generate_coverage(outdir, ignores): |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 3056 | |
| 3057 | for filename in glob.glob("%s/**/handler.log" %outdir, recursive=True): |
Anas Nashif | f29087e | 2019-01-25 09:37:38 -0500 | [diff] [blame] | 3058 | gcov_data = retrieve_gcov_data(filename) |
| 3059 | capture_complete = gcov_data['complete'] |
| 3060 | extracted_coverage_info = gcov_data['data'] |
| 3061 | if capture_complete: |
| 3062 | create_gcda_files(extracted_coverage_info) |
| 3063 | verbose("Gcov data captured: {}".format(filename)) |
| 3064 | else: |
| 3065 | error("Gcov data capture incomplete: {}".format(filename)) |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 3066 | |
Anas Nashif | 47cf4bf | 2019-01-24 21:50:59 -0500 | [diff] [blame] | 3067 | gcov_tool = options.gcov_tool |
| 3068 | |
Jaakko Hannikainen | 54c90bc | 2016-08-31 14:17:03 +0300 | [diff] [blame] | 3069 | with open(os.path.join(outdir, "coverage.log"), "a") as coveragelog: |
| 3070 | coveragefile = os.path.join(outdir, "coverage.info") |
| 3071 | ztestfile = os.path.join(outdir, "ztest.info") |
Anas Nashif | 47cf4bf | 2019-01-24 21:50:59 -0500 | [diff] [blame] | 3072 | subprocess.call(["lcov", "--gcov-tool", gcov_tool, |
| 3073 | "--capture", "--directory", outdir, |
| 3074 | "--rc", "lcov_branch_coverage=1", |
| 3075 | "--output-file", coveragefile], stdout=coveragelog) |
Jaakko Hannikainen | 54c90bc | 2016-08-31 14:17:03 +0300 | [diff] [blame] | 3076 | # We want to remove tests/* and tests/ztest/test/* but save tests/ztest |
Anas Nashif | 47cf4bf | 2019-01-24 21:50:59 -0500 | [diff] [blame] | 3077 | subprocess.call(["lcov", "--gcov-tool", gcov_tool, "--extract", coveragefile, |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3078 | os.path.join(ZEPHYR_BASE, "tests", "ztest", "*"), |
Alberto Escolar Piedras | bc101c5 | 2018-02-11 09:33:55 +0100 | [diff] [blame] | 3079 | "--output-file", ztestfile, |
| 3080 | "--rc", "lcov_branch_coverage=1"], stdout=coveragelog) |
| 3081 | |
Anas Nashif | 3cbffef | 2018-11-07 23:50:54 -0500 | [diff] [blame] | 3082 | if os.path.exists(ztestfile) and os.path.getsize(ztestfile) > 0: |
Anas Nashif | 47cf4bf | 2019-01-24 21:50:59 -0500 | [diff] [blame] | 3083 | subprocess.call(["lcov", "--gcov-tool", gcov_tool, "--remove", ztestfile, |
Alberto Escolar Piedras | bc101c5 | 2018-02-11 09:33:55 +0100 | [diff] [blame] | 3084 | os.path.join(ZEPHYR_BASE, "tests/ztest/test/*"), |
| 3085 | "--output-file", ztestfile, |
| 3086 | "--rc", "lcov_branch_coverage=1"], |
| 3087 | stdout=coveragelog) |
| 3088 | files = [coveragefile, ztestfile]; |
| 3089 | else: |
| 3090 | files = [coveragefile]; |
| 3091 | |
Jaakko Hannikainen | 54c90bc | 2016-08-31 14:17:03 +0300 | [diff] [blame] | 3092 | for i in ignores: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3093 | subprocess.call( |
Anas Nashif | 47cf4bf | 2019-01-24 21:50:59 -0500 | [diff] [blame] | 3094 | ["lcov", "--gcov-tool", gcov_tool, "--remove", |
| 3095 | coveragefile, i, "--output-file", |
| 3096 | coveragefile, "--rc", "lcov_branch_coverage=1"], |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3097 | stdout=coveragelog) |
Alberto Escolar Piedras | bc101c5 | 2018-02-11 09:33:55 +0100 | [diff] [blame] | 3098 | |
Alberto Escolar Piedras | 834b86f | 2019-02-03 15:48:07 +0100 | [diff] [blame] | 3099 | #The --ignore-errors source option is added to avoid it exiting due to |
| 3100 | #samples/application_development/external_lib/ |
Alberto Escolar Piedras | bc101c5 | 2018-02-11 09:33:55 +0100 | [diff] [blame] | 3101 | ret = subprocess.call(["genhtml", "--legend", "--branch-coverage", |
Alberto Escolar Piedras | 834b86f | 2019-02-03 15:48:07 +0100 | [diff] [blame] | 3102 | "--ignore-errors", "source", |
Alberto Escolar Piedras | bc101c5 | 2018-02-11 09:33:55 +0100 | [diff] [blame] | 3103 | "-output-directory", |
| 3104 | os.path.join(outdir, "coverage")] + files, |
| 3105 | stdout=coveragelog) |
| 3106 | if ret==0: |
| 3107 | info("HTML report generated: %s"% |
| 3108 | os.path.join(outdir, "coverage","index.html")); |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3109 | |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 3110 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3111 | def main(): |
Andrew Boie | 4b18247 | 2015-07-31 12:25:22 -0700 | [diff] [blame] | 3112 | start_time = time.time() |
Oleg Zhurakivskyy | 99aacd9 | 2018-08-17 15:02:28 +0300 | [diff] [blame] | 3113 | global VERBOSE, INLINE_LOGS, JOBS, log_file |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3114 | global options |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 3115 | global run_individual_tests |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3116 | options = parse_arguments() |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 3117 | |
Alberto Escolar Piedras | c026c2e | 2018-06-21 09:30:20 +0200 | [diff] [blame] | 3118 | if options.coverage: |
| 3119 | options.enable_coverage = True |
| 3120 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3121 | if options.size: |
| 3122 | for fn in options.size: |
Andrew Boie | 52fef67 | 2016-11-29 12:21:59 -0800 | [diff] [blame] | 3123 | size_report(SizeCalculator(fn, [])) |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 3124 | sys.exit(0) |
| 3125 | |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 3126 | |
| 3127 | if options.device_testing: |
| 3128 | if options.device_serial is None or len(options.platform) != 1: |
| 3129 | sys.exit(1) |
| 3130 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3131 | VERBOSE += options.verbose |
| 3132 | INLINE_LOGS = options.inline_logs |
| 3133 | if options.log_file: |
| 3134 | log_file = open(options.log_file, "w") |
Oleg Zhurakivskyy | c97054c | 2018-08-17 14:56:05 +0300 | [diff] [blame] | 3135 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3136 | if options.jobs: |
Oleg Zhurakivskyy | 99aacd9 | 2018-08-17 15:02:28 +0300 | [diff] [blame] | 3137 | JOBS = options.jobs |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3138 | |
Oleg Zhurakivskyy | 99aacd9 | 2018-08-17 15:02:28 +0300 | [diff] [blame] | 3139 | # Decrease JOBS for Ninja, if jobs weren't explicitly set |
Oleg Zhurakivskyy | c97054c | 2018-08-17 14:56:05 +0300 | [diff] [blame] | 3140 | if options.ninja and not options.jobs: |
Oleg Zhurakivskyy | 99aacd9 | 2018-08-17 15:02:28 +0300 | [diff] [blame] | 3141 | JOBS = int(JOBS * 0.75) |
Oleg Zhurakivskyy | c97054c | 2018-08-17 14:56:05 +0300 | [diff] [blame] | 3142 | |
Oleg Zhurakivskyy | 99aacd9 | 2018-08-17 15:02:28 +0300 | [diff] [blame] | 3143 | info("JOBS: %d" % JOBS); |
Oleg Zhurakivskyy | c97054c | 2018-08-17 14:56:05 +0300 | [diff] [blame] | 3144 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3145 | if options.subset: |
| 3146 | subset, sets = options.subset.split("/") |
Anas Nashif | 035799f | 2017-05-13 21:31:53 -0400 | [diff] [blame] | 3147 | if int(subset) > 0 and int(sets) >= int(subset): |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3148 | info("Running only a subset: %s/%s" % (subset, sets)) |
Anas Nashif | 035799f | 2017-05-13 21:31:53 -0400 | [diff] [blame] | 3149 | else: |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3150 | error("You have provided a wrong subset value: %s." % options.subset) |
Anas Nashif | 035799f | 2017-05-13 21:31:53 -0400 | [diff] [blame] | 3151 | return |
| 3152 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3153 | if os.path.exists(options.outdir) and not options.no_clean: |
| 3154 | info("Cleaning output directory " + options.outdir) |
| 3155 | shutil.rmtree(options.outdir) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3156 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3157 | if not options.testcase_root: |
| 3158 | options.testcase_root = [os.path.join(ZEPHYR_BASE, "tests"), |
Andrew Boie | 3d34871 | 2016-04-08 11:52:13 -0700 | [diff] [blame] | 3159 | os.path.join(ZEPHYR_BASE, "samples")] |
| 3160 | |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 3161 | ts = TestSuite(options.board_root, options.testcase_root, options.outdir) |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 3162 | |
Kumar Gala | c84235e | 2018-04-10 13:32:51 -0500 | [diff] [blame] | 3163 | if ts.load_errors: |
| 3164 | sys.exit(1) |
| 3165 | |
Anas Nashif | 75547e2 | 2018-02-24 08:32:14 -0600 | [diff] [blame] | 3166 | if options.list_tags: |
| 3167 | tags = set() |
| 3168 | for n,tc in ts.testcases.items(): |
| 3169 | tags = tags.union(tc.tags) |
| 3170 | |
| 3171 | for t in tags: |
| 3172 | print("- {}".format(t)) |
| 3173 | |
| 3174 | return |
| 3175 | |
Anas Nashif | 5d6e7eb | 2018-06-01 09:51:08 -0500 | [diff] [blame] | 3176 | |
| 3177 | def export_tests(filename, tests): |
| 3178 | with open(filename, "wt") as csvfile: |
| 3179 | fieldnames = ['section', 'subsection', 'title', 'reference'] |
| 3180 | cw = csv.DictWriter(csvfile, fieldnames, lineterminator=os.linesep) |
| 3181 | for test in tests: |
| 3182 | data = test.split(".") |
| 3183 | subsec = " ".join(data[1].split("_")).title() |
| 3184 | rowdict = { |
| 3185 | "section": data[0].capitalize(), |
| 3186 | "subsection": subsec, |
| 3187 | "title": test, |
| 3188 | "reference": test |
| 3189 | } |
| 3190 | cw.writerow(rowdict) |
| 3191 | |
| 3192 | if options.export_tests: |
| 3193 | cnt = 0 |
| 3194 | unq = [] |
| 3195 | for n,tc in ts.testcases.items(): |
| 3196 | for c in tc.cases: |
| 3197 | unq.append(c) |
| 3198 | |
| 3199 | tests = sorted(set(unq)) |
| 3200 | export_tests(options.export_tests, tests) |
| 3201 | return |
| 3202 | |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 3203 | run_individual_tests = [] |
Anas Nashif | 5d6e7eb | 2018-06-01 09:51:08 -0500 | [diff] [blame] | 3204 | |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 3205 | if options.test: |
| 3206 | run_individual_tests = options.test |
| 3207 | |
| 3208 | if options.list_tests or options.sub_test: |
Anas Nashif | c0149cc | 2018-04-14 23:12:58 -0500 | [diff] [blame] | 3209 | cnt = 0 |
Anas Nashif | a3abe96 | 2018-05-05 19:10:22 -0500 | [diff] [blame] | 3210 | unq = [] |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 3211 | run_individual_tests = [] |
Anas Nashif | c0149cc | 2018-04-14 23:12:58 -0500 | [diff] [blame] | 3212 | for n,tc in ts.testcases.items(): |
| 3213 | for c in tc.cases: |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 3214 | if options.sub_test and c in options.sub_test: |
| 3215 | if tc.name not in run_individual_tests: |
| 3216 | run_individual_tests.append(tc.name) |
Anas Nashif | a3abe96 | 2018-05-05 19:10:22 -0500 | [diff] [blame] | 3217 | unq.append(c) |
Anas Nashif | c0149cc | 2018-04-14 23:12:58 -0500 | [diff] [blame] | 3218 | |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 3219 | if options.sub_test: |
| 3220 | if run_individual_tests: |
| 3221 | info("Running the following tests:") |
| 3222 | for t in run_individual_tests: |
| 3223 | print(" - {}".format(t)) |
| 3224 | else: |
| 3225 | info("Tests not found") |
| 3226 | return |
| 3227 | |
| 3228 | elif options.list_tests: |
| 3229 | for u in sorted(set(unq)): |
| 3230 | cnt = cnt + 1 |
| 3231 | print(" - {}".format(u)) |
| 3232 | print("{} total.".format(cnt)) |
| 3233 | return |
Anas Nashif | c0149cc | 2018-04-14 23:12:58 -0500 | [diff] [blame] | 3234 | |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 3235 | discards = [] |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3236 | if options.load_tests: |
| 3237 | ts.load_from_file(options.load_tests) |
Anas Nashif | f4d8ecc | 2019-03-02 15:43:23 -0500 | [diff] [blame] | 3238 | elif options.only_failed: |
| 3239 | ts.get_last_failed() |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 3240 | else: |
Anas Nashif | 4f02888 | 2017-12-30 11:48:43 -0500 | [diff] [blame] | 3241 | discards = ts.apply_filters() |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3242 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3243 | if options.discard_report: |
| 3244 | ts.discard_report(options.discard_report) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3245 | |
Anas Nashif | 30551f4 | 2018-01-12 21:56:59 -0500 | [diff] [blame] | 3246 | if VERBOSE > 1 and discards: |
Anas Nashif | f18e2ab | 2018-01-13 07:57:42 -0500 | [diff] [blame] | 3247 | # if we are using command line platform filter, no need to list every |
| 3248 | # other platform as excluded, we know that already. |
| 3249 | # Show only the discards that apply to the selected platforms on the |
| 3250 | # command line |
| 3251 | |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 3252 | for i, reason in discards.items(): |
Anas Nashif | f18e2ab | 2018-01-13 07:57:42 -0500 | [diff] [blame] | 3253 | if options.platform and i.platform.name not in options.platform: |
| 3254 | continue |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3255 | debug( |
| 3256 | "{:<25} {:<50} {}SKIPPED{}: {}".format( |
| 3257 | i.platform.name, |
| 3258 | i.test.name, |
| 3259 | COLOR_YELLOW, |
| 3260 | COLOR_NORMAL, |
| 3261 | reason)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3262 | |
Anas Nashif | 1a5bba7 | 2018-01-05 08:07:45 -0500 | [diff] [blame] | 3263 | |
Alberto Escolar Piedras | 3777b44 | 2018-10-08 08:57:13 +0200 | [diff] [blame] | 3264 | def native_and_unit_first(a, b): |
| 3265 | if a[0].startswith('unit_testing'): |
Anas Nashif | 1a5bba7 | 2018-01-05 08:07:45 -0500 | [diff] [blame] | 3266 | return -1 |
Alberto Escolar Piedras | 3777b44 | 2018-10-08 08:57:13 +0200 | [diff] [blame] | 3267 | if b[0].startswith('unit_testing'): |
Anas Nashif | 1a5bba7 | 2018-01-05 08:07:45 -0500 | [diff] [blame] | 3268 | return 1 |
Alberto Escolar Piedras | 3777b44 | 2018-10-08 08:57:13 +0200 | [diff] [blame] | 3269 | if a[0].startswith('native_posix'): |
| 3270 | return -1 |
| 3271 | if b[0].startswith('native_posix'): |
| 3272 | return 1 |
| 3273 | if a[0].split("/",1)[0].endswith("_bsim"): |
| 3274 | return -1 |
| 3275 | if b[0].split("/",1)[0].endswith("_bsim"): |
| 3276 | return 1 |
| 3277 | |
Anas Nashif | 1a5bba7 | 2018-01-05 08:07:45 -0500 | [diff] [blame] | 3278 | return (a > b) - (a < b) |
| 3279 | |
| 3280 | ts.instances = OrderedDict(sorted(ts.instances.items(), |
Alberto Escolar Piedras | 3777b44 | 2018-10-08 08:57:13 +0200 | [diff] [blame] | 3281 | key=cmp_to_key(native_and_unit_first))) |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 3282 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3283 | if options.save_tests: |
| 3284 | ts.run_report(options.save_tests) |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 3285 | return |
| 3286 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3287 | if options.subset: |
Anas Nashif | 1a5bba7 | 2018-01-05 08:07:45 -0500 | [diff] [blame] | 3288 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3289 | subset, sets = options.subset.split("/") |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 3290 | total = len(ts.instances) |
Anas Nashif | 035799f | 2017-05-13 21:31:53 -0400 | [diff] [blame] | 3291 | per_set = round(total / int(sets)) |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3292 | start = (int(subset) - 1) * per_set |
Anas Nashif | 035799f | 2017-05-13 21:31:53 -0400 | [diff] [blame] | 3293 | if subset == sets: |
| 3294 | end = total |
| 3295 | else: |
| 3296 | end = start + per_set |
| 3297 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3298 | sliced_instances = islice(ts.instances.items(), start, end) |
Anas Nashif | 035799f | 2017-05-13 21:31:53 -0400 | [diff] [blame] | 3299 | ts.instances = OrderedDict(sliced_instances) |
| 3300 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3301 | info("%d tests selected, %d tests discarded due to filters" % |
| 3302 | (len(ts.instances), len(discards))) |
| 3303 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3304 | if options.dry_run: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3305 | return |
| 3306 | |
| 3307 | if VERBOSE or not TERMINAL: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3308 | goals = ts.execute( |
| 3309 | chatty_test_cb, |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 3310 | ts.instances) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3311 | else: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3312 | goals = ts.execute( |
| 3313 | terse_test_cb, |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 3314 | ts.instances) |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 3315 | info("") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3316 | |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 3317 | if options.detailed_report: |
| 3318 | ts.testcase_target_report(options.detailed_report) |
| 3319 | |
Daniel Leung | 7f85010 | 2016-04-08 11:07:32 -0700 | [diff] [blame] | 3320 | # figure out which report to use for size comparison |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3321 | if options.compare_report: |
| 3322 | report_to_use = options.compare_report |
| 3323 | elif options.last_metrics: |
Daniel Leung | 7f85010 | 2016-04-08 11:07:32 -0700 | [diff] [blame] | 3324 | report_to_use = LAST_SANITY |
| 3325 | else: |
| 3326 | report_to_use = RELEASE_DATA |
| 3327 | |
| 3328 | deltas = ts.compare_metrics(report_to_use) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3329 | warnings = 0 |
Anas Nashif | 424a3db | 2018-02-20 08:37:24 -0600 | [diff] [blame] | 3330 | if deltas and options.show_footprint: |
Andrew Boie | ea7928f | 2015-08-14 14:27:38 -0700 | [diff] [blame] | 3331 | for i, metric, value, delta, lower_better in deltas: |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3332 | if not options.all_deltas and ((delta < 0 and lower_better) or |
Andrew Boie | ea7928f | 2015-08-14 14:27:38 -0700 | [diff] [blame] | 3333 | (delta > 0 and not lower_better)): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3334 | continue |
| 3335 | |
Andrew Boie | ea7928f | 2015-08-14 14:27:38 -0700 | [diff] [blame] | 3336 | percentage = (float(delta) / float(value - delta)) |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3337 | if not options.all_deltas and (percentage < |
| 3338 | (options.footprint_threshold / 100.0)): |
Andrew Boie | ea7928f | 2015-08-14 14:27:38 -0700 | [diff] [blame] | 3339 | continue |
| 3340 | |
Daniel Leung | 00525c2 | 2016-04-11 10:27:56 -0700 | [diff] [blame] | 3341 | info("{:<25} {:<60} {}{}{}: {} {:<+4}, is now {:6} {:+.2%}".format( |
Andrew Boie | ea7928f | 2015-08-14 14:27:38 -0700 | [diff] [blame] | 3342 | i.platform.name, i.test.name, COLOR_YELLOW, |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3343 | "INFO" if options.all_deltas else "WARNING", COLOR_NORMAL, |
Andrew Boie | 829c056 | 2015-10-13 09:44:19 -0700 | [diff] [blame] | 3344 | metric, delta, value, percentage)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3345 | warnings += 1 |
| 3346 | |
| 3347 | if warnings: |
| 3348 | info("Deltas based on metrics from last %s" % |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3349 | ("release" if not options.last_metrics else "run")) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3350 | |
| 3351 | failed = 0 |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 3352 | for name, goal in goals.items(): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3353 | if goal.failed: |
| 3354 | failed += 1 |
Sebastian Bøe | 03ed095 | 2018-11-13 13:36:19 +0100 | [diff] [blame] | 3355 | elif goal.metrics.get("unrecognized") and not options.disable_unrecognized_section_test: |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 3356 | info("%sFAILED%s: %s has unrecognized binary sections: %s" % |
| 3357 | (COLOR_RED, COLOR_NORMAL, goal.name, |
| 3358 | str(goal.metrics["unrecognized"]))) |
| 3359 | failed += 1 |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3360 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3361 | if options.coverage: |
Jaakko Hannikainen | 54c90bc | 2016-08-31 14:17:03 +0300 | [diff] [blame] | 3362 | info("Generating coverage files...") |
Anas Nashif | 4df6c56 | 2018-11-07 19:29:04 -0500 | [diff] [blame] | 3363 | generate_coverage(options.outdir, ["*generated*", "tests/*", "samples/*"]) |
Jaakko Hannikainen | 54c90bc | 2016-08-31 14:17:03 +0300 | [diff] [blame] | 3364 | |
Anas Nashif | 0605fa3 | 2017-05-07 08:51:02 -0400 | [diff] [blame] | 3365 | duration = time.time() - start_time |
Andrew Boie | 4b18247 | 2015-07-31 12:25:22 -0700 | [diff] [blame] | 3366 | info("%s%d of %d%s tests passed with %s%d%s warnings in %d seconds" % |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3367 | (COLOR_RED if failed else COLOR_GREEN, len(goals) - failed, |
| 3368 | len(goals), COLOR_NORMAL, COLOR_YELLOW if warnings else COLOR_NORMAL, |
| 3369 | warnings, COLOR_NORMAL, duration)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3370 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3371 | if options.testcase_report: |
| 3372 | ts.testcase_report(options.testcase_report) |
| 3373 | if not options.no_update: |
Anas Nashif | 4f02888 | 2017-12-30 11:48:43 -0500 | [diff] [blame] | 3374 | ts.testcase_xunit_report(LAST_SANITY_XUNIT, duration) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3375 | ts.testcase_report(LAST_SANITY) |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3376 | if options.release: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3377 | ts.testcase_report(RELEASE_DATA) |
Inaky Perez-Gonzalez | 9a36cb6 | 2016-11-29 10:43:40 -0800 | [diff] [blame] | 3378 | if log_file: |
| 3379 | log_file.close() |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3380 | if failed or (warnings and options.warnings_as_errors): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3381 | sys.exit(1) |
| 3382 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3383 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3384 | if __name__ == "__main__": |
| 3385 | main() |