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 : |
Anas Nashif | 3ae5262 | 2019-04-06 09:08:09 -0400 | [diff] [blame] | 3 | # SPDX-License-Identifier: Apache-2.0 |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 4 | """Zephyr Sanity Tests |
| 5 | |
Marc Herbert | e5cedca | 2019-04-08 14:02:34 -0700 | [diff] [blame] | 6 | Also check the "User and Developer Guides" at https://docs.zephyrproject.org/ |
| 7 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 8 | This script scans for the set of unit test applications in the git |
| 9 | repository and attempts to execute them. By default, it tries to |
| 10 | build each test case on one platform per architecture, using a precedence |
Paul Sokolovsky | ff70add | 2017-06-16 01:31:54 +0300 | [diff] [blame] | 11 | list defined in an architecture configuration file, and if possible |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 12 | run the tests in any available emulators or simulators on the system. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 13 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 14 | Test cases are detected by the presence of a 'testcase.yaml' or a sample.yaml |
| 15 | files in the application's project directory. This file may contain one or more |
| 16 | blocks, each identifying a test scenario. The title of the block is a name for |
| 17 | the test case, which only needs to be unique for the test cases specified in |
| 18 | that testcase meta-data. The full canonical name for each test case is <path to |
| 19 | test case>/<block>. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 20 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 21 | Each test block in the testcase meta data can define the following key/value |
| 22 | pairs: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 23 | |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 24 | tags: <list of tags> (required) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 25 | A set of string tags for the testcase. Usually pertains to |
| 26 | functional domains but can be anything. Command line invocations |
| 27 | of this script can filter the set of tests to run based on tag. |
| 28 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 29 | skip: <True|False> (default False) |
Anas Nashif | 2bd99bc | 2015-10-12 13:10:57 -0400 | [diff] [blame] | 30 | skip testcase unconditionally. This can be used for broken tests. |
| 31 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 32 | slow: <True|False> (default False) |
Andy Ross | dc4151f | 2019-01-03 14:17:43 -0800 | [diff] [blame] | 33 | Don't build or run this test case unless --enable-slow was passed |
| 34 | in on the command line. Intended for time-consuming test cases |
| 35 | that are only run under certain circumstances, like daily |
| 36 | builds. |
Andrew Boie | 6bb087c | 2016-02-10 13:39:00 -0800 | [diff] [blame] | 37 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 38 | extra_args: <list of extra arguments> |
Sebastian Bøe | c218261 | 2017-11-09 12:25:02 +0100 | [diff] [blame] | 39 | Extra cache entries to pass to CMake when building or running the |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 40 | test case. |
| 41 | |
Anas Nashif | ebc329d | 2017-10-17 09:00:33 -0400 | [diff] [blame] | 42 | extra_configs: <list of extra configurations> |
| 43 | Extra configuration options to be merged with a master prj.conf |
| 44 | when building or running the test case. |
| 45 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 46 | build_only: <True|False> (default False) |
Marc Herbert | e5cedca | 2019-04-08 14:02:34 -0700 | [diff] [blame] | 47 | If true, don't try to run the test even if the selected platform |
| 48 | supports it. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 49 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 50 | build_on_all: <True|False> (default False) |
| 51 | If true, attempt to build test on all available platforms. |
| 52 | |
| 53 | depends_on: <list of features> |
| 54 | A board or platform can announce what features it supports, this option |
| 55 | will enable the test only those platforms that provide this feature. |
| 56 | |
| 57 | min_ram: <integer> |
| 58 | minimum amount of RAM needed for this test to build and run. This is |
| 59 | compared with information provided by the board metadata. |
| 60 | |
| 61 | min_flash: <integer> |
| 62 | minimum amount of ROM needed for this test to build and run. This is |
| 63 | compared with information provided by the board metadata. |
| 64 | |
| 65 | timeout: <number of seconds> |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 66 | Length of time to run test in emulator before automatically killing it. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 67 | Default to 60 seconds. |
| 68 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 69 | arch_whitelist: <list of arches, such as x86, arm, arc> |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 70 | Set of architectures that this test case should only be run for. |
| 71 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 72 | arch_exclude: <list of arches, such as x86, arm, arc> |
Anas Nashif | 30d1387 | 2015-10-05 10:02:45 -0400 | [diff] [blame] | 73 | Set of architectures that this test case should not run on. |
| 74 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 75 | platform_whitelist: <list of platforms> |
Anas Nashif | 30d1387 | 2015-10-05 10:02:45 -0400 | [diff] [blame] | 76 | Set of platforms that this test case should only be run for. |
| 77 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 78 | platform_exclude: <list of platforms> |
Anas Nashif | 30d1387 | 2015-10-05 10:02:45 -0400 | [diff] [blame] | 79 | Set of platforms that this test case should not run on. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 80 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 81 | extra_sections: <list of extra binary sections> |
Andrew Boie | 52fef67 | 2016-11-29 12:21:59 -0800 | [diff] [blame] | 82 | When computing sizes, sanitycheck will report errors if it finds |
| 83 | extra, unexpected sections in the Zephyr binary unless they are named |
| 84 | here. They will not be included in the size calculation. |
| 85 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 86 | filter: <expression> |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 87 | Filter whether the testcase should be run by evaluating an expression |
| 88 | against an environment containing the following values: |
| 89 | |
| 90 | { ARCH : <architecture>, |
| 91 | PLATFORM : <platform>, |
Javier B Perez | 7941454 | 2016-08-08 12:24:59 -0500 | [diff] [blame] | 92 | <all CONFIG_* key/value pairs in the test's generated defconfig>, |
Anas Nashif | 45a9786 | 2019-01-09 08:46:42 -0500 | [diff] [blame] | 93 | <all DT_* key/value pairs in the test's generated device tree file>, |
| 94 | <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] | 95 | *<env>: any environment variable available |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | The grammar for the expression language is as follows: |
| 99 | |
| 100 | expression ::= expression "and" expression |
| 101 | | expression "or" expression |
| 102 | | "not" expression |
| 103 | | "(" expression ")" |
| 104 | | symbol "==" constant |
| 105 | | symbol "!=" constant |
| 106 | | symbol "<" number |
| 107 | | symbol ">" number |
| 108 | | symbol ">=" number |
| 109 | | symbol "<=" number |
| 110 | | symbol "in" list |
Andrew Boie | 7a87f9f | 2016-06-02 12:27:54 -0700 | [diff] [blame] | 111 | | symbol ":" string |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 112 | | symbol |
| 113 | |
| 114 | list ::= "[" list_contents "]" |
| 115 | |
| 116 | list_contents ::= constant |
| 117 | | list_contents "," constant |
| 118 | |
| 119 | constant ::= number |
| 120 | | string |
| 121 | |
| 122 | |
| 123 | For the case where expression ::= symbol, it evaluates to true |
| 124 | if the symbol is defined to a non-empty string. |
| 125 | |
| 126 | Operator precedence, starting from lowest to highest: |
| 127 | |
| 128 | or (left associative) |
| 129 | and (left associative) |
| 130 | not (right associative) |
| 131 | all comparison operators (non-associative) |
| 132 | |
| 133 | arch_whitelist, arch_exclude, platform_whitelist, platform_exclude |
| 134 | are all syntactic sugar for these expressions. For instance |
| 135 | |
| 136 | arch_exclude = x86 arc |
| 137 | |
| 138 | Is the same as: |
| 139 | |
| 140 | filter = not ARCH in ["x86", "arc"] |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 141 | |
Andrew Boie | 7a87f9f | 2016-06-02 12:27:54 -0700 | [diff] [blame] | 142 | The ':' operator compiles the string argument as a regular expression, |
| 143 | and then returns a true value only if the symbol's value in the environment |
Anas Nashif | 578ae40 | 2019-07-12 07:54:35 -0700 | [diff] [blame] | 144 | matches. For example, if CONFIG_SOC="stm32f107xc" then |
Andrew Boie | 7a87f9f | 2016-06-02 12:27:54 -0700 | [diff] [blame] | 145 | |
Anas Nashif | 578ae40 | 2019-07-12 07:54:35 -0700 | [diff] [blame] | 146 | filter = CONFIG_SOC : "stm.*" |
Andrew Boie | 7a87f9f | 2016-06-02 12:27:54 -0700 | [diff] [blame] | 147 | |
| 148 | Would match it. |
| 149 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 150 | The set of test cases that actually run depends on directives in the testcase |
| 151 | filed and options passed in on the command line. If there is any confusion, |
Anas Nashif | 12d8cce | 2019-11-20 03:47:27 -0800 | [diff] [blame] | 152 | running with -v or examining the discard report (sanitycheck_discard.csv) |
| 153 | can help show why particular test cases were skipped. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 154 | |
| 155 | Metrics (such as pass/fail state and binary size) for the last code |
| 156 | release are stored in scripts/sanity_chk/sanity_last_release.csv. |
| 157 | To update this, pass the --all --release options. |
| 158 | |
Genaro Saucedo Tejada | 28bba92 | 2016-10-24 18:00:58 -0500 | [diff] [blame] | 159 | To load arguments from a file, write '+' before the file name, e.g., |
| 160 | +file_name. File content must be one or more valid arguments separated by |
| 161 | line break instead of white spaces. |
| 162 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 163 | Most everyday users will run with no arguments. |
Andy Ross | dc4151f | 2019-01-03 14:17:43 -0800 | [diff] [blame] | 164 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 165 | """ |
| 166 | |
Sebastian Bøe | 56d7471 | 2019-01-21 15:48:46 +0100 | [diff] [blame] | 167 | import os |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 168 | import contextlib |
Anas Nashif | a4c368e | 2018-10-15 09:45:59 -0400 | [diff] [blame] | 169 | import string |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 170 | import mmap |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 171 | import argparse |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 172 | import sys |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 173 | import re |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 174 | import subprocess |
| 175 | import multiprocessing |
| 176 | import select |
| 177 | import shutil |
Marc Herbert | af1090c | 2019-04-30 14:11:29 -0700 | [diff] [blame] | 178 | import shlex |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 179 | import signal |
| 180 | import threading |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 181 | import concurrent.futures |
| 182 | from threading import BoundedSemaphore |
| 183 | import queue |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 184 | import time |
| 185 | import csv |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 186 | import yaml |
Andrew Boie | 5d4eb78 | 2015-10-02 10:04:56 -0700 | [diff] [blame] | 187 | import glob |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 188 | import serial |
Daniel Leung | 6b17007 | 2016-04-07 12:10:25 -0700 | [diff] [blame] | 189 | import concurrent |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 190 | import xml.etree.ElementTree as ET |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 191 | import logging |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 192 | from colorama import Fore |
Anas Nashif | 035799f | 2017-05-13 21:31:53 -0400 | [diff] [blame] | 193 | from collections import OrderedDict |
| 194 | from itertools import islice |
Anas Nashif | e24350c | 2018-07-11 15:09:22 -0500 | [diff] [blame] | 195 | from pathlib import Path |
| 196 | from distutils.spawn import find_executable |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 197 | |
Anas Nashif | 434995c | 2019-12-01 13:55:11 -0500 | [diff] [blame] | 198 | try: |
| 199 | from anytree import Node, RenderTree, find |
| 200 | except ImportError: |
| 201 | print("Install the anytree module to use the --test-tree option") |
| 202 | |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 203 | try: |
| 204 | from tabulate import tabulate |
| 205 | except ImportError: |
| 206 | print("Install tabulate python module with pip to use --device-testing option.") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 207 | |
Kumar Gala | 7733b94 | 2019-09-12 17:08:43 -0500 | [diff] [blame] | 208 | ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") |
| 209 | if not ZEPHYR_BASE: |
| 210 | sys.exit("$ZEPHYR_BASE environment variable undefined") |
| 211 | |
| 212 | sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts", "dts")) |
| 213 | import edtlib |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 214 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 215 | hw_map_local = threading.Lock() |
Anas Nashif | c1ea452 | 2019-10-11 07:32:45 -0700 | [diff] [blame] | 216 | report_lock = threading.Lock() |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 217 | |
Marc Herbert | 1c8632c | 2019-04-15 17:58:45 -0700 | [diff] [blame] | 218 | # Use this for internal comparisons; that's what canonicalization is |
| 219 | # for. Don't use it when invoking other components of the build system |
| 220 | # to avoid confusing and hard to trace inconsistencies in error messages |
| 221 | # and logs, generated Makefiles, etc. compared to when users invoke these |
| 222 | # components directly. |
| 223 | # Note "normalization" is different from canonicalization, see os.path. |
| 224 | canonical_zephyr_base = os.path.realpath(ZEPHYR_BASE) |
| 225 | |
Andrew Boie | 3ea7892 | 2016-03-24 14:46:00 -0700 | [diff] [blame] | 226 | sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/")) |
| 227 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 228 | from sanity_chk import scl |
| 229 | from sanity_chk import expr_parser |
| 230 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 231 | VERBOSE = 0 |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 232 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 233 | RELEASE_DATA = os.path.join(ZEPHYR_BASE, "scripts", "sanity_chk", |
| 234 | "sanity_last_release.csv") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 235 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 236 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 237 | logger = logging.getLogger('sanitycheck') |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 238 | logger.setLevel(logging.DEBUG) |
| 239 | |
| 240 | |
Anas Nashif | 45a9786 | 2019-01-09 08:46:42 -0500 | [diff] [blame] | 241 | class CMakeCacheEntry: |
| 242 | '''Represents a CMake cache entry. |
| 243 | |
| 244 | This class understands the type system in a CMakeCache.txt, and |
| 245 | converts the following cache types to Python types: |
| 246 | |
| 247 | Cache Type Python type |
| 248 | ---------- ------------------------------------------- |
| 249 | FILEPATH str |
| 250 | PATH str |
| 251 | STRING str OR list of str (if ';' is in the value) |
| 252 | BOOL bool |
| 253 | INTERNAL str OR list of str (if ';' is in the value) |
| 254 | ---------- ------------------------------------------- |
| 255 | ''' |
| 256 | |
| 257 | # Regular expression for a cache entry. |
| 258 | # |
| 259 | # CMake variable names can include escape characters, allowing a |
| 260 | # wider set of names than is easy to match with a regular |
| 261 | # expression. To be permissive here, use a non-greedy match up to |
| 262 | # the first colon (':'). This breaks if the variable name has a |
| 263 | # colon inside, but it's good enough. |
| 264 | CACHE_ENTRY = re.compile( |
| 265 | r'''(?P<name>.*?) # name |
| 266 | :(?P<type>FILEPATH|PATH|STRING|BOOL|INTERNAL) # type |
| 267 | =(?P<value>.*) # value |
| 268 | ''', re.X) |
| 269 | |
| 270 | @classmethod |
| 271 | def _to_bool(cls, val): |
| 272 | # Convert a CMake BOOL string into a Python bool. |
| 273 | # |
| 274 | # "True if the constant is 1, ON, YES, TRUE, Y, or a |
| 275 | # non-zero number. False if the constant is 0, OFF, NO, |
| 276 | # FALSE, N, IGNORE, NOTFOUND, the empty string, or ends in |
| 277 | # the suffix -NOTFOUND. Named boolean constants are |
| 278 | # case-insensitive. If the argument is not one of these |
| 279 | # constants, it is treated as a variable." |
| 280 | # |
| 281 | # https://cmake.org/cmake/help/v3.0/command/if.html |
| 282 | val = val.upper() |
| 283 | if val in ('ON', 'YES', 'TRUE', 'Y'): |
| 284 | return 1 |
| 285 | elif val in ('OFF', 'NO', 'FALSE', 'N', 'IGNORE', 'NOTFOUND', ''): |
| 286 | return 0 |
| 287 | elif val.endswith('-NOTFOUND'): |
| 288 | return 0 |
| 289 | else: |
| 290 | try: |
| 291 | v = int(val) |
| 292 | return v != 0 |
| 293 | except ValueError as exc: |
| 294 | raise ValueError('invalid bool {}'.format(val)) from exc |
| 295 | |
| 296 | @classmethod |
| 297 | def from_line(cls, line, line_no): |
| 298 | # Comments can only occur at the beginning of a line. |
| 299 | # (The value of an entry could contain a comment character). |
| 300 | if line.startswith('//') or line.startswith('#'): |
| 301 | return None |
| 302 | |
| 303 | # Whitespace-only lines do not contain cache entries. |
| 304 | if not line.strip(): |
| 305 | return None |
| 306 | |
| 307 | m = cls.CACHE_ENTRY.match(line) |
| 308 | if not m: |
| 309 | return None |
| 310 | |
| 311 | name, type_, value = (m.group(g) for g in ('name', 'type', 'value')) |
| 312 | if type_ == 'BOOL': |
| 313 | try: |
| 314 | value = cls._to_bool(value) |
| 315 | except ValueError as exc: |
| 316 | args = exc.args + ('on line {}: {}'.format(line_no, line),) |
| 317 | raise ValueError(args) from exc |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 318 | elif type_ in ['STRING', 'INTERNAL']: |
Anas Nashif | 45a9786 | 2019-01-09 08:46:42 -0500 | [diff] [blame] | 319 | # If the value is a CMake list (i.e. is a string which |
| 320 | # contains a ';'), convert to a Python list. |
| 321 | if ';' in value: |
| 322 | value = value.split(';') |
| 323 | |
| 324 | return CMakeCacheEntry(name, value) |
| 325 | |
| 326 | def __init__(self, name, value): |
| 327 | self.name = name |
| 328 | self.value = value |
| 329 | |
| 330 | def __str__(self): |
| 331 | fmt = 'CMakeCacheEntry(name={}, value={})' |
| 332 | return fmt.format(self.name, self.value) |
| 333 | |
| 334 | |
| 335 | class CMakeCache: |
| 336 | '''Parses and represents a CMake cache file.''' |
| 337 | |
| 338 | @staticmethod |
| 339 | def from_file(cache_file): |
| 340 | return CMakeCache(cache_file) |
| 341 | |
| 342 | def __init__(self, cache_file): |
| 343 | self.cache_file = cache_file |
| 344 | self.load(cache_file) |
| 345 | |
| 346 | def load(self, cache_file): |
| 347 | entries = [] |
| 348 | with open(cache_file, 'r') as cache: |
| 349 | for line_no, line in enumerate(cache): |
| 350 | entry = CMakeCacheEntry.from_line(line, line_no) |
| 351 | if entry: |
| 352 | entries.append(entry) |
| 353 | self._entries = OrderedDict((e.name, e) for e in entries) |
| 354 | |
| 355 | def get(self, name, default=None): |
| 356 | entry = self._entries.get(name) |
| 357 | if entry is not None: |
| 358 | return entry.value |
| 359 | else: |
| 360 | return default |
| 361 | |
| 362 | def get_list(self, name, default=None): |
| 363 | if default is None: |
| 364 | default = [] |
| 365 | entry = self._entries.get(name) |
| 366 | if entry is not None: |
| 367 | value = entry.value |
| 368 | if isinstance(value, list): |
| 369 | return value |
| 370 | elif isinstance(value, str): |
| 371 | return [value] if value else [] |
| 372 | else: |
| 373 | msg = 'invalid value {} type {}' |
| 374 | raise RuntimeError(msg.format(value, type(value))) |
| 375 | else: |
| 376 | return default |
| 377 | |
| 378 | def __contains__(self, name): |
| 379 | return name in self._entries |
| 380 | |
| 381 | def __getitem__(self, name): |
| 382 | return self._entries[name].value |
| 383 | |
| 384 | def __setitem__(self, name, entry): |
| 385 | if not isinstance(entry, CMakeCacheEntry): |
| 386 | msg = 'improper type {} for value {}, expecting CMakeCacheEntry' |
| 387 | raise TypeError(msg.format(type(entry), entry)) |
| 388 | self._entries[name] = entry |
| 389 | |
| 390 | def __delitem__(self, name): |
| 391 | del self._entries[name] |
| 392 | |
| 393 | def __iter__(self): |
| 394 | return iter(self._entries.values()) |
| 395 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 396 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 397 | class SanityCheckException(Exception): |
| 398 | pass |
| 399 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 400 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 401 | class SanityRuntimeError(SanityCheckException): |
| 402 | pass |
| 403 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 404 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 405 | class ConfigurationError(SanityCheckException): |
| 406 | def __init__(self, cfile, message): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 407 | SanityCheckException.__init__(self, cfile + ": " + message) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 408 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 409 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 410 | class BuildError(SanityCheckException): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 411 | pass |
| 412 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 413 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 414 | class ExecutionError(SanityCheckException): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 415 | pass |
| 416 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 417 | |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 418 | class HarnessImporter: |
| 419 | |
| 420 | def __init__(self, name): |
| 421 | sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/sanity_chk")) |
| 422 | module = __import__("harness") |
| 423 | if name: |
| 424 | my_class = getattr(module, name) |
| 425 | else: |
| 426 | my_class = getattr(module, "Test") |
| 427 | |
| 428 | self.instance = my_class() |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 429 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 430 | |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 431 | class Handler: |
Anas Nashif | d18ec53 | 2019-04-11 23:20:39 -0400 | [diff] [blame] | 432 | def __init__(self, instance, type_str="build"): |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 433 | """Constructor |
| 434 | |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 435 | """ |
| 436 | self.lock = threading.Lock() |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 437 | |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 438 | self.state = "waiting" |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 439 | self.run = False |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 440 | self.duration = 0 |
Anas Nashif | d18ec53 | 2019-04-11 23:20:39 -0400 | [diff] [blame] | 441 | self.type_str = type_str |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 442 | |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 443 | self.binary = None |
Jan Kowalewski | 265895b | 2019-01-07 16:40:24 +0100 | [diff] [blame] | 444 | self.pid_fn = None |
Anas Nashif | 99f5a6c | 2018-07-07 08:45:53 -0500 | [diff] [blame] | 445 | self.call_make_run = False |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 446 | |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 447 | self.name = instance.name |
| 448 | self.instance = instance |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 449 | self.timeout = instance.testcase.timeout |
| 450 | self.sourcedir = instance.testcase.source_dir |
| 451 | self.build_dir = instance.build_dir |
| 452 | self.log = os.path.join(self.build_dir, "handler.log") |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 453 | self.returncode = 0 |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 454 | self.set_state("running", self.duration) |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 455 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 456 | self.args = [] |
| 457 | |
| 458 | def set_state(self, state, duration): |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 459 | self.lock.acquire() |
| 460 | self.state = state |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 461 | self.duration = duration |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 462 | self.lock.release() |
| 463 | |
| 464 | def get_state(self): |
| 465 | self.lock.acquire() |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 466 | ret = (self.state, self.duration) |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 467 | self.lock.release() |
| 468 | return ret |
| 469 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 470 | def record(self, harness): |
| 471 | if harness.recording: |
Anas Nashif | 9e7a2cd | 2019-12-05 13:07:27 -0500 | [diff] [blame] | 472 | filename = os.path.join(self.build_dir, "recording.csv") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 473 | with open(filename, "at") as csvfile: |
| 474 | cw = csv.writer(csvfile, harness.fieldnames, lineterminator=os.linesep) |
| 475 | cw.writerow(harness.fieldnames) |
| 476 | for instance in harness.recording: |
| 477 | cw.writerow(instance) |
| 478 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 479 | |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 480 | class BinaryHandler(Handler): |
Anas Nashif | d18ec53 | 2019-04-11 23:20:39 -0400 | [diff] [blame] | 481 | def __init__(self, instance, type_str): |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 482 | """Constructor |
| 483 | |
| 484 | @param instance Test Instance |
| 485 | """ |
Anas Nashif | d18ec53 | 2019-04-11 23:20:39 -0400 | [diff] [blame] | 486 | super().__init__(instance, type_str) |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 487 | |
Alberto Escolar Piedras | 661bc82 | 2018-12-11 15:13:05 +0100 | [diff] [blame] | 488 | self.terminated = False |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 489 | |
Anas Nashif | 6c0e170 | 2019-12-05 15:24:52 -0500 | [diff] [blame] | 490 | # Tool options |
| 491 | self.valgrind = False |
| 492 | self.lsan = False |
| 493 | self.asan = False |
| 494 | self.coverage = False |
| 495 | |
Jan Kowalewski | 265895b | 2019-01-07 16:40:24 +0100 | [diff] [blame] | 496 | def try_kill_process_by_pid(self): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 497 | if self.pid_fn: |
Jan Kowalewski | 265895b | 2019-01-07 16:40:24 +0100 | [diff] [blame] | 498 | pid = int(open(self.pid_fn).read()) |
| 499 | os.unlink(self.pid_fn) |
| 500 | self.pid_fn = None # clear so we don't try to kill the binary twice |
| 501 | try: |
| 502 | os.kill(pid, signal.SIGTERM) |
| 503 | except ProcessLookupError: |
| 504 | pass |
| 505 | |
Kumar Gala | 34b1ef8 | 2019-12-12 04:38:42 -0600 | [diff] [blame] | 506 | def terminate(self, proc): |
| 507 | # encapsulate terminate functionality so we do it consistently where ever |
| 508 | # we might want to terminate the proc. We need try_kill_process_by_pid |
| 509 | # because of both how newer ninja (1.6.0 or greater) and .NET / renode |
| 510 | # work. Newer ninja's don't seem to pass SIGTERM down to the children |
| 511 | # so we need to use try_kill_process_by_pid. |
| 512 | self.try_kill_process_by_pid() |
| 513 | proc.terminate() |
| 514 | self.terminated = True |
| 515 | |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 516 | def _output_reader(self, proc, harness): |
| 517 | log_out_fp = open(self.log, "wt") |
| 518 | for line in iter(proc.stdout.readline, b''): |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 519 | logger.debug("OUTPUT: {0}".format(line.decode('utf-8').rstrip())) |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 520 | log_out_fp.write(line.decode('utf-8')) |
| 521 | log_out_fp.flush() |
| 522 | harness.handle(line.decode('utf-8').rstrip()) |
| 523 | if harness.state: |
Alberto Escolar Piedras | 661bc82 | 2018-12-11 15:13:05 +0100 | [diff] [blame] | 524 | try: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 525 | # POSIX arch based ztests end on their own, |
| 526 | # so let's give it up to 100ms to do so |
Alberto Escolar Piedras | 661bc82 | 2018-12-11 15:13:05 +0100 | [diff] [blame] | 527 | proc.wait(0.1) |
| 528 | except subprocess.TimeoutExpired: |
Kumar Gala | 34b1ef8 | 2019-12-12 04:38:42 -0600 | [diff] [blame] | 529 | self.terminate(proc) |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 530 | break |
| 531 | |
| 532 | log_out_fp.close() |
| 533 | |
| 534 | def handle(self): |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 535 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 536 | harness_name = self.instance.testcase.harness.capitalize() |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 537 | harness_import = HarnessImporter(harness_name) |
| 538 | harness = harness_import.instance |
| 539 | harness.configure(self.instance) |
| 540 | |
Anas Nashif | 99f5a6c | 2018-07-07 08:45:53 -0500 | [diff] [blame] | 541 | if self.call_make_run: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 542 | command = [get_generator()[0], "run"] |
Anas Nashif | 99f5a6c | 2018-07-07 08:45:53 -0500 | [diff] [blame] | 543 | else: |
| 544 | command = [self.binary] |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 545 | |
Anas Nashif | c1ea452 | 2019-10-11 07:32:45 -0700 | [diff] [blame] | 546 | run_valgrind = False |
Anas Nashif | 6c0e170 | 2019-12-05 15:24:52 -0500 | [diff] [blame] | 547 | if self.valgrind and shutil.which("valgrind"): |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 548 | command = ["valgrind", "--error-exitcode=2", |
Alberto Escolar Piedras | 3980e0c | 2018-12-12 17:41:04 +0100 | [diff] [blame] | 549 | "--leak-check=full", |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 550 | "--suppressions=" + ZEPHYR_BASE + "/scripts/valgrind.supp", |
| 551 | "--log-file=" + self.build_dir + "/valgrind.log" |
Alberto Escolar Piedras | 3980e0c | 2018-12-12 17:41:04 +0100 | [diff] [blame] | 552 | ] + command |
Anas Nashif | c1ea452 | 2019-10-11 07:32:45 -0700 | [diff] [blame] | 553 | run_valgrind = True |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 554 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 555 | logger.debug("Spawning process: " + |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 556 | " ".join(shlex.quote(word) for word in command) + os.linesep + |
| 557 | "in directory: " + self.build_dir) |
Alberto Escolar Piedras | 649368c | 2019-07-02 09:59:35 +0200 | [diff] [blame] | 558 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 559 | start_time = time.time() |
Alberto Escolar Piedras | 649368c | 2019-07-02 09:59:35 +0200 | [diff] [blame] | 560 | |
Anas Nashif | 89c8304 | 2019-11-05 05:55:39 -0800 | [diff] [blame] | 561 | env = os.environ.copy() |
Anas Nashif | 6c0e170 | 2019-12-05 15:24:52 -0500 | [diff] [blame] | 562 | if self.asan: |
Jan Van Winkel | 21212f3 | 2019-09-12 00:03:35 +0200 | [diff] [blame] | 563 | env["ASAN_OPTIONS"] = "log_path=stdout:" + \ |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 564 | env.get("ASAN_OPTIONS", "") |
Anas Nashif | 6c0e170 | 2019-12-05 15:24:52 -0500 | [diff] [blame] | 565 | if not self.lsan: |
Jan Van Winkel | 21212f3 | 2019-09-12 00:03:35 +0200 | [diff] [blame] | 566 | env["ASAN_OPTIONS"] += "detect_leaks=0" |
| 567 | with subprocess.Popen(command, stdout=subprocess.PIPE, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 568 | stderr=subprocess.PIPE, cwd=self.build_dir, env=env) as proc: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 569 | logger.debug("Spawning BinaryHandler Thread for %s" % self.name) |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 570 | t = threading.Thread(target=self._output_reader, args=(proc, harness,), daemon=True) |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 571 | t.start() |
| 572 | t.join(self.timeout) |
| 573 | if t.is_alive(): |
Kumar Gala | 34b1ef8 | 2019-12-12 04:38:42 -0600 | [diff] [blame] | 574 | self.terminate(proc) |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 575 | t.join() |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 576 | proc.wait() |
| 577 | self.returncode = proc.returncode |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 578 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 579 | handler_time = time.time() - start_time |
Alberto Escolar Piedras | 649368c | 2019-07-02 09:59:35 +0200 | [diff] [blame] | 580 | |
Anas Nashif | 6c0e170 | 2019-12-05 15:24:52 -0500 | [diff] [blame] | 581 | if self.coverage: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 582 | subprocess.call(["GCOV_PREFIX=" + self.build_dir, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 583 | "gcov", self.sourcedir, "-b", "-s", self.build_dir], shell=True) |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 584 | |
Jan Kowalewski | 265895b | 2019-01-07 16:40:24 +0100 | [diff] [blame] | 585 | self.try_kill_process_by_pid() |
| 586 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 587 | # FIXME: This is needed when killing the simulator, the console is |
Anas Nashif | 99f5a6c | 2018-07-07 08:45:53 -0500 | [diff] [blame] | 588 | # garbled and needs to be reset. Did not find a better way to do that. |
| 589 | |
| 590 | subprocess.call(["stty", "sane"]) |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 591 | self.instance.results = harness.tests |
Anas Nashif | c1ea452 | 2019-10-11 07:32:45 -0700 | [diff] [blame] | 592 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 593 | if not self.terminated and self.returncode != 0: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 594 | # When a process is killed, the default handler returns 128 + SIGTERM |
| 595 | # so in that case the return code itself is not meaningful |
Anas Nashif | f72d190 | 2019-10-18 17:20:44 -0400 | [diff] [blame] | 596 | self.set_state("failed", handler_time) |
Anas Nashif | 17d066b | 2019-12-17 14:37:16 -0500 | [diff] [blame] | 597 | self.instance.reason = "Failed" |
Anas Nashif | c1ea452 | 2019-10-11 07:32:45 -0700 | [diff] [blame] | 598 | elif run_valgrind and self.returncode == 2: |
| 599 | self.set_state("failed", handler_time) |
| 600 | self.instance.reason = "Valgrind error" |
Alberto Escolar Piedras | 661bc82 | 2018-12-11 15:13:05 +0100 | [diff] [blame] | 601 | elif harness.state: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 602 | self.set_state(harness.state, handler_time) |
Anas Nashif | df7ee61 | 2018-07-07 06:09:01 -0500 | [diff] [blame] | 603 | else: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 604 | self.set_state("timeout", handler_time) |
Anas Nashif | 17d066b | 2019-12-17 14:37:16 -0500 | [diff] [blame] | 605 | self.instance.reason = "Timeout" |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 606 | |
| 607 | self.record(harness) |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 608 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 609 | |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 610 | class DeviceHandler(Handler): |
| 611 | |
Anas Nashif | d18ec53 | 2019-04-11 23:20:39 -0400 | [diff] [blame] | 612 | def __init__(self, instance, type_str): |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 613 | """Constructor |
| 614 | |
| 615 | @param instance Test Instance |
| 616 | """ |
Anas Nashif | d18ec53 | 2019-04-11 23:20:39 -0400 | [diff] [blame] | 617 | super().__init__(instance, type_str) |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 618 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 619 | self.suite = None |
| 620 | |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 621 | def monitor_serial(self, ser, halt_fileno, harness): |
Anas Nashif | 4a9f3e6 | 2018-07-06 18:58:18 -0500 | [diff] [blame] | 622 | log_out_fp = open(self.log, "wt") |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 623 | |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 624 | ser_fileno = ser.fileno() |
| 625 | readlist = [halt_fileno, ser_fileno] |
| 626 | |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 627 | while ser.isOpen(): |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 628 | readable, _, _ = select.select(readlist, [], [], self.timeout) |
| 629 | |
| 630 | if halt_fileno in readable: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 631 | logger.debug('halted') |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 632 | ser.close() |
| 633 | break |
| 634 | if ser_fileno not in readable: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 635 | continue # Timeout. |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 636 | |
| 637 | serial_line = None |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 638 | try: |
| 639 | serial_line = ser.readline() |
| 640 | except TypeError: |
| 641 | pass |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 642 | except serial.SerialException: |
Anas Nashif | 5923760 | 2019-03-03 10:36:35 -0500 | [diff] [blame] | 643 | ser.close() |
| 644 | break |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 645 | |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 646 | # Just because ser_fileno has data doesn't mean an entire line |
| 647 | # is available yet. |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 648 | if serial_line: |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 649 | sl = serial_line.decode('utf-8', 'ignore') |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 650 | logger.debug("DEVICE: {0}".format(sl.rstrip())) |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 651 | |
| 652 | log_out_fp.write(sl) |
| 653 | log_out_fp.flush() |
| 654 | harness.handle(sl.rstrip()) |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 655 | |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 656 | if harness.state: |
| 657 | ser.close() |
| 658 | break |
| 659 | |
| 660 | log_out_fp.close() |
| 661 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 662 | def device_is_available(self, device): |
| 663 | for i in self.suite.connected_hardware: |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 664 | if i['platform'] == device and i['available'] and i['serial']: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 665 | return True |
| 666 | |
| 667 | return False |
| 668 | |
| 669 | def get_available_device(self, device): |
| 670 | for i in self.suite.connected_hardware: |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 671 | if i['platform'] == device and i['available'] and i['serial']: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 672 | i['available'] = False |
| 673 | i['counter'] += 1 |
| 674 | return i |
| 675 | |
| 676 | return None |
| 677 | |
| 678 | def make_device_available(self, serial): |
| 679 | with hw_map_local: |
| 680 | for i in self.suite.connected_hardware: |
| 681 | if i['serial'] == serial: |
| 682 | i['available'] = True |
| 683 | |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 684 | def handle(self): |
| 685 | out_state = "failed" |
| 686 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 687 | if options.west_flash: |
| 688 | command = ["west", "flash", "--skip-rebuild", "-d", self.build_dir] |
| 689 | if options.west_runner: |
Michael Scott | 421ce46 | 2019-06-18 09:37:46 -0700 | [diff] [blame] | 690 | command.append("--runner") |
| 691 | command.append(options.west_runner) |
Jorgen Kvalvaag | d50fb31 | 2019-09-02 15:25:20 +0200 | [diff] [blame] | 692 | # There are three ways this option is used. |
Andy Doan | 79c4884 | 2019-02-08 10:09:04 -0600 | [diff] [blame] | 693 | # 1) bare: --west-flash |
| 694 | # This results in options.west_flash == [] |
| 695 | # 2) with a value: --west-flash="--board-id=42" |
| 696 | # This results in options.west_flash == "--board-id=42" |
Jorgen Kvalvaag | d50fb31 | 2019-09-02 15:25:20 +0200 | [diff] [blame] | 697 | # 3) Multiple values: --west-flash="--board-id=42,--erase" |
| 698 | # This results in options.west_flash == "--board-id=42 --erase" |
Andy Doan | 79c4884 | 2019-02-08 10:09:04 -0600 | [diff] [blame] | 699 | if options.west_flash != []: |
| 700 | command.append('--') |
Jorgen Kvalvaag | d50fb31 | 2019-09-02 15:25:20 +0200 | [diff] [blame] | 701 | command.extend(options.west_flash.split(',')) |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 702 | else: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 703 | command = [get_generator()[0], "-C", self.build_dir, "flash"] |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 704 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 705 | while not self.device_is_available(self.instance.platform.name): |
| 706 | time.sleep(1) |
| 707 | |
| 708 | hardware = self.get_available_device(self.instance.platform.name) |
| 709 | |
| 710 | runner = hardware.get('runner', None) |
| 711 | if runner: |
Peter Bigot | da73848 | 2019-11-21 11:55:26 -0600 | [diff] [blame] | 712 | board_id = hardware.get("probe_id", hardware.get("id", None)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 713 | product = hardware.get("product", None) |
| 714 | command = ["west", "flash", "--skip-rebuild", "-d", self.build_dir] |
| 715 | command.append("--runner") |
| 716 | command.append(hardware.get('runner', None)) |
| 717 | if runner == "pyocd": |
| 718 | command.append("--board-id") |
| 719 | command.append(board_id) |
| 720 | elif runner == "nrfjprog": |
| 721 | command.append('--') |
| 722 | command.append("--snr") |
| 723 | command.append(board_id) |
| 724 | elif runner == "openocd" and product == "STM32 STLink": |
| 725 | command.append('--') |
| 726 | command.append("--cmd-pre-init") |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 727 | command.append("hla_serial %s" % (board_id)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 728 | elif runner == "openocd" and product == "EDBG CMSIS-DAP": |
| 729 | command.append('--') |
| 730 | command.append("--cmd-pre-init") |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 731 | command.append("cmsis_dap_serial %s" % (board_id)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 732 | elif runner == "jlink": |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 733 | command.append("--tool-opt=-SelectEmuBySN %s" % (board_id)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 734 | |
| 735 | serial_device = hardware['serial'] |
| 736 | |
| 737 | try: |
| 738 | ser = serial.Serial( |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 739 | serial_device, |
| 740 | baudrate=115200, |
| 741 | parity=serial.PARITY_NONE, |
| 742 | stopbits=serial.STOPBITS_ONE, |
| 743 | bytesize=serial.EIGHTBITS, |
| 744 | timeout=self.timeout |
| 745 | ) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 746 | except serial.SerialException as e: |
| 747 | self.set_state("failed", 0) |
Anas Nashif | 17d066b | 2019-12-17 14:37:16 -0500 | [diff] [blame] | 748 | self.instance.reason = "Failed" |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 749 | logger.error("Serial device error: %s" % (str(e))) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 750 | self.make_device_available(serial_device) |
| 751 | return |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 752 | |
| 753 | ser.flush() |
| 754 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 755 | harness_name = self.instance.testcase.harness.capitalize() |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 756 | harness_import = HarnessImporter(harness_name) |
| 757 | harness = harness_import.instance |
| 758 | harness.configure(self.instance) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 759 | read_pipe, write_pipe = os.pipe() |
| 760 | start_time = time.time() |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 761 | |
Marti Bolivar | 5591ca2 | 2019-02-07 15:53:39 -0700 | [diff] [blame] | 762 | t = threading.Thread(target=self.monitor_serial, daemon=True, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 763 | args=(ser, read_pipe, harness)) |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 764 | t.start() |
| 765 | |
Anas Nashif | 33ed7aa | 2019-11-25 12:18:23 -0500 | [diff] [blame] | 766 | d_log = "{}/device.log".format(self.instance.build_dir) |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 767 | logger.debug('Flash command: %s', command) |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 768 | try: |
Anas Nashif | 33ed7aa | 2019-11-25 12:18:23 -0500 | [diff] [blame] | 769 | stdout = stderr = None |
| 770 | with subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE) as proc: |
| 771 | try: |
| 772 | (stdout, stderr) = proc.communicate(timeout=30) |
Anas Nashif | fa8085e | 2019-12-09 16:42:58 -0500 | [diff] [blame] | 773 | logger.debug(stdout.decode()) |
| 774 | |
Anas Nashif | 33ed7aa | 2019-11-25 12:18:23 -0500 | [diff] [blame] | 775 | if proc.returncode != 0: |
| 776 | self.instance.reason = "Device issue (Flash?)" |
| 777 | with open(d_log, "w") as dlog_fp: |
| 778 | dlog_fp.write(stderr.decode()) |
| 779 | except subprocess.TimeoutExpired: |
| 780 | proc.kill() |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 781 | (stdout, stderr) = proc.communicate() |
Anas Nashif | 33ed7aa | 2019-11-25 12:18:23 -0500 | [diff] [blame] | 782 | self.instance.reason = "Device issue (Timeout)" |
| 783 | |
| 784 | with open(d_log, "w") as dlog_fp: |
| 785 | dlog_fp.write(stderr.decode()) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 786 | |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 787 | except subprocess.CalledProcessError: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 788 | os.write(write_pipe, b'x') # halt the thread |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 789 | |
| 790 | t.join(self.timeout) |
| 791 | if t.is_alive(): |
| 792 | out_state = "timeout" |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 793 | |
| 794 | if ser.isOpen(): |
| 795 | ser.close() |
| 796 | |
Anas Nashif | 17d066b | 2019-12-17 14:37:16 -0500 | [diff] [blame] | 797 | handler_time = time.time() - start_time |
| 798 | |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 799 | if out_state == "timeout": |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 800 | for c in self.instance.testcase.cases: |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 801 | if c not in harness.tests: |
| 802 | harness.tests[c] = "BLOCK" |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 803 | |
Anas Nashif | 17d066b | 2019-12-17 14:37:16 -0500 | [diff] [blame] | 804 | self.instance.reason = "Timeout" |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 805 | |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 806 | self.instance.results = harness.tests |
Anas Nashif | 17d066b | 2019-12-17 14:37:16 -0500 | [diff] [blame] | 807 | |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 808 | if harness.state: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 809 | self.set_state(harness.state, handler_time) |
Anas Nashif | 17d066b | 2019-12-17 14:37:16 -0500 | [diff] [blame] | 810 | if harness.state == "failed": |
| 811 | self.instance.reason = "Failed" |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 812 | else: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 813 | self.set_state(out_state, handler_time) |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 814 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 815 | self.make_device_available(serial_device) |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 816 | |
Anas Nashif | 3a00d0c | 2019-11-12 11:07:15 -0500 | [diff] [blame] | 817 | self.record(harness) |
| 818 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 819 | |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 820 | class QEMUHandler(Handler): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 821 | """Spawns a thread to monitor QEMU output from pipes |
| 822 | |
Anas Nashif | 3ac7b3a | 2017-08-03 10:03:02 -0400 | [diff] [blame] | 823 | 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] | 824 | We need to do this as once qemu starts, it runs forever until killed. |
| 825 | Test cases emit special messages to the console as they run, we check |
| 826 | for these to collect whether the test passed or failed. |
| 827 | """ |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 828 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 829 | def __init__(self, instance, type_str): |
| 830 | """Constructor |
| 831 | |
| 832 | @param instance Test instance |
| 833 | """ |
| 834 | |
| 835 | super().__init__(instance, type_str) |
| 836 | self.fifo_fn = os.path.join(instance.build_dir, "qemu-fifo") |
| 837 | |
| 838 | self.pid_fn = os.path.join(instance.build_dir, "qemu.pid") |
| 839 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 840 | @staticmethod |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 841 | def _thread(handler, timeout, outdir, logfile, fifo_fn, pid_fn, results, harness): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 842 | fifo_in = fifo_fn + ".in" |
| 843 | fifo_out = fifo_fn + ".out" |
| 844 | |
| 845 | # These in/out nodes are named from QEMU's perspective, not ours |
| 846 | if os.path.exists(fifo_in): |
| 847 | os.unlink(fifo_in) |
| 848 | os.mkfifo(fifo_in) |
| 849 | if os.path.exists(fifo_out): |
| 850 | os.unlink(fifo_out) |
| 851 | os.mkfifo(fifo_out) |
| 852 | |
| 853 | # We don't do anything with out_fp but we need to open it for |
| 854 | # writing so that QEMU doesn't block, due to the way pipes work |
| 855 | out_fp = open(fifo_in, "wb") |
| 856 | # Disable internal buffering, we don't |
| 857 | # want read() or poll() to ever block if there is data in there |
| 858 | in_fp = open(fifo_out, "rb", buffering=0) |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 859 | log_out_fp = open(logfile, "wt") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 860 | |
| 861 | start_time = time.time() |
| 862 | timeout_time = start_time + timeout |
| 863 | p = select.poll() |
| 864 | p.register(in_fp, select.POLLIN) |
Anas Nashif | 39ae72b | 2018-08-29 01:45:38 -0400 | [diff] [blame] | 865 | out_state = None |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 866 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 867 | line = "" |
Anas Nashif | 74dbe33 | 2019-01-17 17:11:37 -0500 | [diff] [blame] | 868 | timeout_extended = False |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 869 | while True: |
| 870 | this_timeout = int((timeout_time - time.time()) * 1000) |
| 871 | if this_timeout < 0 or not p.poll(this_timeout): |
Anas Nashif | 39ae72b | 2018-08-29 01:45:38 -0400 | [diff] [blame] | 872 | if not out_state: |
| 873 | out_state = "timeout" |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 874 | break |
| 875 | |
Genaro Saucedo Tejada | 2968b36 | 2016-08-09 15:11:53 -0500 | [diff] [blame] | 876 | try: |
| 877 | c = in_fp.read(1).decode("utf-8") |
| 878 | except UnicodeDecodeError: |
| 879 | # Test is writing something weird, fail |
| 880 | out_state = "unexpected byte" |
| 881 | break |
| 882 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 883 | if c == "": |
| 884 | # EOF, this shouldn't happen unless QEMU crashes |
| 885 | out_state = "unexpected eof" |
| 886 | break |
| 887 | line = line + c |
| 888 | if c != "\n": |
| 889 | continue |
| 890 | |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 891 | # line contains a full line of data output from QEMU |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 892 | log_out_fp.write(line) |
| 893 | log_out_fp.flush() |
| 894 | line = line.strip() |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 895 | logger.debug("QEMU: %s" % line) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 896 | |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 897 | harness.handle(line) |
| 898 | if harness.state: |
Anas Nashif | 39ae72b | 2018-08-29 01:45:38 -0400 | [diff] [blame] | 899 | # if we have registered a fail make sure the state is not |
| 900 | # overridden by a false success message coming from the |
| 901 | # testsuite |
| 902 | if out_state != 'failed': |
| 903 | out_state = harness.state |
| 904 | |
| 905 | # if we get some state, that means test is doing well, we reset |
Marc Herbert | 9e57338 | 2019-07-03 12:49:42 -0700 | [diff] [blame] | 906 | # the timeout and wait for 2 more seconds to catch anything |
| 907 | # printed late. We wait much longer if code |
Andrew Boie | 095b82a | 2019-07-02 17:03:48 -0700 | [diff] [blame] | 908 | # coverage is enabled since dumping this information can |
| 909 | # take some time. |
Anas Nashif | f29087e | 2019-01-25 09:37:38 -0500 | [diff] [blame] | 910 | if not timeout_extended or harness.capture_coverage: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 911 | timeout_extended = True |
Anas Nashif | f29087e | 2019-01-25 09:37:38 -0500 | [diff] [blame] | 912 | if harness.capture_coverage: |
Andrew Boie | d62e229 | 2019-07-01 15:01:48 -0700 | [diff] [blame] | 913 | timeout_time = time.time() + 30 |
Anas Nashif | f29087e | 2019-01-25 09:37:38 -0500 | [diff] [blame] | 914 | else: |
Anas Nashif | 74dbe33 | 2019-01-17 17:11:37 -0500 | [diff] [blame] | 915 | timeout_time = time.time() + 2 |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 916 | line = "" |
| 917 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 918 | handler.record(harness) |
| 919 | |
| 920 | handler_time = time.time() - start_time |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 921 | logger.debug("QEMU complete (%s) after %f seconds" % |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 922 | (out_state, handler_time)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 923 | handler.set_state(out_state, handler_time) |
Anas Nashif | 17d066b | 2019-12-17 14:37:16 -0500 | [diff] [blame] | 924 | if out_state == "timeout": |
| 925 | handler.instance.reason = "Timeout" |
| 926 | elif out_state == "failed": |
| 927 | handler.instance.reason = "Failed" |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 928 | |
| 929 | log_out_fp.close() |
| 930 | out_fp.close() |
| 931 | in_fp.close() |
Anas Nashif | d6476ee | 2019-04-11 11:40:09 -0400 | [diff] [blame] | 932 | if os.path.exists(pid_fn): |
| 933 | pid = int(open(pid_fn).read()) |
| 934 | os.unlink(pid_fn) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 935 | |
Anas Nashif | d6476ee | 2019-04-11 11:40:09 -0400 | [diff] [blame] | 936 | try: |
| 937 | if pid: |
| 938 | os.kill(pid, signal.SIGTERM) |
| 939 | except ProcessLookupError: |
| 940 | # Oh well, as long as it's dead! User probably sent Ctrl-C |
| 941 | pass |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 942 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 943 | os.unlink(fifo_in) |
| 944 | os.unlink(fifo_out) |
| 945 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 946 | def handle(self): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 947 | self.results = {} |
Anas Nashif | 1377375 | 2018-07-06 18:20:23 -0500 | [diff] [blame] | 948 | self.run = True |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 949 | |
| 950 | # We pass this to QEMU which looks for fifos with .in and .out |
| 951 | # suffixes. |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 952 | self.fifo_fn = os.path.join(self.instance.build_dir, "qemu-fifo") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 953 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 954 | self.pid_fn = os.path.join(self.instance.build_dir, "qemu.pid") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 955 | if os.path.exists(self.pid_fn): |
| 956 | os.unlink(self.pid_fn) |
| 957 | |
Anas Nashif | 4a9f3e6 | 2018-07-06 18:58:18 -0500 | [diff] [blame] | 958 | self.log_fn = self.log |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 959 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 960 | harness_import = HarnessImporter(self.instance.testcase.harness.capitalize()) |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 961 | harness = harness_import.instance |
Anas Nashif | d3384fb | 2018-02-22 06:44:16 -0600 | [diff] [blame] | 962 | harness.configure(self.instance) |
| 963 | self.thread = threading.Thread(name=self.name, target=QEMUHandler._thread, |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 964 | args=(self, self.timeout, self.build_dir, |
Jaakko Hannikainen | ca505f8 | 2016-08-22 15:03:46 +0300 | [diff] [blame] | 965 | self.log_fn, self.fifo_fn, |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 966 | self.pid_fn, self.results, harness)) |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 967 | |
| 968 | self.instance.results = harness.tests |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 969 | self.thread.daemon = True |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 970 | logger.debug("Spawning QEMUHandler Thread for %s" % self.name) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 971 | self.thread.start() |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 972 | subprocess.call(["stty", "sane"]) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 973 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 974 | logger.debug("Running %s (%s)" % (self.name, self.type_str)) |
Stephanos Ioannidis | e1827c0 | 2019-11-12 14:11:31 +0900 | [diff] [blame] | 975 | command = [get_generator()[0]] |
| 976 | command += ["-C", self.build_dir, "run"] |
| 977 | |
| 978 | with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.build_dir) as proc: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 979 | logger.debug("Spawning QEMUHandler Thread for %s" % self.name) |
Stephanos Ioannidis | e1827c0 | 2019-11-12 14:11:31 +0900 | [diff] [blame] | 980 | proc.wait() |
| 981 | self.returncode = proc.returncode |
| 982 | |
| 983 | if self.returncode != 0: |
| 984 | self.set_state("failed", 0) |
| 985 | self.instance.reason = "Exited with {}".format(self.returncode) |
| 986 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 987 | def get_fifo(self): |
| 988 | return self.fifo_fn |
| 989 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 990 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 991 | class SizeCalculator: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 992 | alloc_sections = [ |
| 993 | "bss", |
| 994 | "noinit", |
| 995 | "app_bss", |
| 996 | "app_noinit", |
| 997 | "ccm_bss", |
| 998 | "ccm_noinit" |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 999 | ] |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1000 | |
| 1001 | rw_sections = [ |
| 1002 | "datas", |
| 1003 | "initlevel", |
| 1004 | "exceptions", |
| 1005 | "initshell", |
| 1006 | "_static_thread_area", |
| 1007 | "_k_timer_area", |
| 1008 | "_k_mem_slab_area", |
| 1009 | "_k_mem_pool_area", |
| 1010 | "sw_isr_table", |
| 1011 | "_k_sem_area", |
| 1012 | "_k_mutex_area", |
| 1013 | "app_shmem_regions", |
| 1014 | "_k_fifo_area", |
| 1015 | "_k_lifo_area", |
| 1016 | "_k_stack_area", |
| 1017 | "_k_msgq_area", |
| 1018 | "_k_mbox_area", |
| 1019 | "_k_pipe_area", |
| 1020 | "net_if", |
| 1021 | "net_if_dev", |
| 1022 | "net_stack", |
| 1023 | "net_l2_data", |
| 1024 | "_k_queue_area", |
| 1025 | "_net_buf_pool_area", |
| 1026 | "app_datas", |
| 1027 | "kobject_data", |
| 1028 | "mmu_tables", |
| 1029 | "app_pad", |
| 1030 | "priv_stacks", |
| 1031 | "ccm_data", |
| 1032 | "usb_descriptor", |
| 1033 | "usb_data", "usb_bos_desc", |
| 1034 | 'log_backends_sections', |
| 1035 | 'log_dynamic_sections', |
| 1036 | 'log_const_sections', |
| 1037 | "app_smem", |
| 1038 | 'shell_root_cmds_sections', |
| 1039 | 'log_const_sections', |
| 1040 | "font_entry_sections", |
| 1041 | "priv_stacks_noinit", |
| 1042 | "_TEXT_SECTION_NAME_2", |
| 1043 | "_GCOV_BSS_SECTION_NAME", |
| 1044 | "gcov", |
| 1045 | "nocache" |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1046 | ] |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 1047 | |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 1048 | # These get copied into RAM only on non-XIP |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1049 | ro_sections = [ |
| 1050 | "text", |
| 1051 | "ctors", |
| 1052 | "init_array", |
| 1053 | "reset", |
| 1054 | "object_access", |
| 1055 | "rodata", |
| 1056 | "devconfig", |
| 1057 | "net_l2", |
| 1058 | "vector", |
| 1059 | "sw_isr_table", |
| 1060 | "_settings_handlers_area", |
| 1061 | "_bt_channels_area", |
| 1062 | "_bt_br_channels_area", |
| 1063 | "_bt_services_area", |
| 1064 | "vectors", |
| 1065 | "net_socket_register", |
| 1066 | "net_ppp_proto" |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1067 | ] |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 1068 | |
Andrew Boie | 52fef67 | 2016-11-29 12:21:59 -0800 | [diff] [blame] | 1069 | def __init__(self, filename, extra_sections): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1070 | """Constructor |
| 1071 | |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 1072 | @param filename Path to the output binary |
| 1073 | The <filename> is parsed by objdump to determine section sizes |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1074 | """ |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1075 | # Make sure this is an ELF binary |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 1076 | with open(filename, "rb") as f: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1077 | magic = f.read(4) |
| 1078 | |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 1079 | try: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1080 | if magic != b'\x7fELF': |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 1081 | raise SanityRuntimeError("%s is not an ELF binary" % filename) |
| 1082 | except Exception as e: |
| 1083 | print(str(e)) |
| 1084 | sys.exit(2) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1085 | |
| 1086 | # 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] | 1087 | # GREP can not be used as it returns an error if the symbol is not |
| 1088 | # found. |
| 1089 | is_xip_command = "nm " + filename + \ |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1090 | " | awk '/CONFIG_XIP/ { print $3 }'" |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1091 | is_xip_output = subprocess.check_output( |
| 1092 | is_xip_command, shell=True, stderr=subprocess.STDOUT).decode( |
| 1093 | "utf-8").strip() |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 1094 | try: |
| 1095 | if is_xip_output.endswith("no symbols"): |
| 1096 | raise SanityRuntimeError("%s has no symbol information" % filename) |
| 1097 | except Exception as e: |
| 1098 | print(str(e)) |
| 1099 | sys.exit(2) |
| 1100 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1101 | self.is_xip = (len(is_xip_output) != 0) |
| 1102 | |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 1103 | self.filename = filename |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 1104 | self.sections = [] |
| 1105 | self.rom_size = 0 |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1106 | self.ram_size = 0 |
Andrew Boie | 52fef67 | 2016-11-29 12:21:59 -0800 | [diff] [blame] | 1107 | self.extra_sections = extra_sections |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1108 | |
| 1109 | self._calculate_sizes() |
| 1110 | |
| 1111 | def get_ram_size(self): |
| 1112 | """Get the amount of RAM the application will use up on the device |
| 1113 | |
| 1114 | @return amount of RAM, in bytes |
| 1115 | """ |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 1116 | return self.ram_size |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1117 | |
| 1118 | def get_rom_size(self): |
| 1119 | """Get the size of the data that this application uses on device's flash |
| 1120 | |
| 1121 | @return amount of ROM, in bytes |
| 1122 | """ |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 1123 | return self.rom_size |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1124 | |
| 1125 | def unrecognized_sections(self): |
| 1126 | """Get a list of sections inside the binary that weren't recognized |
| 1127 | |
David B. Kinder | 29963c3 | 2017-06-16 12:32:42 -0700 | [diff] [blame] | 1128 | @return list of unrecognized section names |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1129 | """ |
| 1130 | slist = [] |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 1131 | for v in self.sections: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1132 | if not v["recognized"]: |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 1133 | slist.append(v["name"]) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1134 | return slist |
| 1135 | |
| 1136 | def _calculate_sizes(self): |
| 1137 | """ Calculate RAM and ROM usage by section """ |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 1138 | objdump_command = "objdump -h " + self.filename |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1139 | objdump_output = subprocess.check_output( |
| 1140 | objdump_command, shell=True).decode("utf-8").splitlines() |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1141 | |
| 1142 | for line in objdump_output: |
| 1143 | words = line.split() |
| 1144 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1145 | if not words: # Skip lines that are too short |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1146 | continue |
| 1147 | |
| 1148 | index = words[0] |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1149 | if not index[0].isdigit(): # Skip lines that do not start |
| 1150 | continue # with a digit |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1151 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1152 | name = words[1] # Skip lines with section names |
| 1153 | if name[0] == '.': # starting with '.' |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1154 | continue |
| 1155 | |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 1156 | # TODO this doesn't actually reflect the size in flash or RAM as |
| 1157 | # it doesn't include linker-imposed padding between sections. |
| 1158 | # It is close though. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1159 | size = int(words[2], 16) |
Andrew Boie | 9882dcd | 2015-10-07 14:25:51 -0700 | [diff] [blame] | 1160 | if size == 0: |
| 1161 | continue |
| 1162 | |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 1163 | load_addr = int(words[4], 16) |
| 1164 | virt_addr = int(words[3], 16) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1165 | |
| 1166 | # 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] | 1167 | # Unrecognized section names are not included in the calculations. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1168 | recognized = True |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 1169 | if name in SizeCalculator.alloc_sections: |
| 1170 | self.ram_size += size |
| 1171 | stype = "alloc" |
| 1172 | elif name in SizeCalculator.rw_sections: |
| 1173 | self.ram_size += size |
| 1174 | self.rom_size += size |
| 1175 | stype = "rw" |
| 1176 | elif name in SizeCalculator.ro_sections: |
| 1177 | self.rom_size += size |
| 1178 | if not self.is_xip: |
| 1179 | self.ram_size += size |
| 1180 | stype = "ro" |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1181 | else: |
Andrew Boie | 73b4ee6 | 2015-10-07 11:33:22 -0700 | [diff] [blame] | 1182 | stype = "unknown" |
Andrew Boie | 52fef67 | 2016-11-29 12:21:59 -0800 | [diff] [blame] | 1183 | if name not in self.extra_sections: |
| 1184 | recognized = False |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1185 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1186 | self.sections.append({"name": name, "load_addr": load_addr, |
| 1187 | "size": size, "virt_addr": virt_addr, |
| 1188 | "type": stype, "recognized": recognized}) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1189 | |
| 1190 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1191 | # "list" - List of strings |
| 1192 | # "list:<type>" - List of <type> |
| 1193 | # "set" - Set of unordered, unique strings |
| 1194 | # "set:<type>" - Set of <type> |
| 1195 | # "float" - Floating point |
| 1196 | # "int" - Integer |
| 1197 | # "bool" - Boolean |
| 1198 | # "str" - String |
| 1199 | |
| 1200 | # XXX Be sure to update __doc__ if you change any of this!! |
| 1201 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1202 | platform_valid_keys = { |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1203 | "supported_toolchains": {"type": "list", "default": []}, |
| 1204 | "env": {"type": "list", "default": []} |
| 1205 | } |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1206 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1207 | testcase_valid_keys = {"tags": {"type": "set", "required": False}, |
| 1208 | "type": {"type": "str", "default": "integration"}, |
| 1209 | "extra_args": {"type": "list"}, |
| 1210 | "extra_configs": {"type": "list"}, |
| 1211 | "build_only": {"type": "bool", "default": False}, |
| 1212 | "build_on_all": {"type": "bool", "default": False}, |
| 1213 | "skip": {"type": "bool", "default": False}, |
| 1214 | "slow": {"type": "bool", "default": False}, |
| 1215 | "timeout": {"type": "int", "default": 60}, |
| 1216 | "min_ram": {"type": "int", "default": 8}, |
| 1217 | "depends_on": {"type": "set"}, |
| 1218 | "min_flash": {"type": "int", "default": 32}, |
| 1219 | "arch_whitelist": {"type": "set"}, |
| 1220 | "arch_exclude": {"type": "set"}, |
| 1221 | "extra_sections": {"type": "list", "default": []}, |
| 1222 | "platform_exclude": {"type": "set"}, |
| 1223 | "platform_whitelist": {"type": "set"}, |
| 1224 | "toolchain_exclude": {"type": "set"}, |
| 1225 | "toolchain_whitelist": {"type": "set"}, |
Anas Nashif | ab94016 | 2017-12-08 10:17:57 -0500 | [diff] [blame] | 1226 | "filter": {"type": "str"}, |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 1227 | "harness": {"type": "str"}, |
Praful Swarnakar | cf89e28 | 2018-09-13 02:58:28 +0530 | [diff] [blame] | 1228 | "harness_config": {"type": "map", "default": {}} |
Anas Nashif | ab94016 | 2017-12-08 10:17:57 -0500 | [diff] [blame] | 1229 | } |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1230 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 1231 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1232 | class SanityConfigParser: |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1233 | """Class to read test case files with semantic checking |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1234 | """ |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1235 | |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 1236 | def __init__(self, filename, schema): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1237 | """Instantiate a new SanityConfigParser object |
| 1238 | |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1239 | @param filename Source .yaml file to read |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1240 | """ |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1241 | self.data = {} |
| 1242 | self.schema = schema |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1243 | self.filename = filename |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1244 | self.tests = {} |
| 1245 | self.common = {} |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1246 | |
| 1247 | def load(self): |
| 1248 | self.data = scl.yaml_load_verify(self.filename, self.schema) |
| 1249 | |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1250 | if 'tests' in self.data: |
| 1251 | self.tests = self.data['tests'] |
| 1252 | if 'common' in self.data: |
| 1253 | self.common = self.data['common'] |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1254 | |
| 1255 | def _cast_value(self, value, typestr): |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1256 | if isinstance(value, str): |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1257 | v = value.strip() |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1258 | if typestr == "str": |
| 1259 | return v |
| 1260 | |
| 1261 | elif typestr == "float": |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1262 | return float(value) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1263 | |
| 1264 | elif typestr == "int": |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1265 | return int(value) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1266 | |
| 1267 | elif typestr == "bool": |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1268 | return value |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1269 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1270 | elif typestr.startswith("list") and isinstance(value, list): |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 1271 | return value |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1272 | elif typestr.startswith("list") and isinstance(value, str): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1273 | vs = v.split() |
| 1274 | if len(typestr) > 4 and typestr[4] == ":": |
| 1275 | return [self._cast_value(vsi, typestr[5:]) for vsi in vs] |
| 1276 | else: |
| 1277 | return vs |
| 1278 | |
| 1279 | elif typestr.startswith("set"): |
| 1280 | vs = v.split() |
| 1281 | if len(typestr) > 3 and typestr[3] == ":": |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1282 | return {self._cast_value(vsi, typestr[4:]) for vsi in vs} |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1283 | else: |
| 1284 | return set(vs) |
| 1285 | |
Anas Nashif | 576be98 | 2017-12-23 20:20:27 -0500 | [diff] [blame] | 1286 | elif typestr.startswith("map"): |
| 1287 | return value |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1288 | else: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1289 | raise ConfigurationError( |
| 1290 | self.filename, "unknown type '%s'" % value) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1291 | |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1292 | def get_test(self, name, valid_keys): |
| 1293 | """Get a dictionary representing the keys/values within a test |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1294 | |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1295 | @param name The test in the .yaml file to retrieve data from |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1296 | @param valid_keys A dictionary representing the intended semantics |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1297 | 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] | 1298 | 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] | 1299 | here, it will generate an error. Each value in this dictionary |
| 1300 | is another dictionary containing metadata: |
| 1301 | |
| 1302 | "default" - Default value if not given |
| 1303 | "type" - Data type to convert the text value to. Simple types |
| 1304 | supported are "str", "float", "int", "bool" which will get |
| 1305 | converted to respective Python data types. "set" and "list" |
| 1306 | may also be specified which will split the value by |
| 1307 | whitespace (but keep the elements as strings). finally, |
| 1308 | "list:<type>" and "set:<type>" may be given which will |
| 1309 | perform a type conversion after splitting the value up. |
| 1310 | "required" - If true, raise an error if not defined. If false |
| 1311 | and "default" isn't specified, a type conversion will be |
| 1312 | done on an empty string |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1313 | @return A dictionary containing the test key-value pairs with |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1314 | type conversion and default values filled in per valid_keys |
| 1315 | """ |
| 1316 | |
| 1317 | d = {} |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1318 | for k, v in self.common.items(): |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 1319 | d[k] = v |
Anas Nashif | 75547e2 | 2018-02-24 08:32:14 -0600 | [diff] [blame] | 1320 | |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1321 | for k, v in self.tests[name].items(): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1322 | if k not in valid_keys: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1323 | raise ConfigurationError( |
| 1324 | self.filename, |
| 1325 | "Unknown config key '%s' in definition for '%s'" % |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1326 | (k, name)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1327 | |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 1328 | if k in d: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1329 | if isinstance(d[k], str): |
Paul Sokolovsky | 8c6d2e2 | 2019-08-29 13:20:57 +0300 | [diff] [blame] | 1330 | # By default, we just concatenate string values of keys |
| 1331 | # which appear both in "common" and per-test sections, |
| 1332 | # but some keys are handled in adhoc way based on their |
| 1333 | # semantics. |
| 1334 | if k == "filter": |
| 1335 | d[k] = "(%s) and (%s)" % (d[k], v) |
| 1336 | else: |
| 1337 | d[k] += " " + v |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 1338 | else: |
| 1339 | d[k] = v |
Anas Nashif | 75547e2 | 2018-02-24 08:32:14 -0600 | [diff] [blame] | 1340 | |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 1341 | for k, kinfo in valid_keys.items(): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1342 | if k not in d: |
| 1343 | if "required" in kinfo: |
| 1344 | required = kinfo["required"] |
| 1345 | else: |
| 1346 | required = False |
| 1347 | |
| 1348 | if required: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1349 | raise ConfigurationError( |
| 1350 | self.filename, |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1351 | "missing required value for '%s' in test '%s'" % |
| 1352 | (k, name)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1353 | else: |
| 1354 | if "default" in kinfo: |
| 1355 | default = kinfo["default"] |
| 1356 | else: |
| 1357 | default = self._cast_value("", kinfo["type"]) |
| 1358 | d[k] = default |
| 1359 | else: |
| 1360 | try: |
| 1361 | d[k] = self._cast_value(d[k], kinfo["type"]) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1362 | except ValueError: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1363 | raise ConfigurationError( |
Anas Nashif | b4754ed | 2017-12-05 17:27:58 -0500 | [diff] [blame] | 1364 | self.filename, "bad %s value '%s' for key '%s' in name '%s'" % |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1365 | (kinfo["type"], d[k], k, name)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1366 | |
| 1367 | return d |
| 1368 | |
| 1369 | |
| 1370 | class Platform: |
| 1371 | """Class representing metadata for a particular platform |
| 1372 | |
Anas Nashif | c740608 | 2015-12-13 15:00:31 -0500 | [diff] [blame] | 1373 | Maps directly to BOARD when building""" |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 1374 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1375 | platform_schema = scl.yaml_load(os.path.join(ZEPHYR_BASE, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1376 | "scripts", "sanity_chk", "platform-schema.yaml")) |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 1377 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1378 | def __init__(self): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1379 | """Constructor. |
| 1380 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1381 | """ |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1382 | |
| 1383 | self.name = "" |
| 1384 | self.sanitycheck = True |
| 1385 | # if no RAM size is specified by the board, take a default of 128K |
| 1386 | self.ram = 128 |
| 1387 | |
| 1388 | self.ignore_tags = [] |
| 1389 | self.default = False |
| 1390 | # if no flash size is specified by the board, take a default of 512K |
| 1391 | self.flash = 512 |
| 1392 | self.supported = set() |
| 1393 | |
| 1394 | self.arch = "" |
| 1395 | self.type = "na" |
| 1396 | self.simulation = "na" |
| 1397 | self.supported_toolchains = [] |
| 1398 | self.env = [] |
| 1399 | self.env_satisfied = True |
| 1400 | self.filter_data = dict() |
| 1401 | |
| 1402 | def load(self, platform_file): |
| 1403 | scp = SanityConfigParser(platform_file, self.platform_schema) |
| 1404 | scp.load() |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1405 | data = scp.data |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1406 | |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1407 | self.name = data['identifier'] |
Anas Nashif | f3d48e1 | 2018-07-24 08:14:42 -0500 | [diff] [blame] | 1408 | self.sanitycheck = data.get("sanitycheck", True) |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1409 | # 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] | 1410 | self.ram = data.get("ram", 128) |
| 1411 | testing = data.get("testing", {}) |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1412 | self.ignore_tags = testing.get("ignore_tags", []) |
| 1413 | self.default = testing.get("default", False) |
| 1414 | # 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] | 1415 | self.flash = data.get("flash", 512) |
Anas Nashif | 9527693 | 2017-07-31 08:47:41 -0400 | [diff] [blame] | 1416 | self.supported = set() |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1417 | for supp_feature in data.get("supported", []): |
Anas Nashif | 9527693 | 2017-07-31 08:47:41 -0400 | [diff] [blame] | 1418 | for item in supp_feature.split(":"): |
| 1419 | self.supported.add(item) |
| 1420 | |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1421 | self.arch = data['arch'] |
Anas Nashif | cc16422 | 2017-12-26 11:02:46 -0500 | [diff] [blame] | 1422 | self.type = data.get('type', "na") |
Anas Nashif | 8acdbd7 | 2018-01-04 14:15:22 -0500 | [diff] [blame] | 1423 | self.simulation = data.get('simulation', "na") |
Anas Nashif | 255625b | 2017-12-05 15:08:26 -0500 | [diff] [blame] | 1424 | self.supported_toolchains = data.get("toolchain", []) |
Anas Nashif | 924a4e7 | 2018-10-18 12:25:55 -0400 | [diff] [blame] | 1425 | self.env = data.get("env", []) |
| 1426 | self.env_satisfied = True |
| 1427 | for env in self.env: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1428 | if not os.environ.get(env, None): |
Anas Nashif | 924a4e7 | 2018-10-18 12:25:55 -0400 | [diff] [blame] | 1429 | self.env_satisfied = False |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1430 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1431 | def __repr__(self): |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1432 | return "<%s on %s>" % (self.name, self.arch) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1433 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 1434 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1435 | class TestCase(object): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1436 | """Class representing a test application |
| 1437 | """ |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1438 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1439 | def __init__(self): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1440 | """TestCase constructor. |
| 1441 | |
Anas Nashif | 877d3ca | 2017-12-05 17:39:29 -0500 | [diff] [blame] | 1442 | 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] | 1443 | Multiple TestCase instances may be generated from a single testcase.yaml, |
Anas Nashif | 877d3ca | 2017-12-05 17:39:29 -0500 | [diff] [blame] | 1444 | each one corresponds to an entry within that file. |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1445 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1446 | 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] | 1447 | a testcase.yaml can define multiple tests, the canonical name for |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1448 | the test case is <workdir>/<name>. |
| 1449 | |
Marc Herbert | 1c8632c | 2019-04-15 17:58:45 -0700 | [diff] [blame] | 1450 | @param testcase_root os.path.abspath() of one of the --testcase-root |
| 1451 | @param workdir Sub-directory of testcase_root where the |
| 1452 | .yaml test configuration file was found |
Anas Nashif | 877d3ca | 2017-12-05 17:39:29 -0500 | [diff] [blame] | 1453 | @param name Name of this test case, corresponding to the entry name |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1454 | in the test case configuration file. For many test cases that just |
| 1455 | define one test, can be anything and is usually "test". This is |
| 1456 | really only used to distinguish between different cases when |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1457 | the testcase.yaml defines multiple tests |
Anas Nashif | 877d3ca | 2017-12-05 17:39:29 -0500 | [diff] [blame] | 1458 | @param tc_dict Dictionary with test values for this test case |
Anas Nashif | a792a3d | 2017-04-04 18:47:49 -0400 | [diff] [blame] | 1459 | from the testcase.yaml file |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1460 | """ |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 1461 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1462 | self.id = "" |
| 1463 | self.source_dir = "" |
| 1464 | self.yamlfile = "" |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1465 | self.cases = [] |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1466 | self.name = "" |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 1467 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1468 | self.type = None |
| 1469 | self.tags = None |
| 1470 | self.extra_args = None |
| 1471 | self.extra_configs = None |
| 1472 | self.arch_whitelist = None |
| 1473 | self.arch_exclude = None |
| 1474 | self.skip = None |
| 1475 | self.platform_exclude = None |
| 1476 | self.platform_whitelist = None |
| 1477 | self.toolchain_exclude = None |
| 1478 | self.toolchain_whitelist = None |
| 1479 | self.tc_filter = None |
| 1480 | self.timeout = 60 |
| 1481 | self.harness = "" |
| 1482 | self.harness_config = {} |
| 1483 | self.build_only = True |
| 1484 | self.build_on_all = False |
| 1485 | self.slow = False |
| 1486 | self.min_ram = None |
| 1487 | self.depends_on = None |
| 1488 | self.min_flash = None |
| 1489 | self.extra_sections = None |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1490 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1491 | @staticmethod |
| 1492 | def get_unique(testcase_root, workdir, name): |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 1493 | |
Marc Herbert | 1c8632c | 2019-04-15 17:58:45 -0700 | [diff] [blame] | 1494 | canonical_testcase_root = os.path.realpath(testcase_root) |
Tyler Hall | bb35925 | 2019-06-19 02:11:35 -0400 | [diff] [blame] | 1495 | if Path(canonical_zephyr_base) in Path(canonical_testcase_root).parents: |
Marc Herbert | 1c8632c | 2019-04-15 17:58:45 -0700 | [diff] [blame] | 1496 | # This is in ZEPHYR_BASE, so include path in name for uniqueness |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 1497 | # FIXME: We should not depend on path of test for unique names. |
Marc Herbert | 1c8632c | 2019-04-15 17:58:45 -0700 | [diff] [blame] | 1498 | relative_tc_root = os.path.relpath(canonical_testcase_root, |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 1499 | start=canonical_zephyr_base) |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 1500 | else: |
Marc Herbert | 1c8632c | 2019-04-15 17:58:45 -0700 | [diff] [blame] | 1501 | relative_tc_root = "" |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 1502 | |
Marc Herbert | 1c8632c | 2019-04-15 17:58:45 -0700 | [diff] [blame] | 1503 | # workdir can be "." |
| 1504 | unique = os.path.normpath(os.path.join(relative_tc_root, workdir, name)) |
Anas Nashif | f18ad9d | 2018-11-20 09:03:17 -0500 | [diff] [blame] | 1505 | return unique |
| 1506 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1507 | @staticmethod |
| 1508 | def scan_file(inf_name): |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1509 | suite_regex = re.compile( |
Inaky Perez-Gonzalez | 75e2d90 | 2018-04-26 00:17:01 -0700 | [diff] [blame] | 1510 | # do not match until end-of-line, otherwise we won't allow |
| 1511 | # stc_regex below to catch the ones that are declared in the same |
| 1512 | # line--as we only search starting the end of this match |
| 1513 | 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] | 1514 | re.MULTILINE) |
| 1515 | stc_regex = re.compile( |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1516 | br"^\s*" # empy space at the beginning is ok |
Inaky Perez-Gonzalez | 75e2d90 | 2018-04-26 00:17:01 -0700 | [diff] [blame] | 1517 | # catch the case where it is declared in the same sentence, e.g: |
| 1518 | # |
| 1519 | # ztest_test_suite(mutex_complex, ztest_user_unit_test(TESTNAME)); |
| 1520 | br"(?:ztest_test_suite\([a-zA-Z0-9_]+,\s*)?" |
| 1521 | # Catch ztest[_user]_unit_test-[_setup_teardown](TESTNAME) |
Anas Nashif | 9091a01 | 2019-11-24 09:22:22 -0500 | [diff] [blame] | 1522 | br"ztest_(?:1cpu_)?(?:user_)?unit_test(?:_setup_teardown)?" |
Inaky Perez-Gonzalez | 75e2d90 | 2018-04-26 00:17:01 -0700 | [diff] [blame] | 1523 | # Consume the argument that becomes the extra testcse |
| 1524 | br"\(\s*" |
| 1525 | br"(?P<stc_name>[a-zA-Z0-9_]+)" |
| 1526 | # _setup_teardown() variant has two extra arguments that we ignore |
| 1527 | br"(?:\s*,\s*[a-zA-Z0-9_]+\s*,\s*[a-zA-Z0-9_]+)?" |
| 1528 | br"\s*\)", |
| 1529 | # We don't check how it finishes; we don't care |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1530 | re.MULTILINE) |
| 1531 | suite_run_regex = re.compile( |
| 1532 | br"^\s*ztest_run_test_suite\((?P<suite_name>[a-zA-Z0-9_]+)\)", |
| 1533 | re.MULTILINE) |
| 1534 | achtung_regex = re.compile( |
| 1535 | br"(#ifdef|#endif)", |
| 1536 | re.MULTILINE) |
| 1537 | warnings = None |
| 1538 | |
| 1539 | with open(inf_name) as inf: |
Anas Nashif | 19d67e4 | 2019-11-21 11:33:12 -0500 | [diff] [blame] | 1540 | if os.name == 'nt': |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1541 | mmap_args = {'fileno': inf.fileno(), 'length': 0, 'access': mmap.ACCESS_READ} |
Anas Nashif | 19d67e4 | 2019-11-21 11:33:12 -0500 | [diff] [blame] | 1542 | else: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1543 | mmap_args = {'fileno': inf.fileno(), 'length': 0, 'flags': mmap.MAP_PRIVATE, 'prot': mmap.PROT_READ, |
| 1544 | 'offset': 0} |
Anas Nashif | 19d67e4 | 2019-11-21 11:33:12 -0500 | [diff] [blame] | 1545 | |
| 1546 | with contextlib.closing(mmap.mmap(**mmap_args)) as main_c: |
Ulf Magnusson | 5c2e814 | 2019-10-29 11:50:26 +0100 | [diff] [blame] | 1547 | # contextlib makes pylint think main_c isn't subscriptable |
| 1548 | # pylint: disable=unsubscriptable-object |
| 1549 | |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1550 | suite_regex_match = suite_regex.search(main_c) |
| 1551 | if not suite_regex_match: |
| 1552 | # can't find ztest_test_suite, maybe a client, because |
| 1553 | # it includes ztest.h |
| 1554 | return None, None |
| 1555 | |
| 1556 | suite_run_match = suite_run_regex.search(main_c) |
| 1557 | if not suite_run_match: |
| 1558 | raise ValueError("can't find ztest_run_test_suite") |
| 1559 | |
| 1560 | achtung_matches = re.findall( |
| 1561 | achtung_regex, |
| 1562 | main_c[suite_regex_match.end():suite_run_match.start()]) |
| 1563 | if achtung_matches: |
| 1564 | warnings = "found invalid %s in ztest_test_suite()" \ |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1565 | % ", ".join({match.decode() for match in achtung_matches}) |
Inaky Perez-Gonzalez | 75e2d90 | 2018-04-26 00:17:01 -0700 | [diff] [blame] | 1566 | _matches = re.findall( |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1567 | stc_regex, |
| 1568 | main_c[suite_regex_match.end():suite_run_match.start()]) |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1569 | matches = [match.decode().replace("test_", "") for match in _matches] |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1570 | return matches, warnings |
| 1571 | |
| 1572 | def scan_path(self, path): |
| 1573 | subcases = [] |
| 1574 | for filename in glob.glob(os.path.join(path, "src", "*.c")): |
| 1575 | try: |
| 1576 | _subcases, warnings = self.scan_file(filename) |
| 1577 | if warnings: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 1578 | logger.error("%s: %s" % (filename, warnings)) |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1579 | if _subcases: |
| 1580 | subcases += _subcases |
| 1581 | except ValueError as e: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 1582 | logger.error("%s: can't find: %s" % (filename, e)) |
Anas Nashif | 434995c | 2019-12-01 13:55:11 -0500 | [diff] [blame] | 1583 | for filename in glob.glob(os.path.join(path, "*.c")): |
| 1584 | try: |
| 1585 | _subcases, warnings = self.scan_file(filename) |
| 1586 | if warnings: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 1587 | logger.error("%s: %s" % (filename, warnings)) |
Anas Nashif | 434995c | 2019-12-01 13:55:11 -0500 | [diff] [blame] | 1588 | if _subcases: |
| 1589 | subcases += _subcases |
| 1590 | except ValueError as e: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 1591 | logger.error("%s: can't find: %s" % (filename, e)) |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1592 | return subcases |
| 1593 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1594 | def parse_subcases(self, test_path): |
Anas Nashif | 9091a01 | 2019-11-24 09:22:22 -0500 | [diff] [blame] | 1595 | results = self.scan_path(test_path) |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1596 | for sub in results: |
Inaky Perez-Gonzalez | 75e2d90 | 2018-04-26 00:17:01 -0700 | [diff] [blame] | 1597 | name = "{}.{}".format(self.id, sub) |
Anas Nashif | aae71d7 | 2018-04-21 22:26:48 -0500 | [diff] [blame] | 1598 | self.cases.append(name) |
| 1599 | |
Anas Nashif | f16e92c | 2019-03-31 16:58:12 -0400 | [diff] [blame] | 1600 | if not results: |
| 1601 | self.cases.append(self.id) |
| 1602 | |
Anas Nashif | 75547e2 | 2018-02-24 08:32:14 -0600 | [diff] [blame] | 1603 | def __str__(self): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1604 | return self.name |
| 1605 | |
| 1606 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1607 | class TestInstance: |
| 1608 | """Class representing the execution of a particular TestCase on a platform |
| 1609 | |
| 1610 | @param test The TestCase object we want to build/execute |
| 1611 | @param platform Platform object that we want to build and run against |
| 1612 | @param base_outdir Base directory for all test results. The actual |
| 1613 | out directory used is <outdir>/<platform>/<test case name> |
| 1614 | """ |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 1615 | |
Anas Nashif | 9e7a2cd | 2019-12-05 13:07:27 -0500 | [diff] [blame] | 1616 | def __init__(self, testcase, platform, outdir): |
Anas Nashif | 7dd19ea | 2018-11-14 08:46:49 -0500 | [diff] [blame] | 1617 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1618 | self.testcase = testcase |
| 1619 | self.platform = platform |
| 1620 | |
| 1621 | self.status = None |
| 1622 | self.reason = "N/A" |
| 1623 | self.metrics = dict() |
| 1624 | self.handler = None |
Anas Nashif | 9e7a2cd | 2019-12-05 13:07:27 -0500 | [diff] [blame] | 1625 | self.outdir = outdir |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1626 | |
| 1627 | self.name = os.path.join(platform.name, testcase.name) |
Anas Nashif | 9e7a2cd | 2019-12-05 13:07:27 -0500 | [diff] [blame] | 1628 | self.build_dir = os.path.join(outdir, platform.name, testcase.name) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1629 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1630 | self.build_only = True |
| 1631 | self.run = False |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1632 | |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 1633 | self.results = {} |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1634 | |
Marc Herbert | 0f7255c | 2019-04-05 14:14:21 -0700 | [diff] [blame] | 1635 | def __lt__(self, other): |
| 1636 | return self.name < other.name |
| 1637 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1638 | def check_build_or_run(self, build_only=False, enable_slow=False, device_testing=False, fixture=[]): |
| 1639 | |
Anas Nashif | 19d67e4 | 2019-11-21 11:33:12 -0500 | [diff] [blame] | 1640 | # right now we only support building on windows. running is still work |
| 1641 | # in progress. |
Anas Nashif | 19d67e4 | 2019-11-21 11:33:12 -0500 | [diff] [blame] | 1642 | if os.name == 'nt': |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1643 | self.build_only = True |
| 1644 | self.run = False |
| 1645 | return |
Anas Nashif | 7dd19ea | 2018-11-14 08:46:49 -0500 | [diff] [blame] | 1646 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1647 | _build_only = True |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1648 | |
| 1649 | # we asked for build-only on the command line |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1650 | if build_only or self.testcase.build_only: |
| 1651 | self.build_only = True |
| 1652 | self.run = False |
| 1653 | return |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1654 | |
| 1655 | # Do not run slow tests: |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1656 | skip_slow = self.testcase.slow and not enable_slow |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1657 | if skip_slow: |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1658 | self.build_only = True |
| 1659 | self.run = False |
| 1660 | return |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1661 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1662 | runnable = bool(self.testcase.type == "unit" or \ |
| 1663 | self.platform.type == "native" or \ |
| 1664 | self.platform.simulation in ["nsim", "renode", "qemu"] or \ |
| 1665 | device_testing) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1666 | |
| 1667 | if self.platform.simulation == "nsim": |
| 1668 | if not find_executable("nsimdrv"): |
| 1669 | runnable = False |
| 1670 | |
| 1671 | if self.platform.simulation == "renode": |
| 1672 | if not find_executable("renode"): |
| 1673 | runnable = False |
| 1674 | |
| 1675 | # console harness allows us to run the test and capture data. |
| 1676 | if self.testcase.harness == 'console': |
| 1677 | |
| 1678 | # if we have a fixture that is also being supplied on the |
| 1679 | # command-line, then we need to run the test, not just build it. |
| 1680 | if "fixture" in self.testcase.harness_config: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1681 | fixture_cfg = self.testcase.harness_config['fixture'] |
| 1682 | if fixture_cfg in fixture: |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1683 | _build_only = False |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1684 | else: |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1685 | _build_only = True |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1686 | else: |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1687 | _build_only = False |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1688 | elif self.testcase.harness: |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1689 | _build_only = True |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1690 | else: |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1691 | _build_only = False |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1692 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1693 | self.build_only = not (not _build_only and runnable) |
| 1694 | self.run = not self.build_only |
| 1695 | return |
Anas Nashif | 7dd19ea | 2018-11-14 08:46:49 -0500 | [diff] [blame] | 1696 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1697 | def create_overlay(self, platform, enable_asan=False, enable_coverage=False, coverage_platform=[]): |
Marc Herbert | c7633de | 2019-07-06 15:52:31 -0700 | [diff] [blame] | 1698 | # Create this in a "sanitycheck/" subdirectory otherwise this |
| 1699 | # will pass this overlay to kconfig.py *twice* and kconfig.cmake |
| 1700 | # will silently give that second time precedence over any |
| 1701 | # --extra-args=CONFIG_* |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1702 | subdir = os.path.join(self.build_dir, "sanitycheck") |
Marc Herbert | c7633de | 2019-07-06 15:52:31 -0700 | [diff] [blame] | 1703 | os.makedirs(subdir, exist_ok=True) |
| 1704 | file = os.path.join(subdir, "testcase_extra.conf") |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1705 | |
Anas Nashif | f4d8ecc | 2019-03-02 15:43:23 -0500 | [diff] [blame] | 1706 | with open(file, "w") as f: |
| 1707 | content = "" |
Anas Nashif | 3cbffef | 2018-11-07 23:50:54 -0500 | [diff] [blame] | 1708 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1709 | if self.testcase.extra_configs: |
| 1710 | content = "\n".join(self.testcase.extra_configs) |
Anas Nashif | 3cbffef | 2018-11-07 23:50:54 -0500 | [diff] [blame] | 1711 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1712 | if enable_coverage: |
| 1713 | if platform.name in coverage_platform: |
Anas Nashif | f4d8ecc | 2019-03-02 15:43:23 -0500 | [diff] [blame] | 1714 | content = content + "\nCONFIG_COVERAGE=y" |
| 1715 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1716 | if enable_asan: |
Jan Van Winkel | 21212f3 | 2019-09-12 00:03:35 +0200 | [diff] [blame] | 1717 | if platform.type == "native": |
| 1718 | content = content + "\nCONFIG_ASAN=y" |
| 1719 | |
Anas Nashif | f4d8ecc | 2019-03-02 15:43:23 -0500 | [diff] [blame] | 1720 | f.write(content) |
Anas Nashif | fa695d2 | 2017-10-04 16:14:27 -0400 | [diff] [blame] | 1721 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1722 | def calculate_sizes(self): |
| 1723 | """Get the RAM/ROM sizes of a test case. |
| 1724 | |
| 1725 | This can only be run after the instance has been executed by |
| 1726 | MakeGenerator, otherwise there won't be any binaries to measure. |
| 1727 | |
| 1728 | @return A SizeCalculator object |
| 1729 | """ |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1730 | fns = glob.glob(os.path.join(self.build_dir, "zephyr", "*.elf")) |
| 1731 | fns.extend(glob.glob(os.path.join(self.build_dir, "zephyr", "*.exe"))) |
Anas Nashif | f8dcad4 | 2016-10-27 18:10:08 -0400 | [diff] [blame] | 1732 | fns = [x for x in fns if not x.endswith('_prebuilt.elf')] |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1733 | if len(fns) != 1: |
Andrew Boie | 5d4eb78 | 2015-10-02 10:04:56 -0700 | [diff] [blame] | 1734 | raise BuildError("Missing/multiple output ELF binary") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1735 | |
| 1736 | return SizeCalculator(fns[0], self.testcase.extra_sections) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1737 | |
| 1738 | def __repr__(self): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1739 | return "<TestCase %s on %s>" % (self.testcase.name, self.platform.name) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 1740 | |
| 1741 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1742 | class CMake(): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1743 | config_re = re.compile('(CONFIG_[A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$') |
| 1744 | dt_re = re.compile('([A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$') |
| 1745 | |
| 1746 | def __init__(self, testcase, platform, source_dir, build_dir): |
| 1747 | |
| 1748 | self.cwd = None |
| 1749 | self.capture_output = True |
| 1750 | |
| 1751 | self.defconfig = {} |
| 1752 | self.cmake_cache = {} |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1753 | |
| 1754 | self.instance = None |
| 1755 | self.testcase = testcase |
| 1756 | self.platform = platform |
| 1757 | self.source_dir = source_dir |
| 1758 | self.build_dir = build_dir |
| 1759 | self.log = "build.log" |
| 1760 | |
| 1761 | def parse_generated(self): |
| 1762 | self.defconfig = {} |
| 1763 | return {} |
| 1764 | |
| 1765 | def run_build(self, args=[]): |
| 1766 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 1767 | logger.debug("Building %s for %s" % (self.source_dir, self.platform.name)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1768 | |
| 1769 | cmake_args = [] |
| 1770 | cmake_args.extend(args) |
| 1771 | cmake = shutil.which('cmake') |
| 1772 | cmd = [cmake] + cmake_args |
| 1773 | kwargs = dict() |
| 1774 | |
| 1775 | if self.capture_output: |
| 1776 | kwargs['stdout'] = subprocess.PIPE |
| 1777 | # CMake sends the output of message() to stderr unless it's STATUS |
| 1778 | kwargs['stderr'] = subprocess.STDOUT |
| 1779 | |
| 1780 | if self.cwd: |
| 1781 | kwargs['cwd'] = self.cwd |
| 1782 | |
| 1783 | p = subprocess.Popen(cmd, **kwargs) |
| 1784 | out, _ = p.communicate() |
| 1785 | |
| 1786 | results = {} |
| 1787 | if p.returncode == 0: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1788 | msg = "Finished building %s for %s" % (self.source_dir, self.platform.name) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1789 | |
| 1790 | self.instance.status = "passed" |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1791 | results = {'msg': msg, "returncode": p.returncode, "instance": self.instance} |
| 1792 | |
| 1793 | if out: |
| 1794 | log_msg = out.decode(sys.getdefaultencoding()) |
| 1795 | with open(os.path.join(self.build_dir, self.log), "a") as log: |
| 1796 | log.write(log_msg) |
| 1797 | |
| 1798 | else: |
| 1799 | return None |
| 1800 | else: |
| 1801 | # A real error occurred, raise an exception |
| 1802 | if out: |
| 1803 | log_msg = out.decode(sys.getdefaultencoding()) |
| 1804 | with open(os.path.join(self.build_dir, self.log), "a") as log: |
| 1805 | log.write(log_msg) |
| 1806 | |
| 1807 | overflow_flash = "region `FLASH' overflowed by" |
| 1808 | overflow_ram = "region `RAM' overflowed by" |
| 1809 | |
| 1810 | if log_msg: |
| 1811 | if log_msg.find(overflow_flash) > 0 or log_msg.find(overflow_ram) > 0: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 1812 | logger.debug("RAM/ROM Overflow") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1813 | self.instance.status = "skipped" |
| 1814 | self.instance.reason = "overflow" |
| 1815 | else: |
| 1816 | self.instance.status = "failed" |
| 1817 | self.instance.reason = "Build failure" |
| 1818 | |
| 1819 | results = { |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1820 | "returncode": p.returncode, |
| 1821 | "instance": self.instance, |
| 1822 | } |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1823 | |
| 1824 | return results |
| 1825 | |
| 1826 | def run_cmake(self, args=[]): |
| 1827 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 1828 | ldflags = "-Wl,--fatal-warnings" |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1829 | logger.debug("Running cmake on %s for %s" % (self.source_dir, self.platform.name)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1830 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 1831 | # fixme: add additional cflags based on options |
Anas Nashif | a5984ab | 2019-10-22 07:36:24 -0700 | [diff] [blame] | 1832 | cmake_args = [ |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1833 | '-B{}'.format(self.build_dir), |
| 1834 | '-S{}'.format(self.source_dir), |
| 1835 | '-DEXTRA_CFLAGS="-Werror ', |
| 1836 | '-DEXTRA_AFLAGS=-Wa,--fatal-warnings', |
| 1837 | '-DEXTRA_LDFLAGS="{}'.format(ldflags), |
| 1838 | '-G{}'.format(get_generator()[1]) |
| 1839 | ] |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1840 | |
Anas Nashif | d91f993 | 2019-11-30 10:15:23 -0500 | [diff] [blame] | 1841 | if options.cmake_only: |
| 1842 | cmake_args.append("-DCMAKE_EXPORT_COMPILE_COMMANDS=1") |
| 1843 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1844 | args = ["-D{}".format(a.replace('"', '')) for a in args] |
| 1845 | cmake_args.extend(args) |
| 1846 | |
| 1847 | cmake_opts = ['-DBOARD={}'.format(self.platform.name)] |
| 1848 | cmake_args.extend(cmake_opts) |
| 1849 | |
| 1850 | cmake = shutil.which('cmake') |
| 1851 | cmd = [cmake] + cmake_args |
| 1852 | kwargs = dict() |
| 1853 | |
| 1854 | if self.capture_output: |
| 1855 | kwargs['stdout'] = subprocess.PIPE |
| 1856 | # CMake sends the output of message() to stderr unless it's STATUS |
| 1857 | kwargs['stderr'] = subprocess.STDOUT |
| 1858 | |
| 1859 | if self.cwd: |
| 1860 | kwargs['cwd'] = self.cwd |
| 1861 | |
| 1862 | p = subprocess.Popen(cmd, **kwargs) |
| 1863 | out, _ = p.communicate() |
| 1864 | |
| 1865 | if p.returncode == 0: |
| 1866 | filter_results = self.parse_generated() |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1867 | msg = "Finished building %s for %s" % (self.source_dir, self.platform.name) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1868 | |
| 1869 | results = {'msg': msg, 'filter': filter_results} |
| 1870 | |
| 1871 | else: |
| 1872 | self.instance.status = "failed" |
| 1873 | self.instance.reason = "Cmake build failure" |
| 1874 | results = {"returncode": p.returncode} |
| 1875 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1876 | if out: |
| 1877 | with open(os.path.join(self.build_dir, self.log), "a") as log: |
| 1878 | log_msg = out.decode(sys.getdefaultencoding()) |
| 1879 | log.write(log_msg) |
| 1880 | |
| 1881 | return results |
| 1882 | |
| 1883 | |
| 1884 | class FilterBuilder(CMake): |
| 1885 | |
| 1886 | def __init__(self, testcase, platform, source_dir, build_dir): |
| 1887 | super().__init__(testcase, platform, source_dir, build_dir) |
| 1888 | |
| 1889 | self.log = "config-sanitycheck.log" |
| 1890 | |
| 1891 | def parse_generated(self): |
| 1892 | |
| 1893 | if self.platform.name == "unit_testing": |
| 1894 | return {} |
| 1895 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1896 | cmake_cache_path = os.path.join(self.build_dir, "CMakeCache.txt") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1897 | defconfig_path = os.path.join(self.build_dir, "zephyr", ".config") |
| 1898 | |
| 1899 | with open(defconfig_path, "r") as fp: |
| 1900 | defconfig = {} |
| 1901 | for line in fp.readlines(): |
| 1902 | m = self.config_re.match(line) |
| 1903 | if not m: |
| 1904 | if line.strip() and not line.startswith("#"): |
| 1905 | sys.stderr.write("Unrecognized line %s\n" % line) |
| 1906 | continue |
| 1907 | defconfig[m.group(1)] = m.group(2).strip() |
| 1908 | |
| 1909 | self.defconfig = defconfig |
| 1910 | |
| 1911 | cmake_conf = {} |
| 1912 | try: |
| 1913 | cache = CMakeCache.from_file(cmake_cache_path) |
| 1914 | except FileNotFoundError: |
| 1915 | cache = {} |
| 1916 | |
| 1917 | for k in iter(cache): |
| 1918 | cmake_conf[k.name] = k.value |
| 1919 | |
| 1920 | self.cmake_cache = cmake_conf |
| 1921 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1922 | filter_data = { |
| 1923 | "ARCH": self.platform.arch, |
| 1924 | "PLATFORM": self.platform.name |
| 1925 | } |
| 1926 | filter_data.update(os.environ) |
| 1927 | filter_data.update(self.defconfig) |
| 1928 | filter_data.update(self.cmake_cache) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1929 | |
Anas Nashif | 556f3cb | 2019-11-05 15:36:15 -0800 | [diff] [blame] | 1930 | dts_path = os.path.join(self.build_dir, "zephyr", self.platform.name + ".dts.pre.tmp") |
Kumar Gala | ae88e44 | 2019-11-06 04:55:24 -0600 | [diff] [blame] | 1931 | if self.testcase and self.testcase.tc_filter: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1932 | try: |
Kumar Gala | ae88e44 | 2019-11-06 04:55:24 -0600 | [diff] [blame] | 1933 | if os.path.exists(dts_path): |
| 1934 | edt = edtlib.EDT(dts_path, [os.path.join(ZEPHYR_BASE, "dts", "bindings")]) |
| 1935 | else: |
| 1936 | edt = None |
Kumar Gala | 7733b94 | 2019-09-12 17:08:43 -0500 | [diff] [blame] | 1937 | res = expr_parser.parse(self.testcase.tc_filter, filter_data, edt) |
| 1938 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1939 | except (ValueError, SyntaxError) as se: |
| 1940 | sys.stderr.write( |
| 1941 | "Failed processing %s\n" % self.testcase.yamlfile) |
| 1942 | raise se |
| 1943 | |
| 1944 | if not res: |
| 1945 | return {os.path.join(self.platform.name, self.testcase.name): True} |
| 1946 | else: |
| 1947 | return {os.path.join(self.platform.name, self.testcase.name): False} |
| 1948 | else: |
| 1949 | self.platform.filter_data = filter_data |
| 1950 | return filter_data |
| 1951 | |
| 1952 | |
| 1953 | class ProjectBuilder(FilterBuilder): |
| 1954 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1955 | def __init__(self, suite, instance, **kwargs): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 1956 | super().__init__(instance.testcase, instance.platform, instance.testcase.source_dir, instance.build_dir) |
| 1957 | |
| 1958 | self.log = "build.log" |
| 1959 | self.instance = instance |
| 1960 | self.suite = suite |
| 1961 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 1962 | self.lsan = kwargs.get('lsan', False) |
| 1963 | self.asan = kwargs.get('asan', False) |
| 1964 | self.valgrind = kwargs.get('valgrind', False) |
| 1965 | self.extra_args = kwargs.get('extra_args', []) |
| 1966 | self.device_testing = kwargs.get('device_testing', False) |
| 1967 | self.cmake_only = kwargs.get('cmake_only', False) |
| 1968 | self.coverage = kwargs.get('coverage', False) |
Anas Nashif | e9eb009 | 2019-12-10 16:31:22 -0500 | [diff] [blame] | 1969 | self.inline_logs = kwargs.get('inline_logs', False) |
| 1970 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 1971 | @staticmethod |
| 1972 | def log_info(filename, inline_logs): |
Anas Nashif | e9eb009 | 2019-12-10 16:31:22 -0500 | [diff] [blame] | 1973 | filename = os.path.relpath(os.path.realpath(filename)) |
| 1974 | if inline_logs: |
| 1975 | logger.info("{:-^100}".format(filename)) |
| 1976 | |
| 1977 | try: |
| 1978 | with open(filename) as fp: |
| 1979 | data = fp.read() |
| 1980 | except Exception as e: |
| 1981 | data = "Unable to read log data (%s)\n" % (str(e)) |
| 1982 | |
| 1983 | logger.error(data) |
| 1984 | |
| 1985 | logger.info("{:-^100}".format(filename)) |
| 1986 | else: |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 1987 | logger.error("see: " + Fore.YELLOW + filename + Fore.RESET) |
Anas Nashif | e9eb009 | 2019-12-10 16:31:22 -0500 | [diff] [blame] | 1988 | |
| 1989 | def log_info_file(self, inline_logs): |
| 1990 | build_dir = self.instance.build_dir |
| 1991 | h_log = "{}/handler.log".format(build_dir) |
| 1992 | b_log = "{}/build.log".format(build_dir) |
| 1993 | v_log = "{}/valgrind.log".format(build_dir) |
| 1994 | d_log = "{}/device.log".format(build_dir) |
| 1995 | |
| 1996 | if os.path.exists(v_log) and "Valgrind" in self.instance.reason: |
| 1997 | self.log_info("{}".format(v_log), inline_logs) |
Anas Nashif | 17d066b | 2019-12-17 14:37:16 -0500 | [diff] [blame] | 1998 | elif os.path.exists(d_log) and os.path.getsize(d_log) > 0: |
Anas Nashif | e9eb009 | 2019-12-10 16:31:22 -0500 | [diff] [blame] | 1999 | self.log_info("{}".format(d_log), inline_logs) |
Anas Nashif | 17d066b | 2019-12-17 14:37:16 -0500 | [diff] [blame] | 2000 | elif os.path.exists(h_log) and os.path.getsize(h_log) > 0: |
Anas Nashif | e9eb009 | 2019-12-10 16:31:22 -0500 | [diff] [blame] | 2001 | self.log_info("{}".format(h_log), inline_logs) |
| 2002 | else: |
| 2003 | self.log_info("{}".format(b_log), inline_logs) |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2004 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2005 | def setup_handler(self): |
| 2006 | |
| 2007 | instance = self.instance |
| 2008 | args = [] |
| 2009 | |
| 2010 | # FIXME: Needs simplification |
| 2011 | if instance.platform.simulation == "qemu": |
| 2012 | instance.handler = QEMUHandler(instance, "qemu") |
| 2013 | args.append("QEMU_PIPE=%s" % instance.handler.get_fifo()) |
| 2014 | instance.handler.call_make_run = True |
| 2015 | elif instance.testcase.type == "unit": |
| 2016 | instance.handler = BinaryHandler(instance, "unit") |
| 2017 | instance.handler.binary = os.path.join(instance.build_dir, "testbinary") |
| 2018 | elif instance.platform.type == "native": |
Anas Nashif | 6c0e170 | 2019-12-05 15:24:52 -0500 | [diff] [blame] | 2019 | handler = BinaryHandler(instance, "native") |
| 2020 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2021 | handler.asan = self.asan |
| 2022 | handler.valgrind = self.valgrind |
| 2023 | handler.lsan = self.lsan |
| 2024 | handler.coverage = self.coverage |
Anas Nashif | 6c0e170 | 2019-12-05 15:24:52 -0500 | [diff] [blame] | 2025 | |
| 2026 | handler.binary = os.path.join(instance.build_dir, "zephyr", "zephyr.exe") |
| 2027 | instance.handler = handler |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2028 | elif instance.platform.simulation == "nsim": |
| 2029 | if find_executable("nsimdrv"): |
| 2030 | instance.handler = BinaryHandler(instance, "nsim") |
| 2031 | instance.handler.call_make_run = True |
| 2032 | elif instance.platform.simulation == "renode": |
| 2033 | if find_executable("renode"): |
| 2034 | instance.handler = BinaryHandler(instance, "renode") |
| 2035 | instance.handler.pid_fn = os.path.join(instance.build_dir, "renode.pid") |
| 2036 | instance.handler.call_make_run = True |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2037 | elif self.device_testing: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2038 | instance.handler = DeviceHandler(instance, "device") |
| 2039 | |
| 2040 | if instance.handler: |
| 2041 | instance.handler.args = args |
| 2042 | |
| 2043 | def process(self, message): |
| 2044 | op = message.get('op') |
| 2045 | |
| 2046 | if not self.instance.handler: |
| 2047 | self.setup_handler() |
| 2048 | |
| 2049 | # The build process, call cmake and build with configured generator |
| 2050 | if op == "cmake": |
| 2051 | results = self.cmake() |
| 2052 | if self.instance.status == "failed": |
| 2053 | pipeline.put({"op": "report", "test": self.instance}) |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2054 | elif self.cmake_only: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2055 | pipeline.put({"op": "report", "test": self.instance}) |
| 2056 | else: |
| 2057 | if self.instance.name in results['filter'] and results['filter'][self.instance.name]: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2058 | logger.debug("filtering %s" % self.instance.name) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2059 | self.instance.status = "skipped" |
| 2060 | self.instance.reason = "filter" |
| 2061 | pipeline.put({"op": "report", "test": self.instance}) |
| 2062 | else: |
| 2063 | pipeline.put({"op": "build", "test": self.instance}) |
| 2064 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2065 | elif op == "build": |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2066 | logger.debug("build test: %s" % self.instance.name) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2067 | results = self.build() |
| 2068 | |
| 2069 | if results.get('returncode', 1) > 0: |
| 2070 | pipeline.put({"op": "report", "test": self.instance}) |
| 2071 | else: |
| 2072 | if self.instance.run: |
| 2073 | pipeline.put({"op": "run", "test": self.instance}) |
| 2074 | else: |
| 2075 | pipeline.put({"op": "report", "test": self.instance}) |
| 2076 | # Run the generated binary using one of the supported handlers |
| 2077 | elif op == "run": |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2078 | logger.debug("run test: %s" % self.instance.name) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2079 | self.run() |
| 2080 | self.instance.status, _ = self.instance.handler.get_state() |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2081 | pipeline.put({ |
| 2082 | "op": "report", |
| 2083 | "test": self.instance, |
| 2084 | "state": "executed", |
| 2085 | "status": self.instance.status, |
Stephanos Ioannidis | 9388900 | 2019-11-11 20:31:03 +0900 | [diff] [blame] | 2086 | "reason": self.instance.reason} |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2087 | ) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2088 | |
| 2089 | # Report results and output progress to screen |
| 2090 | elif op == "report": |
Anas Nashif | c1ea452 | 2019-10-11 07:32:45 -0700 | [diff] [blame] | 2091 | with report_lock: |
| 2092 | self.report_out() |
| 2093 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2094 | def report_out(self): |
| 2095 | total_tests_width = len(str(self.suite.total_tests)) |
| 2096 | self.suite.total_done += 1 |
| 2097 | instance = self.instance |
| 2098 | |
| 2099 | if instance.status in ["failed", "timeout"]: |
| 2100 | self.suite.total_failed += 1 |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2101 | if VERBOSE: |
| 2102 | status = Fore.RED + "FAILED " + Fore.RESET + instance.reason |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2103 | else: |
Anas Nashif | 67f9ecb | 2019-12-09 10:46:19 -0500 | [diff] [blame] | 2104 | print("") |
| 2105 | logger.error( |
| 2106 | "{:<25} {:<50} {}FAILED{}: {}".format( |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2107 | instance.platform.name, |
| 2108 | instance.testcase.name, |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2109 | Fore.RED, |
| 2110 | Fore.RESET, |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2111 | instance.reason)) |
Anas Nashif | c1ea452 | 2019-10-11 07:32:45 -0700 | [diff] [blame] | 2112 | if not VERBOSE: |
Anas Nashif | e9eb009 | 2019-12-10 16:31:22 -0500 | [diff] [blame] | 2113 | self.log_info_file(self.inline_logs) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2114 | elif instance.status == "skipped": |
| 2115 | self.suite.total_skipped += 1 |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2116 | status = Fore.YELLOW + "SKIPPED" + Fore.RESET |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2117 | else: |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2118 | status = Fore.GREEN + "PASSED" + Fore.RESET |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2119 | |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2120 | if VERBOSE: |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2121 | if self.cmake_only: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2122 | more_info = "cmake" |
| 2123 | elif instance.status == "skipped": |
| 2124 | more_info = instance.reason |
| 2125 | else: |
| 2126 | if instance.handler and instance.run: |
| 2127 | more_info = instance.handler.type_str |
| 2128 | htime = instance.handler.duration |
| 2129 | if htime: |
| 2130 | more_info += " {:.3f}s".format(htime) |
| 2131 | else: |
| 2132 | more_info = "build" |
| 2133 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2134 | logger.info("{:>{}}/{} {:<25} {:<50} {} ({})".format( |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2135 | self.suite.total_done, total_tests_width, self.suite.total_tests, instance.platform.name, |
| 2136 | instance.testcase.name, status, more_info)) |
| 2137 | |
| 2138 | if instance.status in ["failed", "timeout"]: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2139 | self.log_info_file(self.inline_logs) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2140 | else: |
Anas Nashif | 67f9ecb | 2019-12-09 10:46:19 -0500 | [diff] [blame] | 2141 | sys.stdout.write("\rINFO - Total complete: %s%4d/%4d%s %2d%% skipped: %s%4d%s, failed: %s%4d%s" % ( |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2142 | Fore.GREEN, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2143 | self.suite.total_done, |
| 2144 | self.suite.total_tests, |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2145 | Fore.RESET, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2146 | int((float(self.suite.total_done) / self.suite.total_tests) * 100), |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2147 | Fore.YELLOW if self.suite.total_skipped > 0 else Fore.RESET, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2148 | self.suite.total_skipped, |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2149 | Fore.RESET, |
| 2150 | Fore.RED if self.suite.total_failed > 0 else Fore.RESET, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2151 | self.suite.total_failed, |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2152 | Fore.RESET |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2153 | ) |
| 2154 | ) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2155 | sys.stdout.flush() |
| 2156 | |
| 2157 | def cmake(self): |
| 2158 | |
| 2159 | instance = self.instance |
| 2160 | args = self.testcase.extra_args[:] |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2161 | args += self.extra_args |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2162 | |
| 2163 | if instance.handler: |
| 2164 | args += instance.handler.args |
| 2165 | |
| 2166 | # merge overlay files into one variable |
| 2167 | overlays = "" |
| 2168 | idx = 0 |
| 2169 | for arg in args: |
| 2170 | match = re.search('OVERLAY_CONFIG="(.*)"', arg) |
| 2171 | if match: |
| 2172 | overlays += match.group(1) |
| 2173 | del args[idx] |
| 2174 | idx += 1 |
| 2175 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2176 | if (self.testcase.extra_configs or self.coverage or |
| 2177 | self.asan): |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2178 | args.append("OVERLAY_CONFIG=\"%s %s\"" % (overlays, |
| 2179 | os.path.join(instance.build_dir, |
| 2180 | "sanitycheck", "testcase_extra.conf"))) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2181 | |
| 2182 | results = self.run_cmake(args) |
| 2183 | return results |
| 2184 | |
| 2185 | def build(self): |
| 2186 | results = self.run_build(['--build', self.build_dir]) |
| 2187 | return results |
| 2188 | |
| 2189 | def run(self): |
| 2190 | |
| 2191 | instance = self.instance |
| 2192 | |
| 2193 | if instance.handler.type_str == "device": |
| 2194 | instance.handler.suite = self.suite |
| 2195 | |
| 2196 | instance.handler.handle() |
| 2197 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2198 | sys.stdout.flush() |
| 2199 | |
| 2200 | |
| 2201 | pipeline = queue.LifoQueue() |
| 2202 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 2203 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2204 | class BoundedExecutor(concurrent.futures.ThreadPoolExecutor): |
| 2205 | """BoundedExecutor behaves as a ThreadPoolExecutor which will block on |
| 2206 | calls to submit() once the limit given as "bound" work items are queued for |
| 2207 | execution. |
| 2208 | :param bound: Integer - the maximum number of items in the work queue |
| 2209 | :param max_workers: Integer - the size of the thread pool |
| 2210 | """ |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2211 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2212 | def __init__(self, bound, max_workers, **kwargs): |
| 2213 | super().__init__(max_workers) |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 2214 | # self.executor = ThreadPoolExecutor(max_workers=max_workers) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2215 | self.semaphore = BoundedSemaphore(bound + max_workers) |
| 2216 | |
| 2217 | def submit(self, fn, *args, **kwargs): |
| 2218 | self.semaphore.acquire() |
| 2219 | try: |
| 2220 | future = super().submit(fn, *args, **kwargs) |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 2221 | except Exception: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2222 | self.semaphore.release() |
| 2223 | raise |
| 2224 | else: |
| 2225 | future.add_done_callback(lambda x: self.semaphore.release()) |
| 2226 | return future |
| 2227 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2228 | |
| 2229 | class TestSuite: |
Andrew Boie | 60823c2 | 2017-02-10 09:43:07 -0800 | [diff] [blame] | 2230 | config_re = re.compile('(CONFIG_[A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$') |
Anas Nashif | 1c65b6b | 2018-12-02 19:12:21 -0500 | [diff] [blame] | 2231 | dt_re = re.compile('([A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$') |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2232 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2233 | tc_schema = scl.yaml_load( |
Oleg Zhurakivskyy | 4282208 | 2018-08-17 14:54:41 +0300 | [diff] [blame] | 2234 | os.path.join(ZEPHYR_BASE, |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2235 | "scripts", "sanity_chk", "testcase-schema.yaml")) |
Inaky Perez-Gonzalez | 662dde6 | 2017-07-24 10:24:35 -0700 | [diff] [blame] | 2236 | |
Anas Nashif | 37f9dc5 | 2018-02-23 08:53:46 -0600 | [diff] [blame] | 2237 | def __init__(self, board_root_list, testcase_roots, outdir): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2238 | |
| 2239 | self.roots = testcase_roots |
| 2240 | if not isinstance(board_root_list, list): |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 2241 | self.board_roots = [board_root_list] |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2242 | else: |
| 2243 | self.board_roots = board_root_list |
| 2244 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2245 | # Testsuite Options |
| 2246 | self.coverage_platform = [] |
| 2247 | self.build_only = False |
| 2248 | self.cmake_only = False |
| 2249 | self.enable_slow = False |
| 2250 | self.device_testing = False |
| 2251 | self.fixture = [] |
| 2252 | self.enable_coverage = False |
| 2253 | self.enable_lsan = False |
| 2254 | self.enable_asan = False |
| 2255 | self.enable_valgrind = False |
| 2256 | self.extra_args = [] |
Anas Nashif | e9eb009 | 2019-12-10 16:31:22 -0500 | [diff] [blame] | 2257 | self.inline_logs = False |
Anas Nashif | c5ee395 | 2019-12-10 16:38:45 -0500 | [diff] [blame] | 2258 | self.enable_sizes_report = False |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2259 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2260 | # Keep track of which test cases we've filtered out and why |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2261 | self.testcases = {} |
| 2262 | self.platforms = [] |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 2263 | self.selected_platforms = [] |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2264 | self.default_platforms = [] |
Andrew Boie | b391e66 | 2015-08-31 15:25:45 -0700 | [diff] [blame] | 2265 | self.outdir = os.path.abspath(outdir) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2266 | self.discards = None |
Kumar Gala | c84235e | 2018-04-10 13:32:51 -0500 | [diff] [blame] | 2267 | self.load_errors = 0 |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2268 | self.instances = dict() |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2269 | |
Anas Nashif | 11ee525 | 2019-12-04 12:59:10 -0500 | [diff] [blame] | 2270 | self.total_tests = 0 # number of test instances |
| 2271 | self.total_cases = 0 # number of test cases |
| 2272 | self.total_done = 0 # tests completed |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2273 | self.total_failed = 0 |
| 2274 | self.total_skipped = 0 |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2275 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2276 | self.total_platforms = 0 |
| 2277 | self.start_time = 0 |
| 2278 | self.duration = 0 |
| 2279 | self.warnings = 0 |
| 2280 | self.cv = threading.Condition() |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 2281 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2282 | # hardcoded for now |
| 2283 | self.connected_hardware = [] |
Andrew Boie | 3d34871 | 2016-04-08 11:52:13 -0700 | [diff] [blame] | 2284 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2285 | def config(self): |
| 2286 | logger.info("coverage platform: {}".format(self.coverage_platform)) |
| 2287 | |
Anas Nashif | f16ed8e | 2019-12-09 16:22:27 -0500 | [diff] [blame] | 2288 | # Debug Functions |
| 2289 | @staticmethod |
| 2290 | def info(what): |
| 2291 | sys.stdout.write(what + "\n") |
| 2292 | sys.stdout.flush() |
| 2293 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2294 | def update(self): |
| 2295 | self.total_tests = len(self.instances) |
| 2296 | self.total_cases = len(self.testcases) |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 2297 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2298 | def compare_metrics(self, filename): |
| 2299 | # name, datatype, lower results better |
| 2300 | interesting_metrics = [("ram_size", int, True), |
| 2301 | ("rom_size", int, True)] |
| 2302 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2303 | if not os.path.exists(filename): |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2304 | logger.info("Cannot compare metrics, %s not found" % filename) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2305 | return [] |
| 2306 | |
| 2307 | results = [] |
| 2308 | saved_metrics = {} |
| 2309 | with open(filename) as fp: |
| 2310 | cr = csv.DictReader(fp) |
| 2311 | for row in cr: |
| 2312 | d = {} |
| 2313 | for m, _, _ in interesting_metrics: |
| 2314 | d[m] = row[m] |
| 2315 | saved_metrics[(row["test"], row["platform"])] = d |
| 2316 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2317 | for instance in self.instances.values(): |
| 2318 | mkey = (instance.testcase.name, instance.platform.name) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2319 | if mkey not in saved_metrics: |
| 2320 | continue |
| 2321 | sm = saved_metrics[mkey] |
| 2322 | for metric, mtype, lower_better in interesting_metrics: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2323 | if metric not in instance.metrics: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2324 | continue |
| 2325 | if sm[metric] == "": |
| 2326 | continue |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2327 | delta = instance.metrics.get(metric, 0) - mtype(sm[metric]) |
Andrew Boie | ea7928f | 2015-08-14 14:27:38 -0700 | [diff] [blame] | 2328 | if delta == 0: |
| 2329 | continue |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2330 | results.append((instance, metric, instance.metrics.get(metric, 0), delta, |
Andrew Boie | ea7928f | 2015-08-14 14:27:38 -0700 | [diff] [blame] | 2331 | lower_better)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 2332 | return results |
| 2333 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2334 | def misc_reports(self, report, show_footprint, all_deltas, |
| 2335 | footprint_threshold, last_metrics): |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2336 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2337 | if not report: |
| 2338 | return |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2339 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2340 | deltas = self.compare_metrics(report) |
| 2341 | warnings = 0 |
| 2342 | if deltas and show_footprint: |
| 2343 | for i, metric, value, delta, lower_better in deltas: |
| 2344 | if not all_deltas and ((delta < 0 and lower_better) or |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2345 | (delta > 0 and not lower_better)): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2346 | continue |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2347 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2348 | percentage = (float(delta) / float(value - delta)) |
| 2349 | if not all_deltas and (percentage < |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2350 | (footprint_threshold / 100.0)): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2351 | continue |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2352 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2353 | logger.info("{:<25} {:<60} {}{}{}: {} {:<+4}, is now {:6} {:+.2%}".format( |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2354 | i.platform.name, i.testcase.name, Fore.YELLOW, |
| 2355 | "INFO" if all_deltas else "WARNING", Fore.RESET, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2356 | metric, delta, value, percentage)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2357 | warnings += 1 |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2358 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2359 | if warnings: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2360 | logger.warning("Deltas based on metrics from last %s" % |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2361 | ("release" if not last_metrics else "run")) |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 2362 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2363 | def summary(self, unrecognized_sections): |
| 2364 | failed = 0 |
| 2365 | for instance in self.instances.values(): |
| 2366 | if instance.status == "failed": |
| 2367 | failed += 1 |
| 2368 | elif instance.metrics.get("unrecognized") and not unrecognized_sections: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2369 | logger.error("%sFAILED%s: %s has unrecognized binary sections: %s" % |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2370 | (Fore.RED, Fore.RESET, instance.name, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2371 | str(instance.metrics.get("unrecognized", [])))) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2372 | failed += 1 |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2373 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2374 | if self.total_tests and self.total_tests != self.total_skipped: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2375 | pass_rate = (float(self.total_tests - self.total_failed - self.total_skipped) / float( |
| 2376 | self.total_tests - self.total_skipped)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2377 | else: |
| 2378 | pass_rate = 0 |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2379 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2380 | logger.info( |
| 2381 | "{}{} of {}{} tests passed ({:.2%}), {}{}{} failed, {} skipped with {}{}{} warnings in {:.2f} seconds".format( |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2382 | Fore.RED if failed else Fore.GREEN, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2383 | self.total_tests - self.total_failed - self.total_skipped, |
| 2384 | self.total_tests, |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2385 | Fore.RESET, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2386 | pass_rate, |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2387 | Fore.RED if self.total_failed else Fore.RESET, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2388 | self.total_failed, |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2389 | Fore.RESET, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2390 | self.total_skipped, |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2391 | Fore.YELLOW if self.warnings else Fore.RESET, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2392 | self.warnings, |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 2393 | Fore.RESET, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2394 | self.duration)) |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2395 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2396 | self.total_platforms = len(self.platforms) |
| 2397 | if self.platforms: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2398 | logger.info("In total {} test cases were executed on {} out of total {} platforms ({:02.2f}%)".format( |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2399 | self.total_cases, |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 2400 | len(self.selected_platforms), |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2401 | self.total_platforms, |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 2402 | (100 * len(self.selected_platforms) / len(self.platforms)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2403 | )) |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2404 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2405 | def save_reports(self, name, report_dir, no_update, release, only_failed): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2406 | if not self.instances: |
| 2407 | return |
Anas Nashif | 61e2163 | 2018-04-08 13:30:16 -0500 | [diff] [blame] | 2408 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2409 | if name: |
| 2410 | report_name = name |
| 2411 | else: |
| 2412 | report_name = "sanitycheck" |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2413 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2414 | if report_dir: |
| 2415 | os.makedirs(report_dir, exist_ok=True) |
| 2416 | filename = os.path.join(report_dir, report_name) |
| 2417 | outdir = report_dir |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2418 | else: |
Anas Nashif | 9e7a2cd | 2019-12-05 13:07:27 -0500 | [diff] [blame] | 2419 | filename = os.path.join(self.outdir, report_name) |
| 2420 | outdir = self.outdir |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 2421 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2422 | if not no_update: |
| 2423 | self.xunit_report(filename + ".xml", only_failed) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2424 | self.csv_report(filename + ".csv") |
| 2425 | self.target_report(outdir) |
| 2426 | if self.discards: |
| 2427 | self.discard_report(filename + "_discard.csv") |
| 2428 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2429 | if release: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2430 | self.csv_report(RELEASE_DATA) |
| 2431 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2432 | def add_configurations(self): |
| 2433 | |
| 2434 | for board_root in self.board_roots: |
| 2435 | board_root = os.path.abspath(board_root) |
| 2436 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2437 | logger.debug("Reading platform configuration files under %s..." % |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2438 | board_root) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2439 | |
| 2440 | for file in glob.glob(os.path.join(board_root, "*", "*", "*.yaml")): |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2441 | logger.debug("Found plaform configuration " + file) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2442 | try: |
| 2443 | platform = Platform() |
| 2444 | platform.load(file) |
| 2445 | if platform.sanitycheck: |
| 2446 | self.platforms.append(platform) |
| 2447 | if platform.default: |
| 2448 | self.default_platforms.append(platform.name) |
| 2449 | |
| 2450 | except RuntimeError as e: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2451 | logger.error("E: %s: can't load: %s" % (file, e)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2452 | self.load_errors += 1 |
| 2453 | |
Anas Nashif | eabaa7f | 2019-11-18 07:49:17 -0800 | [diff] [blame] | 2454 | def get_all_tests(self): |
| 2455 | tests = [] |
| 2456 | for _, tc in self.testcases.items(): |
| 2457 | for case in tc.cases: |
| 2458 | tests.append(case) |
| 2459 | |
| 2460 | return tests |
| 2461 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2462 | @staticmethod |
| 2463 | def get_toolchain(): |
| 2464 | toolchain = os.environ.get("ZEPHYR_TOOLCHAIN_VARIANT", None) or \ |
| 2465 | os.environ.get("ZEPHYR_GCC_VARIANT", None) |
| 2466 | |
| 2467 | if toolchain == "gccarmemb": |
| 2468 | # Remove this translation when gccarmemb is no longer supported. |
| 2469 | toolchain = "gnuarmemb" |
| 2470 | |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 2471 | try: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2472 | if not toolchain: |
| 2473 | raise SanityRuntimeError("E: Variable ZEPHYR_TOOLCHAIN_VARIANT is not defined") |
Anas Nashif | b4bdd66 | 2018-08-15 17:12:28 -0500 | [diff] [blame] | 2474 | except Exception as e: |
| 2475 | print(str(e)) |
| 2476 | sys.exit(2) |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2477 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2478 | return toolchain |
| 2479 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2480 | def add_testcases(self): |
| 2481 | for root in self.roots: |
| 2482 | root = os.path.abspath(root) |
| 2483 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2484 | logger.debug("Reading test case configuration files under %s..." % root) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2485 | |
| 2486 | for dirpath, dirnames, filenames in os.walk(root, topdown=True): |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2487 | logger.debug("scanning %s" % dirpath) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2488 | if 'sample.yaml' in filenames: |
| 2489 | filename = 'sample.yaml' |
| 2490 | elif 'testcase.yaml' in filenames: |
| 2491 | filename = 'testcase.yaml' |
| 2492 | else: |
| 2493 | continue |
| 2494 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2495 | logger.debug("Found possible test case in " + dirpath) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2496 | |
| 2497 | dirnames[:] = [] |
| 2498 | tc_path = os.path.join(dirpath, filename) |
| 2499 | self.add_testcase(tc_path, root) |
| 2500 | |
| 2501 | def add_testcase(self, tc_data_file, root): |
| 2502 | try: |
| 2503 | parsed_data = SanityConfigParser(tc_data_file, self.tc_schema) |
| 2504 | parsed_data.load() |
| 2505 | |
| 2506 | tc_path = os.path.dirname(tc_data_file) |
| 2507 | workdir = os.path.relpath(tc_path, root) |
| 2508 | |
| 2509 | for name in parsed_data.tests.keys(): |
| 2510 | tc = TestCase() |
| 2511 | tc.name = tc.get_unique(root, workdir, name) |
| 2512 | |
| 2513 | tc_dict = parsed_data.get_test(name, testcase_valid_keys) |
| 2514 | |
| 2515 | tc.source_dir = tc_path |
| 2516 | tc.yamlfile = tc_data_file |
| 2517 | |
| 2518 | tc.id = name |
| 2519 | tc.type = tc_dict["type"] |
| 2520 | tc.tags = tc_dict["tags"] |
| 2521 | tc.extra_args = tc_dict["extra_args"] |
| 2522 | tc.extra_configs = tc_dict["extra_configs"] |
| 2523 | tc.arch_whitelist = tc_dict["arch_whitelist"] |
| 2524 | tc.arch_exclude = tc_dict["arch_exclude"] |
| 2525 | tc.skip = tc_dict["skip"] |
| 2526 | tc.platform_exclude = tc_dict["platform_exclude"] |
| 2527 | tc.platform_whitelist = tc_dict["platform_whitelist"] |
| 2528 | tc.toolchain_exclude = tc_dict["toolchain_exclude"] |
| 2529 | tc.toolchain_whitelist = tc_dict["toolchain_whitelist"] |
| 2530 | tc.tc_filter = tc_dict["filter"] |
| 2531 | tc.timeout = tc_dict["timeout"] |
| 2532 | tc.harness = tc_dict["harness"] |
| 2533 | tc.harness_config = tc_dict["harness_config"] |
| 2534 | tc.build_only = tc_dict["build_only"] |
| 2535 | tc.build_on_all = tc_dict["build_on_all"] |
| 2536 | tc.slow = tc_dict["slow"] |
| 2537 | tc.min_ram = tc_dict["min_ram"] |
| 2538 | tc.depends_on = tc_dict["depends_on"] |
| 2539 | tc.min_flash = tc_dict["min_flash"] |
| 2540 | tc.extra_sections = tc_dict["extra_sections"] |
| 2541 | |
| 2542 | tc.parse_subcases(tc_path) |
| 2543 | |
| 2544 | if tc.name: |
| 2545 | self.testcases[tc.name] = tc |
| 2546 | |
| 2547 | except Exception as e: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2548 | logger.error("%s: can't load (skipping): %s" % (tc_data_file, e)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2549 | self.load_errors += 1 |
| 2550 | return False |
| 2551 | |
| 2552 | return True |
| 2553 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2554 | def get_platform(self, name): |
| 2555 | selected_platform = None |
| 2556 | for platform in self.platforms: |
| 2557 | if platform.name == name: |
| 2558 | selected_platform = platform |
| 2559 | break |
| 2560 | return selected_platform |
| 2561 | |
| 2562 | def get_last_failed(self): |
Anas Nashif | 9e7a2cd | 2019-12-05 13:07:27 -0500 | [diff] [blame] | 2563 | last_run = os.path.join(self.outdir, "sanitycheck.csv") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2564 | try: |
| 2565 | if not os.path.exists(last_run): |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2566 | raise SanityRuntimeError("Couldn't find last sanitycheck run.: %s" % last_run) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2567 | except Exception as e: |
| 2568 | print(str(e)) |
| 2569 | sys.exit(2) |
| 2570 | |
| 2571 | total_tests = 0 |
| 2572 | with open(last_run, "r") as fp: |
| 2573 | cr = csv.DictReader(fp) |
| 2574 | instance_list = [] |
| 2575 | for row in cr: |
| 2576 | total_tests += 1 |
| 2577 | if row["passed"] == "True": |
| 2578 | continue |
| 2579 | test = row["test"] |
| 2580 | platform = self.get_platform(row["platform"]) |
| 2581 | instance = TestInstance(self.testcases[test], platform, self.outdir) |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2582 | instance.check_build_or_run( |
| 2583 | self.build_only, |
| 2584 | self.enable_slow, |
| 2585 | self.device_testing, |
| 2586 | self.fixture |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2587 | ) |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2588 | instance.create_overlay(platform, self.enable_asan, self.enable_coverage, self.coverage_platform) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2589 | instance_list.append(instance) |
| 2590 | self.add_instances(instance_list) |
| 2591 | |
| 2592 | tests_to_run = len(self.instances) |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2593 | logger.info("%d tests passed already, retrying %d tests" % (total_tests - tests_to_run, tests_to_run)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2594 | |
| 2595 | def load_from_file(self, file): |
| 2596 | try: |
| 2597 | if not os.path.exists(file): |
| 2598 | raise SanityRuntimeError( |
| 2599 | "Couldn't find input file with list of tests.") |
| 2600 | except Exception as e: |
| 2601 | print(str(e)) |
| 2602 | sys.exit(2) |
| 2603 | |
| 2604 | with open(file, "r") as fp: |
| 2605 | cr = csv.DictReader(fp) |
| 2606 | instance_list = [] |
| 2607 | for row in cr: |
| 2608 | if row["arch"] == "arch": |
| 2609 | continue |
| 2610 | test = row["test"] |
| 2611 | platform = self.get_platform(row["platform"]) |
| 2612 | instance = TestInstance(self.testcases[test], platform, self.outdir) |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2613 | instance.check_build_or_run( |
| 2614 | self.build_only, |
| 2615 | self.enable_slow, |
| 2616 | self.device_testing, |
| 2617 | self.fixture |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2618 | ) |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2619 | instance.create_overlay(platform, self.enable_asan, self.enable_coverage, self.coverage_platform) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2620 | instance_list.append(instance) |
| 2621 | self.add_instances(instance_list) |
| 2622 | |
Anas Nashif | f5e5ef0 | 2019-12-06 19:20:48 -0500 | [diff] [blame] | 2623 | def apply_filters(self, **kwargs): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2624 | |
| 2625 | toolchain = self.get_toolchain() |
| 2626 | |
| 2627 | discards = {} |
Anas Nashif | f5e5ef0 | 2019-12-06 19:20:48 -0500 | [diff] [blame] | 2628 | platform_filter = kwargs.get('platform') |
| 2629 | testcase_filter = kwargs.get('run_individual_tests') |
| 2630 | arch_filter = kwargs.get('arch') |
| 2631 | tag_filter = kwargs.get('tag') |
| 2632 | exclude_tag = kwargs.get('exclude_tag') |
| 2633 | all_filter = kwargs.get('all') |
| 2634 | device_testing_filter = kwargs.get('device_testing') |
| 2635 | force_toolchain = kwargs.get('force_toolchain') |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2636 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2637 | logger.debug("platform filter: " + str(platform_filter)) |
| 2638 | logger.debug(" arch_filter: " + str(arch_filter)) |
| 2639 | logger.debug(" tag_filter: " + str(tag_filter)) |
| 2640 | logger.debug(" exclude_tag: " + str(exclude_tag)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2641 | |
| 2642 | default_platforms = False |
| 2643 | |
| 2644 | if platform_filter: |
| 2645 | platforms = list(filter(lambda p: p.name in platform_filter, self.platforms)) |
| 2646 | else: |
| 2647 | platforms = self.platforms |
| 2648 | |
Anas Nashif | f5e5ef0 | 2019-12-06 19:20:48 -0500 | [diff] [blame] | 2649 | if all_filter: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2650 | logger.info("Selecting all possible platforms per test case") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2651 | # When --all used, any --platform arguments ignored |
| 2652 | platform_filter = [] |
| 2653 | elif not platform_filter: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2654 | logger.info("Selecting default platforms per test case") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2655 | default_platforms = True |
| 2656 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2657 | logger.info("Building initial testcase list...") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2658 | |
| 2659 | for tc_name, tc in self.testcases.items(): |
| 2660 | # list of instances per testcase, aka configurations. |
| 2661 | instance_list = [] |
| 2662 | for plat in platforms: |
| 2663 | instance = TestInstance(tc, plat, self.outdir) |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2664 | instance.check_build_or_run( |
| 2665 | self.build_only, |
| 2666 | self.enable_slow, |
| 2667 | self.device_testing, |
| 2668 | self.fixture |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2669 | ) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2670 | |
| 2671 | if (plat.arch == "unit") != (tc.type == "unit"): |
| 2672 | # Discard silently |
| 2673 | continue |
| 2674 | |
Anas Nashif | f5e5ef0 | 2019-12-06 19:20:48 -0500 | [diff] [blame] | 2675 | if device_testing_filter and instance.build_only: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2676 | discards[instance] = "Not runnable on device" |
| 2677 | continue |
| 2678 | |
| 2679 | if tc.skip: |
| 2680 | discards[instance] = "Skip filter" |
| 2681 | continue |
| 2682 | |
| 2683 | if tc.build_on_all and not platform_filter: |
| 2684 | platform_filter = [] |
| 2685 | |
| 2686 | if tag_filter and not tc.tags.intersection(tag_filter): |
| 2687 | discards[instance] = "Command line testcase tag filter" |
| 2688 | continue |
| 2689 | |
| 2690 | if exclude_tag and tc.tags.intersection(exclude_tag): |
| 2691 | discards[instance] = "Command line testcase exclude filter" |
| 2692 | continue |
| 2693 | |
| 2694 | if testcase_filter and tc_name not in testcase_filter: |
| 2695 | discards[instance] = "Testcase name filter" |
| 2696 | continue |
| 2697 | |
| 2698 | if arch_filter and plat.arch not in arch_filter: |
| 2699 | discards[instance] = "Command line testcase arch filter" |
| 2700 | continue |
| 2701 | |
| 2702 | if tc.arch_whitelist and plat.arch not in tc.arch_whitelist: |
| 2703 | discards[instance] = "Not in test case arch whitelist" |
| 2704 | continue |
| 2705 | |
| 2706 | if tc.arch_exclude and plat.arch in tc.arch_exclude: |
| 2707 | discards[instance] = "In test case arch exclude" |
| 2708 | continue |
| 2709 | |
| 2710 | if tc.platform_exclude and plat.name in tc.platform_exclude: |
| 2711 | discards[instance] = "In test case platform exclude" |
| 2712 | continue |
| 2713 | |
| 2714 | if tc.toolchain_exclude and toolchain in tc.toolchain_exclude: |
| 2715 | discards[instance] = "In test case toolchain exclude" |
| 2716 | continue |
| 2717 | |
| 2718 | if platform_filter and plat.name not in platform_filter: |
| 2719 | discards[instance] = "Command line platform filter" |
| 2720 | continue |
| 2721 | |
| 2722 | if tc.platform_whitelist and plat.name not in tc.platform_whitelist: |
| 2723 | discards[instance] = "Not in testcase platform whitelist" |
| 2724 | continue |
| 2725 | |
| 2726 | if tc.toolchain_whitelist and toolchain not in tc.toolchain_whitelist: |
| 2727 | discards[instance] = "Not in testcase toolchain whitelist" |
| 2728 | continue |
| 2729 | |
| 2730 | if not plat.env_satisfied: |
| 2731 | discards[instance] = "Environment ({}) not satisfied".format(", ".join(plat.env)) |
| 2732 | continue |
| 2733 | |
Anas Nashif | f5e5ef0 | 2019-12-06 19:20:48 -0500 | [diff] [blame] | 2734 | if not force_toolchain \ |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2735 | and toolchain and (toolchain not in plat.supported_toolchains) \ |
| 2736 | and tc.type != 'unit': |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2737 | discards[instance] = "Not supported by the toolchain" |
| 2738 | continue |
| 2739 | |
| 2740 | if plat.ram < tc.min_ram: |
| 2741 | discards[instance] = "Not enough RAM" |
| 2742 | continue |
| 2743 | |
| 2744 | if tc.depends_on: |
| 2745 | dep_intersection = tc.depends_on.intersection(set(plat.supported)) |
| 2746 | if dep_intersection != set(tc.depends_on): |
| 2747 | discards[instance] = "No hardware support" |
| 2748 | continue |
| 2749 | |
| 2750 | if plat.flash < tc.min_flash: |
| 2751 | discards[instance] = "Not enough FLASH" |
| 2752 | continue |
| 2753 | |
| 2754 | if set(plat.ignore_tags) & tc.tags: |
| 2755 | discards[instance] = "Excluded tags per platform" |
| 2756 | continue |
| 2757 | |
| 2758 | # if nothing stopped us until now, it means this configuration |
| 2759 | # needs to be added. |
| 2760 | instance_list.append(instance) |
| 2761 | |
| 2762 | # no configurations, so jump to next testcase |
| 2763 | if not instance_list: |
| 2764 | continue |
| 2765 | |
| 2766 | # if sanitycheck was launched with no platform options at all, we |
| 2767 | # take all default platforms |
| 2768 | if default_platforms and not tc.build_on_all: |
| 2769 | if tc.platform_whitelist: |
| 2770 | a = set(self.default_platforms) |
| 2771 | b = set(tc.platform_whitelist) |
| 2772 | c = a.intersection(b) |
| 2773 | if c: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2774 | aa = list(filter(lambda tc: tc.platform.name in c, instance_list)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2775 | self.add_instances(aa) |
| 2776 | else: |
| 2777 | self.add_instances(instance_list[:1]) |
| 2778 | else: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2779 | instances = list(filter(lambda tc: tc.platform.default, instance_list)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2780 | self.add_instances(instances) |
| 2781 | |
| 2782 | for instance in list(filter(lambda tc: not tc.platform.default, instance_list)): |
| 2783 | discards[instance] = "Not a default test platform" |
| 2784 | |
| 2785 | else: |
| 2786 | self.add_instances(instance_list) |
| 2787 | |
| 2788 | for _, case in self.instances.items(): |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2789 | case.create_overlay(case.platform, self.enable_asan, self.enable_coverage, self.coverage_platform) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2790 | |
| 2791 | self.discards = discards |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 2792 | self.selected_platforms = set(p.platform.name for p in self.instances.values()) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2793 | |
| 2794 | return discards |
| 2795 | |
| 2796 | def add_instances(self, instance_list): |
| 2797 | for instance in instance_list: |
| 2798 | self.instances[instance.name] = instance |
| 2799 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2800 | def add_tasks_to_queue(self, test_only=False): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2801 | for instance in self.instances.values(): |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2802 | if test_only: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2803 | if instance.run: |
| 2804 | pipeline.put({"op": "run", "test": instance, "status": "built"}) |
| 2805 | else: |
| 2806 | if instance.status not in ['passed', 'skipped']: |
| 2807 | instance.status = None |
| 2808 | pipeline.put({"op": "cmake", "test": instance}) |
| 2809 | |
| 2810 | return "DONE FEEDING" |
| 2811 | |
Anas Nashif | c5ee395 | 2019-12-10 16:38:45 -0500 | [diff] [blame] | 2812 | def execute(self): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2813 | def calc_one_elf_size(instance): |
| 2814 | if instance.status not in ["failed", "skipped"]: |
| 2815 | if instance.platform.type != "native": |
| 2816 | size_calc = instance.calculate_sizes() |
| 2817 | instance.metrics["ram_size"] = size_calc.get_ram_size() |
| 2818 | instance.metrics["rom_size"] = size_calc.get_rom_size() |
| 2819 | instance.metrics["unrecognized"] = size_calc.unrecognized_sections() |
| 2820 | else: |
| 2821 | instance.metrics["ram_size"] = 0 |
| 2822 | instance.metrics["rom_size"] = 0 |
| 2823 | instance.metrics["unrecognized"] = [] |
| 2824 | |
| 2825 | instance.metrics["handler_time"] = instance.handler.duration if instance.handler else 0 |
| 2826 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2827 | logger.info("Adding tasks to the queue...") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2828 | # We can use a with statement to ensure threads are cleaned up promptly |
| 2829 | with BoundedExecutor(bound=self.jobs, max_workers=self.jobs) as executor: |
| 2830 | |
| 2831 | # start a future for a thread which sends work in through the queue |
| 2832 | future_to_test = { |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2833 | executor.submit(self.add_tasks_to_queue, self.test_only): 'FEEDER DONE'} |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2834 | |
| 2835 | while future_to_test: |
| 2836 | # check for status of the futures which are currently working |
| 2837 | done, _ = concurrent.futures.wait( |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2838 | future_to_test, timeout=0.25, |
| 2839 | return_when=concurrent.futures.FIRST_COMPLETED) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2840 | |
| 2841 | # if there is incoming work, start a new future |
| 2842 | while not pipeline.empty(): |
| 2843 | # fetch a url from the queue |
| 2844 | message = pipeline.get() |
| 2845 | test = message['test'] |
| 2846 | |
| 2847 | # Start the load operation and mark the future with its URL |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2848 | pb = ProjectBuilder(self, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2849 | test, |
| 2850 | lsan=self.enable_lsan, |
| 2851 | asan=self.enable_asan, |
| 2852 | coverage=self.enable_coverage, |
| 2853 | extra_args=self.extra_args, |
| 2854 | device_testing=self.device_testing, |
| 2855 | cmake_only=self.cmake_only, |
| 2856 | valgrind=self.enable_valgrind, |
| 2857 | inline_logs=self.inline_logs |
| 2858 | ) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2859 | future_to_test[executor.submit(pb.process, message)] = test.name |
| 2860 | |
| 2861 | # process any completed futures |
| 2862 | for future in done: |
| 2863 | test = future_to_test[future] |
| 2864 | try: |
| 2865 | data = future.result() |
| 2866 | except Exception as exc: |
Anas Nashif | 4f04386 | 2019-11-05 06:01:49 -0800 | [diff] [blame] | 2867 | sys.exit('%r generated an exception: %s' % (test, exc)) |
| 2868 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2869 | else: |
| 2870 | if data: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2871 | logger.debug(data) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2872 | |
| 2873 | # remove the now completed future |
| 2874 | del future_to_test[future] |
| 2875 | |
Anas Nashif | c5ee395 | 2019-12-10 16:38:45 -0500 | [diff] [blame] | 2876 | if self.enable_size_report and not self.cmake_only: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2877 | # Parallelize size calculation |
| 2878 | executor = concurrent.futures.ThreadPoolExecutor(self.jobs) |
| 2879 | futures = [executor.submit(calc_one_elf_size, instance) |
| 2880 | for instance in self.instances.values()] |
| 2881 | concurrent.futures.wait(futures) |
| 2882 | else: |
| 2883 | for instance in self.instances.values(): |
| 2884 | instance.metrics["ram_size"] = 0 |
| 2885 | instance.metrics["rom_size"] = 0 |
| 2886 | instance.metrics["handler_time"] = instance.handler.duration if instance.handler else 0 |
| 2887 | instance.metrics["unrecognized"] = [] |
| 2888 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2889 | def discard_report(self, filename): |
| 2890 | |
| 2891 | try: |
| 2892 | if self.discards is None: |
| 2893 | raise SanityRuntimeError("apply_filters() hasn't been run!") |
| 2894 | except Exception as e: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 2895 | logger.error(str(e)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2896 | sys.exit(2) |
| 2897 | |
| 2898 | with open(filename, "wt") as csvfile: |
| 2899 | fieldnames = ["test", "arch", "platform", "reason"] |
| 2900 | cw = csv.DictWriter(csvfile, fieldnames, lineterminator=os.linesep) |
| 2901 | cw.writeheader() |
| 2902 | for instance, reason in sorted(self.discards.items()): |
| 2903 | rowdict = {"test": instance.testcase.name, |
| 2904 | "arch": instance.platform.arch, |
| 2905 | "platform": instance.platform.name, |
| 2906 | "reason": reason} |
| 2907 | cw.writerow(rowdict) |
| 2908 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2909 | def target_report(self, outdir): |
| 2910 | run = "Sanitycheck" |
| 2911 | eleTestsuite = None |
| 2912 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2913 | platforms = {inst.platform.name for _, inst in self.instances.items()} |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2914 | for platform in platforms: |
| 2915 | errors = 0 |
| 2916 | passes = 0 |
| 2917 | fails = 0 |
| 2918 | duration = 0 |
| 2919 | skips = 0 |
| 2920 | for _, instance in self.instances.items(): |
| 2921 | if instance.platform.name != platform: |
| 2922 | continue |
| 2923 | |
| 2924 | handler_time = instance.metrics.get('handler_time', 0) |
| 2925 | duration += handler_time |
| 2926 | for k in instance.results.keys(): |
| 2927 | if instance.results[k] == 'PASS': |
| 2928 | passes += 1 |
| 2929 | elif instance.results[k] == 'BLOCK': |
| 2930 | errors += 1 |
| 2931 | elif instance.results[k] == 'SKIP': |
| 2932 | skips += 1 |
| 2933 | else: |
| 2934 | fails += 1 |
| 2935 | |
| 2936 | eleTestsuites = ET.Element('testsuites') |
| 2937 | eleTestsuite = ET.SubElement(eleTestsuites, 'testsuite', |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2938 | name=run, time="%f" % duration, |
| 2939 | tests="%d" % (errors + passes + fails), |
| 2940 | failures="%d" % fails, |
| 2941 | errors="%d" % errors, skipped="%d" % skips) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2942 | |
| 2943 | handler_time = 0 |
| 2944 | |
| 2945 | # print out test results |
| 2946 | for _, instance in self.instances.items(): |
| 2947 | if instance.platform.name != platform: |
| 2948 | continue |
| 2949 | handler_time = instance.metrics.get('handler_time', 0) |
| 2950 | for k in instance.results.keys(): |
| 2951 | eleTestcase = ET.SubElement( |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 2952 | eleTestsuite, 'testcase', |
| 2953 | classname="%s:%s" % (instance.platform.name, os.path.basename(instance.testcase.name)), |
| 2954 | name="%s" % (k), time="%f" % handler_time) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2955 | if instance.results[k] in ['FAIL', 'BLOCK']: |
| 2956 | el = None |
| 2957 | |
| 2958 | if instance.results[k] == 'FAIL': |
| 2959 | el = ET.SubElement( |
| 2960 | eleTestcase, |
| 2961 | 'failure', |
| 2962 | type="failure", |
| 2963 | message="failed") |
| 2964 | elif instance.results[k] == 'BLOCK': |
| 2965 | el = ET.SubElement( |
| 2966 | eleTestcase, |
| 2967 | 'error', |
| 2968 | type="failure", |
| 2969 | message="failed") |
Anas Nashif | 9e7a2cd | 2019-12-05 13:07:27 -0500 | [diff] [blame] | 2970 | p = os.path.join(self.outdir, instance.platform.name, instance.testcase.name) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2971 | log_file = os.path.join(p, "handler.log") |
| 2972 | |
| 2973 | if os.path.exists(log_file): |
| 2974 | with open(log_file, "rb") as f: |
| 2975 | log = f.read().decode("utf-8") |
| 2976 | filtered_string = ''.join(filter(lambda x: x in string.printable, log)) |
| 2977 | el.text = filtered_string |
| 2978 | |
| 2979 | elif instance.results[k] == 'SKIP': |
| 2980 | el = ET.SubElement( |
| 2981 | eleTestcase, |
| 2982 | 'skipped', |
| 2983 | type="skipped", |
| 2984 | message="Skipped") |
| 2985 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2986 | result = ET.tostring(eleTestsuites) |
| 2987 | with open(os.path.join(outdir, platform + ".xml"), 'wb') as f: |
| 2988 | f.write(result) |
| 2989 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 2990 | def xunit_report(self, filename, append=False): |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2991 | fails = 0 |
| 2992 | passes = 0 |
| 2993 | errors = 0 |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2994 | skips = 0 |
| 2995 | duration = 0 |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 2996 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 2997 | for instance in self.instances.values(): |
| 2998 | handler_time = instance.metrics.get('handler_time', 0) |
| 2999 | duration += handler_time |
| 3000 | if instance.status == "failed": |
| 3001 | if instance.reason in ['build_error', 'handler_crash']: |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 3002 | errors += 1 |
| 3003 | else: |
| 3004 | fails += 1 |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3005 | elif instance.status == 'skipped': |
| 3006 | skips += 1 |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 3007 | else: |
| 3008 | passes += 1 |
| 3009 | |
| 3010 | run = "Sanitycheck" |
| 3011 | eleTestsuite = None |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 3012 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3013 | # When we re-run the tests, we re-use the results and update only with |
| 3014 | # the newly run tests. |
Anas Nashif | 0605fa3 | 2017-05-07 08:51:02 -0400 | [diff] [blame] | 3015 | if os.path.exists(filename) and append: |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 3016 | tree = ET.parse(filename) |
| 3017 | eleTestsuites = tree.getroot() |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3018 | eleTestsuite = tree.findall('testsuite')[0] |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 3019 | else: |
| 3020 | eleTestsuites = ET.Element('testsuites') |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3021 | eleTestsuite = ET.SubElement(eleTestsuites, 'testsuite', |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3022 | name=run, time="%f" % duration, |
| 3023 | tests="%d" % (errors + passes + fails + skips), |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3024 | failures="%d" % fails, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3025 | errors="%d" % (errors), skip="%s" % (skips)) |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 3026 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3027 | for instance in self.instances.values(): |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 3028 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3029 | # remove testcases that are a re-run |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 3030 | if append: |
| 3031 | for tc in eleTestsuite.findall('testcase'): |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3032 | if tc.get('classname') == "%s:%s" % ( |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3033 | instance.platform.name, instance.testcase.name): |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 3034 | eleTestsuite.remove(tc) |
| 3035 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3036 | handler_time = 0 |
| 3037 | if instance.status != "failed" and instance.handler: |
| 3038 | handler_time = instance.metrics.get("handler_time", 0) |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 3039 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3040 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3041 | eleTestcase = ET.SubElement( |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3042 | eleTestsuite, |
| 3043 | 'testcase', |
| 3044 | classname="%s:%s" % (instance.platform.name, instance.testcase.name), |
| 3045 | name="%s" % (instance.testcase.name), |
| 3046 | time="%f" % handler_time) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3047 | |
| 3048 | if instance.status == "failed": |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3049 | failure = ET.SubElement( |
| 3050 | eleTestcase, |
| 3051 | 'failure', |
| 3052 | type="failure", |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3053 | message=instance.reason) |
Anas Nashif | 9e7a2cd | 2019-12-05 13:07:27 -0500 | [diff] [blame] | 3054 | p = ("%s/%s/%s" % (self.outdir, instance.platform.name, instance.testcase.name)) |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 3055 | bl = os.path.join(p, "build.log") |
Anas Nashif | c96c90a | 2019-02-05 07:38:32 -0500 | [diff] [blame] | 3056 | hl = os.path.join(p, "handler.log") |
| 3057 | log_file = bl |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3058 | if instance.reason != 'Build error': |
Anas Nashif | c96c90a | 2019-02-05 07:38:32 -0500 | [diff] [blame] | 3059 | if os.path.exists(hl): |
| 3060 | log_file = hl |
| 3061 | else: |
| 3062 | log_file = bl |
Anas Nashif | accc8eb | 2017-05-01 16:33:43 -0400 | [diff] [blame] | 3063 | |
Anas Nashif | c96c90a | 2019-02-05 07:38:32 -0500 | [diff] [blame] | 3064 | if os.path.exists(log_file): |
| 3065 | with open(log_file, "rb") as f: |
Anas Nashif | 712d345 | 2017-12-29 22:09:03 -0500 | [diff] [blame] | 3066 | log = f.read().decode("utf-8") |
Anas Nashif | a4c368e | 2018-10-15 09:45:59 -0400 | [diff] [blame] | 3067 | filtered_string = ''.join(filter(lambda x: x in string.printable, log)) |
| 3068 | failure.text = filtered_string |
Anas Nashif | ba4643b | 2018-09-23 09:41:59 -0500 | [diff] [blame] | 3069 | f.close() |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3070 | elif instance.status == "skipped": |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3071 | ET.SubElement(eleTestcase, 'skipped', type="skipped", message="Skipped") |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 3072 | |
| 3073 | result = ET.tostring(eleTestsuites) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3074 | with open(filename, 'wb') as report: |
| 3075 | report.write(result) |
Anas Nashif | b3311ed | 2017-04-13 14:44:48 -0400 | [diff] [blame] | 3076 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3077 | def csv_report(self, filename): |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 3078 | with open(filename, "wt") as csvfile: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3079 | fieldnames = ["test", "arch", "platform", "passed", "status", |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3080 | "extra_args", "handler", "handler_time", "ram_size", |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3081 | "rom_size"] |
| 3082 | cw = csv.DictWriter(csvfile, fieldnames, lineterminator=os.linesep) |
| 3083 | cw.writeheader() |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3084 | for instance in sorted(self.instances.values()): |
| 3085 | rowdict = {"test": instance.testcase.name, |
| 3086 | "arch": instance.platform.arch, |
| 3087 | "platform": instance.platform.name, |
| 3088 | "extra_args": " ".join(instance.testcase.extra_args), |
| 3089 | "handler": instance.platform.simulation} |
| 3090 | |
| 3091 | if instance.status in ["failed", "timeout"]: |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3092 | rowdict["passed"] = False |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3093 | rowdict["status"] = instance.reason |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3094 | else: |
| 3095 | rowdict["passed"] = True |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3096 | if instance.handler: |
| 3097 | rowdict["handler_time"] = instance.metrics.get("handler_time", 0) |
| 3098 | ram_size = instance.metrics.get("ram_size", 0) |
| 3099 | rom_size = instance.metrics.get("rom_size", 0) |
| 3100 | rowdict["ram_size"] = ram_size |
| 3101 | rowdict["rom_size"] = rom_size |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3102 | cw.writerow(rowdict) |
| 3103 | |
Anas Nashif | 19ca783 | 2019-11-18 08:16:21 -0800 | [diff] [blame] | 3104 | def get_testcase(self, identifier): |
| 3105 | results = [] |
| 3106 | for _, tc in self.testcases.items(): |
| 3107 | for case in tc.cases: |
| 3108 | if case == identifier: |
| 3109 | results.append(tc) |
| 3110 | return results |
| 3111 | |
| 3112 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3113 | def parse_arguments(): |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3114 | parser = argparse.ArgumentParser( |
| 3115 | description=__doc__, |
| 3116 | formatter_class=argparse.RawDescriptionHelpFormatter) |
Genaro Saucedo Tejada | 28bba92 | 2016-10-24 18:00:58 -0500 | [diff] [blame] | 3117 | parser.fromfile_prefix_chars = "+" |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3118 | |
Marc Herbert | 932a33a | 2019-03-12 11:37:53 -0700 | [diff] [blame] | 3119 | case_select = parser.add_argument_group("Test case selection", |
| 3120 | """ |
| 3121 | Artificially long but functional example: |
| 3122 | $ ./scripts/sanitycheck -v \\ |
Marc Herbert | e5cedca | 2019-04-08 14:02:34 -0700 | [diff] [blame] | 3123 | --testcase-root tests/ztest/base \\ |
| 3124 | --testcase-root tests/kernel \\ |
Marc Herbert | 932a33a | 2019-03-12 11:37:53 -0700 | [diff] [blame] | 3125 | --test tests/ztest/base/testing.ztest.verbose_0 \\ |
| 3126 | --test tests/kernel/fifo/fifo_api/kernel.fifo.poll |
| 3127 | |
| 3128 | "kernel.fifo.poll" is one of the test section names in |
| 3129 | __/fifo_api/testcase.yaml |
| 3130 | """) |
Marc Herbert | edf1759 | 2019-03-08 12:39:11 -0800 | [diff] [blame] | 3131 | |
Anas Nashif | 07d54c0 | 2018-07-21 19:29:08 -0500 | [diff] [blame] | 3132 | parser.add_argument("--force-toolchain", action="store_true", |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3133 | help="Do not filter based on toolchain, use the set " |
| 3134 | " toolchain unconditionally") |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3135 | parser.add_argument( |
| 3136 | "-p", "--platform", action="append", |
| 3137 | help="Platform filter for testing. This option may be used multiple " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3138 | "times. Testcases will only be built/run on the platforms " |
| 3139 | "specified. If this option is not used, then platforms marked " |
| 3140 | "as default in the platform metadata file will be chosen " |
| 3141 | "to build and test. ") |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3142 | parser.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3143 | "-a", "--arch", action="append", |
| 3144 | help="Arch filter for testing. Takes precedence over --platform. " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3145 | "If unspecified, test all arches. Multiple invocations " |
| 3146 | "are treated as a logical 'or' relationship") |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3147 | parser.add_argument( |
| 3148 | "-t", "--tag", action="append", |
| 3149 | help="Specify tags to restrict which tests to run by tag value. " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3150 | "Default is to not do any tag filtering. Multiple invocations " |
| 3151 | "are treated as a logical 'or' relationship") |
Anas Nashif | dfa86e2 | 2016-10-24 17:08:56 -0400 | [diff] [blame] | 3152 | parser.add_argument("-e", "--exclude-tag", action="append", |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3153 | help="Specify tags of tests that should not run. " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3154 | "Default is to run all tests with all tags.") |
Marc Herbert | edf1759 | 2019-03-08 12:39:11 -0800 | [diff] [blame] | 3155 | case_select.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3156 | "-f", |
| 3157 | "--only-failed", |
| 3158 | action="store_true", |
| 3159 | help="Run only those tests that failed the previous sanity check " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3160 | "invocation.") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3161 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3162 | parser.add_argument( |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3163 | "--retry-failed", type=int, default=0, |
| 3164 | help="Retry failing tests again, up to the number of times specified.") |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 3165 | |
Marc Herbert | 0c465bb | 2019-03-11 17:28:36 -0700 | [diff] [blame] | 3166 | test_xor_subtest = case_select.add_mutually_exclusive_group() |
| 3167 | |
| 3168 | test_xor_subtest.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3169 | "-s", "--test", action="append", |
| 3170 | help="Run only the specified test cases. These are named by " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3171 | "<path/relative/to/Zephyr/base/section.name.in.testcase.yaml>") |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 3172 | |
Marc Herbert | 0c465bb | 2019-03-11 17:28:36 -0700 | [diff] [blame] | 3173 | test_xor_subtest.add_argument( |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 3174 | "--sub-test", action="append", |
Marc Herbert | 932a33a | 2019-03-12 11:37:53 -0700 | [diff] [blame] | 3175 | help="""Recursively find sub-test functions and run the entire |
| 3176 | test section where they were found, including all sibling test |
| 3177 | functions. Sub-tests are named by: |
| 3178 | section.name.in.testcase.yaml.function_name_without_test_prefix |
| 3179 | Example: kernel.fifo.poll.fifo_loop |
| 3180 | """) |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 3181 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3182 | parser.add_argument( |
| 3183 | "-l", "--all", action="store_true", |
| 3184 | help="Build/test on all platforms. Any --platform arguments " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3185 | "ignored.") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3186 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3187 | parser.add_argument( |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3188 | "-o", "--report-dir", |
| 3189 | help="""Output reports containing results of the test run into the |
| 3190 | specified directory. |
| 3191 | The output will be both in CSV and JUNIT format |
| 3192 | (sanitycheck.csv and sanitycheck.xml). |
| 3193 | """) |
| 3194 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3195 | parser.add_argument( |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3196 | "--report-name", |
| 3197 | help="""Create a report with a custom name. |
| 3198 | """) |
| 3199 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3200 | parser.add_argument("--report-excluded", |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3201 | action="store_true", |
| 3202 | help="""List all tests that are never run based on current scope and |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3203 | coverage. If you are looking for accurate results, run this with |
| 3204 | --all, but this will take a while...""") |
| 3205 | |
Daniel Leung | 7f85010 | 2016-04-08 11:07:32 -0700 | [diff] [blame] | 3206 | parser.add_argument("--compare-report", |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3207 | help="Use this report file for size comparison") |
Daniel Leung | 7f85010 | 2016-04-08 11:07:32 -0700 | [diff] [blame] | 3208 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3209 | parser.add_argument( |
| 3210 | "-B", "--subset", |
| 3211 | help="Only run a subset of the tests, 1/4 for running the first 25%%, " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3212 | "3/5 means run the 3rd fifth of the total. " |
| 3213 | "This option is useful when running a large number of tests on " |
| 3214 | "different hosts to speed up execution time.") |
Anas Nashif | a8a1388 | 2017-12-30 13:01:06 -0500 | [diff] [blame] | 3215 | |
| 3216 | parser.add_argument( |
| 3217 | "-N", "--ninja", action="store_true", |
Anas Nashif | 25f6ab6 | 2018-03-06 07:15:11 -0600 | [diff] [blame] | 3218 | help="Use the Ninja generator with CMake") |
Anas Nashif | a8a1388 | 2017-12-30 13:01:06 -0500 | [diff] [blame] | 3219 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3220 | parser.add_argument( |
| 3221 | "-y", "--dry-run", action="store_true", |
Anas Nashif | 12d8cce | 2019-11-20 03:47:27 -0800 | [diff] [blame] | 3222 | help="""Create the filtered list of test cases, but don't actually |
| 3223 | run them. Useful if you're just interested in the discard report |
| 3224 | generated for every run and saved in the specified output |
| 3225 | directory (sanitycheck_discard.csv). |
| 3226 | """) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3227 | |
Anas Nashif | 75547e2 | 2018-02-24 08:32:14 -0600 | [diff] [blame] | 3228 | parser.add_argument("--list-tags", action="store_true", |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3229 | help="list all tags in selected tests") |
Anas Nashif | 75547e2 | 2018-02-24 08:32:14 -0600 | [diff] [blame] | 3230 | |
Marc Herbert | edf1759 | 2019-03-08 12:39:11 -0800 | [diff] [blame] | 3231 | case_select.add_argument("--list-tests", action="store_true", |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3232 | help="""List of all sub-test functions recursively found in |
Marc Herbert | 932a33a | 2019-03-12 11:37:53 -0700 | [diff] [blame] | 3233 | all --testcase-root arguments. Note different sub-tests can share |
| 3234 | the same section name and come from different directories. |
| 3235 | The output is flattened and reports --sub-test names only, |
| 3236 | not their directories. For instance net.socket.getaddrinfo_ok |
| 3237 | and net.socket.fd_set belong to different directories. |
| 3238 | """) |
Anas Nashif | c0149cc | 2018-04-14 23:12:58 -0500 | [diff] [blame] | 3239 | |
Anas Nashif | 434995c | 2019-12-01 13:55:11 -0500 | [diff] [blame] | 3240 | case_select.add_argument("--test-tree", action="store_true", |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3241 | help="""Output the testsuite in a tree form""") |
Anas Nashif | 434995c | 2019-12-01 13:55:11 -0500 | [diff] [blame] | 3242 | |
Anas Nashif | 19ca783 | 2019-11-18 08:16:21 -0800 | [diff] [blame] | 3243 | case_select.add_argument("--list-test-duplicates", action="store_true", |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3244 | help="""List tests with duplicate identifiers. |
Anas Nashif | 19ca783 | 2019-11-18 08:16:21 -0800 | [diff] [blame] | 3245 | """) |
| 3246 | |
Anas Nashif | 5d6e7eb | 2018-06-01 09:51:08 -0500 | [diff] [blame] | 3247 | parser.add_argument("--export-tests", action="store", |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3248 | metavar="FILENAME", |
| 3249 | help="Export tests case meta-data to a file in CSV format.") |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 3250 | |
Anas Nashif | 654ec598 | 2019-04-11 08:38:21 -0400 | [diff] [blame] | 3251 | parser.add_argument("--timestamps", |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3252 | action="store_true", |
| 3253 | help="Print all messages with time stamps") |
Anas Nashif | 654ec598 | 2019-04-11 08:38:21 -0400 | [diff] [blame] | 3254 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3255 | parser.add_argument( |
| 3256 | "-r", "--release", action="store_true", |
| 3257 | help="Update the benchmark database with the results of this test " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3258 | "run. Intended to be run by CI when tagging an official " |
| 3259 | "release. This database is used as a basis for comparison " |
| 3260 | "when looking for deltas in metrics such as footprint") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3261 | parser.add_argument("-w", "--warnings-as-errors", action="store_true", |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3262 | help="Treat warning conditions as errors") |
| 3263 | parser.add_argument( |
| 3264 | "-v", |
| 3265 | "--verbose", |
| 3266 | action="count", |
| 3267 | default=0, |
| 3268 | help="Emit debugging information, call multiple times to increase " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3269 | "verbosity") |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3270 | parser.add_argument( |
| 3271 | "-i", "--inline-logs", action="store_true", |
| 3272 | help="Upon test failure, print relevant log data to stdout " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3273 | "instead of just a path to it") |
Inaky Perez-Gonzalez | 9a36cb6 | 2016-11-29 10:43:40 -0800 | [diff] [blame] | 3274 | parser.add_argument("--log-file", metavar="FILENAME", action="store", |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3275 | help="log also to file") |
| 3276 | parser.add_argument( |
| 3277 | "-m", "--last-metrics", action="store_true", |
| 3278 | help="Instead of comparing metrics from the last --release, " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3279 | "compare with the results of the previous sanity check " |
| 3280 | "invocation") |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3281 | parser.add_argument( |
| 3282 | "-u", |
| 3283 | "--no-update", |
| 3284 | action="store_true", |
| 3285 | help="do not update the results of the last run of the sanity " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3286 | "checks") |
Marc Herbert | edf1759 | 2019-03-08 12:39:11 -0800 | [diff] [blame] | 3287 | case_select.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3288 | "-F", |
| 3289 | "--load-tests", |
| 3290 | metavar="FILENAME", |
| 3291 | action="store", |
Marc Herbert | 932a33a | 2019-03-12 11:37:53 -0700 | [diff] [blame] | 3292 | help="Load list of tests and platforms to be run from file.") |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 3293 | |
Marc Herbert | edf1759 | 2019-03-08 12:39:11 -0800 | [diff] [blame] | 3294 | case_select.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3295 | "-E", |
| 3296 | "--save-tests", |
| 3297 | metavar="FILENAME", |
| 3298 | action="store", |
Marc Herbert | 682961a | 2019-03-20 16:48:49 -0700 | [diff] [blame] | 3299 | help="Append list of tests and platforms to be run to file.") |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 3300 | |
Andy Doan | cbecadd | 2019-02-08 10:19:10 -0600 | [diff] [blame] | 3301 | test_or_build = parser.add_mutually_exclusive_group() |
| 3302 | test_or_build.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3303 | "-b", "--build-only", action="store_true", |
| 3304 | help="Only build the code, do not execute any of it in QEMU") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3305 | |
Andy Doan | cbecadd | 2019-02-08 10:19:10 -0600 | [diff] [blame] | 3306 | test_or_build.add_argument( |
| 3307 | "--test-only", action="store_true", |
| 3308 | help="""Only run device tests with current artifacts, do not build |
| 3309 | the code""") |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3310 | parser.add_argument( |
Kumar Gala | 84cf9dc | 2019-06-15 09:36:06 -0500 | [diff] [blame] | 3311 | "--cmake-only", action="store_true", |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3312 | help="Only run cmake, do not build or run.") |
Kumar Gala | 84cf9dc | 2019-06-15 09:36:06 -0500 | [diff] [blame] | 3313 | |
| 3314 | parser.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3315 | "-j", "--jobs", type=int, |
Marc Herbert | 9e57338 | 2019-07-03 12:49:42 -0700 | [diff] [blame] | 3316 | help="Number of jobs for building, defaults to number of CPU threads, " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3317 | "overcommited by factor 2 when --build-only") |
Anas Nashif | 73440ea | 2018-02-19 10:57:03 -0600 | [diff] [blame] | 3318 | |
| 3319 | parser.add_argument( |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3320 | "--show-footprint", action="store_true", |
| 3321 | help="Show footprint statistics and deltas since last release." |
| 3322 | ) |
Anas Nashif | 424a3db | 2018-02-20 08:37:24 -0600 | [diff] [blame] | 3323 | parser.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3324 | "-H", "--footprint-threshold", type=float, default=5, |
| 3325 | help="When checking test case footprint sizes, warn the user if " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3326 | "the new app size is greater then the specified percentage " |
| 3327 | "from the last release. Default is 5. 0 to warn on any " |
| 3328 | "increase on app size") |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3329 | parser.add_argument( |
| 3330 | "-D", "--all-deltas", action="store_true", |
| 3331 | help="Show all footprint deltas, positive or negative. Implies " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3332 | "--footprint-threshold=0") |
Håkon Øye Amundsen | de223cc | 2018-04-25 06:24:25 +0000 | [diff] [blame] | 3333 | parser.add_argument( |
| 3334 | "-O", "--outdir", |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3335 | default=os.path.join(os.getcwd(), "sanity-out"), |
Håkon Øye Amundsen | de223cc | 2018-04-25 06:24:25 +0000 | [diff] [blame] | 3336 | help="Output directory for logs and binaries. " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3337 | "Default is 'sanity-out' in the current directory. " |
| 3338 | "This directory will be deleted unless '--no-clean' is set.") |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3339 | parser.add_argument( |
| 3340 | "-n", "--no-clean", action="store_true", |
| 3341 | help="Do not delete the outdir before building. Will result in " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3342 | "faster compilation since builds will be incremental") |
Marc Herbert | edf1759 | 2019-03-08 12:39:11 -0800 | [diff] [blame] | 3343 | case_select.add_argument( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3344 | "-T", "--testcase-root", action="append", default=[], |
| 3345 | help="Base directory to recursively search for test cases. All " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3346 | "testcase.yaml files under here will be processed. May be " |
| 3347 | "called multiple times. Defaults to the 'samples/' and " |
| 3348 | "'tests/' directories at the base of the Zephyr tree.") |
Anas Nashif | 7dd19ea | 2018-11-14 08:46:49 -0500 | [diff] [blame] | 3349 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3350 | board_root_list = ["%s/boards" % ZEPHYR_BASE, |
| 3351 | "%s/scripts/sanity_chk/boards" % ZEPHYR_BASE] |
Anas Nashif | 7dd19ea | 2018-11-14 08:46:49 -0500 | [diff] [blame] | 3352 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3353 | parser.add_argument( |
Thomas Stilwell | 5310510 | 2019-10-23 14:25:09 +0200 | [diff] [blame] | 3354 | "-A", "--board-root", action="append", default=board_root_list, |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3355 | help="""Directory to search for board configuration files. All .yaml |
| 3356 | files in the directory will be processed. The directory should have the same |
| 3357 | structure in the main Zephyr tree: boards/<arch>/<board_name>/""") |
| 3358 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3359 | parser.add_argument( |
| 3360 | "-z", "--size", action="append", |
| 3361 | help="Don't run sanity checks. Instead, produce a report to " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3362 | "stdout detailing RAM/ROM sizes on the specified filenames. " |
| 3363 | "All other command line arguments ignored.") |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3364 | parser.add_argument( |
| 3365 | "-S", "--enable-slow", action="store_true", |
| 3366 | help="Execute time-consuming test cases that have been marked " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3367 | "as 'slow' in testcase.yaml. Normally these are only built.") |
Sebastian Bøe | 03ed095 | 2018-11-13 13:36:19 +0100 | [diff] [blame] | 3368 | parser.add_argument( |
| 3369 | "--disable-unrecognized-section-test", action="store_true", |
| 3370 | default=False, |
| 3371 | help="Skip the 'unrecognized section' test.") |
Andrew Boie | 5512105 | 2016-07-20 11:52:04 -0700 | [diff] [blame] | 3372 | parser.add_argument("-R", "--enable-asserts", action="store_true", |
Kumar Gala | 0d48cbe | 2018-01-26 10:22:20 -0600 | [diff] [blame] | 3373 | default=True, |
Andrew Boie | 29599f6 | 2018-05-24 13:33:09 -0700 | [diff] [blame] | 3374 | help="deprecated, left for compatibility") |
Kumar Gala | 0d48cbe | 2018-01-26 10:22:20 -0600 | [diff] [blame] | 3375 | parser.add_argument("--disable-asserts", action="store_false", |
| 3376 | dest="enable_asserts", |
Andrew Boie | 29599f6 | 2018-05-24 13:33:09 -0700 | [diff] [blame] | 3377 | help="deprecated, left for compatibility") |
Anas Nashif | e3febe9 | 2016-11-30 14:25:44 -0500 | [diff] [blame] | 3378 | parser.add_argument("-Q", "--error-on-deprecations", action="store_false", |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3379 | help="Error on deprecation warnings.") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3380 | parser.add_argument("--enable-size-report", action="store_true", |
| 3381 | help="Enable expensive computation of RAM/ROM segment sizes.") |
Sebastian Bøe | c218261 | 2017-11-09 12:25:02 +0100 | [diff] [blame] | 3382 | |
| 3383 | parser.add_argument( |
| 3384 | "-x", "--extra-args", action="append", default=[], |
Alberto Escolar Piedras | 25e0636 | 2018-02-10 17:40:33 +0100 | [diff] [blame] | 3385 | help="""Extra CMake cache entries to define when building test cases. |
| 3386 | May be called multiple times. The key-value entries will be |
Sebastian Bøe | c218261 | 2017-11-09 12:25:02 +0100 | [diff] [blame] | 3387 | prefixed with -D before being passed to CMake. |
| 3388 | |
| 3389 | E.g |
| 3390 | "sanitycheck -x=USE_CCACHE=0" |
| 3391 | will translate to |
| 3392 | "cmake -DUSE_CCACHE=0" |
| 3393 | |
| 3394 | which will ultimately disable ccache. |
| 3395 | """ |
| 3396 | ) |
Michael Scott | 421ce46 | 2019-06-18 09:37:46 -0700 | [diff] [blame] | 3397 | |
Andy Doan | 79c4884 | 2019-02-08 10:09:04 -0600 | [diff] [blame] | 3398 | parser.add_argument( |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3399 | "--device-testing", action="store_true", |
| 3400 | help="Test on device directly. Specify the serial device to " |
| 3401 | "use with the --device-serial option.") |
| 3402 | |
| 3403 | parser.add_argument( |
| 3404 | "-X", "--fixture", action="append", default=[], |
| 3405 | help="Specify a fixture that a board might support") |
| 3406 | parser.add_argument( |
| 3407 | "--device-serial", |
| 3408 | help="Serial device for accessing the board (e.g., /dev/ttyACM0)") |
| 3409 | |
| 3410 | parser.add_argument("--generate-hardware-map", |
| 3411 | help="""Probe serial devices connected to this platform |
| 3412 | and create a hardware map file to be used with |
| 3413 | --device-testing |
| 3414 | """) |
| 3415 | |
| 3416 | parser.add_argument("--hardware-map", |
| 3417 | help="""Load hardware map from a file. This will be used |
| 3418 | for testing on hardware that is listed in the file. |
| 3419 | """) |
| 3420 | |
| 3421 | parser.add_argument( |
Andy Doan | 79c4884 | 2019-02-08 10:09:04 -0600 | [diff] [blame] | 3422 | "--west-flash", nargs='?', const=[], |
| 3423 | help="""Uses west instead of ninja or make to flash when running with |
Jorgen Kvalvaag | d50fb31 | 2019-09-02 15:25:20 +0200 | [diff] [blame] | 3424 | --device-testing. Supports comma-separated argument list. |
Andy Doan | 79c4884 | 2019-02-08 10:09:04 -0600 | [diff] [blame] | 3425 | |
Michael Scott | 4ca5439 | 2019-07-09 14:21:30 -0700 | [diff] [blame] | 3426 | E.g "sanitycheck --device-testing --device-serial /dev/ttyACM0 |
Jorgen Kvalvaag | d50fb31 | 2019-09-02 15:25:20 +0200 | [diff] [blame] | 3427 | --west-flash="--board-id=foobar,--erase" |
| 3428 | will translate to "west flash -- --board-id=foobar --erase" |
Michael Scott | 4ca5439 | 2019-07-09 14:21:30 -0700 | [diff] [blame] | 3429 | |
| 3430 | NOTE: device-testing must be enabled to use this option. |
Andy Doan | 79c4884 | 2019-02-08 10:09:04 -0600 | [diff] [blame] | 3431 | """ |
| 3432 | ) |
Michael Scott | 421ce46 | 2019-06-18 09:37:46 -0700 | [diff] [blame] | 3433 | parser.add_argument( |
| 3434 | "--west-runner", |
| 3435 | help="""Uses the specified west runner instead of default when running |
| 3436 | with --west-flash. |
| 3437 | |
| 3438 | E.g "sanitycheck --device-testing --device-serial /dev/ttyACM0 |
| 3439 | --west-flash --west-runner=pyocd" |
| 3440 | will translate to "west flash --runner pyocd" |
| 3441 | |
| 3442 | NOTE: west-flash must be enabled to use this option. |
| 3443 | """ |
| 3444 | ) |
Jan Van Winkel | 21212f3 | 2019-09-12 00:03:35 +0200 | [diff] [blame] | 3445 | |
| 3446 | valgrind_asan_group = parser.add_mutually_exclusive_group() |
| 3447 | |
| 3448 | valgrind_asan_group.add_argument( |
Anas Nashif | c1ea452 | 2019-10-11 07:32:45 -0700 | [diff] [blame] | 3449 | "--enable-valgrind", action="store_true", |
| 3450 | help="""Run binary through valgrind and check for several memory access |
Jan Van Winkel | 21212f3 | 2019-09-12 00:03:35 +0200 | [diff] [blame] | 3451 | errors. Valgrind needs to be installed on the host. This option only |
Anas Nashif | c1ea452 | 2019-10-11 07:32:45 -0700 | [diff] [blame] | 3452 | works with host binaries such as those generated for the native_posix |
Jan Van Winkel | 21212f3 | 2019-09-12 00:03:35 +0200 | [diff] [blame] | 3453 | configuration and is mutual exclusive with --enable-asan. |
| 3454 | """) |
| 3455 | |
| 3456 | valgrind_asan_group.add_argument( |
| 3457 | "--enable-asan", action="store_true", |
| 3458 | help="""Enable address sanitizer to check for several memory access |
| 3459 | errors. Libasan needs to be installed on the host. This option only |
| 3460 | works with host binaries such as those generated for the native_posix |
| 3461 | configuration and is mutual exclusive with --enable-valgrind. |
| 3462 | """) |
| 3463 | |
| 3464 | parser.add_argument( |
| 3465 | "--enable-lsan", action="store_true", |
| 3466 | help="""Enable leak sanitizer to check for heap memory leaks. |
| 3467 | Libasan needs to be installed on the host. This option only |
| 3468 | works with host binaries such as those generated for the native_posix |
| 3469 | configuration and when --enable-asan is given. |
Anas Nashif | c1ea452 | 2019-10-11 07:32:45 -0700 | [diff] [blame] | 3470 | """) |
Andrew Boie | 8047a6f | 2019-07-02 15:43:29 -0700 | [diff] [blame] | 3471 | |
Alberto Escolar Piedras | c026c2e | 2018-06-21 09:30:20 +0200 | [diff] [blame] | 3472 | parser.add_argument("--enable-coverage", action="store_true", |
Anas Nashif | 8d72bb9 | 2018-11-07 23:05:42 -0500 | [diff] [blame] | 3473 | help="Enable code coverage using gcov.") |
Alberto Escolar Piedras | c026c2e | 2018-06-21 09:30:20 +0200 | [diff] [blame] | 3474 | |
Jaakko Hannikainen | 54c90bc | 2016-08-31 14:17:03 +0300 | [diff] [blame] | 3475 | parser.add_argument("-C", "--coverage", action="store_true", |
Andrew Boie | 8047a6f | 2019-07-02 15:43:29 -0700 | [diff] [blame] | 3476 | help="Generate coverage reports. Implies " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3477 | "--enable_coverage.") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3478 | |
Andrew Boie | 8047a6f | 2019-07-02 15:43:29 -0700 | [diff] [blame] | 3479 | parser.add_argument("--coverage-platform", action="append", default=[], |
Anas Nashif | dbd7649 | 2018-11-23 20:24:19 -0500 | [diff] [blame] | 3480 | help="Plarforms to run coverage reports on. " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3481 | "This option may be used multiple times. " |
| 3482 | "Default to what was selected with --platform.") |
Anas Nashif | dbd7649 | 2018-11-23 20:24:19 -0500 | [diff] [blame] | 3483 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3484 | parser.add_argument("--gcov-tool", default=None, |
| 3485 | help="Path to the gcov tool to use for code coverage " |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3486 | "reports") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3487 | |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3488 | parser.add_argument("--coverage-tool", choices=['lcov', 'gcovr'], default='lcov', |
| 3489 | help="Tool to use to generate coverage report.") |
| 3490 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3491 | return parser.parse_args() |
| 3492 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3493 | |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 3494 | def size_report(sc): |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3495 | logger.info(sc.filename) |
| 3496 | logger.info("SECTION NAME VMA LMA SIZE HEX SZ TYPE") |
Andrew Boie | 9882dcd | 2015-10-07 14:25:51 -0700 | [diff] [blame] | 3497 | for i in range(len(sc.sections)): |
| 3498 | v = sc.sections[i] |
| 3499 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3500 | logger.info("%-17s 0x%08x 0x%08x %8d 0x%05x %-7s" % |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3501 | (v["name"], v["virt_addr"], v["load_addr"], v["size"], v["size"], |
| 3502 | v["type"])) |
Andrew Boie | 9882dcd | 2015-10-07 14:25:51 -0700 | [diff] [blame] | 3503 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3504 | logger.info("Totals: %d bytes (ROM), %d bytes (RAM)" % |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3505 | (sc.rom_size, sc.ram_size)) |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3506 | logger.info("") |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 3507 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3508 | |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3509 | class CoverageTool: |
| 3510 | """ Base class for every supported coverage tool |
| 3511 | """ |
| 3512 | |
| 3513 | def __init__(self): |
| 3514 | self.gcov_tool = options.gcov_tool |
| 3515 | |
| 3516 | @staticmethod |
| 3517 | def factory(tool): |
| 3518 | if tool == 'lcov': |
| 3519 | return Lcov() |
| 3520 | if tool == 'gcovr': |
| 3521 | return Gcovr() |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3522 | logger.error("Unsupported coverage tool specified: {}".format(tool)) |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3523 | |
| 3524 | @staticmethod |
| 3525 | def retrieve_gcov_data(intput_file): |
| 3526 | if VERBOSE: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3527 | logger.debug("Working on %s" % intput_file) |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3528 | extracted_coverage_info = {} |
| 3529 | capture_data = False |
| 3530 | capture_complete = False |
| 3531 | with open(intput_file, 'r') as fp: |
| 3532 | for line in fp.readlines(): |
| 3533 | if re.search("GCOV_COVERAGE_DUMP_START", line): |
| 3534 | capture_data = True |
| 3535 | continue |
| 3536 | if re.search("GCOV_COVERAGE_DUMP_END", line): |
| 3537 | capture_complete = True |
| 3538 | break |
| 3539 | # Loop until the coverage data is found. |
| 3540 | if not capture_data: |
| 3541 | continue |
| 3542 | if line.startswith("*"): |
| 3543 | sp = line.split("<") |
| 3544 | if len(sp) > 1: |
| 3545 | # Remove the leading delimiter "*" |
| 3546 | file_name = sp[0][1:] |
| 3547 | # Remove the trailing new line char |
| 3548 | hex_dump = sp[1][:-1] |
| 3549 | else: |
| 3550 | continue |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 3551 | else: |
| 3552 | continue |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3553 | extracted_coverage_info.update({file_name: hex_dump}) |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3554 | if not capture_data: |
| 3555 | capture_complete = True |
| 3556 | return {'complete': capture_complete, 'data': extracted_coverage_info} |
| 3557 | |
| 3558 | @staticmethod |
| 3559 | def create_gcda_files(extracted_coverage_info): |
| 3560 | if VERBOSE: |
Anas Nashif | 6d66a7a | 2019-12-08 12:11:43 -0500 | [diff] [blame] | 3561 | logger.debug("Generating gcda files") |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3562 | for filename, hexdump_val in extracted_coverage_info.items(): |
| 3563 | # if kobject_hash is given for coverage gcovr fails |
| 3564 | # hence skipping it problem only in gcovr v4.1 |
| 3565 | if "kobject_hash" in filename: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3566 | filename = (filename[:-4]) + "gcno" |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3567 | try: |
| 3568 | os.remove(filename) |
| 3569 | except Exception: |
| 3570 | pass |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 3571 | continue |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 3572 | |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3573 | with open(filename, 'wb') as fp: |
| 3574 | fp.write(bytes.fromhex(hexdump_val)) |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 3575 | |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3576 | def generate(self, outdir): |
| 3577 | for filename in glob.glob("%s/**/handler.log" % outdir, recursive=True): |
| 3578 | gcov_data = self.__class__.retrieve_gcov_data(filename) |
| 3579 | capture_complete = gcov_data['complete'] |
| 3580 | extracted_coverage_info = gcov_data['data'] |
| 3581 | if capture_complete: |
| 3582 | self.__class__.create_gcda_files(extracted_coverage_info) |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3583 | logger.debug("Gcov data captured: {}".format(filename)) |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3584 | else: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3585 | logger.error("Gcov data capture incomplete: {}".format(filename)) |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 3586 | |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3587 | with open(os.path.join(outdir, "coverage.log"), "a") as coveragelog: |
| 3588 | ret = self._generate(outdir, coveragelog) |
| 3589 | if ret == 0: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3590 | logger.info("HTML report generated: {}".format( |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3591 | os.path.join(outdir, "coverage", "index.html"))) |
Anas Nashif | db9592a | 2018-10-08 10:19:41 -0400 | [diff] [blame] | 3592 | |
Anas Nashif | 47cf4bf | 2019-01-24 21:50:59 -0500 | [diff] [blame] | 3593 | |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3594 | class Lcov(CoverageTool): |
| 3595 | |
| 3596 | def __init__(self): |
| 3597 | super().__init__() |
| 3598 | self.ignores = [] |
| 3599 | |
| 3600 | def add_ignore_file(self, pattern): |
| 3601 | self.ignores.append('*' + pattern + '*') |
| 3602 | |
| 3603 | def add_ignore_directory(self, pattern): |
| 3604 | self.ignores.append(pattern + '/*') |
| 3605 | |
| 3606 | def _generate(self, outdir, coveragelog): |
Jaakko Hannikainen | 54c90bc | 2016-08-31 14:17:03 +0300 | [diff] [blame] | 3607 | coveragefile = os.path.join(outdir, "coverage.info") |
| 3608 | ztestfile = os.path.join(outdir, "ztest.info") |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3609 | subprocess.call(["lcov", "--gcov-tool", self.gcov_tool, |
| 3610 | "--capture", "--directory", outdir, |
| 3611 | "--rc", "lcov_branch_coverage=1", |
| 3612 | "--output-file", coveragefile], stdout=coveragelog) |
Jaakko Hannikainen | 54c90bc | 2016-08-31 14:17:03 +0300 | [diff] [blame] | 3613 | # We want to remove tests/* and tests/ztest/test/* but save tests/ztest |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3614 | subprocess.call(["lcov", "--gcov-tool", self.gcov_tool, "--extract", |
| 3615 | coveragefile, |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3616 | os.path.join(ZEPHYR_BASE, "tests", "ztest", "*"), |
Alberto Escolar Piedras | bc101c5 | 2018-02-11 09:33:55 +0100 | [diff] [blame] | 3617 | "--output-file", ztestfile, |
| 3618 | "--rc", "lcov_branch_coverage=1"], stdout=coveragelog) |
| 3619 | |
Anas Nashif | 3cbffef | 2018-11-07 23:50:54 -0500 | [diff] [blame] | 3620 | if os.path.exists(ztestfile) and os.path.getsize(ztestfile) > 0: |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3621 | subprocess.call(["lcov", "--gcov-tool", self.gcov_tool, "--remove", |
| 3622 | ztestfile, |
Alberto Escolar Piedras | bc101c5 | 2018-02-11 09:33:55 +0100 | [diff] [blame] | 3623 | os.path.join(ZEPHYR_BASE, "tests/ztest/test/*"), |
| 3624 | "--output-file", ztestfile, |
| 3625 | "--rc", "lcov_branch_coverage=1"], |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3626 | stdout=coveragelog) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3627 | files = [coveragefile, ztestfile] |
Alberto Escolar Piedras | bc101c5 | 2018-02-11 09:33:55 +0100 | [diff] [blame] | 3628 | else: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3629 | files = [coveragefile] |
Alberto Escolar Piedras | bc101c5 | 2018-02-11 09:33:55 +0100 | [diff] [blame] | 3630 | |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3631 | for i in self.ignores: |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3632 | subprocess.call( |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3633 | ["lcov", "--gcov-tool", self.gcov_tool, "--remove", |
| 3634 | coveragefile, i, "--output-file", |
| 3635 | coveragefile, "--rc", "lcov_branch_coverage=1"], |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3636 | stdout=coveragelog) |
Alberto Escolar Piedras | bc101c5 | 2018-02-11 09:33:55 +0100 | [diff] [blame] | 3637 | |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3638 | # The --ignore-errors source option is added to avoid it exiting due to |
| 3639 | # samples/application_development/external_lib/ |
| 3640 | return subprocess.call(["genhtml", "--legend", "--branch-coverage", |
| 3641 | "--ignore-errors", "source", |
| 3642 | "-output-directory", |
| 3643 | os.path.join(outdir, "coverage")] + files, |
Alberto Escolar Piedras | bc101c5 | 2018-02-11 09:33:55 +0100 | [diff] [blame] | 3644 | stdout=coveragelog) |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 3645 | |
| 3646 | |
| 3647 | class Gcovr(CoverageTool): |
| 3648 | |
| 3649 | def __init__(self): |
| 3650 | super().__init__() |
| 3651 | self.ignores = [] |
| 3652 | |
| 3653 | def add_ignore_file(self, pattern): |
| 3654 | self.ignores.append('.*' + pattern + '.*') |
| 3655 | |
| 3656 | def add_ignore_directory(self, pattern): |
| 3657 | self.ignores.append(pattern + '/.*') |
| 3658 | |
| 3659 | @staticmethod |
| 3660 | def _interleave_list(prefix, list): |
| 3661 | tuple_list = [(prefix, item) for item in list] |
| 3662 | return [item for sublist in tuple_list for item in sublist] |
| 3663 | |
| 3664 | def _generate(self, outdir, coveragelog): |
| 3665 | coveragefile = os.path.join(outdir, "coverage.json") |
| 3666 | ztestfile = os.path.join(outdir, "ztest.json") |
| 3667 | |
| 3668 | excludes = Gcovr._interleave_list("-e", self.ignores) |
| 3669 | |
| 3670 | # We want to remove tests/* and tests/ztest/test/* but save tests/ztest |
| 3671 | subprocess.call(["gcovr", "-r", ZEPHYR_BASE, "--gcov-executable", |
| 3672 | self.gcov_tool, "-e", "tests/*"] + excludes + |
| 3673 | ["--json", "-o", coveragefile, outdir], |
| 3674 | stdout=coveragelog) |
| 3675 | |
| 3676 | subprocess.call(["gcovr", "-r", ZEPHYR_BASE, "--gcov-executable", |
| 3677 | self.gcov_tool, "-f", "tests/ztest", "-e", |
| 3678 | "tests/ztest/test/*", "--json", "-o", ztestfile, |
| 3679 | outdir], stdout=coveragelog) |
| 3680 | |
| 3681 | if os.path.exists(ztestfile) and os.path.getsize(ztestfile) > 0: |
| 3682 | files = [coveragefile, ztestfile] |
| 3683 | else: |
| 3684 | files = [coveragefile] |
| 3685 | |
| 3686 | subdir = os.path.join(outdir, "coverage") |
| 3687 | os.makedirs(subdir, exist_ok=True) |
| 3688 | |
| 3689 | tracefiles = self._interleave_list("--add-tracefile", files) |
| 3690 | |
| 3691 | return subprocess.call(["gcovr", "-r", ZEPHYR_BASE, "--html", |
| 3692 | "--html-details"] + tracefiles + |
| 3693 | ["-o", os.path.join(subdir, "index.html")], |
| 3694 | stdout=coveragelog) |
| 3695 | |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 3696 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3697 | def get_generator(): |
| 3698 | if options.ninja: |
| 3699 | generator_cmd = "ninja" |
| 3700 | generator = "Ninja" |
| 3701 | else: |
| 3702 | generator_cmd = "make" |
| 3703 | generator = "Unix Makefiles" |
| 3704 | return generator_cmd, generator |
| 3705 | |
| 3706 | |
| 3707 | def export_tests(filename, tests): |
| 3708 | with open(filename, "wt") as csvfile: |
| 3709 | fieldnames = ['section', 'subsection', 'title', 'reference'] |
| 3710 | cw = csv.DictWriter(csvfile, fieldnames, lineterminator=os.linesep) |
| 3711 | for test in tests: |
| 3712 | data = test.split(".") |
Anas Nashif | 19ca783 | 2019-11-18 08:16:21 -0800 | [diff] [blame] | 3713 | if len(data) > 1: |
| 3714 | subsec = " ".join(data[1].split("_")).title() |
| 3715 | rowdict = { |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3716 | "section": data[0].capitalize(), |
| 3717 | "subsection": subsec, |
| 3718 | "title": test, |
| 3719 | "reference": test |
| 3720 | } |
Anas Nashif | 19ca783 | 2019-11-18 08:16:21 -0800 | [diff] [blame] | 3721 | cw.writerow(rowdict) |
| 3722 | else: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3723 | logger.info("{} can't be exported".format(test)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3724 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3725 | |
| 3726 | def native_and_unit_first(a, b): |
| 3727 | if a[0].startswith('unit_testing'): |
| 3728 | return -1 |
| 3729 | if b[0].startswith('unit_testing'): |
| 3730 | return 1 |
| 3731 | if a[0].startswith('native_posix'): |
| 3732 | return -1 |
| 3733 | if b[0].startswith('native_posix'): |
| 3734 | return 1 |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3735 | if a[0].split("/", 1)[0].endswith("_bsim"): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3736 | return -1 |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3737 | if b[0].split("/", 1)[0].endswith("_bsim"): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3738 | return 1 |
| 3739 | |
| 3740 | return (a > b) - (a < b) |
| 3741 | |
| 3742 | |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3743 | class HardwareMap: |
| 3744 | manufacturer = [ |
| 3745 | 'ARM', |
| 3746 | 'SEGGER', |
| 3747 | 'MBED', |
| 3748 | 'STMicroelectronics', |
| 3749 | 'Atmel Corp.', |
| 3750 | 'Texas Instruments', |
| 3751 | 'Silicon Labs', |
Maksim Masalski | 1b4b9ef | 2019-12-18 14:48:24 +0800 | [diff] [blame] | 3752 | 'NXP Semiconductors', |
| 3753 | 'Microchip Technology Inc.', |
| 3754 | 'FTDI' |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3755 | ] |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3756 | |
| 3757 | runner_mapping = { |
| 3758 | 'pyocd': [ |
| 3759 | 'DAPLink CMSIS-DAP', |
| 3760 | 'MBED CMSIS-DAP' |
| 3761 | ], |
| 3762 | 'jlink': [ |
| 3763 | 'J-Link', |
| 3764 | 'J-Link OB' |
| 3765 | ], |
| 3766 | 'openocd': [ |
| 3767 | 'STM32 STLink', '^XDS110.*' |
Maksim Masalski | 1b4b9ef | 2019-12-18 14:48:24 +0800 | [diff] [blame] | 3768 | ], |
| 3769 | 'dediprog': [ |
| 3770 | 'TTL232R-3V3', |
| 3771 | 'MCP2200 USB Serial Port Emulator' |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3772 | ] |
| 3773 | } |
| 3774 | |
| 3775 | def __init__(self): |
| 3776 | self.detected = [] |
| 3777 | self.connected_hardware = [] |
| 3778 | |
| 3779 | def load_device_from_cmdline(self, serial, platform): |
| 3780 | device = { |
| 3781 | "serial": serial, |
| 3782 | "platform": platform, |
| 3783 | "counter": 0, |
| 3784 | "available": True, |
| 3785 | "connected": True |
| 3786 | } |
| 3787 | self.connected_hardware.append(device) |
| 3788 | |
| 3789 | def load_hardware_map(self, map_file): |
| 3790 | with open(map_file, 'r') as stream: |
| 3791 | try: |
| 3792 | self.connected_hardware = yaml.safe_load(stream) |
| 3793 | except yaml.YAMLError as exc: |
| 3794 | print(exc) |
| 3795 | for i in self.connected_hardware: |
| 3796 | i['counter'] = 0 |
| 3797 | |
| 3798 | def scan_hw(self): |
| 3799 | from serial.tools import list_ports |
| 3800 | |
| 3801 | serial_devices = list_ports.comports() |
Anas Nashif | 6d66a7a | 2019-12-08 12:11:43 -0500 | [diff] [blame] | 3802 | logger.info("Scanning connected hardware...") |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3803 | for d in serial_devices: |
| 3804 | if d.manufacturer in self.manufacturer: |
| 3805 | |
| 3806 | # TI XDS110 can have multiple serial devices for a single board |
| 3807 | # assume endpoint 0 is the serial, skip all others |
| 3808 | if d.manufacturer == 'Texas Instruments' and not d.location.endswith('0'): |
| 3809 | continue |
| 3810 | s_dev = {} |
| 3811 | s_dev['platform'] = "unknown" |
| 3812 | s_dev['id'] = d.serial_number |
| 3813 | s_dev['serial'] = d.device |
| 3814 | s_dev['product'] = d.product |
| 3815 | s_dev['runner'] = 'unknown' |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3816 | for runner, _ in self.runner_mapping.items(): |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3817 | products = self.runner_mapping.get(runner) |
| 3818 | if d.product in products: |
| 3819 | s_dev['runner'] = runner |
| 3820 | continue |
| 3821 | # Try regex matching |
| 3822 | for p in products: |
| 3823 | if re.match(p, d.product): |
| 3824 | s_dev['runner'] = runner |
| 3825 | |
| 3826 | s_dev['available'] = True |
| 3827 | s_dev['connected'] = True |
| 3828 | self.detected.append(s_dev) |
| 3829 | else: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3830 | logger.warning("Unsupported device (%s): %s" % (d.manufacturer, d)) |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3831 | |
| 3832 | def write_map(self, hwm_file): |
| 3833 | # use existing map |
| 3834 | if os.path.exists(hwm_file): |
| 3835 | with open(hwm_file, 'r') as yaml_file: |
| 3836 | hwm = yaml.load(yaml_file, Loader=yaml.FullLoader) |
| 3837 | # disconnect everything |
| 3838 | for h in hwm: |
| 3839 | h['connected'] = False |
| 3840 | h['serial'] = None |
| 3841 | |
| 3842 | for d in self.detected: |
| 3843 | for h in hwm: |
| 3844 | if d['id'] == h['id'] and d['product'] == h['product']: |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3845 | h['connected'] = True |
| 3846 | h['serial'] = d['serial'] |
| 3847 | d['match'] = True |
| 3848 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3849 | new = list(filter(lambda n: not n.get('match', False), self.detected)) |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3850 | hwm = hwm + new |
| 3851 | |
Anas Nashif | 6d66a7a | 2019-12-08 12:11:43 -0500 | [diff] [blame] | 3852 | logger.info("Registered devices:") |
Anas Nashif | 0c69c28 | 2019-12-18 10:41:27 -0500 | [diff] [blame^] | 3853 | self.dump(hwm) |
Anas Nashif | e5006d1 | 2019-12-01 11:41:22 -0500 | [diff] [blame] | 3854 | |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3855 | with open(hwm_file, 'w') as yaml_file: |
| 3856 | yaml.dump(hwm, yaml_file, default_flow_style=False) |
| 3857 | |
| 3858 | else: |
| 3859 | # create new file |
| 3860 | with open(hwm_file, 'w') as yaml_file: |
| 3861 | yaml.dump(self.detected, yaml_file, default_flow_style=False) |
Anas Nashif | 0c69c28 | 2019-12-18 10:41:27 -0500 | [diff] [blame^] | 3862 | logger.info("Detected devices:") |
| 3863 | self.dump(self.detected) |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3864 | |
Anas Nashif | 0c69c28 | 2019-12-18 10:41:27 -0500 | [diff] [blame^] | 3865 | @staticmethod |
| 3866 | def dump(hwmap=[], filtered=[], header=[], connected_only=False): |
| 3867 | print("") |
| 3868 | table = [] |
| 3869 | if not header: |
| 3870 | header = ["Platform", "ID", "Serial device"] |
| 3871 | for p in sorted(hwmap, key=lambda i: i['platform']): |
| 3872 | platform = p.get('platform') |
| 3873 | connected = p.get('connected', False) |
| 3874 | if filtered and platform not in filtered: |
| 3875 | continue |
| 3876 | |
| 3877 | if not connected_only or connected: |
| 3878 | table.append([platform, p.get('id', None), p.get('serial')]) |
| 3879 | |
| 3880 | print(tabulate(table, headers=header, tablefmt="github")) |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3881 | |
Anas Nashif | f5e5ef0 | 2019-12-06 19:20:48 -0500 | [diff] [blame] | 3882 | options = None |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3883 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3884 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 3885 | def main(): |
Andrew Boie | 4b18247 | 2015-07-31 12:25:22 -0700 | [diff] [blame] | 3886 | start_time = time.time() |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3887 | global VERBOSE |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3888 | global options |
Andrew Boie | 1578ef7 | 2019-07-03 10:19:29 -0700 | [diff] [blame] | 3889 | |
Anas Nashif | f5e5ef0 | 2019-12-06 19:20:48 -0500 | [diff] [blame] | 3890 | options = parse_arguments() |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3891 | |
| 3892 | # Cleanup |
| 3893 | if options.no_clean or options.only_failed or options.test_only: |
| 3894 | if os.path.exists(options.outdir): |
| 3895 | logger.info("Keeping artifacts untouched") |
| 3896 | elif os.path.exists(options.outdir): |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3897 | for i in range(1, 100): |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3898 | new_out = options.outdir + ".{}".format(i) |
| 3899 | if not os.path.exists(new_out): |
| 3900 | logger.info("Renaming output directory to {}".format(new_out)) |
| 3901 | shutil.move(options.outdir, new_out) |
| 3902 | break |
| 3903 | |
| 3904 | os.makedirs(options.outdir, exist_ok=True) |
| 3905 | |
| 3906 | # create file handler which logs even debug messages |
| 3907 | if options.log_file: |
| 3908 | fh = logging.FileHandler(options.log_file) |
| 3909 | else: |
| 3910 | fh = logging.FileHandler(os.path.join(options.outdir, "sanitycheck.log")) |
| 3911 | |
| 3912 | fh.setLevel(logging.DEBUG) |
| 3913 | |
| 3914 | # create console handler with a higher log level |
| 3915 | ch = logging.StreamHandler() |
| 3916 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3917 | VERBOSE += options.verbose |
| 3918 | if VERBOSE > 1: |
| 3919 | ch.setLevel(logging.DEBUG) |
| 3920 | else: |
| 3921 | ch.setLevel(logging.INFO) |
| 3922 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3923 | # create formatter and add it to the handlers |
Anas Nashif | d4cef07 | 2019-12-08 11:58:00 -0500 | [diff] [blame] | 3924 | if options.timestamps: |
| 3925 | formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') |
| 3926 | else: |
Anas Nashif | 6d66a7a | 2019-12-08 12:11:43 -0500 | [diff] [blame] | 3927 | formatter = logging.Formatter('%(levelname)-7s - %(message)s') |
Anas Nashif | d4cef07 | 2019-12-08 11:58:00 -0500 | [diff] [blame] | 3928 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3929 | formatter_file = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') |
| 3930 | ch.setFormatter(formatter) |
| 3931 | fh.setFormatter(formatter_file) |
| 3932 | |
| 3933 | # add the handlers to logger |
| 3934 | logger.addHandler(ch) |
| 3935 | logger.addHandler(fh) |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 3936 | |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3937 | hwm = HardwareMap() |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3938 | if options.generate_hardware_map: |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3939 | hwm.scan_hw() |
| 3940 | hwm.write_map(options.generate_hardware_map) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3941 | return |
| 3942 | |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3943 | if not options.device_testing and options.hardware_map: |
| 3944 | hwm.load_hardware_map(options.hardware_map) |
| 3945 | |
Anas Nashif | 6d66a7a | 2019-12-08 12:11:43 -0500 | [diff] [blame] | 3946 | logger.info("Available devices:") |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3947 | table = [] |
Anas Nashif | 0c69c28 | 2019-12-18 10:41:27 -0500 | [diff] [blame^] | 3948 | hwm.dump(hwmap=hwm.connected_hardware, connected_only=True) |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 3949 | return |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 3950 | |
Michael Scott | 421ce46 | 2019-06-18 09:37:46 -0700 | [diff] [blame] | 3951 | if options.west_runner and not options.west_flash: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3952 | logger.error("west-runner requires west-flash to be enabled") |
Michael Scott | 421ce46 | 2019-06-18 09:37:46 -0700 | [diff] [blame] | 3953 | sys.exit(1) |
| 3954 | |
Michael Scott | 4ca5439 | 2019-07-09 14:21:30 -0700 | [diff] [blame] | 3955 | if options.west_flash and not options.device_testing: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3956 | logger.error("west-flash requires device-testing to be enabled") |
Michael Scott | 4ca5439 | 2019-07-09 14:21:30 -0700 | [diff] [blame] | 3957 | sys.exit(1) |
| 3958 | |
Alberto Escolar Piedras | c026c2e | 2018-06-21 09:30:20 +0200 | [diff] [blame] | 3959 | if options.coverage: |
| 3960 | options.enable_coverage = True |
Christian Taedcke | c415a4e | 2019-11-23 23:25:36 +0100 | [diff] [blame] | 3961 | |
| 3962 | if not options.coverage_platform: |
| 3963 | options.coverage_platform = options.platform |
Alberto Escolar Piedras | c026c2e | 2018-06-21 09:30:20 +0200 | [diff] [blame] | 3964 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3965 | if options.size: |
| 3966 | for fn in options.size: |
Andrew Boie | 52fef67 | 2016-11-29 12:21:59 -0800 | [diff] [blame] | 3967 | size_report(SizeCalculator(fn, [])) |
Andrew Boie | bbd670c | 2015-08-17 13:16:11 -0700 | [diff] [blame] | 3968 | sys.exit(0) |
| 3969 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3970 | if options.subset: |
| 3971 | subset, sets = options.subset.split("/") |
Anas Nashif | 035799f | 2017-05-13 21:31:53 -0400 | [diff] [blame] | 3972 | if int(subset) > 0 and int(sets) >= int(subset): |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3973 | logger.info("Running only a subset: %s/%s" % (subset, sets)) |
Anas Nashif | 035799f | 2017-05-13 21:31:53 -0400 | [diff] [blame] | 3974 | else: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 3975 | logger.error("You have provided a wrong subset value: %s." % options.subset) |
Anas Nashif | 035799f | 2017-05-13 21:31:53 -0400 | [diff] [blame] | 3976 | return |
| 3977 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 3978 | if not options.testcase_root: |
| 3979 | options.testcase_root = [os.path.join(ZEPHYR_BASE, "tests"), |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 3980 | os.path.join(ZEPHYR_BASE, "samples")] |
Andrew Boie | 3d34871 | 2016-04-08 11:52:13 -0700 | [diff] [blame] | 3981 | |
Anas Nashif | e0d931f | 2019-12-09 15:23:43 -0500 | [diff] [blame] | 3982 | if options.show_footprint or options.compare_report or options.release: |
| 3983 | options.enable_size_report = True |
| 3984 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 3985 | suite = TestSuite(options.board_root, options.testcase_root, options.outdir) |
| 3986 | |
| 3987 | # Set testsuite options from command line. |
| 3988 | suite.build_only = options.build_only |
Anas Nashif | c5ee395 | 2019-12-10 16:38:45 -0500 | [diff] [blame] | 3989 | suite.cmake_only = options.cmake_only |
| 3990 | suite.test_only = options.test_only |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 3991 | suite.enable_slow = options.enable_slow |
| 3992 | suite.device_testing = options.device_testing |
| 3993 | suite.fixture = options.fixture |
| 3994 | suite.enable_asan = options.enable_asan |
| 3995 | suite.enable_lsan = options.enable_lsan |
| 3996 | suite.enable_coverage = options.enable_coverage |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 3997 | suite.enable_valgrind = options.enable_valgrind |
| 3998 | suite.coverage_platform = options.coverage_platform |
Anas Nashif | e9eb009 | 2019-12-10 16:31:22 -0500 | [diff] [blame] | 3999 | suite.inline_logs = options.inline_logs |
Anas Nashif | c5ee395 | 2019-12-10 16:38:45 -0500 | [diff] [blame] | 4000 | suite.enable_size_report = options.enable_size_report |
Anas Nashif | 51ae4ed | 2019-12-05 11:02:02 -0500 | [diff] [blame] | 4001 | |
| 4002 | # Set number of jobs |
| 4003 | if options.jobs: |
| 4004 | suite.jobs = options.jobs |
| 4005 | elif options.build_only: |
| 4006 | suite.jobs = multiprocessing.cpu_count() * 2 |
| 4007 | else: |
| 4008 | suite.jobs = multiprocessing.cpu_count() |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 4009 | logger.info("JOBS: %d" % suite.jobs) |
Anas Nashif | 51ae4ed | 2019-12-05 11:02:02 -0500 | [diff] [blame] | 4010 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4011 | suite.add_testcases() |
| 4012 | suite.add_configurations() |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 4013 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4014 | if options.device_testing: |
| 4015 | if options.hardware_map: |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 4016 | hwm.load_hardware_map(options.hardware_map) |
| 4017 | suite.connected_hardware = hwm.connected_hardware |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4018 | if not options.platform: |
| 4019 | options.platform = [] |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 4020 | for platform in hwm.connected_hardware: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4021 | if platform['connected']: |
| 4022 | options.platform.append(platform['platform']) |
| 4023 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 4024 | elif options.device_serial: # back-ward compatibility |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4025 | if options.platform and len(options.platform) == 1: |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 4026 | hwm.load_device_from_cmdline(options.device_serial, options.platform[0]) |
Anas Nashif | ebf8dae | 2019-12-16 09:22:21 -0500 | [diff] [blame] | 4027 | suite.connected_hardware = hwm.connected_hardware |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4028 | else: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 4029 | logger.error("""When --device-testing is used with --device-serial, only one |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4030 | platform is allowed""") |
| 4031 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4032 | if suite.load_errors: |
Kumar Gala | c84235e | 2018-04-10 13:32:51 -0500 | [diff] [blame] | 4033 | sys.exit(1) |
| 4034 | |
Anas Nashif | 75547e2 | 2018-02-24 08:32:14 -0600 | [diff] [blame] | 4035 | if options.list_tags: |
| 4036 | tags = set() |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4037 | for _, tc in suite.testcases.items(): |
Anas Nashif | 75547e2 | 2018-02-24 08:32:14 -0600 | [diff] [blame] | 4038 | tags = tags.union(tc.tags) |
| 4039 | |
| 4040 | for t in tags: |
| 4041 | print("- {}".format(t)) |
| 4042 | |
| 4043 | return |
| 4044 | |
Anas Nashif | 5d6e7eb | 2018-06-01 09:51:08 -0500 | [diff] [blame] | 4045 | if options.export_tests: |
| 4046 | cnt = 0 |
Anas Nashif | eabaa7f | 2019-11-18 07:49:17 -0800 | [diff] [blame] | 4047 | tests = suite.get_all_tests() |
Anas Nashif | 5d6e7eb | 2018-06-01 09:51:08 -0500 | [diff] [blame] | 4048 | export_tests(options.export_tests, tests) |
| 4049 | return |
| 4050 | |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 4051 | run_individual_tests = [] |
Anas Nashif | 5d6e7eb | 2018-06-01 09:51:08 -0500 | [diff] [blame] | 4052 | |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 4053 | if options.test: |
| 4054 | run_individual_tests = options.test |
| 4055 | |
Anas Nashif | 434995c | 2019-12-01 13:55:11 -0500 | [diff] [blame] | 4056 | if options.list_tests or options.test_tree or options.list_test_duplicates or options.sub_test: |
Anas Nashif | 49b22d4 | 2019-06-14 13:45:34 -0400 | [diff] [blame] | 4057 | cnt = 0 |
Anas Nashif | eabaa7f | 2019-11-18 07:49:17 -0800 | [diff] [blame] | 4058 | all_tests = suite.get_all_tests() |
Anas Nashif | 49b22d4 | 2019-06-14 13:45:34 -0400 | [diff] [blame] | 4059 | |
Anas Nashif | 19ca783 | 2019-11-18 08:16:21 -0800 | [diff] [blame] | 4060 | if options.list_test_duplicates: |
| 4061 | import collections |
| 4062 | dupes = [item for item, count in collections.Counter(all_tests).items() if count > 1] |
| 4063 | if dupes: |
| 4064 | print("Tests with duplicate identifiers:") |
| 4065 | for dupe in dupes: |
| 4066 | print("- {}".format(dupe)) |
| 4067 | for dc in suite.get_testcase(dupe): |
| 4068 | print(" - {}".format(dc)) |
| 4069 | else: |
| 4070 | print("No duplicates found.") |
| 4071 | return |
| 4072 | |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 4073 | if options.sub_test: |
Anas Nashif | d11fd78 | 2019-11-18 10:22:56 -0800 | [diff] [blame] | 4074 | for st in options.sub_test: |
| 4075 | subtests = suite.get_testcase(st) |
| 4076 | for sti in subtests: |
| 4077 | run_individual_tests.append(sti.name) |
| 4078 | |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 4079 | if run_individual_tests: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 4080 | logger.info("Running the following tests:") |
Anas Nashif | eabaa7f | 2019-11-18 07:49:17 -0800 | [diff] [blame] | 4081 | for test in run_individual_tests: |
| 4082 | print(" - {}".format(test)) |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 4083 | else: |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 4084 | logger.info("Tests not found") |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 4085 | return |
| 4086 | |
Anas Nashif | 434995c | 2019-12-01 13:55:11 -0500 | [diff] [blame] | 4087 | elif options.list_tests or options.test_tree: |
| 4088 | if options.test_tree: |
| 4089 | testsuite = Node("Testsuite") |
| 4090 | samples = Node("Samples", parent=testsuite) |
| 4091 | tests = Node("Tests", parent=testsuite) |
| 4092 | |
Anas Nashif | c1c3cc6 | 2019-12-01 13:24:33 -0500 | [diff] [blame] | 4093 | for test in sorted(all_tests): |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 4094 | cnt = cnt + 1 |
Anas Nashif | 434995c | 2019-12-01 13:55:11 -0500 | [diff] [blame] | 4095 | if options.list_tests: |
| 4096 | print(" - {}".format(test)) |
| 4097 | |
| 4098 | if options.test_tree: |
| 4099 | if test.startswith("sample."): |
| 4100 | sec = test.split(".") |
| 4101 | area = find(samples, lambda node: node.name == sec[1] and node.parent == samples) |
| 4102 | if not area: |
| 4103 | area = Node(sec[1], parent=samples) |
| 4104 | |
| 4105 | t = Node(test, parent=area) |
| 4106 | else: |
| 4107 | sec = test.split(".") |
| 4108 | area = find(tests, lambda node: node.name == sec[0] and node.parent == tests) |
| 4109 | if not area: |
| 4110 | area = Node(sec[0], parent=tests) |
| 4111 | |
| 4112 | if area and len(sec) > 2: |
| 4113 | subarea = find(area, lambda node: node.name == sec[1] and node.parent == area) |
| 4114 | if not subarea: |
| 4115 | subarea = Node(sec[1], parent=area) |
| 4116 | |
| 4117 | t = Node(test, parent=subarea) |
| 4118 | |
| 4119 | if options.list_tests: |
| 4120 | print("{} total.".format(cnt)) |
| 4121 | |
| 4122 | if options.test_tree: |
| 4123 | for pre, _, node in RenderTree(testsuite): |
| 4124 | print("%s%s" % (pre, node.name)) |
| 4125 | |
Anas Nashif | 1ea5d7b | 2018-07-12 09:25:22 -0500 | [diff] [blame] | 4126 | return |
Anas Nashif | c0149cc | 2018-04-14 23:12:58 -0500 | [diff] [blame] | 4127 | |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 4128 | discards = [] |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4129 | |
| 4130 | if options.only_failed: |
| 4131 | suite.get_last_failed() |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 4132 | suite.selected_platforms = set(p.platform.name for p in suite.instances.values()) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4133 | elif options.load_tests: |
| 4134 | suite.load_from_file(options.load_tests) |
| 4135 | elif options.test_only: |
| 4136 | last_run = os.path.join(options.outdir, "sanitycheck.csv") |
| 4137 | suite.load_from_file(last_run) |
Anas Nashif | bd166f4 | 2017-09-02 12:32:08 -0400 | [diff] [blame] | 4138 | else: |
Anas Nashif | f5e5ef0 | 2019-12-06 19:20:48 -0500 | [diff] [blame] | 4139 | discards = suite.apply_filters( |
| 4140 | build_only=options.build_only, |
| 4141 | enable_slow=options.enable_slow, |
| 4142 | platform=options.platform, |
| 4143 | arch=options.arch, |
| 4144 | tag=options.tag, |
| 4145 | exclude_tag=options.exclude_tag, |
| 4146 | force_toolchain=options.force_toolchain, |
| 4147 | all=options.all, |
| 4148 | run_individual_tests=run_individual_tests, |
| 4149 | device_testing=options.device_testing |
| 4150 | |
| 4151 | ) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 4152 | |
Anas Nashif | 30551f4 | 2018-01-12 21:56:59 -0500 | [diff] [blame] | 4153 | if VERBOSE > 1 and discards: |
Anas Nashif | f18e2ab | 2018-01-13 07:57:42 -0500 | [diff] [blame] | 4154 | # if we are using command line platform filter, no need to list every |
| 4155 | # other platform as excluded, we know that already. |
| 4156 | # Show only the discards that apply to the selected platforms on the |
| 4157 | # command line |
| 4158 | |
Andrew Boie | 08ce5a5 | 2016-02-22 13:28:10 -0800 | [diff] [blame] | 4159 | for i, reason in discards.items(): |
Anas Nashif | f18e2ab | 2018-01-13 07:57:42 -0500 | [diff] [blame] | 4160 | if options.platform and i.platform.name not in options.platform: |
| 4161 | continue |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 4162 | logger.debug( |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 4163 | "{:<25} {:<50} {}SKIPPED{}: {}".format( |
| 4164 | i.platform.name, |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4165 | i.testcase.name, |
Anas Nashif | 9744568 | 2019-12-16 09:36:40 -0500 | [diff] [blame] | 4166 | Fore.YELLOW, |
| 4167 | Fore.RESET, |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 4168 | reason)) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 4169 | |
Anas Nashif | 49b22d4 | 2019-06-14 13:45:34 -0400 | [diff] [blame] | 4170 | if options.report_excluded: |
Anas Nashif | eabaa7f | 2019-11-18 07:49:17 -0800 | [diff] [blame] | 4171 | all_tests = suite.get_all_tests() |
Anas Nashif | 49b22d4 | 2019-06-14 13:45:34 -0400 | [diff] [blame] | 4172 | to_be_run = set() |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 4173 | for i, p in suite.instances.items(): |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4174 | to_be_run.update(p.testcase.cases) |
Anas Nashif | 49b22d4 | 2019-06-14 13:45:34 -0400 | [diff] [blame] | 4175 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4176 | if all_tests - to_be_run: |
Anas Nashif | 49b22d4 | 2019-06-14 13:45:34 -0400 | [diff] [blame] | 4177 | print("Tests that never build or run:") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4178 | for not_run in all_tests - to_be_run: |
Anas Nashif | 49b22d4 | 2019-06-14 13:45:34 -0400 | [diff] [blame] | 4179 | print("- {}".format(not_run)) |
| 4180 | |
| 4181 | return |
| 4182 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 4183 | if options.subset: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 4184 | # suite.instances = OrderedDict(sorted(suite.instances.items(), |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4185 | # key=cmp_to_key(native_and_unit_first))) |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 4186 | subset, sets = options.subset.split("/") |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4187 | total = len(suite.instances) |
Anas Nashif | 035799f | 2017-05-13 21:31:53 -0400 | [diff] [blame] | 4188 | per_set = round(total / int(sets)) |
Anas Nashif | 3ba1d43 | 2017-12-05 15:28:44 -0500 | [diff] [blame] | 4189 | start = (int(subset) - 1) * per_set |
Anas Nashif | 035799f | 2017-05-13 21:31:53 -0400 | [diff] [blame] | 4190 | if subset == sets: |
| 4191 | end = total |
| 4192 | else: |
| 4193 | end = start + per_set |
| 4194 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4195 | sliced_instances = islice(suite.instances.items(), start, end) |
| 4196 | suite.instances = OrderedDict(sliced_instances) |
Anas Nashif | 035799f | 2017-05-13 21:31:53 -0400 | [diff] [blame] | 4197 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4198 | if options.save_tests: |
| 4199 | suite.csv_report(options.save_tests) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 4200 | return |
| 4201 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 4202 | logger.info("%d test configurations selected, %d configurations discarded due to filters." % |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 4203 | (len(suite.instances), len(discards))) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4204 | |
Peter Bigot | 3d46ea5 | 2019-11-21 12:00:18 -0600 | [diff] [blame] | 4205 | if options.device_testing: |
| 4206 | print("\nDevice testing on:") |
Anas Nashif | 0c69c28 | 2019-12-18 10:41:27 -0500 | [diff] [blame^] | 4207 | hwm.dump(suite.connected_hardware, suite.selected_platforms) |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 4208 | print("") |
Peter Bigot | 3d46ea5 | 2019-11-21 12:00:18 -0600 | [diff] [blame] | 4209 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4210 | if options.dry_run: |
| 4211 | duration = time.time() - start_time |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 4212 | logger.info("Completed in %d seconds" % (duration)) |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4213 | return |
| 4214 | |
| 4215 | retries = options.retry_failed + 1 |
| 4216 | completed = 0 |
| 4217 | |
| 4218 | suite.update() |
| 4219 | suite.start_time = start_time |
| 4220 | |
| 4221 | while True: |
| 4222 | completed += 1 |
| 4223 | |
| 4224 | if completed > 1: |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 4225 | logger.info("%d Iteration:" % (completed)) |
| 4226 | time.sleep(60) # waiting for the system to settle down |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4227 | suite.total_done = suite.total_tests - suite.total_failed |
| 4228 | suite.total_failed = 0 |
| 4229 | |
Anas Nashif | c5ee395 | 2019-12-10 16:38:45 -0500 | [diff] [blame] | 4230 | suite.execute() |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 4231 | print("") |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 4232 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4233 | retries = retries - 1 |
| 4234 | if retries == 0 or suite.total_failed == 0: |
| 4235 | break |
Anas Nashif | e0a6a0b | 2018-02-15 20:07:24 -0600 | [diff] [blame] | 4236 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4237 | suite.misc_reports(options.compare_report, options.show_footprint, |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 4238 | options.all_deltas, options.footprint_threshold, options.last_metrics) |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 4239 | |
Anas Nashif | 83a98e5 | 2019-11-24 07:42:06 -0500 | [diff] [blame] | 4240 | suite.duration = time.time() - start_time |
| 4241 | suite.summary(options.disable_unrecognized_section_test) |
| 4242 | |
Anas Nashif | e10b651 | 2017-12-30 13:01:45 -0500 | [diff] [blame] | 4243 | if options.coverage: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4244 | if options.gcov_tool is None: |
Alberto Escolar Piedras | af30f2b | 2019-09-12 14:44:08 +0200 | [diff] [blame] | 4245 | use_system_gcov = False |
Andrew Boie | 49cf486 | 2019-07-08 12:02:13 -0700 | [diff] [blame] | 4246 | |
| 4247 | for plat in options.coverage_platform: |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4248 | ts_plat = suite.get_platform(plat) |
Alberto Escolar Piedras | af30f2b | 2019-09-12 14:44:08 +0200 | [diff] [blame] | 4249 | if ts_plat and (ts_plat.type in {"native", "unit"}): |
| 4250 | use_system_gcov = True |
Andrew Boie | 49cf486 | 2019-07-08 12:02:13 -0700 | [diff] [blame] | 4251 | |
Alberto Escolar Piedras | af30f2b | 2019-09-12 14:44:08 +0200 | [diff] [blame] | 4252 | if use_system_gcov or "ZEPHYR_SDK_INSTALL_DIR" not in os.environ: |
Andrew Boie | 49cf486 | 2019-07-08 12:02:13 -0700 | [diff] [blame] | 4253 | options.gcov_tool = "gcov" |
| 4254 | else: |
| 4255 | options.gcov_tool = os.path.join(os.environ["ZEPHYR_SDK_INSTALL_DIR"], |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 4256 | "i586-zephyr-elf/bin/i586-zephyr-elf-gcov") |
Andrew Boie | 49cf486 | 2019-07-08 12:02:13 -0700 | [diff] [blame] | 4257 | |
Anas Nashif | 7a361b8 | 2019-12-06 11:37:40 -0500 | [diff] [blame] | 4258 | logger.info("Generating coverage files...") |
Christian Taedcke | ed22c5e | 2019-11-23 16:47:33 +0100 | [diff] [blame] | 4259 | coverage_tool = CoverageTool.factory(options.coverage_tool) |
| 4260 | coverage_tool.add_ignore_file('generated') |
| 4261 | coverage_tool.add_ignore_directory('tests') |
| 4262 | coverage_tool.add_ignore_directory('samples') |
| 4263 | coverage_tool.generate(options.outdir) |
Jaakko Hannikainen | 54c90bc | 2016-08-31 14:17:03 +0300 | [diff] [blame] | 4264 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4265 | if options.device_testing: |
| 4266 | print("\nHardware distribution summary:\n") |
Anas Nashif | 5f90882 | 2019-11-25 08:19:25 -0500 | [diff] [blame] | 4267 | table = [] |
| 4268 | header = ['Board', 'ID', 'Counter'] |
| 4269 | for p in hwm.connected_hardware: |
| 4270 | if p['connected'] and p['platform'] in suite.selected_platforms: |
| 4271 | row = [p['platform'], p.get('id', None), p['counter']] |
| 4272 | table.append(row) |
| 4273 | print(tabulate(table, headers=header, tablefmt="github")) |
| 4274 | |
Anas Nashif | 5665684 | 2019-12-10 12:26:00 -0500 | [diff] [blame] | 4275 | suite.save_reports(options.report_name, |
| 4276 | options.report_dir, |
| 4277 | options.no_update, |
| 4278 | options.release, |
| 4279 | options.only_failed) |
| 4280 | |
Anas Nashif | 83fc06a | 2019-06-22 11:04:10 -0400 | [diff] [blame] | 4281 | if suite.total_failed or (suite.warnings and options.warnings_as_errors): |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 4282 | sys.exit(1) |
| 4283 | |
Anas Nashif | d988238 | 2019-12-12 09:58:28 -0500 | [diff] [blame] | 4284 | |
Andrew Boie | 6acbe63 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 4285 | if __name__ == "__main__": |
| 4286 | main() |