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