2016-02-22 22:28:10 +01:00
|
|
|
#!/usr/bin/env python3
|
2017-04-05 00:47:49 +02:00
|
|
|
# vim: set syntax=python ts=4 :
|
2019-04-06 15:08:09 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2015-07-17 21:03:52 +02:00
|
|
|
"""Zephyr Sanity Tests
|
|
|
|
|
|
|
|
This script scans for the set of unit test applications in the git
|
|
|
|
repository and attempts to execute them. By default, it tries to
|
|
|
|
build each test case on one platform per architecture, using a precedence
|
2017-06-16 00:31:54 +02:00
|
|
|
list defined in an architecture configuration file, and if possible
|
2015-07-17 21:03:52 +02:00
|
|
|
run the tests in the QEMU emulator.
|
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
Test cases are detected by the presence of a 'testcase.yaml' or a sample.yaml
|
|
|
|
files in the application's project directory. This file may contain one or more
|
|
|
|
blocks, each identifying a test scenario. The title of the block is a name for
|
|
|
|
the test case, which only needs to be unique for the test cases specified in
|
|
|
|
that testcase meta-data. The full canonical name for each test case is <path to
|
|
|
|
test case>/<block>.
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
Each test block in the testcase meta data can define the following key/value
|
|
|
|
pairs:
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-10-04 22:14:27 +02:00
|
|
|
tags: <list of tags> (required)
|
2015-07-17 21:03:52 +02:00
|
|
|
A set of string tags for the testcase. Usually pertains to
|
|
|
|
functional domains but can be anything. Command line invocations
|
|
|
|
of this script can filter the set of tests to run based on tag.
|
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
skip: <True|False> (default False)
|
2015-10-12 19:10:57 +02:00
|
|
|
skip testcase unconditionally. This can be used for broken tests.
|
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
slow: <True|False> (default False)
|
2019-01-03 23:17:43 +01:00
|
|
|
Don't build or run this test case unless --enable-slow was passed
|
|
|
|
in on the command line. Intended for time-consuming test cases
|
|
|
|
that are only run under certain circumstances, like daily
|
|
|
|
builds.
|
2016-02-10 22:39:00 +01:00
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
extra_args: <list of extra arguments>
|
2017-11-09 12:25:02 +01:00
|
|
|
Extra cache entries to pass to CMake when building or running the
|
2015-07-17 21:03:52 +02:00
|
|
|
test case.
|
|
|
|
|
2017-10-17 15:00:33 +02:00
|
|
|
extra_configs: <list of extra configurations>
|
|
|
|
Extra configuration options to be merged with a master prj.conf
|
|
|
|
when building or running the test case.
|
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
build_only: <True|False> (default False)
|
2015-07-17 21:03:52 +02:00
|
|
|
If true, don't try to run the test under QEMU even if the
|
|
|
|
selected platform supports it.
|
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
build_on_all: <True|False> (default False)
|
|
|
|
If true, attempt to build test on all available platforms.
|
|
|
|
|
|
|
|
depends_on: <list of features>
|
|
|
|
A board or platform can announce what features it supports, this option
|
|
|
|
will enable the test only those platforms that provide this feature.
|
|
|
|
|
|
|
|
min_ram: <integer>
|
|
|
|
minimum amount of RAM needed for this test to build and run. This is
|
|
|
|
compared with information provided by the board metadata.
|
|
|
|
|
|
|
|
min_flash: <integer>
|
|
|
|
minimum amount of ROM needed for this test to build and run. This is
|
|
|
|
compared with information provided by the board metadata.
|
|
|
|
|
|
|
|
timeout: <number of seconds>
|
2015-07-17 21:03:52 +02:00
|
|
|
Length of time to run test in QEMU before automatically killing it.
|
|
|
|
Default to 60 seconds.
|
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
arch_whitelist: <list of arches, such as x86, arm, arc>
|
2015-07-17 21:03:52 +02:00
|
|
|
Set of architectures that this test case should only be run for.
|
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
arch_exclude: <list of arches, such as x86, arm, arc>
|
2015-10-05 16:02:45 +02:00
|
|
|
Set of architectures that this test case should not run on.
|
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
platform_whitelist: <list of platforms>
|
2015-10-05 16:02:45 +02:00
|
|
|
Set of platforms that this test case should only be run for.
|
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
platform_exclude: <list of platforms>
|
2015-10-05 16:02:45 +02:00
|
|
|
Set of platforms that this test case should not run on.
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
extra_sections: <list of extra binary sections>
|
2016-11-29 21:21:59 +01:00
|
|
|
When computing sizes, sanitycheck will report errors if it finds
|
|
|
|
extra, unexpected sections in the Zephyr binary unless they are named
|
|
|
|
here. They will not be included in the size calculation.
|
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
filter: <expression>
|
2016-03-24 22:46:00 +01:00
|
|
|
Filter whether the testcase should be run by evaluating an expression
|
|
|
|
against an environment containing the following values:
|
|
|
|
|
|
|
|
{ ARCH : <architecture>,
|
|
|
|
PLATFORM : <platform>,
|
2016-08-08 19:24:59 +02:00
|
|
|
<all CONFIG_* key/value pairs in the test's generated defconfig>,
|
2019-01-09 14:46:42 +01:00
|
|
|
<all DT_* key/value pairs in the test's generated device tree file>,
|
|
|
|
<all CMake key/value pairs in the test's generated CMakeCache.txt file>,
|
2016-08-08 19:24:59 +02:00
|
|
|
*<env>: any environment variable available
|
2016-03-24 22:46:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
The grammar for the expression language is as follows:
|
|
|
|
|
|
|
|
expression ::= expression "and" expression
|
|
|
|
| expression "or" expression
|
|
|
|
| "not" expression
|
|
|
|
| "(" expression ")"
|
|
|
|
| symbol "==" constant
|
|
|
|
| symbol "!=" constant
|
|
|
|
| symbol "<" number
|
|
|
|
| symbol ">" number
|
|
|
|
| symbol ">=" number
|
|
|
|
| symbol "<=" number
|
|
|
|
| symbol "in" list
|
2016-06-02 21:27:54 +02:00
|
|
|
| symbol ":" string
|
2016-03-24 22:46:00 +01:00
|
|
|
| symbol
|
|
|
|
|
|
|
|
list ::= "[" list_contents "]"
|
|
|
|
|
|
|
|
list_contents ::= constant
|
|
|
|
| list_contents "," constant
|
|
|
|
|
|
|
|
constant ::= number
|
|
|
|
| string
|
|
|
|
|
|
|
|
|
|
|
|
For the case where expression ::= symbol, it evaluates to true
|
|
|
|
if the symbol is defined to a non-empty string.
|
|
|
|
|
|
|
|
Operator precedence, starting from lowest to highest:
|
|
|
|
|
|
|
|
or (left associative)
|
|
|
|
and (left associative)
|
|
|
|
not (right associative)
|
|
|
|
all comparison operators (non-associative)
|
|
|
|
|
|
|
|
arch_whitelist, arch_exclude, platform_whitelist, platform_exclude
|
|
|
|
are all syntactic sugar for these expressions. For instance
|
|
|
|
|
|
|
|
arch_exclude = x86 arc
|
|
|
|
|
|
|
|
Is the same as:
|
|
|
|
|
|
|
|
filter = not ARCH in ["x86", "arc"]
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2016-06-02 21:27:54 +02:00
|
|
|
The ':' operator compiles the string argument as a regular expression,
|
|
|
|
and then returns a true value only if the symbol's value in the environment
|
|
|
|
matches. For example, if CONFIG_SOC="quark_se" then
|
|
|
|
|
|
|
|
filter = CONFIG_SOC : "quark.*"
|
|
|
|
|
|
|
|
Would match it.
|
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
The set of test cases that actually run depends on directives in the testcase
|
|
|
|
filed and options passed in on the command line. If there is any confusion,
|
|
|
|
running with -v or --discard-report can help show why particular test cases
|
|
|
|
were skipped.
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
Metrics (such as pass/fail state and binary size) for the last code
|
|
|
|
release are stored in scripts/sanity_chk/sanity_last_release.csv.
|
|
|
|
To update this, pass the --all --release options.
|
|
|
|
|
2016-10-25 01:00:58 +02:00
|
|
|
To load arguments from a file, write '+' before the file name, e.g.,
|
|
|
|
+file_name. File content must be one or more valid arguments separated by
|
|
|
|
line break instead of white spaces.
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
Most everyday users will run with no arguments.
|
2019-01-03 23:17:43 +01:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
"""
|
|
|
|
|
2019-01-21 15:48:46 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
if os.name == 'nt':
|
|
|
|
print("Running sanitycheck on Windows is not supported yet.")
|
|
|
|
print("https://github.com/zephyrproject-rtos/zephyr/issues/2664")
|
|
|
|
exit(1)
|
|
|
|
|
2018-04-22 05:26:48 +02:00
|
|
|
import contextlib
|
2018-10-15 15:45:59 +02:00
|
|
|
import string
|
2018-04-22 05:26:48 +02:00
|
|
|
import mmap
|
2015-07-17 21:03:52 +02:00
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import multiprocessing
|
|
|
|
import select
|
|
|
|
import shutil
|
|
|
|
import signal
|
|
|
|
import threading
|
|
|
|
import time
|
2019-04-11 14:38:21 +02:00
|
|
|
import datetime
|
2015-07-17 21:03:52 +02:00
|
|
|
import csv
|
2015-10-02 19:04:56 +02:00
|
|
|
import glob
|
2018-02-19 17:57:03 +01:00
|
|
|
import serial
|
2016-04-07 21:10:25 +02:00
|
|
|
import concurrent
|
|
|
|
import concurrent.futures
|
2017-04-13 20:44:48 +02:00
|
|
|
import xml.etree.ElementTree as ET
|
2017-05-17 15:29:09 +02:00
|
|
|
from xml.sax.saxutils import escape
|
2017-05-14 03:31:53 +02:00
|
|
|
from collections import OrderedDict
|
|
|
|
from itertools import islice
|
2018-01-05 14:07:45 +01:00
|
|
|
from functools import cmp_to_key
|
2018-07-11 22:09:22 +02:00
|
|
|
from pathlib import Path
|
|
|
|
from distutils.spawn import find_executable
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-07-24 19:24:35 +02:00
|
|
|
import logging
|
2017-12-05 21:28:44 +01:00
|
|
|
from sanity_chk import scl
|
|
|
|
from sanity_chk import expr_parser
|
|
|
|
|
2017-07-24 19:24:35 +02:00
|
|
|
log_format = "%(levelname)s %(name)s::%(module)s.%(funcName)s():%(lineno)d: %(message)s"
|
2017-12-05 21:28:44 +01:00
|
|
|
logging.basicConfig(format=log_format, level=30)
|
2017-07-24 19:24:35 +02:00
|
|
|
|
2018-08-17 13:54:41 +02:00
|
|
|
ZEPHYR_BASE = os.environ.get("ZEPHYR_BASE")
|
|
|
|
if not ZEPHYR_BASE:
|
2015-08-06 13:25:42 +02:00
|
|
|
sys.stderr.write("$ZEPHYR_BASE environment variable undefined.\n")
|
2015-07-17 21:03:52 +02:00
|
|
|
exit(1)
|
2017-07-24 19:24:35 +02:00
|
|
|
|
2016-03-24 22:46:00 +01:00
|
|
|
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/"))
|
|
|
|
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
VERBOSE = 0
|
|
|
|
LAST_SANITY = os.path.join(ZEPHYR_BASE, "scripts", "sanity_chk",
|
|
|
|
"last_sanity.csv")
|
2017-04-13 20:44:48 +02:00
|
|
|
LAST_SANITY_XUNIT = os.path.join(ZEPHYR_BASE, "scripts", "sanity_chk",
|
2017-12-05 21:28:44 +01:00
|
|
|
"last_sanity.xml")
|
2015-07-17 21:03:52 +02:00
|
|
|
RELEASE_DATA = os.path.join(ZEPHYR_BASE, "scripts", "sanity_chk",
|
|
|
|
"sanity_last_release.csv")
|
2018-08-17 17:31:38 +02:00
|
|
|
JOBS = multiprocessing.cpu_count() * 2
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
if os.isatty(sys.stdout.fileno()):
|
|
|
|
TERMINAL = True
|
|
|
|
COLOR_NORMAL = '\033[0m'
|
|
|
|
COLOR_RED = '\033[91m'
|
|
|
|
COLOR_GREEN = '\033[92m'
|
|
|
|
COLOR_YELLOW = '\033[93m'
|
|
|
|
else:
|
|
|
|
TERMINAL = False
|
|
|
|
COLOR_NORMAL = ""
|
|
|
|
COLOR_RED = ""
|
|
|
|
COLOR_GREEN = ""
|
|
|
|
COLOR_YELLOW = ""
|
|
|
|
|
2019-01-09 14:46:42 +01:00
|
|
|
class CMakeCacheEntry:
|
|
|
|
'''Represents a CMake cache entry.
|
|
|
|
|
|
|
|
This class understands the type system in a CMakeCache.txt, and
|
|
|
|
converts the following cache types to Python types:
|
|
|
|
|
|
|
|
Cache Type Python type
|
|
|
|
---------- -------------------------------------------
|
|
|
|
FILEPATH str
|
|
|
|
PATH str
|
|
|
|
STRING str OR list of str (if ';' is in the value)
|
|
|
|
BOOL bool
|
|
|
|
INTERNAL str OR list of str (if ';' is in the value)
|
|
|
|
---------- -------------------------------------------
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Regular expression for a cache entry.
|
|
|
|
#
|
|
|
|
# CMake variable names can include escape characters, allowing a
|
|
|
|
# wider set of names than is easy to match with a regular
|
|
|
|
# expression. To be permissive here, use a non-greedy match up to
|
|
|
|
# the first colon (':'). This breaks if the variable name has a
|
|
|
|
# colon inside, but it's good enough.
|
|
|
|
CACHE_ENTRY = re.compile(
|
|
|
|
r'''(?P<name>.*?) # name
|
|
|
|
:(?P<type>FILEPATH|PATH|STRING|BOOL|INTERNAL) # type
|
|
|
|
=(?P<value>.*) # value
|
|
|
|
''', re.X)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def _to_bool(cls, val):
|
|
|
|
# Convert a CMake BOOL string into a Python bool.
|
|
|
|
#
|
|
|
|
# "True if the constant is 1, ON, YES, TRUE, Y, or a
|
|
|
|
# non-zero number. False if the constant is 0, OFF, NO,
|
|
|
|
# FALSE, N, IGNORE, NOTFOUND, the empty string, or ends in
|
|
|
|
# the suffix -NOTFOUND. Named boolean constants are
|
|
|
|
# case-insensitive. If the argument is not one of these
|
|
|
|
# constants, it is treated as a variable."
|
|
|
|
#
|
|
|
|
# https://cmake.org/cmake/help/v3.0/command/if.html
|
|
|
|
val = val.upper()
|
|
|
|
if val in ('ON', 'YES', 'TRUE', 'Y'):
|
|
|
|
return 1
|
|
|
|
elif val in ('OFF', 'NO', 'FALSE', 'N', 'IGNORE', 'NOTFOUND', ''):
|
|
|
|
return 0
|
|
|
|
elif val.endswith('-NOTFOUND'):
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
v = int(val)
|
|
|
|
return v != 0
|
|
|
|
except ValueError as exc:
|
|
|
|
raise ValueError('invalid bool {}'.format(val)) from exc
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def from_line(cls, line, line_no):
|
|
|
|
# Comments can only occur at the beginning of a line.
|
|
|
|
# (The value of an entry could contain a comment character).
|
|
|
|
if line.startswith('//') or line.startswith('#'):
|
|
|
|
return None
|
|
|
|
|
|
|
|
# Whitespace-only lines do not contain cache entries.
|
|
|
|
if not line.strip():
|
|
|
|
return None
|
|
|
|
|
|
|
|
m = cls.CACHE_ENTRY.match(line)
|
|
|
|
if not m:
|
|
|
|
return None
|
|
|
|
|
|
|
|
name, type_, value = (m.group(g) for g in ('name', 'type', 'value'))
|
|
|
|
if type_ == 'BOOL':
|
|
|
|
try:
|
|
|
|
value = cls._to_bool(value)
|
|
|
|
except ValueError as exc:
|
|
|
|
args = exc.args + ('on line {}: {}'.format(line_no, line),)
|
|
|
|
raise ValueError(args) from exc
|
|
|
|
elif type_ == 'STRING' or type_ == 'INTERNAL':
|
|
|
|
# If the value is a CMake list (i.e. is a string which
|
|
|
|
# contains a ';'), convert to a Python list.
|
|
|
|
if ';' in value:
|
|
|
|
value = value.split(';')
|
|
|
|
|
|
|
|
return CMakeCacheEntry(name, value)
|
|
|
|
|
|
|
|
def __init__(self, name, value):
|
|
|
|
self.name = name
|
|
|
|
self.value = value
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
fmt = 'CMakeCacheEntry(name={}, value={})'
|
|
|
|
return fmt.format(self.name, self.value)
|
|
|
|
|
|
|
|
|
|
|
|
class CMakeCache:
|
|
|
|
'''Parses and represents a CMake cache file.'''
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def from_file(cache_file):
|
|
|
|
return CMakeCache(cache_file)
|
|
|
|
|
|
|
|
def __init__(self, cache_file):
|
|
|
|
self.cache_file = cache_file
|
|
|
|
self.load(cache_file)
|
|
|
|
|
|
|
|
def load(self, cache_file):
|
|
|
|
entries = []
|
|
|
|
with open(cache_file, 'r') as cache:
|
|
|
|
for line_no, line in enumerate(cache):
|
|
|
|
entry = CMakeCacheEntry.from_line(line, line_no)
|
|
|
|
if entry:
|
|
|
|
entries.append(entry)
|
|
|
|
self._entries = OrderedDict((e.name, e) for e in entries)
|
|
|
|
|
|
|
|
def get(self, name, default=None):
|
|
|
|
entry = self._entries.get(name)
|
|
|
|
if entry is not None:
|
|
|
|
return entry.value
|
|
|
|
else:
|
|
|
|
return default
|
|
|
|
|
|
|
|
def get_list(self, name, default=None):
|
|
|
|
if default is None:
|
|
|
|
default = []
|
|
|
|
entry = self._entries.get(name)
|
|
|
|
if entry is not None:
|
|
|
|
value = entry.value
|
|
|
|
if isinstance(value, list):
|
|
|
|
return value
|
|
|
|
elif isinstance(value, str):
|
|
|
|
return [value] if value else []
|
|
|
|
else:
|
|
|
|
msg = 'invalid value {} type {}'
|
|
|
|
raise RuntimeError(msg.format(value, type(value)))
|
|
|
|
else:
|
|
|
|
return default
|
|
|
|
|
|
|
|
def __contains__(self, name):
|
|
|
|
return name in self._entries
|
|
|
|
|
|
|
|
def __getitem__(self, name):
|
|
|
|
return self._entries[name].value
|
|
|
|
|
|
|
|
def __setitem__(self, name, entry):
|
|
|
|
if not isinstance(entry, CMakeCacheEntry):
|
|
|
|
msg = 'improper type {} for value {}, expecting CMakeCacheEntry'
|
|
|
|
raise TypeError(msg.format(type(entry), entry))
|
|
|
|
self._entries[name] = entry
|
|
|
|
|
|
|
|
def __delitem__(self, name):
|
|
|
|
del self._entries[name]
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return iter(self._entries.values())
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
class SanityCheckException(Exception):
|
|
|
|
pass
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
class SanityRuntimeError(SanityCheckException):
|
|
|
|
pass
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
class ConfigurationError(SanityCheckException):
|
|
|
|
def __init__(self, cfile, message):
|
|
|
|
self.cfile = cfile
|
|
|
|
self.message = message
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return repr(self.cfile + ": " + self.message)
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
class MakeError(SanityCheckException):
|
|
|
|
pass
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
class BuildError(MakeError):
|
|
|
|
pass
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
class ExecutionError(MakeError):
|
|
|
|
pass
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2016-11-29 19:43:40 +01:00
|
|
|
log_file = None
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
# Debug Functions
|
2019-04-11 14:38:21 +02:00
|
|
|
def info(what, show_time=True):
|
|
|
|
if options.timestamps and show_time:
|
|
|
|
date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
what = "{}: {}".format(date, what)
|
2016-02-22 22:28:10 +01:00
|
|
|
sys.stdout.write(what + "\n")
|
2017-10-27 13:53:24 +02:00
|
|
|
sys.stdout.flush()
|
2016-11-29 19:43:40 +01:00
|
|
|
if log_file:
|
|
|
|
log_file.write(what + "\n")
|
|
|
|
log_file.flush()
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
def error(what):
|
2019-04-11 14:38:21 +02:00
|
|
|
if options.timestamps:
|
|
|
|
date = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
|
|
|
|
what = "{}: {}".format(date, what)
|
2015-07-17 21:03:52 +02:00
|
|
|
sys.stderr.write(COLOR_RED + what + COLOR_NORMAL + "\n")
|
2016-11-29 19:43:40 +01:00
|
|
|
if log_file:
|
|
|
|
log_file(what + "\n")
|
|
|
|
log_file.flush()
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2016-02-22 22:28:10 +01:00
|
|
|
def debug(what):
|
|
|
|
if VERBOSE >= 1:
|
|
|
|
info(what)
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
def verbose(what):
|
|
|
|
if VERBOSE >= 2:
|
2016-02-22 22:28:10 +01:00
|
|
|
info(what)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-24 02:20:27 +01:00
|
|
|
class HarnessImporter:
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2017-12-24 02:20:27 +01:00
|
|
|
def __init__(self, name):
|
|
|
|
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/sanity_chk"))
|
|
|
|
module = __import__("harness")
|
|
|
|
if name:
|
|
|
|
my_class = getattr(module, name)
|
|
|
|
else:
|
|
|
|
my_class = getattr(module, "Test")
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2017-12-24 02:20:27 +01:00
|
|
|
self.instance = my_class()
|
|
|
|
|
|
|
|
class Handler:
|
|
|
|
def __init__(self, instance):
|
2016-08-22 14:03:46 +02:00
|
|
|
"""Constructor
|
|
|
|
|
|
|
|
@param name Arbitrary name of the created thread
|
2017-11-25 23:20:07 +01:00
|
|
|
@param outdir Working directory, should be where handler pid file (qemu.pid for example)
|
|
|
|
gets created by the build system
|
|
|
|
@param log_fn Absolute path to write out handler's log data
|
|
|
|
@param timeout Kill the handler process if it doesn't finish up within
|
2016-08-22 14:03:46 +02:00
|
|
|
the given number of seconds
|
|
|
|
"""
|
|
|
|
self.lock = threading.Lock()
|
|
|
|
self.state = "waiting"
|
2018-07-07 01:20:23 +02:00
|
|
|
self.run = False
|
2016-08-22 14:03:46 +02:00
|
|
|
self.metrics = {}
|
2017-11-25 23:14:12 +01:00
|
|
|
self.metrics["handler_time"] = 0
|
2016-08-22 14:03:46 +02:00
|
|
|
self.metrics["ram_size"] = 0
|
|
|
|
self.metrics["rom_size"] = 0
|
|
|
|
|
2018-07-07 13:09:01 +02:00
|
|
|
self.binary = None
|
2019-01-07 16:40:24 +01:00
|
|
|
self.pid_fn = None
|
2018-07-07 15:45:53 +02:00
|
|
|
self.call_make_run = False
|
2018-07-07 13:09:01 +02:00
|
|
|
|
2018-02-22 13:44:16 +01:00
|
|
|
self.name = instance.name
|
|
|
|
self.instance = instance
|
|
|
|
self.timeout = instance.test.timeout
|
2018-11-20 15:03:17 +01:00
|
|
|
self.sourcedir = instance.test.test_path
|
2018-02-22 13:44:16 +01:00
|
|
|
self.outdir = instance.outdir
|
2018-07-07 01:58:18 +02:00
|
|
|
self.log = os.path.join(self.outdir, "handler.log")
|
2018-02-22 13:44:16 +01:00
|
|
|
self.returncode = 0
|
|
|
|
self.set_state("running", {})
|
|
|
|
|
2016-08-22 14:03:46 +02:00
|
|
|
def set_state(self, state, metrics):
|
|
|
|
self.lock.acquire()
|
|
|
|
self.state = state
|
|
|
|
self.metrics.update(metrics)
|
|
|
|
self.lock.release()
|
|
|
|
|
|
|
|
def get_state(self):
|
|
|
|
self.lock.acquire()
|
|
|
|
ret = (self.state, self.metrics)
|
|
|
|
self.lock.release()
|
|
|
|
return ret
|
|
|
|
|
2018-07-07 13:09:01 +02:00
|
|
|
class BinaryHandler(Handler):
|
|
|
|
def __init__(self, instance):
|
|
|
|
"""Constructor
|
|
|
|
|
|
|
|
@param instance Test Instance
|
|
|
|
"""
|
|
|
|
super().__init__(instance)
|
|
|
|
|
|
|
|
self.valgrind = False
|
2018-12-11 15:13:05 +01:00
|
|
|
self.terminated = False
|
2018-07-07 13:09:01 +02:00
|
|
|
|
2019-01-07 16:40:24 +01:00
|
|
|
def try_kill_process_by_pid(self):
|
|
|
|
if self.pid_fn != None:
|
|
|
|
pid = int(open(self.pid_fn).read())
|
|
|
|
os.unlink(self.pid_fn)
|
|
|
|
self.pid_fn = None # clear so we don't try to kill the binary twice
|
|
|
|
try:
|
|
|
|
os.kill(pid, signal.SIGTERM)
|
|
|
|
except ProcessLookupError:
|
|
|
|
pass
|
|
|
|
|
2018-07-07 13:09:01 +02:00
|
|
|
def _output_reader(self, proc, harness):
|
|
|
|
log_out_fp = open(self.log, "wt")
|
|
|
|
for line in iter(proc.stdout.readline, b''):
|
|
|
|
verbose("OUTPUT: {0}".format(line.decode('utf-8').rstrip()))
|
|
|
|
log_out_fp.write(line.decode('utf-8'))
|
|
|
|
log_out_fp.flush()
|
|
|
|
harness.handle(line.decode('utf-8').rstrip())
|
|
|
|
if harness.state:
|
2018-12-11 15:13:05 +01:00
|
|
|
try:
|
|
|
|
#POSIX arch based ztests end on their own,
|
|
|
|
#so let's give it up to 100ms to do so
|
|
|
|
proc.wait(0.1)
|
|
|
|
except subprocess.TimeoutExpired:
|
|
|
|
proc.terminate()
|
|
|
|
self.terminated = True
|
2018-07-07 13:09:01 +02:00
|
|
|
break
|
|
|
|
|
|
|
|
log_out_fp.close()
|
|
|
|
|
|
|
|
def handle(self):
|
|
|
|
|
|
|
|
harness_name = self.instance.test.harness.capitalize()
|
|
|
|
harness_import = HarnessImporter(harness_name)
|
|
|
|
harness = harness_import.instance
|
|
|
|
harness.configure(self.instance)
|
|
|
|
|
2018-07-07 15:45:53 +02:00
|
|
|
if self.call_make_run:
|
|
|
|
if options.ninja:
|
|
|
|
generator_cmd = "ninja"
|
|
|
|
else:
|
|
|
|
generator_cmd = "make"
|
|
|
|
command = [generator_cmd, "-C", self.outdir, "run"]
|
|
|
|
else:
|
|
|
|
command = [self.binary]
|
2018-07-07 13:09:01 +02:00
|
|
|
|
|
|
|
if shutil.which("valgrind") and self.valgrind:
|
|
|
|
command = ["valgrind", "--error-exitcode=2",
|
2018-12-12 17:41:04 +01:00
|
|
|
"--leak-check=full",
|
|
|
|
"--suppressions="+ZEPHYR_BASE+"/scripts/valgrind.supp",
|
|
|
|
"--log-file="+self.outdir+"/valgrind.log"
|
|
|
|
] + command
|
2018-07-07 13:09:01 +02:00
|
|
|
|
|
|
|
with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc:
|
|
|
|
t = threading.Thread(target=self._output_reader, args=(proc, harness, ))
|
|
|
|
t.start()
|
|
|
|
t.join(self.timeout)
|
|
|
|
if t.is_alive():
|
2019-01-07 16:40:24 +01:00
|
|
|
self.try_kill_process_by_pid()
|
2018-07-07 13:09:01 +02:00
|
|
|
proc.terminate()
|
2018-12-11 15:13:05 +01:00
|
|
|
self.terminated = True
|
2018-07-07 13:09:01 +02:00
|
|
|
t.join()
|
|
|
|
proc.wait()
|
|
|
|
self.returncode = proc.returncode
|
|
|
|
|
|
|
|
if options.enable_coverage:
|
|
|
|
returncode = subprocess.call(["GCOV_PREFIX=" + self.outdir,
|
|
|
|
"gcov", self.sourcedir, "-b", "-s", self.outdir], shell=True)
|
|
|
|
|
2019-01-07 16:40:24 +01:00
|
|
|
self.try_kill_process_by_pid()
|
|
|
|
|
2018-07-07 15:45:53 +02:00
|
|
|
# FIME: This is needed when killing the simulator, the console is
|
|
|
|
# garbled and needs to be reset. Did not find a better way to do that.
|
|
|
|
|
|
|
|
subprocess.call(["stty", "sane"])
|
2018-07-07 13:09:01 +02:00
|
|
|
self.instance.results = harness.tests
|
2018-12-11 15:13:05 +01:00
|
|
|
if self.terminated==False and self.returncode != 0:
|
|
|
|
#When a process is killed, the default handler returns 128 + SIGTERM
|
|
|
|
#so in that case the return code itself is not meaningful
|
|
|
|
self.set_state("error", {})
|
|
|
|
elif harness.state:
|
2018-07-07 13:09:01 +02:00
|
|
|
self.set_state(harness.state, {})
|
|
|
|
else:
|
2018-12-11 15:13:05 +01:00
|
|
|
self.set_state("timeout", {})
|
2018-02-19 17:57:03 +01:00
|
|
|
|
|
|
|
class DeviceHandler(Handler):
|
|
|
|
|
|
|
|
def __init__(self, instance):
|
|
|
|
"""Constructor
|
|
|
|
|
|
|
|
@param instance Test Instance
|
|
|
|
"""
|
|
|
|
super().__init__(instance)
|
|
|
|
|
2019-02-07 23:53:39 +01:00
|
|
|
def monitor_serial(self, ser, halt_fileno, harness):
|
2018-07-07 01:58:18 +02:00
|
|
|
log_out_fp = open(self.log, "wt")
|
2018-02-19 17:57:03 +01:00
|
|
|
|
2019-02-07 23:53:39 +01:00
|
|
|
ser_fileno = ser.fileno()
|
|
|
|
readlist = [halt_fileno, ser_fileno]
|
|
|
|
|
2018-02-19 17:57:03 +01:00
|
|
|
while ser.isOpen():
|
2019-02-07 23:53:39 +01:00
|
|
|
readable, _, _ = select.select(readlist, [], [], self.timeout)
|
|
|
|
|
|
|
|
if halt_fileno in readable:
|
|
|
|
verbose('halted')
|
|
|
|
ser.close()
|
|
|
|
break
|
|
|
|
if ser_fileno not in readable:
|
|
|
|
continue # Timeout.
|
|
|
|
|
|
|
|
serial_line = None
|
2018-04-08 20:30:16 +02:00
|
|
|
try:
|
|
|
|
serial_line = ser.readline()
|
|
|
|
except TypeError:
|
|
|
|
pass
|
2019-03-03 16:36:35 +01:00
|
|
|
except serial.serialutil.SerialException:
|
|
|
|
ser.close()
|
|
|
|
break
|
2018-04-08 20:30:16 +02:00
|
|
|
|
2019-02-07 23:53:39 +01:00
|
|
|
# Just because ser_fileno has data doesn't mean an entire line
|
|
|
|
# is available yet.
|
2018-02-19 17:57:03 +01:00
|
|
|
if serial_line:
|
2018-02-22 13:44:16 +01:00
|
|
|
sl = serial_line.decode('utf-8', 'ignore')
|
|
|
|
verbose("DEVICE: {0}".format(sl.rstrip()))
|
|
|
|
|
|
|
|
log_out_fp.write(sl)
|
|
|
|
log_out_fp.flush()
|
|
|
|
harness.handle(sl.rstrip())
|
2019-02-07 23:53:39 +01:00
|
|
|
|
2018-02-19 17:57:03 +01:00
|
|
|
if harness.state:
|
|
|
|
ser.close()
|
|
|
|
break
|
|
|
|
|
|
|
|
log_out_fp.close()
|
|
|
|
|
|
|
|
def handle(self):
|
|
|
|
out_state = "failed"
|
|
|
|
|
2018-02-22 13:44:16 +01:00
|
|
|
if options.ninja:
|
|
|
|
generator_cmd = "ninja"
|
|
|
|
else:
|
|
|
|
generator_cmd = "make"
|
|
|
|
|
|
|
|
command = [generator_cmd, "-C", self.outdir, "flash"]
|
|
|
|
|
2018-02-19 17:57:03 +01:00
|
|
|
device = options.device_serial
|
|
|
|
ser = serial.Serial(
|
|
|
|
device,
|
|
|
|
baudrate=115200,
|
|
|
|
parity=serial.PARITY_NONE,
|
|
|
|
stopbits=serial.STOPBITS_ONE,
|
|
|
|
bytesize=serial.EIGHTBITS,
|
|
|
|
timeout=self.timeout
|
|
|
|
)
|
|
|
|
|
|
|
|
ser.flush()
|
|
|
|
|
|
|
|
harness_name = self.instance.test.harness.capitalize()
|
|
|
|
harness_import = HarnessImporter(harness_name)
|
|
|
|
harness = harness_import.instance
|
|
|
|
harness.configure(self.instance)
|
2019-02-07 23:53:39 +01:00
|
|
|
rpipe, wpipe = os.pipe()
|
2018-02-19 17:57:03 +01:00
|
|
|
|
2019-02-07 23:53:39 +01:00
|
|
|
t = threading.Thread(target=self.monitor_serial, daemon=True,
|
|
|
|
args=(ser, rpipe, harness))
|
2018-02-19 17:57:03 +01:00
|
|
|
t.start()
|
|
|
|
|
2018-04-08 20:30:16 +02:00
|
|
|
try:
|
2019-02-07 23:50:55 +01:00
|
|
|
if VERBOSE:
|
|
|
|
subprocess.check_call(command)
|
|
|
|
else:
|
|
|
|
subprocess.check_output(command, stderr=subprocess.PIPE)
|
2018-04-08 20:30:16 +02:00
|
|
|
except subprocess.CalledProcessError:
|
2019-02-07 23:53:39 +01:00
|
|
|
os.write(wpipe, b'x') # halt the thread
|
2018-02-19 17:57:03 +01:00
|
|
|
|
|
|
|
t.join(self.timeout)
|
|
|
|
if t.is_alive():
|
|
|
|
out_state = "timeout"
|
|
|
|
|
|
|
|
if ser.isOpen():
|
|
|
|
ser.close()
|
|
|
|
|
2018-02-22 13:44:16 +01:00
|
|
|
if out_state == "timeout":
|
|
|
|
for c in self.instance.test.cases:
|
|
|
|
if c not in harness.tests:
|
|
|
|
harness.tests[c] = "BLOCK"
|
2018-04-08 20:30:16 +02:00
|
|
|
|
|
|
|
self.instance.results = harness.tests
|
2018-02-19 17:57:03 +01:00
|
|
|
if harness.state:
|
|
|
|
self.set_state(harness.state, {})
|
|
|
|
else:
|
|
|
|
self.set_state(out_state, {})
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2016-08-22 14:03:46 +02:00
|
|
|
class QEMUHandler(Handler):
|
2015-07-17 21:03:52 +02:00
|
|
|
"""Spawns a thread to monitor QEMU output from pipes
|
|
|
|
|
2017-08-03 16:03:02 +02:00
|
|
|
We pass QEMU_PIPE to 'make run' and monitor the pipes for output.
|
2015-07-17 21:03:52 +02:00
|
|
|
We need to do this as once qemu starts, it runs forever until killed.
|
|
|
|
Test cases emit special messages to the console as they run, we check
|
|
|
|
for these to collect whether the test passed or failed.
|
|
|
|
"""
|
|
|
|
|
|
|
|
@staticmethod
|
2017-12-24 02:20:27 +01:00
|
|
|
def _thread(handler, timeout, outdir, logfile, fifo_fn, pid_fn, results, harness):
|
2015-07-17 21:03:52 +02:00
|
|
|
fifo_in = fifo_fn + ".in"
|
|
|
|
fifo_out = fifo_fn + ".out"
|
|
|
|
|
|
|
|
# These in/out nodes are named from QEMU's perspective, not ours
|
|
|
|
if os.path.exists(fifo_in):
|
|
|
|
os.unlink(fifo_in)
|
|
|
|
os.mkfifo(fifo_in)
|
|
|
|
if os.path.exists(fifo_out):
|
|
|
|
os.unlink(fifo_out)
|
|
|
|
os.mkfifo(fifo_out)
|
|
|
|
|
|
|
|
# We don't do anything with out_fp but we need to open it for
|
|
|
|
# writing so that QEMU doesn't block, due to the way pipes work
|
|
|
|
out_fp = open(fifo_in, "wb")
|
|
|
|
# Disable internal buffering, we don't
|
|
|
|
# want read() or poll() to ever block if there is data in there
|
|
|
|
in_fp = open(fifo_out, "rb", buffering=0)
|
2016-02-22 22:28:10 +01:00
|
|
|
log_out_fp = open(logfile, "wt")
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
start_time = time.time()
|
|
|
|
timeout_time = start_time + timeout
|
|
|
|
p = select.poll()
|
|
|
|
p.register(in_fp, select.POLLIN)
|
2018-08-29 07:45:38 +02:00
|
|
|
out_state = None
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
metrics = {}
|
|
|
|
line = ""
|
2019-01-17 23:11:37 +01:00
|
|
|
timeout_extended = False
|
2015-07-17 21:03:52 +02:00
|
|
|
while True:
|
|
|
|
this_timeout = int((timeout_time - time.time()) * 1000)
|
|
|
|
if this_timeout < 0 or not p.poll(this_timeout):
|
2018-08-29 07:45:38 +02:00
|
|
|
if not out_state:
|
|
|
|
out_state = "timeout"
|
2015-07-17 21:03:52 +02:00
|
|
|
break
|
|
|
|
|
2016-08-09 22:11:53 +02:00
|
|
|
try:
|
|
|
|
c = in_fp.read(1).decode("utf-8")
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
# Test is writing something weird, fail
|
|
|
|
out_state = "unexpected byte"
|
|
|
|
break
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
if c == "":
|
|
|
|
# EOF, this shouldn't happen unless QEMU crashes
|
|
|
|
out_state = "unexpected eof"
|
|
|
|
break
|
|
|
|
line = line + c
|
|
|
|
if c != "\n":
|
|
|
|
continue
|
|
|
|
|
2016-08-22 14:03:46 +02:00
|
|
|
# line contains a full line of data output from QEMU
|
2015-07-17 21:03:52 +02:00
|
|
|
log_out_fp.write(line)
|
|
|
|
log_out_fp.flush()
|
|
|
|
line = line.strip()
|
|
|
|
verbose("QEMU: %s" % line)
|
|
|
|
|
2017-12-24 02:20:27 +01:00
|
|
|
harness.handle(line)
|
|
|
|
if harness.state:
|
2018-08-29 07:45:38 +02:00
|
|
|
# if we have registered a fail make sure the state is not
|
|
|
|
# overridden by a false success message coming from the
|
|
|
|
# testsuite
|
|
|
|
if out_state != 'failed':
|
|
|
|
out_state = harness.state
|
|
|
|
|
|
|
|
# if we get some state, that means test is doing well, we reset
|
2019-01-17 23:11:37 +01:00
|
|
|
# the timeout and wait for 2 more seconds just in case we have
|
2018-08-29 07:45:38 +02:00
|
|
|
# crashed after test has completed
|
2019-01-25 15:37:38 +01:00
|
|
|
if not timeout_extended or harness.capture_coverage:
|
|
|
|
timeout_extended= True
|
|
|
|
if harness.capture_coverage:
|
|
|
|
timeout_time = time.time() + 10
|
|
|
|
else:
|
2019-01-17 23:11:37 +01:00
|
|
|
timeout_time = time.time() + 2
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
# TODO: Add support for getting numerical performance data
|
|
|
|
# from test cases. Will involve extending test case reporting
|
|
|
|
# APIs. Add whatever gets reported to the metrics dictionary
|
|
|
|
line = ""
|
|
|
|
|
2017-11-25 23:14:12 +01:00
|
|
|
metrics["handler_time"] = time.time() - start_time
|
2015-07-17 21:03:52 +02:00
|
|
|
verbose("QEMU complete (%s) after %f seconds" %
|
2017-11-25 23:14:12 +01:00
|
|
|
(out_state, metrics["handler_time"]))
|
2015-07-17 21:03:52 +02:00
|
|
|
handler.set_state(out_state, metrics)
|
|
|
|
|
|
|
|
log_out_fp.close()
|
|
|
|
out_fp.close()
|
|
|
|
in_fp.close()
|
2019-04-11 17:40:09 +02:00
|
|
|
if os.path.exists(pid_fn):
|
|
|
|
pid = int(open(pid_fn).read())
|
|
|
|
os.unlink(pid_fn)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2019-04-11 17:40:09 +02:00
|
|
|
try:
|
|
|
|
if pid:
|
|
|
|
os.kill(pid, signal.SIGTERM)
|
|
|
|
except ProcessLookupError:
|
|
|
|
# Oh well, as long as it's dead! User probably sent Ctrl-C
|
|
|
|
pass
|
2016-02-22 22:28:10 +01:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
os.unlink(fifo_in)
|
|
|
|
os.unlink(fifo_out)
|
|
|
|
|
2017-12-24 02:20:27 +01:00
|
|
|
def __init__(self, instance):
|
2015-07-17 21:03:52 +02:00
|
|
|
"""Constructor
|
|
|
|
|
2018-02-22 13:44:16 +01:00
|
|
|
@param instance Test instance
|
2015-07-17 21:03:52 +02:00
|
|
|
"""
|
2017-12-24 02:20:27 +01:00
|
|
|
|
|
|
|
super().__init__(instance)
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
self.results = {}
|
2018-07-07 01:20:23 +02:00
|
|
|
self.run = True
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
# We pass this to QEMU which looks for fifos with .in and .out
|
|
|
|
# suffixes.
|
2017-12-24 02:20:27 +01:00
|
|
|
self.fifo_fn = os.path.join(instance.outdir, "qemu-fifo")
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-24 02:20:27 +01:00
|
|
|
self.pid_fn = os.path.join(instance.outdir, "qemu.pid")
|
2015-07-17 21:03:52 +02:00
|
|
|
if os.path.exists(self.pid_fn):
|
|
|
|
os.unlink(self.pid_fn)
|
|
|
|
|
2018-07-07 01:58:18 +02:00
|
|
|
self.log_fn = self.log
|
2017-12-24 02:20:27 +01:00
|
|
|
|
|
|
|
harness_import = HarnessImporter(instance.test.harness.capitalize())
|
|
|
|
harness = harness_import.instance
|
2018-02-22 13:44:16 +01:00
|
|
|
harness.configure(self.instance)
|
|
|
|
self.thread = threading.Thread(name=self.name, target=QEMUHandler._thread,
|
|
|
|
args=(self, self.timeout, self.outdir,
|
2016-08-22 14:03:46 +02:00
|
|
|
self.log_fn, self.fifo_fn,
|
2017-12-24 02:20:27 +01:00
|
|
|
self.pid_fn, self.results, harness))
|
2018-02-16 03:07:24 +01:00
|
|
|
|
|
|
|
self.instance.results = harness.tests
|
2015-07-17 21:03:52 +02:00
|
|
|
self.thread.daemon = True
|
2018-02-22 13:44:16 +01:00
|
|
|
verbose("Spawning QEMU process for %s" % self.name)
|
2015-07-17 21:03:52 +02:00
|
|
|
self.thread.start()
|
|
|
|
|
|
|
|
def get_fifo(self):
|
|
|
|
return self.fifo_fn
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
class SizeCalculator:
|
2015-10-07 20:33:22 +02:00
|
|
|
|
2018-02-10 11:40:40 +01:00
|
|
|
alloc_sections = ["bss", "noinit", "app_bss", "app_noinit", "ccm_bss",
|
|
|
|
"ccm_noinit"]
|
2019-03-09 09:35:40 +01:00
|
|
|
rw_sections = ["datas", "initlevel", "exceptions", "initshell",
|
2018-11-13 00:16:54 +01:00
|
|
|
"_static_thread_area", "_k_timer_area",
|
2018-11-08 23:44:31 +01:00
|
|
|
"_k_mem_slab_area", "_k_mem_pool_area", "sw_isr_table",
|
2019-01-29 21:56:02 +01:00
|
|
|
"_k_sem_area", "_k_mutex_area", "app_shmem_regions",
|
2017-08-31 21:36:45 +02:00
|
|
|
"_k_fifo_area", "_k_lifo_area", "_k_stack_area",
|
|
|
|
"_k_msgq_area", "_k_mbox_area", "_k_pipe_area",
|
2018-02-07 14:00:08 +01:00
|
|
|
"net_if", "net_if_dev", "net_stack", "net_l2_data",
|
2017-08-22 22:15:23 +02:00
|
|
|
"_k_queue_area", "_net_buf_pool_area", "app_datas",
|
2018-02-10 11:40:40 +01:00
|
|
|
"kobject_data", "mmu_tables", "app_pad", "priv_stacks",
|
2018-06-29 19:57:47 +02:00
|
|
|
"ccm_data", "usb_descriptor", "usb_data", "usb_bos_desc",
|
|
|
|
'log_backends_sections', 'log_dynamic_sections',
|
2018-09-13 00:53:15 +02:00
|
|
|
'log_const_sections',"app_smem", 'shell_root_cmds_sections',
|
2018-10-19 19:15:19 +02:00
|
|
|
'log_const_sections',"app_smem", "font_entry_sections",
|
2018-10-08 16:19:41 +02:00
|
|
|
"priv_stacks_noinit", "_TEXT_SECTION_NAME_2",
|
2019-02-16 17:08:33 +01:00
|
|
|
'_GCOV_BSS_SECTION_NAME', 'gcov', 'nocache']
|
2018-10-08 16:19:41 +02:00
|
|
|
|
2015-10-07 20:33:22 +02:00
|
|
|
# These get copied into RAM only on non-XIP
|
userspace: add K_THREAD_ACCCESS_GRANT()
It's possible to declare static threads that start up as K_USER,
but these threads can't do much since they start with permissions on
no kernel objects other than their own thread object.
Rather than do some run-time synchronization to have some other thread
grant the necessary permissions, we introduce macros
to conveniently assign object permissions to these threads when they
are brought up at boot by the kernel. The tables generated here
are constant and live in ROM when possible.
Example usage:
K_THREAD_DEFINE(my_thread, STACK_SIZE, my_thread_entry,
NULL, NULL, NULL, 0, K_USER, K_NO_WAIT);
K_THREAD_ACCESS_GRANT(my_thread, &my_sem, &my_mutex, &my_pipe);
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-17 20:20:22 +02:00
|
|
|
ro_sections = ["text", "ctors", "init_array", "reset", "object_access",
|
2018-11-08 23:44:31 +01:00
|
|
|
"rodata", "devconfig", "net_l2", "vector", "sw_isr_table",
|
2019-03-11 16:26:06 +01:00
|
|
|
"_bt_settings_area", "vectors"]
|
2015-10-07 20:33:22 +02:00
|
|
|
|
2016-11-29 21:21:59 +01:00
|
|
|
def __init__(self, filename, extra_sections):
|
2015-07-17 21:03:52 +02:00
|
|
|
"""Constructor
|
|
|
|
|
2015-08-17 22:16:11 +02:00
|
|
|
@param filename Path to the output binary
|
|
|
|
The <filename> is parsed by objdump to determine section sizes
|
2015-07-17 21:03:52 +02:00
|
|
|
"""
|
|
|
|
# Make sure this is an ELF binary
|
2015-08-17 22:16:11 +02:00
|
|
|
with open(filename, "rb") as f:
|
2015-07-17 21:03:52 +02:00
|
|
|
magic = f.read(4)
|
|
|
|
|
2018-08-16 00:12:28 +02:00
|
|
|
try:
|
|
|
|
if (magic != b'\x7fELF'):
|
|
|
|
raise SanityRuntimeError("%s is not an ELF binary" % filename)
|
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
|
|
|
sys.exit(2)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
# Search for CONFIG_XIP in the ELF's list of symbols using NM and AWK.
|
2017-12-05 21:28:44 +01:00
|
|
|
# GREP can not be used as it returns an error if the symbol is not
|
|
|
|
# found.
|
|
|
|
is_xip_command = "nm " + filename + \
|
|
|
|
" | awk '/CONFIG_XIP/ { print $3 }'"
|
|
|
|
is_xip_output = subprocess.check_output(
|
|
|
|
is_xip_command, shell=True, stderr=subprocess.STDOUT).decode(
|
|
|
|
"utf-8").strip()
|
2018-08-16 00:12:28 +02:00
|
|
|
try:
|
|
|
|
if is_xip_output.endswith("no symbols"):
|
|
|
|
raise SanityRuntimeError("%s has no symbol information" % filename)
|
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
|
|
|
sys.exit(2)
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
self.is_xip = (len(is_xip_output) != 0)
|
|
|
|
|
2015-08-17 22:16:11 +02:00
|
|
|
self.filename = filename
|
2015-10-07 20:33:22 +02:00
|
|
|
self.sections = []
|
|
|
|
self.rom_size = 0
|
2015-07-17 21:03:52 +02:00
|
|
|
self.ram_size = 0
|
2016-11-29 21:21:59 +01:00
|
|
|
self.extra_sections = extra_sections
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
self._calculate_sizes()
|
|
|
|
|
|
|
|
def get_ram_size(self):
|
|
|
|
"""Get the amount of RAM the application will use up on the device
|
|
|
|
|
|
|
|
@return amount of RAM, in bytes
|
|
|
|
"""
|
2015-10-07 20:33:22 +02:00
|
|
|
return self.ram_size
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
def get_rom_size(self):
|
|
|
|
"""Get the size of the data that this application uses on device's flash
|
|
|
|
|
|
|
|
@return amount of ROM, in bytes
|
|
|
|
"""
|
2015-10-07 20:33:22 +02:00
|
|
|
return self.rom_size
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
def unrecognized_sections(self):
|
|
|
|
"""Get a list of sections inside the binary that weren't recognized
|
|
|
|
|
2017-06-16 21:32:42 +02:00
|
|
|
@return list of unrecognized section names
|
2015-07-17 21:03:52 +02:00
|
|
|
"""
|
|
|
|
slist = []
|
2015-10-07 20:33:22 +02:00
|
|
|
for v in self.sections:
|
2015-07-17 21:03:52 +02:00
|
|
|
if not v["recognized"]:
|
2015-10-07 20:33:22 +02:00
|
|
|
slist.append(v["name"])
|
2015-07-17 21:03:52 +02:00
|
|
|
return slist
|
|
|
|
|
|
|
|
def _calculate_sizes(self):
|
|
|
|
""" Calculate RAM and ROM usage by section """
|
2015-08-17 22:16:11 +02:00
|
|
|
objdump_command = "objdump -h " + self.filename
|
2017-12-05 21:28:44 +01:00
|
|
|
objdump_output = subprocess.check_output(
|
|
|
|
objdump_command, shell=True).decode("utf-8").splitlines()
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
for line in objdump_output:
|
|
|
|
words = line.split()
|
|
|
|
|
|
|
|
if (len(words) == 0): # Skip lines that are too short
|
|
|
|
continue
|
|
|
|
|
|
|
|
index = words[0]
|
|
|
|
if (not index[0].isdigit()): # Skip lines that do not start
|
|
|
|
continue # with a digit
|
|
|
|
|
|
|
|
name = words[1] # Skip lines with section names
|
|
|
|
if (name[0] == '.'): # starting with '.'
|
|
|
|
continue
|
|
|
|
|
2015-10-07 20:33:22 +02:00
|
|
|
# TODO this doesn't actually reflect the size in flash or RAM as
|
|
|
|
# it doesn't include linker-imposed padding between sections.
|
|
|
|
# It is close though.
|
2015-07-17 21:03:52 +02:00
|
|
|
size = int(words[2], 16)
|
2015-10-07 23:25:51 +02:00
|
|
|
if size == 0:
|
|
|
|
continue
|
|
|
|
|
2015-10-07 20:33:22 +02:00
|
|
|
load_addr = int(words[4], 16)
|
|
|
|
virt_addr = int(words[3], 16)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
# Add section to memory use totals (for both non-XIP and XIP scenarios)
|
|
|
|
# Unrecognized section names are not included in the calculations.
|
|
|
|
recognized = True
|
2015-10-07 20:33:22 +02:00
|
|
|
if name in SizeCalculator.alloc_sections:
|
|
|
|
self.ram_size += size
|
|
|
|
stype = "alloc"
|
|
|
|
elif name in SizeCalculator.rw_sections:
|
|
|
|
self.ram_size += size
|
|
|
|
self.rom_size += size
|
|
|
|
stype = "rw"
|
|
|
|
elif name in SizeCalculator.ro_sections:
|
|
|
|
self.rom_size += size
|
|
|
|
if not self.is_xip:
|
|
|
|
self.ram_size += size
|
|
|
|
stype = "ro"
|
2015-07-17 21:03:52 +02:00
|
|
|
else:
|
2015-10-07 20:33:22 +02:00
|
|
|
stype = "unknown"
|
2016-11-29 21:21:59 +01:00
|
|
|
if name not in self.extra_sections:
|
|
|
|
recognized = False
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
self.sections.append({"name": name, "load_addr": load_addr,
|
|
|
|
"size": size, "virt_addr": virt_addr,
|
|
|
|
"type": stype, "recognized": recognized})
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
class MakeGoal:
|
|
|
|
"""Metadata class representing one of the sub-makes called by MakeGenerator
|
|
|
|
|
2017-06-16 21:32:42 +02:00
|
|
|
MakeGenerator returns a dictionary of these which can then be associated
|
2015-07-17 21:03:52 +02:00
|
|
|
with TestInstances to get a complete picture of what happened during a test.
|
|
|
|
MakeGenerator is used for tasks outside of building tests (such as
|
|
|
|
defconfigs) which is why MakeGoal is a separate class from TestInstance.
|
|
|
|
"""
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2017-11-25 23:37:17 +01:00
|
|
|
def __init__(self, name, text, handler, make_log, build_log, run_log, handler_log):
|
2015-07-17 21:03:52 +02:00
|
|
|
self.name = name
|
|
|
|
self.text = text
|
2017-11-25 23:37:17 +01:00
|
|
|
self.handler = handler
|
2015-07-17 21:03:52 +02:00
|
|
|
self.make_log = make_log
|
|
|
|
self.build_log = build_log
|
|
|
|
self.run_log = run_log
|
2017-11-25 23:37:17 +01:00
|
|
|
self.handler_log = handler_log
|
2015-07-17 21:03:52 +02:00
|
|
|
self.make_state = "waiting"
|
|
|
|
self.failed = False
|
|
|
|
self.finished = False
|
|
|
|
self.reason = None
|
|
|
|
self.metrics = {}
|
|
|
|
|
|
|
|
def get_error_log(self):
|
|
|
|
if self.make_state == "waiting":
|
|
|
|
# Shouldn't ever see this; breakage in the main Makefile itself.
|
|
|
|
return self.make_log
|
|
|
|
elif self.make_state == "building":
|
|
|
|
# Failure when calling the sub-make to build the code
|
|
|
|
return self.build_log
|
|
|
|
elif self.make_state == "running":
|
2017-08-03 16:03:02 +02:00
|
|
|
# Failure in sub-make for "make run", qemu probably failed to start
|
2015-07-17 21:03:52 +02:00
|
|
|
return self.run_log
|
|
|
|
elif self.make_state == "finished":
|
2017-12-26 17:02:46 +01:00
|
|
|
# Execution handler finished, but timed out or otherwise wasn't successful
|
2017-11-25 23:37:17 +01:00
|
|
|
return self.handler_log
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
def fail(self, reason):
|
|
|
|
self.failed = True
|
|
|
|
self.finished = True
|
|
|
|
self.reason = reason
|
|
|
|
|
|
|
|
def success(self):
|
|
|
|
self.finished = True
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
if self.finished:
|
|
|
|
if self.failed:
|
|
|
|
return "[%s] failed (%s: see %s)" % (self.name, self.reason,
|
|
|
|
self.get_error_log())
|
|
|
|
else:
|
|
|
|
return "[%s] passed" % self.name
|
|
|
|
else:
|
|
|
|
return "[%s] in progress (%s)" % (self.name, self.make_state)
|
|
|
|
|
|
|
|
|
|
|
|
class MakeGenerator:
|
|
|
|
"""Generates a Makefile which just calls a bunch of sub-make sessions
|
|
|
|
|
|
|
|
In any given test suite we may need to build dozens if not hundreds of
|
|
|
|
test cases. The cleanest way to parallelize this is to just let Make
|
|
|
|
do the parallelization, sharing the jobserver among all the different
|
|
|
|
sub-make targets.
|
|
|
|
"""
|
|
|
|
|
|
|
|
GOAL_HEADER_TMPL = """.PHONY: {goal}
|
|
|
|
{goal}:
|
|
|
|
"""
|
|
|
|
|
|
|
|
MAKE_RULE_TMPL = """\t@echo sanity_test_{phase} {goal} >&2
|
2017-10-31 13:33:17 +01:00
|
|
|
\tcmake \\
|
2017-12-30 19:01:06 +01:00
|
|
|
\t\t-G"{generator}"\\
|
2017-10-31 13:33:17 +01:00
|
|
|
\t\t-H{directory}\\
|
|
|
|
\t\t-B{outdir}\\
|
|
|
|
\t\t-DEXTRA_CFLAGS="-Werror {cflags}"\\
|
|
|
|
\t\t-DEXTRA_AFLAGS=-Wa,--fatal-warnings\\
|
2017-12-14 14:42:45 +01:00
|
|
|
\t\t-DEXTRA_LDFLAGS="{ldflags}"\\
|
2017-10-31 13:33:17 +01:00
|
|
|
\t\t{args}\\
|
|
|
|
\t\t>{logfile} 2>&1
|
2017-12-30 19:01:06 +01:00
|
|
|
\t{generator_cmd} -C {outdir}\\
|
|
|
|
\t\t{verb} {make_args}\\
|
2017-10-31 13:33:17 +01:00
|
|
|
\t\t>>{logfile} 2>&1
|
2018-03-23 17:26:41 +01:00
|
|
|
"""
|
|
|
|
MAKE_RULE_TMPL_RUN = """\t@echo sanity_test_{phase} {goal} >&2
|
|
|
|
\t{generator_cmd} -C {outdir}\\
|
|
|
|
\t\t{verb} {make_args}\\
|
|
|
|
\t\t>>{logfile} 2>&1
|
2015-07-17 21:03:52 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
GOAL_FOOTER_TMPL = "\t@echo sanity_test_finished {goal} >&2\n\n"
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
re_make = re.compile(
|
|
|
|
"sanity_test_([A-Za-z0-9]+) (.+)|$|make[:] \*\*\* \[(.+:.+: )?(.+)\] Error.+$")
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2018-02-23 15:53:46 +01:00
|
|
|
def __init__(self, base_outdir):
|
2015-07-17 21:03:52 +02:00
|
|
|
"""MakeGenerator constructor
|
|
|
|
|
|
|
|
@param base_outdir Intended to be the base out directory. A make.log
|
|
|
|
file will be created here which contains the output of the
|
|
|
|
top-level Make session, as well as the dynamic control Makefile
|
|
|
|
@param verbose If true, pass V=1 to all the sub-makes which greatly
|
|
|
|
increases their verbosity
|
|
|
|
"""
|
|
|
|
self.goals = {}
|
|
|
|
if not os.path.exists(base_outdir):
|
|
|
|
os.makedirs(base_outdir)
|
|
|
|
self.logfile = os.path.join(base_outdir, "make.log")
|
|
|
|
self.makefile = os.path.join(base_outdir, "Makefile")
|
2018-02-23 15:53:46 +01:00
|
|
|
self.deprecations = options.error_on_deprecations
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
def _get_rule_header(self, name):
|
|
|
|
return MakeGenerator.GOAL_HEADER_TMPL.format(goal=name)
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
def _get_sub_make(self, name, phase, workdir, outdir,
|
|
|
|
logfile, args, make_args=""):
|
2017-10-31 13:33:17 +01:00
|
|
|
"""
|
|
|
|
@param args Arguments given to CMake
|
|
|
|
@param make_args Arguments given to the Makefile generated by CMake
|
|
|
|
"""
|
2017-12-05 21:28:44 +01:00
|
|
|
args = " ".join(["-D{}".format(a) for a in args])
|
2017-12-14 14:42:45 +01:00
|
|
|
ldflags = ""
|
2018-05-24 22:33:09 +02:00
|
|
|
cflags = ""
|
2016-11-30 20:25:44 +01:00
|
|
|
|
|
|
|
if self.deprecations:
|
|
|
|
cflags = cflags + " -Wno-deprecated-declarations"
|
2017-02-02 22:04:57 +01:00
|
|
|
|
2018-05-02 13:49:51 +02:00
|
|
|
ldflags="-Wl,--fatal-warnings"
|
2017-12-14 14:42:45 +01:00
|
|
|
|
2018-03-06 14:15:11 +01:00
|
|
|
if options.ninja:
|
2018-01-18 14:40:07 +01:00
|
|
|
generator = "Ninja"
|
2018-05-21 19:12:59 +02:00
|
|
|
generator_cmd = "ninja -j1"
|
2018-01-18 14:40:07 +01:00
|
|
|
verb = "-v" if VERBOSE else ""
|
2018-03-06 14:15:11 +01:00
|
|
|
else:
|
|
|
|
generator = "Unix Makefiles"
|
|
|
|
generator_cmd = "$(MAKE)"
|
2018-06-26 19:41:35 +02:00
|
|
|
verb = "VERBOSE=1" if VERBOSE else ""
|
2017-12-30 19:01:06 +01:00
|
|
|
|
2018-03-23 17:26:41 +01:00
|
|
|
if phase == 'running':
|
|
|
|
return MakeGenerator.MAKE_RULE_TMPL_RUN.format(
|
|
|
|
generator_cmd=generator_cmd,
|
|
|
|
phase=phase,
|
|
|
|
goal=name,
|
|
|
|
outdir=outdir,
|
|
|
|
verb=verb,
|
|
|
|
logfile=logfile,
|
|
|
|
make_args=make_args
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
return MakeGenerator.MAKE_RULE_TMPL.format(
|
|
|
|
generator=generator,
|
|
|
|
generator_cmd=generator_cmd,
|
|
|
|
phase=phase,
|
|
|
|
goal=name,
|
|
|
|
outdir=outdir,
|
|
|
|
cflags=cflags,
|
|
|
|
ldflags=ldflags,
|
|
|
|
directory=workdir,
|
|
|
|
verb=verb,
|
|
|
|
args=args,
|
|
|
|
logfile=logfile,
|
|
|
|
make_args=make_args
|
|
|
|
)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
def _get_rule_footer(self, name):
|
|
|
|
return MakeGenerator.GOAL_FOOTER_TMPL.format(goal=name)
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
def add_build_goal(self, name, directory, outdir,
|
|
|
|
args, buildlog, make_args=""):
|
2018-07-07 01:20:23 +02:00
|
|
|
"""Add a goal to invoke a build session
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
@param name A unique string name for this build goal. The results
|
|
|
|
dictionary returned by execute() will be keyed by this name.
|
|
|
|
@param directory Absolute path to working directory, will be passed
|
|
|
|
to make -C
|
|
|
|
@param outdir Absolute path to output directory, will be passed to
|
2017-11-09 12:06:04 +01:00
|
|
|
cmake via -B=<path>
|
|
|
|
@param args Extra command line arguments to pass to 'cmake', typically
|
2015-07-17 21:03:52 +02:00
|
|
|
environment variables or specific Make goals
|
|
|
|
"""
|
2018-07-07 01:20:23 +02:00
|
|
|
|
|
|
|
if not os.path.exists(outdir):
|
|
|
|
os.makedirs(outdir)
|
|
|
|
|
2017-06-22 23:19:11 +02:00
|
|
|
build_logfile = os.path.join(outdir, buildlog)
|
2018-07-07 01:20:23 +02:00
|
|
|
text = self._get_rule_header(name)
|
|
|
|
text += self._get_sub_make(name, "building", directory, outdir, build_logfile,
|
|
|
|
args, make_args=make_args)
|
|
|
|
text += self._get_rule_footer(name)
|
|
|
|
|
|
|
|
self.goals[name] = MakeGoal( name, text, None, self.logfile, build_logfile, None, None)
|
|
|
|
|
|
|
|
def add_goal(self, instance, type, args, make_args=""):
|
2018-07-07 01:58:18 +02:00
|
|
|
|
2018-07-07 01:20:23 +02:00
|
|
|
"""Add a goal to build a Zephyr project and then run it using a handler
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
The generated make goal invokes Make twice, the first time it will
|
|
|
|
build the default goal, and the second will invoke the 'qemu' goal.
|
2018-07-07 01:20:23 +02:00
|
|
|
The output of the handler session will be monitored, and terminated
|
2015-07-17 21:03:52 +02:00
|
|
|
either upon pass/fail result of the test program, or the timeout
|
|
|
|
is reached.
|
|
|
|
|
2017-11-09 12:06:04 +01:00
|
|
|
@param args Extra cache entries to define in CMake.
|
2015-07-17 21:03:52 +02:00
|
|
|
"""
|
|
|
|
|
2017-12-24 02:20:27 +01:00
|
|
|
name = instance.name
|
2018-11-20 15:03:17 +01:00
|
|
|
directory = instance.test.test_path
|
2017-12-24 02:20:27 +01:00
|
|
|
outdir = instance.outdir
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
build_logfile = os.path.join(outdir, "build.log")
|
|
|
|
run_logfile = os.path.join(outdir, "run.log")
|
|
|
|
|
2018-07-07 01:20:23 +02:00
|
|
|
if not os.path.exists(outdir):
|
|
|
|
os.makedirs(outdir)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2018-07-07 01:20:23 +02:00
|
|
|
handler = None
|
|
|
|
if type == "qemu":
|
|
|
|
handler = QEMUHandler(instance)
|
|
|
|
elif type == "native":
|
2018-07-07 13:09:01 +02:00
|
|
|
handler = BinaryHandler(instance)
|
|
|
|
handler.binary = os.path.join(outdir, "zephyr", "zephyr.exe")
|
2019-01-25 00:15:44 +01:00
|
|
|
if options.enable_coverage:
|
|
|
|
args += ["EXTRA_LDFLAGS=--coverage"]
|
2018-07-07 15:45:53 +02:00
|
|
|
elif type == "nsim":
|
|
|
|
handler = BinaryHandler(instance)
|
|
|
|
handler.call_make_run = True
|
2018-07-07 01:20:23 +02:00
|
|
|
elif type == "unit":
|
2018-07-07 13:09:01 +02:00
|
|
|
handler = BinaryHandler(instance)
|
|
|
|
handler.binary = os.path.join(outdir, "testbinary")
|
2019-01-25 00:15:44 +01:00
|
|
|
if options.enable_coverage:
|
|
|
|
args += ["EXTRA_LDFLAGS=--coverage"]
|
2018-07-07 01:20:23 +02:00
|
|
|
elif type == "device":
|
|
|
|
handler = DeviceHandler(instance)
|
2019-01-07 16:40:24 +01:00
|
|
|
elif type == "renode":
|
|
|
|
handler = BinaryHandler(instance)
|
|
|
|
handler.pid_fn = os.path.join(instance.outdir, "renode.pid")
|
|
|
|
handler.call_make_run = True
|
2017-12-24 02:20:27 +01:00
|
|
|
|
2018-06-21 09:30:20 +02:00
|
|
|
|
2018-07-07 01:20:23 +02:00
|
|
|
if type == 'qemu':
|
|
|
|
args.append("QEMU_PIPE=%s" % handler.get_fifo())
|
|
|
|
|
2017-12-26 17:02:46 +01:00
|
|
|
text = (self._get_rule_header(name) +
|
|
|
|
self._get_sub_make(name, "building", directory,
|
2018-07-07 01:20:23 +02:00
|
|
|
outdir, build_logfile, args, make_args=make_args))
|
|
|
|
if handler and handler.run:
|
|
|
|
text += self._get_sub_make(name, "running", directory,
|
|
|
|
outdir, run_logfile,
|
|
|
|
args, make_args="run")
|
2018-02-19 17:57:03 +01:00
|
|
|
|
2018-07-07 01:20:23 +02:00
|
|
|
text += self._get_rule_footer(name)
|
2018-02-19 17:57:03 +01:00
|
|
|
|
|
|
|
self.goals[name] = MakeGoal(name, text, handler, self.logfile, build_logfile,
|
2018-07-07 01:58:18 +02:00
|
|
|
run_logfile, handler.log if handler else None)
|
2018-02-19 17:57:03 +01:00
|
|
|
|
2018-07-07 01:20:23 +02:00
|
|
|
|
2018-02-23 15:53:46 +01:00
|
|
|
def add_test_instance(self, ti, extra_args=[]):
|
2015-07-17 21:03:52 +02:00
|
|
|
"""Add a goal to build/test a TestInstance object
|
|
|
|
|
|
|
|
@param ti TestInstance object to build. The status dictionary returned
|
|
|
|
by execute() will be keyed by its .name field.
|
|
|
|
"""
|
|
|
|
args = ti.test.extra_args[:]
|
2019-02-12 19:59:08 +01:00
|
|
|
|
|
|
|
# merge overlay files into one variable
|
|
|
|
overlays = ""
|
|
|
|
idx = 0
|
|
|
|
for a in args:
|
|
|
|
m = re.search('OVERLAY_CONFIG="(.*)"', a)
|
|
|
|
if m:
|
|
|
|
overlays += m.group(1)
|
|
|
|
del args[idx]
|
|
|
|
idx += 1
|
|
|
|
|
2018-11-08 05:50:54 +01:00
|
|
|
if len(ti.test.extra_configs) > 0 or options.coverage:
|
2019-02-12 19:59:08 +01:00
|
|
|
args.append("OVERLAY_CONFIG=\"%s %s\"" %(overlays,
|
|
|
|
os.path.join(ti.outdir, "overlay.conf")))
|
2017-10-04 22:14:27 +02:00
|
|
|
|
2018-11-08 05:50:54 +01:00
|
|
|
if ti.test.type == "unit" and options.enable_coverage:
|
|
|
|
args.append("COVERAGE=1")
|
|
|
|
|
2017-10-31 13:33:17 +01:00
|
|
|
args.append("BOARD={}".format(ti.platform.name))
|
2016-09-01 19:41:03 +02:00
|
|
|
args.extend(extra_args)
|
2018-02-23 15:37:14 +01:00
|
|
|
|
2018-02-23 15:53:46 +01:00
|
|
|
do_build_only = ti.build_only or options.build_only
|
2019-01-03 23:17:43 +01:00
|
|
|
do_run = not do_build_only
|
|
|
|
skip_slow = ti.test.slow and not options.enable_slow
|
2018-02-23 15:37:14 +01:00
|
|
|
|
2018-07-07 01:20:23 +02:00
|
|
|
# FIXME: Need refactoring and cleanup
|
|
|
|
type = None
|
2018-02-23 15:37:14 +01:00
|
|
|
if ti.platform.qemu_support and do_run:
|
2018-07-07 01:20:23 +02:00
|
|
|
type = "qemu"
|
2016-08-22 14:03:46 +02:00
|
|
|
elif ti.test.type == "unit":
|
2018-07-07 01:20:23 +02:00
|
|
|
type = "unit"
|
2018-02-23 15:37:14 +01:00
|
|
|
elif ti.platform.type == "native" and do_run:
|
2018-07-07 01:20:23 +02:00
|
|
|
type = "native"
|
2018-07-07 15:45:53 +02:00
|
|
|
elif ti.platform.simulation == "nsim" and do_run:
|
2018-07-11 22:09:22 +02:00
|
|
|
if find_executable("nsimdrv"):
|
|
|
|
type = "nsim"
|
2019-01-07 16:40:24 +01:00
|
|
|
elif ti.platform.simulation == "renode" and do_run:
|
|
|
|
if find_executable("renode"):
|
|
|
|
type = "renode"
|
2018-02-23 15:53:46 +01:00
|
|
|
elif options.device_testing and (not ti.build_only) and (not options.build_only):
|
2018-07-07 01:20:23 +02:00
|
|
|
type = "device"
|
2018-02-23 15:53:46 +01:00
|
|
|
|
2019-01-03 23:17:43 +01:00
|
|
|
if not skip_slow:
|
|
|
|
self.add_goal(ti, type, args)
|
|
|
|
else:
|
|
|
|
verbose("Skipping slow test: " + ti.name)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
def execute(self, callback_fn=None, context=None):
|
|
|
|
"""Execute all the registered build goals
|
|
|
|
|
|
|
|
@param callback_fn If not None, a callback function will be called
|
|
|
|
as individual goals transition between states. This function
|
|
|
|
should accept two parameters: a string state and an arbitrary
|
|
|
|
context object, supplied here
|
|
|
|
@param context Context object to pass to the callback function.
|
|
|
|
Type and semantics are specific to that callback function.
|
|
|
|
@return A dictionary mapping goal names to final status.
|
|
|
|
"""
|
|
|
|
|
2016-02-22 22:28:10 +01:00
|
|
|
with open(self.makefile, "wt") as tf, \
|
2015-07-17 21:03:52 +02:00
|
|
|
open(os.devnull, "wb") as devnull, \
|
2016-02-22 22:28:10 +01:00
|
|
|
open(self.logfile, "wt") as make_log:
|
2015-07-17 21:03:52 +02:00
|
|
|
# Create our dynamic Makefile and execute it.
|
|
|
|
# Watch stderr output which is where we will keep
|
|
|
|
# track of build state
|
2019-03-20 21:58:55 +01:00
|
|
|
tf.write('\n# Generated by %s which is expected\n' % __file__)
|
|
|
|
tf.write('# to spawn qemu or testbinary, renode, etc. \n\n')
|
|
|
|
for name, goal in sorted(self.goals.items()):
|
2015-07-17 21:03:52 +02:00
|
|
|
tf.write(goal.text)
|
2019-03-20 21:58:55 +01:00
|
|
|
tf.write("all: %s\n" % (" ".join(sorted(self.goals.keys()))))
|
2015-07-17 21:03:52 +02:00
|
|
|
tf.flush()
|
|
|
|
|
2018-08-17 14:02:28 +02:00
|
|
|
cmd = ["make", "-k", "-j", str(JOBS), "-f", tf.name, "all"]
|
2018-05-21 19:12:59 +02:00
|
|
|
|
2018-06-13 06:10:20 +02:00
|
|
|
# assure language neutral environemnt
|
|
|
|
make_env = os.environ.copy()
|
|
|
|
make_env['LC_MESSAGES'] = 'C.UTF-8'
|
|
|
|
p = subprocess.Popen(cmd, stderr=subprocess.PIPE,
|
|
|
|
stdout=devnull, env=make_env)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
for line in iter(p.stderr.readline, b''):
|
2016-02-22 22:28:10 +01:00
|
|
|
line = line.decode("utf-8")
|
2015-07-17 21:03:52 +02:00
|
|
|
make_log.write(line)
|
|
|
|
verbose("MAKE: " + repr(line.strip()))
|
|
|
|
m = MakeGenerator.re_make.match(line)
|
|
|
|
if not m:
|
|
|
|
continue
|
|
|
|
|
2016-08-22 14:03:46 +02:00
|
|
|
state, name, _, error = m.groups()
|
2015-07-17 21:03:52 +02:00
|
|
|
if error:
|
|
|
|
goal = self.goals[error]
|
2017-01-10 22:32:40 +01:00
|
|
|
# Sometimes QEMU will run an image and then crash out, which
|
2017-08-03 16:03:02 +02:00
|
|
|
# will cause the 'make run' invocation to exit with
|
2017-01-10 22:32:40 +01:00
|
|
|
# nonzero status.
|
|
|
|
# Need to distinguish this case from a compilation failure.
|
2019-04-11 16:31:01 +02:00
|
|
|
if goal.make_state == "building":
|
|
|
|
goal.fail("build_error")
|
|
|
|
elif goal.handler:
|
2018-01-29 14:42:38 +01:00
|
|
|
goal.fail("handler_crash")
|
2017-01-10 22:32:40 +01:00
|
|
|
else:
|
2019-04-11 16:31:01 +02:00
|
|
|
goal.fail("unknown_error")
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
else:
|
2017-12-26 17:02:46 +01:00
|
|
|
goal = self.goals[name]
|
|
|
|
goal.make_state = state
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
if state == "finished":
|
2017-11-25 23:37:17 +01:00
|
|
|
if goal.handler:
|
2017-12-24 02:20:27 +01:00
|
|
|
if hasattr(goal.handler, "handle"):
|
2017-11-25 23:37:17 +01:00
|
|
|
goal.handler.handle()
|
2018-07-07 01:58:18 +02:00
|
|
|
goal.handler_log = goal.handler.log
|
2017-12-26 17:02:46 +01:00
|
|
|
|
2017-11-25 23:37:17 +01:00
|
|
|
thread_status, metrics = goal.handler.get_state()
|
2015-07-17 21:03:52 +02:00
|
|
|
goal.metrics.update(metrics)
|
|
|
|
if thread_status == "passed":
|
|
|
|
goal.success()
|
|
|
|
else:
|
|
|
|
goal.fail(thread_status)
|
|
|
|
else:
|
|
|
|
goal.success()
|
|
|
|
|
|
|
|
if callback_fn:
|
|
|
|
callback_fn(context, self.goals, goal)
|
|
|
|
|
|
|
|
p.wait()
|
|
|
|
return self.goals
|
|
|
|
|
|
|
|
|
|
|
|
# "list" - List of strings
|
|
|
|
# "list:<type>" - List of <type>
|
|
|
|
# "set" - Set of unordered, unique strings
|
|
|
|
# "set:<type>" - Set of <type>
|
|
|
|
# "float" - Floating point
|
|
|
|
# "int" - Integer
|
|
|
|
# "bool" - Boolean
|
|
|
|
# "str" - String
|
|
|
|
|
|
|
|
# XXX Be sure to update __doc__ if you change any of this!!
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
platform_valid_keys = {"qemu_support": {"type": "bool", "default": False},
|
2018-10-18 18:25:55 +02:00
|
|
|
"supported_toolchains": {"type": "list", "default": []},
|
|
|
|
"env": {"type": "list", "default": []}
|
|
|
|
}
|
2017-12-05 21:28:44 +01:00
|
|
|
|
|
|
|
testcase_valid_keys = {"tags": {"type": "set", "required": False},
|
|
|
|
"type": {"type": "str", "default": "integration"},
|
|
|
|
"extra_args": {"type": "list"},
|
|
|
|
"extra_configs": {"type": "list"},
|
|
|
|
"build_only": {"type": "bool", "default": False},
|
|
|
|
"build_on_all": {"type": "bool", "default": False},
|
|
|
|
"skip": {"type": "bool", "default": False},
|
|
|
|
"slow": {"type": "bool", "default": False},
|
|
|
|
"timeout": {"type": "int", "default": 60},
|
|
|
|
"min_ram": {"type": "int", "default": 8},
|
|
|
|
"depends_on": {"type": "set"},
|
|
|
|
"min_flash": {"type": "int", "default": 32},
|
|
|
|
"arch_whitelist": {"type": "set"},
|
|
|
|
"arch_exclude": {"type": "set"},
|
|
|
|
"extra_sections": {"type": "list", "default": []},
|
|
|
|
"platform_exclude": {"type": "set"},
|
|
|
|
"platform_whitelist": {"type": "set"},
|
|
|
|
"toolchain_exclude": {"type": "set"},
|
|
|
|
"toolchain_whitelist": {"type": "set"},
|
2017-12-08 16:17:57 +01:00
|
|
|
"filter": {"type": "str"},
|
2017-12-24 02:20:27 +01:00
|
|
|
"harness": {"type": "str"},
|
2018-09-12 23:28:28 +02:00
|
|
|
"harness_config": {"type": "map", "default": {}}
|
2017-12-08 16:17:57 +01:00
|
|
|
}
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
class SanityConfigParser:
|
2017-04-05 00:47:49 +02:00
|
|
|
"""Class to read test case files with semantic checking
|
2015-07-17 21:03:52 +02:00
|
|
|
"""
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2017-07-24 19:24:35 +02:00
|
|
|
def __init__(self, filename, schema):
|
2015-07-17 21:03:52 +02:00
|
|
|
"""Instantiate a new SanityConfigParser object
|
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
@param filename Source .yaml file to read
|
2015-07-17 21:03:52 +02:00
|
|
|
"""
|
2017-12-05 21:08:26 +01:00
|
|
|
self.data = scl.yaml_load_verify(filename, schema)
|
2015-07-17 21:03:52 +02:00
|
|
|
self.filename = filename
|
2017-12-05 21:08:26 +01:00
|
|
|
self.tests = {}
|
|
|
|
self.common = {}
|
|
|
|
if 'tests' in self.data:
|
|
|
|
self.tests = self.data['tests']
|
|
|
|
if 'common' in self.data:
|
|
|
|
self.common = self.data['common']
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
def _cast_value(self, value, typestr):
|
2017-12-05 21:28:44 +01:00
|
|
|
if isinstance(value, str):
|
2017-04-05 00:47:49 +02:00
|
|
|
v = value.strip()
|
2015-07-17 21:03:52 +02:00
|
|
|
if typestr == "str":
|
|
|
|
return v
|
|
|
|
|
|
|
|
elif typestr == "float":
|
2017-04-05 00:47:49 +02:00
|
|
|
return float(value)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
elif typestr == "int":
|
2017-04-05 00:47:49 +02:00
|
|
|
return int(value)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
elif typestr == "bool":
|
2017-04-05 00:47:49 +02:00
|
|
|
return value
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
elif typestr.startswith("list") and isinstance(value, list):
|
2017-10-04 22:14:27 +02:00
|
|
|
return value
|
2017-12-05 21:28:44 +01:00
|
|
|
elif typestr.startswith("list") and isinstance(value, str):
|
2015-07-17 21:03:52 +02:00
|
|
|
vs = v.split()
|
|
|
|
if len(typestr) > 4 and typestr[4] == ":":
|
|
|
|
return [self._cast_value(vsi, typestr[5:]) for vsi in vs]
|
|
|
|
else:
|
|
|
|
return vs
|
|
|
|
|
|
|
|
elif typestr.startswith("set"):
|
|
|
|
vs = v.split()
|
|
|
|
if len(typestr) > 3 and typestr[3] == ":":
|
|
|
|
return set([self._cast_value(vsi, typestr[4:]) for vsi in vs])
|
|
|
|
else:
|
|
|
|
return set(vs)
|
|
|
|
|
2017-12-24 02:20:27 +01:00
|
|
|
elif typestr.startswith("map"):
|
|
|
|
return value
|
2015-07-17 21:03:52 +02:00
|
|
|
else:
|
2017-12-05 21:28:44 +01:00
|
|
|
raise ConfigurationError(
|
|
|
|
self.filename, "unknown type '%s'" % value)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-05 23:27:58 +01:00
|
|
|
def get_test(self, name, valid_keys):
|
|
|
|
"""Get a dictionary representing the keys/values within a test
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-05 23:27:58 +01:00
|
|
|
@param name The test in the .yaml file to retrieve data from
|
2015-07-17 21:03:52 +02:00
|
|
|
@param valid_keys A dictionary representing the intended semantics
|
2017-12-05 23:27:58 +01:00
|
|
|
for this test. Each key in this dictionary is a key that could
|
2017-04-05 00:47:49 +02:00
|
|
|
be specified, if a key is given in the .yaml file which isn't in
|
2015-07-17 21:03:52 +02:00
|
|
|
here, it will generate an error. Each value in this dictionary
|
|
|
|
is another dictionary containing metadata:
|
|
|
|
|
|
|
|
"default" - Default value if not given
|
|
|
|
"type" - Data type to convert the text value to. Simple types
|
|
|
|
supported are "str", "float", "int", "bool" which will get
|
|
|
|
converted to respective Python data types. "set" and "list"
|
|
|
|
may also be specified which will split the value by
|
|
|
|
whitespace (but keep the elements as strings). finally,
|
|
|
|
"list:<type>" and "set:<type>" may be given which will
|
|
|
|
perform a type conversion after splitting the value up.
|
|
|
|
"required" - If true, raise an error if not defined. If false
|
|
|
|
and "default" isn't specified, a type conversion will be
|
|
|
|
done on an empty string
|
2017-12-05 23:27:58 +01:00
|
|
|
@return A dictionary containing the test key-value pairs with
|
2015-07-17 21:03:52 +02:00
|
|
|
type conversion and default values filled in per valid_keys
|
|
|
|
"""
|
|
|
|
|
|
|
|
d = {}
|
2017-12-05 21:08:26 +01:00
|
|
|
for k, v in self.common.items():
|
2017-10-04 22:14:27 +02:00
|
|
|
d[k] = v
|
2018-02-24 15:32:14 +01:00
|
|
|
|
2017-12-05 23:27:58 +01:00
|
|
|
for k, v in self.tests[name].items():
|
2015-07-17 21:03:52 +02:00
|
|
|
if k not in valid_keys:
|
2017-12-05 21:28:44 +01:00
|
|
|
raise ConfigurationError(
|
|
|
|
self.filename,
|
|
|
|
"Unknown config key '%s' in definition for '%s'" %
|
2017-12-05 23:27:58 +01:00
|
|
|
(k, name))
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-10-04 22:14:27 +02:00
|
|
|
if k in d:
|
2017-12-05 21:28:44 +01:00
|
|
|
if isinstance(d[k], str):
|
2017-10-04 22:14:27 +02:00
|
|
|
d[k] += " " + v
|
|
|
|
else:
|
|
|
|
d[k] = v
|
2018-02-24 15:32:14 +01:00
|
|
|
|
2016-02-22 22:28:10 +01:00
|
|
|
for k, kinfo in valid_keys.items():
|
2015-07-17 21:03:52 +02:00
|
|
|
if k not in d:
|
|
|
|
if "required" in kinfo:
|
|
|
|
required = kinfo["required"]
|
|
|
|
else:
|
|
|
|
required = False
|
|
|
|
|
|
|
|
if required:
|
2017-12-05 21:28:44 +01:00
|
|
|
raise ConfigurationError(
|
|
|
|
self.filename,
|
2017-12-05 23:27:58 +01:00
|
|
|
"missing required value for '%s' in test '%s'" %
|
|
|
|
(k, name))
|
2015-07-17 21:03:52 +02:00
|
|
|
else:
|
|
|
|
if "default" in kinfo:
|
|
|
|
default = kinfo["default"]
|
|
|
|
else:
|
|
|
|
default = self._cast_value("", kinfo["type"])
|
|
|
|
d[k] = default
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
d[k] = self._cast_value(d[k], kinfo["type"])
|
2016-02-22 22:28:10 +01:00
|
|
|
except ValueError as ve:
|
2017-12-05 21:28:44 +01:00
|
|
|
raise ConfigurationError(
|
2017-12-05 23:27:58 +01:00
|
|
|
self.filename, "bad %s value '%s' for key '%s' in name '%s'" %
|
|
|
|
(kinfo["type"], d[k], k, name))
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
return d
|
|
|
|
|
|
|
|
|
|
|
|
class Platform:
|
|
|
|
"""Class representing metadata for a particular platform
|
|
|
|
|
2015-12-13 21:00:31 +01:00
|
|
|
Maps directly to BOARD when building"""
|
2017-07-24 19:24:35 +02:00
|
|
|
|
|
|
|
yaml_platform_schema = scl.yaml_load(
|
2017-12-05 21:28:44 +01:00
|
|
|
os.path.join(
|
2018-08-17 13:54:41 +02:00
|
|
|
ZEPHYR_BASE,
|
2017-12-05 21:28:44 +01:00
|
|
|
"scripts",
|
|
|
|
"sanity_chk",
|
|
|
|
"sanitycheck-platform-schema.yaml"))
|
2017-07-24 19:24:35 +02:00
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
def __init__(self, cfile):
|
2015-07-17 21:03:52 +02:00
|
|
|
"""Constructor.
|
|
|
|
|
2017-12-05 23:39:29 +01:00
|
|
|
@param cfile Path to platform configuration file, which gives
|
|
|
|
info about the platform to be added.
|
2015-07-17 21:03:52 +02:00
|
|
|
"""
|
2017-07-24 19:24:35 +02:00
|
|
|
scp = SanityConfigParser(cfile, self.yaml_platform_schema)
|
2017-12-05 21:08:26 +01:00
|
|
|
data = scp.data
|
2017-04-05 00:47:49 +02:00
|
|
|
|
2017-12-05 21:08:26 +01:00
|
|
|
self.name = data['identifier']
|
2018-07-24 15:14:42 +02:00
|
|
|
self.sanitycheck = data.get("sanitycheck", True)
|
2017-04-05 00:47:49 +02:00
|
|
|
# if no RAM size is specified by the board, take a default of 128K
|
2017-12-05 21:08:26 +01:00
|
|
|
self.ram = data.get("ram", 128)
|
|
|
|
testing = data.get("testing", {})
|
2017-04-05 00:47:49 +02:00
|
|
|
self.ignore_tags = testing.get("ignore_tags", [])
|
|
|
|
self.default = testing.get("default", False)
|
|
|
|
# if no flash size is specified by the board, take a default of 512K
|
2017-12-05 21:08:26 +01:00
|
|
|
self.flash = data.get("flash", 512)
|
2017-07-31 14:47:41 +02:00
|
|
|
self.supported = set()
|
2017-12-05 21:08:26 +01:00
|
|
|
for supp_feature in data.get("supported", []):
|
2017-07-31 14:47:41 +02:00
|
|
|
for item in supp_feature.split(":"):
|
|
|
|
self.supported.add(item)
|
|
|
|
|
2018-01-04 20:15:22 +01:00
|
|
|
self.qemu_support = True if data.get('simulation', "na") == 'qemu' else False
|
2017-12-05 21:08:26 +01:00
|
|
|
self.arch = data['arch']
|
2017-12-26 17:02:46 +01:00
|
|
|
self.type = data.get('type', "na")
|
2018-01-04 20:15:22 +01:00
|
|
|
self.simulation = data.get('simulation', "na")
|
2017-12-05 21:08:26 +01:00
|
|
|
self.supported_toolchains = data.get("toolchain", [])
|
2018-10-18 18:25:55 +02:00
|
|
|
self.env = data.get("env", [])
|
|
|
|
self.env_satisfied = True
|
|
|
|
for env in self.env:
|
|
|
|
if os.environ.get(env, None) == None:
|
|
|
|
self.env_satisfied = False
|
2016-11-03 19:58:53 +01:00
|
|
|
self.defconfig = None
|
2015-07-17 21:03:52 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
def __repr__(self):
|
2017-04-05 00:47:49 +02:00
|
|
|
return "<%s on %s>" % (self.name, self.arch)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Architecture:
|
|
|
|
"""Class representing metadata for a particular architecture
|
|
|
|
"""
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
def __init__(self, name, platforms):
|
2015-07-17 21:03:52 +02:00
|
|
|
"""Architecture constructor
|
|
|
|
|
2017-12-05 23:39:29 +01:00
|
|
|
@param name String name for this architecture
|
|
|
|
@param platforms list of platforms belonging to this architecture
|
2015-07-17 21:03:52 +02:00
|
|
|
"""
|
2017-04-05 00:47:49 +02:00
|
|
|
self.platforms = platforms
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
self.name = name
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "<arch %s>" % self.name
|
|
|
|
|
|
|
|
|
|
|
|
class TestCase:
|
|
|
|
"""Class representing a test application
|
|
|
|
"""
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2017-10-09 19:19:12 +02:00
|
|
|
def __init__(self, testcase_root, workdir, name, tc_dict, yamlfile):
|
2015-07-17 21:03:52 +02:00
|
|
|
"""TestCase constructor.
|
|
|
|
|
2017-12-05 23:39:29 +01:00
|
|
|
This gets called by TestSuite as it finds and reads test yaml files.
|
2017-04-05 00:47:49 +02:00
|
|
|
Multiple TestCase instances may be generated from a single testcase.yaml,
|
2017-12-05 23:39:29 +01:00
|
|
|
each one corresponds to an entry within that file.
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
We need to have a unique name for every single test case. Since
|
2017-04-05 00:47:49 +02:00
|
|
|
a testcase.yaml can define multiple tests, the canonical name for
|
2015-07-17 21:03:52 +02:00
|
|
|
the test case is <workdir>/<name>.
|
|
|
|
|
|
|
|
@param testcase_root Absolute path to the root directory where
|
|
|
|
all the test cases live
|
|
|
|
@param workdir Relative path to the project directory for this
|
|
|
|
test application from the test_case root.
|
2017-12-05 23:39:29 +01:00
|
|
|
@param name Name of this test case, corresponding to the entry name
|
2015-07-17 21:03:52 +02:00
|
|
|
in the test case configuration file. For many test cases that just
|
|
|
|
define one test, can be anything and is usually "test". This is
|
|
|
|
really only used to distinguish between different cases when
|
2017-04-05 00:47:49 +02:00
|
|
|
the testcase.yaml defines multiple tests
|
2017-12-05 23:39:29 +01:00
|
|
|
@param tc_dict Dictionary with test values for this test case
|
2017-04-05 00:47:49 +02:00
|
|
|
from the testcase.yaml file
|
2015-07-17 21:03:52 +02:00
|
|
|
"""
|
2018-11-20 15:03:17 +01:00
|
|
|
self.test_path = os.path.join(testcase_root, workdir)
|
|
|
|
|
2018-04-22 05:26:48 +02:00
|
|
|
self.id = name
|
|
|
|
self.cases = []
|
2016-08-22 14:03:46 +02:00
|
|
|
self.type = tc_dict["type"]
|
2015-07-17 21:03:52 +02:00
|
|
|
self.tags = tc_dict["tags"]
|
|
|
|
self.extra_args = tc_dict["extra_args"]
|
2017-10-04 22:14:27 +02:00
|
|
|
self.extra_configs = tc_dict["extra_configs"]
|
2015-07-17 21:03:52 +02:00
|
|
|
self.arch_whitelist = tc_dict["arch_whitelist"]
|
2015-10-05 16:02:45 +02:00
|
|
|
self.arch_exclude = tc_dict["arch_exclude"]
|
2015-10-12 19:10:57 +02:00
|
|
|
self.skip = tc_dict["skip"]
|
2015-10-05 16:02:45 +02:00
|
|
|
self.platform_exclude = tc_dict["platform_exclude"]
|
2015-07-17 21:03:52 +02:00
|
|
|
self.platform_whitelist = tc_dict["platform_whitelist"]
|
2017-06-28 00:05:30 +02:00
|
|
|
self.toolchain_exclude = tc_dict["toolchain_exclude"]
|
|
|
|
self.toolchain_whitelist = tc_dict["toolchain_whitelist"]
|
2016-03-24 22:46:00 +01:00
|
|
|
self.tc_filter = tc_dict["filter"]
|
2015-07-17 21:03:52 +02:00
|
|
|
self.timeout = tc_dict["timeout"]
|
2017-12-08 18:48:39 +01:00
|
|
|
self.harness = tc_dict["harness"]
|
2017-12-24 02:20:27 +01:00
|
|
|
self.harness_config = tc_dict["harness_config"]
|
2015-07-17 21:03:52 +02:00
|
|
|
self.build_only = tc_dict["build_only"]
|
2017-04-05 00:47:49 +02:00
|
|
|
self.build_on_all = tc_dict["build_on_all"]
|
2016-02-10 22:39:00 +01:00
|
|
|
self.slow = tc_dict["slow"]
|
2017-04-05 00:47:49 +02:00
|
|
|
self.min_ram = tc_dict["min_ram"]
|
|
|
|
self.depends_on = tc_dict["depends_on"]
|
|
|
|
self.min_flash = tc_dict["min_flash"]
|
2016-11-29 21:21:59 +01:00
|
|
|
self.extra_sections = tc_dict["extra_sections"]
|
2017-09-02 18:32:08 +02:00
|
|
|
|
2018-11-20 15:03:17 +01:00
|
|
|
self.name = self.get_unique(testcase_root, workdir, name)
|
2018-04-22 05:26:48 +02:00
|
|
|
|
2015-10-10 15:29:43 +02:00
|
|
|
self.defconfig = {}
|
2018-12-03 01:12:21 +01:00
|
|
|
self.dt_config = {}
|
2019-01-09 14:46:42 +01:00
|
|
|
self.cmake_cache = {}
|
2017-10-09 19:19:12 +02:00
|
|
|
self.yamlfile = yamlfile
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2018-11-20 15:03:17 +01:00
|
|
|
|
|
|
|
def get_unique(self, testcase_root, workdir, name):
|
|
|
|
|
|
|
|
if ZEPHYR_BASE in testcase_root:
|
|
|
|
# This is a Zephyr Test, so include path in name for uniqueness
|
|
|
|
# FIXME: We should not depend on path of test for unique names.
|
|
|
|
|
|
|
|
zephyr_base = os.path.join(os.path.realpath(ZEPHYR_BASE))
|
|
|
|
short_path = os.path.normpath(testcase_root.replace(zephyr_base + "/", ""))
|
|
|
|
else:
|
|
|
|
short_path = ""
|
|
|
|
|
|
|
|
unique = os.path.normpath(os.path.join(short_path, workdir, name))
|
|
|
|
return unique
|
|
|
|
|
2018-04-22 05:26:48 +02:00
|
|
|
def scan_file(self, inf_name):
|
|
|
|
suite_regex = re.compile(
|
2018-04-26 09:17:01 +02:00
|
|
|
# do not match until end-of-line, otherwise we won't allow
|
|
|
|
# stc_regex below to catch the ones that are declared in the same
|
|
|
|
# line--as we only search starting the end of this match
|
|
|
|
br"^\s*ztest_test_suite\(\s*(?P<suite_name>[a-zA-Z0-9_]+)\s*,",
|
2018-04-22 05:26:48 +02:00
|
|
|
re.MULTILINE)
|
|
|
|
stc_regex = re.compile(
|
2018-04-26 09:17:01 +02:00
|
|
|
br"^\s*" # empy space at the beginning is ok
|
|
|
|
# catch the case where it is declared in the same sentence, e.g:
|
|
|
|
#
|
|
|
|
# ztest_test_suite(mutex_complex, ztest_user_unit_test(TESTNAME));
|
|
|
|
br"(?:ztest_test_suite\([a-zA-Z0-9_]+,\s*)?"
|
|
|
|
# Catch ztest[_user]_unit_test-[_setup_teardown](TESTNAME)
|
|
|
|
br"ztest_(?:user_)?unit_test(?:_setup_teardown)?"
|
|
|
|
# Consume the argument that becomes the extra testcse
|
|
|
|
br"\(\s*"
|
|
|
|
br"(?P<stc_name>[a-zA-Z0-9_]+)"
|
|
|
|
# _setup_teardown() variant has two extra arguments that we ignore
|
|
|
|
br"(?:\s*,\s*[a-zA-Z0-9_]+\s*,\s*[a-zA-Z0-9_]+)?"
|
|
|
|
br"\s*\)",
|
|
|
|
# We don't check how it finishes; we don't care
|
2018-04-22 05:26:48 +02:00
|
|
|
re.MULTILINE)
|
|
|
|
suite_run_regex = re.compile(
|
|
|
|
br"^\s*ztest_run_test_suite\((?P<suite_name>[a-zA-Z0-9_]+)\)",
|
|
|
|
re.MULTILINE)
|
|
|
|
achtung_regex = re.compile(
|
|
|
|
br"(#ifdef|#endif)",
|
|
|
|
re.MULTILINE)
|
|
|
|
warnings = None
|
|
|
|
|
|
|
|
with open(inf_name) as inf:
|
|
|
|
with contextlib.closing(mmap.mmap(inf.fileno(), 0, mmap.MAP_PRIVATE,
|
|
|
|
mmap.PROT_READ, 0)) as main_c:
|
|
|
|
suite_regex_match = suite_regex.search(main_c)
|
|
|
|
if not suite_regex_match:
|
|
|
|
# can't find ztest_test_suite, maybe a client, because
|
|
|
|
# it includes ztest.h
|
|
|
|
return None, None
|
|
|
|
|
|
|
|
suite_run_match = suite_run_regex.search(main_c)
|
|
|
|
if not suite_run_match:
|
|
|
|
raise ValueError("can't find ztest_run_test_suite")
|
|
|
|
|
|
|
|
achtung_matches = re.findall(
|
|
|
|
achtung_regex,
|
|
|
|
main_c[suite_regex_match.end():suite_run_match.start()])
|
|
|
|
if achtung_matches:
|
|
|
|
warnings = "found invalid %s in ztest_test_suite()" \
|
2018-04-26 09:17:01 +02:00
|
|
|
% ", ".join(set([
|
|
|
|
match.decode() for match in achtung_matches
|
|
|
|
]))
|
|
|
|
_matches = re.findall(
|
2018-04-22 05:26:48 +02:00
|
|
|
stc_regex,
|
|
|
|
main_c[suite_regex_match.end():suite_run_match.start()])
|
2018-04-26 09:17:01 +02:00
|
|
|
matches = [ match.decode().replace("test_", "") for match in _matches ]
|
2018-04-22 05:26:48 +02:00
|
|
|
return matches, warnings
|
|
|
|
|
|
|
|
def scan_path(self, path):
|
|
|
|
subcases = []
|
|
|
|
for filename in glob.glob(os.path.join(path, "src", "*.c")):
|
|
|
|
try:
|
|
|
|
_subcases, warnings = self.scan_file(filename)
|
|
|
|
if warnings:
|
2018-04-26 09:17:01 +02:00
|
|
|
error("%s: %s" % (filename, warnings))
|
2018-04-22 05:26:48 +02:00
|
|
|
if _subcases:
|
|
|
|
subcases += _subcases
|
|
|
|
except ValueError as e:
|
|
|
|
error("%s: can't find: %s", filename, e)
|
|
|
|
return subcases
|
|
|
|
|
|
|
|
|
|
|
|
def parse_subcases(self):
|
2018-11-20 15:03:17 +01:00
|
|
|
results = self.scan_path(self.test_path)
|
2018-04-22 05:26:48 +02:00
|
|
|
for sub in results:
|
2018-04-26 09:17:01 +02:00
|
|
|
name = "{}.{}".format(self.id, sub)
|
2018-04-22 05:26:48 +02:00
|
|
|
self.cases.append(name)
|
|
|
|
|
2019-03-31 22:58:12 +02:00
|
|
|
if not results:
|
|
|
|
self.cases.append(self.id)
|
|
|
|
|
2018-04-22 05:26:48 +02:00
|
|
|
|
2018-02-24 15:32:14 +01:00
|
|
|
def __str__(self):
|
2015-07-17 21:03:52 +02:00
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class TestInstance:
|
|
|
|
"""Class representing the execution of a particular TestCase on a platform
|
|
|
|
|
|
|
|
@param test The TestCase object we want to build/execute
|
|
|
|
@param platform Platform object that we want to build and run against
|
|
|
|
@param base_outdir Base directory for all test results. The actual
|
|
|
|
out directory used is <outdir>/<platform>/<test case name>
|
|
|
|
"""
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2018-02-23 15:53:46 +01:00
|
|
|
def __init__(self, test, platform, base_outdir):
|
2015-07-17 21:03:52 +02:00
|
|
|
self.test = test
|
|
|
|
self.platform = platform
|
2017-09-02 18:32:08 +02:00
|
|
|
self.name = os.path.join(platform.name, test.name)
|
2018-11-20 15:03:17 +01:00
|
|
|
self.outdir = os.path.join(base_outdir, platform.name, test.name)
|
2018-11-14 14:46:49 +01:00
|
|
|
|
|
|
|
self.build_only = options.build_only or test.build_only \
|
|
|
|
or self.check_dependency()
|
2018-02-16 03:07:24 +01:00
|
|
|
self.results = {}
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2019-04-05 23:14:21 +02:00
|
|
|
def __lt__(self, other):
|
|
|
|
return self.name < other.name
|
|
|
|
|
2018-11-14 14:46:49 +01:00
|
|
|
def check_dependency(self):
|
|
|
|
build_only = False
|
|
|
|
if self.test.harness == 'console':
|
|
|
|
if "fixture" in self.test.harness_config:
|
|
|
|
fixture = self.test.harness_config['fixture']
|
|
|
|
if fixture not in options.fixture:
|
|
|
|
build_only = True
|
|
|
|
elif self.test.harness:
|
|
|
|
build_only = True
|
|
|
|
|
|
|
|
return build_only
|
|
|
|
|
2018-11-24 02:24:19 +01:00
|
|
|
def create_overlay(self, platform):
|
2018-11-08 05:50:54 +01:00
|
|
|
file = os.path.join(self.outdir, "overlay.conf")
|
|
|
|
os.makedirs(self.outdir, exist_ok=True)
|
2019-03-02 21:43:23 +01:00
|
|
|
with open(file, "w") as f:
|
|
|
|
content = ""
|
2018-11-08 05:50:54 +01:00
|
|
|
|
2019-03-02 21:43:23 +01:00
|
|
|
if len(self.test.extra_configs) > 0:
|
|
|
|
content = "\n".join(self.test.extra_configs)
|
2018-11-08 05:50:54 +01:00
|
|
|
|
2019-03-02 21:43:23 +01:00
|
|
|
if options.enable_coverage:
|
|
|
|
if platform in options.coverage_platform:
|
|
|
|
content = content + "\nCONFIG_COVERAGE=y"
|
|
|
|
|
|
|
|
f.write(content)
|
2017-10-04 22:14:27 +02:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
def calculate_sizes(self):
|
|
|
|
"""Get the RAM/ROM sizes of a test case.
|
|
|
|
|
|
|
|
This can only be run after the instance has been executed by
|
|
|
|
MakeGenerator, otherwise there won't be any binaries to measure.
|
|
|
|
|
|
|
|
@return A SizeCalculator object
|
|
|
|
"""
|
2017-10-31 13:33:17 +01:00
|
|
|
fns = glob.glob(os.path.join(self.outdir, "zephyr", "*.elf"))
|
2017-11-24 14:11:25 +01:00
|
|
|
fns.extend(glob.glob(os.path.join(self.outdir, "zephyr", "*.exe")))
|
2016-10-28 00:10:08 +02:00
|
|
|
fns = [x for x in fns if not x.endswith('_prebuilt.elf')]
|
2015-10-02 19:04:56 +02:00
|
|
|
if (len(fns) != 1):
|
|
|
|
raise BuildError("Missing/multiple output ELF binary")
|
2016-11-29 21:21:59 +01:00
|
|
|
return SizeCalculator(fns[0], self.test.extra_sections)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "<TestCase %s on %s>" % (self.test.name, self.platform.name)
|
|
|
|
|
|
|
|
|
2015-08-28 21:36:03 +02:00
|
|
|
def defconfig_cb(context, goals, goal):
|
|
|
|
if not goal.failed:
|
|
|
|
return
|
|
|
|
|
|
|
|
info("%sCould not build defconfig for %s%s" %
|
2017-12-05 21:28:44 +01:00
|
|
|
(COLOR_RED, goal.name, COLOR_NORMAL))
|
2015-08-28 21:36:03 +02:00
|
|
|
if INLINE_LOGS:
|
|
|
|
with open(goal.get_error_log()) as fp:
|
2016-11-29 19:43:40 +01:00
|
|
|
data = fp.read()
|
|
|
|
sys.stdout.write(data)
|
|
|
|
if log_file:
|
|
|
|
log_file.write(data)
|
2015-08-28 21:36:03 +02:00
|
|
|
else:
|
2016-02-22 22:28:10 +01:00
|
|
|
info("\tsee: " + COLOR_YELLOW + goal.get_error_log() + COLOR_NORMAL)
|
2015-08-28 21:36:03 +02:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
class TestSuite:
|
2017-02-10 18:43:07 +01:00
|
|
|
config_re = re.compile('(CONFIG_[A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$')
|
2018-12-03 01:12:21 +01:00
|
|
|
dt_re = re.compile('([A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$')
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-07-24 19:24:35 +02:00
|
|
|
yaml_tc_schema = scl.yaml_load(
|
2018-08-17 13:54:41 +02:00
|
|
|
os.path.join(ZEPHYR_BASE,
|
2017-09-02 12:31:25 +02:00
|
|
|
"scripts", "sanity_chk", "sanitycheck-tc-schema.yaml"))
|
2017-07-24 19:24:35 +02:00
|
|
|
|
2018-02-23 15:53:46 +01:00
|
|
|
def __init__(self, board_root_list, testcase_roots, outdir):
|
2015-07-17 21:03:52 +02:00
|
|
|
# Keep track of which test cases we've filtered out and why
|
|
|
|
self.arches = {}
|
|
|
|
self.testcases = {}
|
|
|
|
self.platforms = []
|
2015-09-01 00:25:45 +02:00
|
|
|
self.outdir = os.path.abspath(outdir)
|
2015-07-17 21:03:52 +02:00
|
|
|
self.instances = {}
|
|
|
|
self.goals = None
|
|
|
|
self.discards = None
|
2018-04-10 20:32:51 +02:00
|
|
|
self.load_errors = 0
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2016-04-08 20:52:13 +02:00
|
|
|
for testcase_root in testcase_roots:
|
|
|
|
testcase_root = os.path.abspath(testcase_root)
|
|
|
|
|
|
|
|
debug("Reading test case configuration files under %s..." %
|
|
|
|
testcase_root)
|
|
|
|
for dirpath, dirnames, filenames in os.walk(testcase_root,
|
|
|
|
topdown=True):
|
|
|
|
verbose("scanning %s" % dirpath)
|
2017-07-24 19:24:35 +02:00
|
|
|
if 'sample.yaml' in filenames:
|
|
|
|
filename = 'sample.yaml'
|
|
|
|
elif 'testcase.yaml' in filenames:
|
|
|
|
filename = 'testcase.yaml'
|
|
|
|
else:
|
|
|
|
continue
|
2018-04-08 20:30:16 +02:00
|
|
|
|
2017-07-24 19:24:35 +02:00
|
|
|
verbose("Found possible test case in " + dirpath)
|
|
|
|
dirnames[:] = []
|
|
|
|
yaml_path = os.path.join(dirpath, filename)
|
|
|
|
try:
|
2017-12-05 21:28:44 +01:00
|
|
|
parsed_data = SanityConfigParser(
|
|
|
|
yaml_path, self.yaml_tc_schema)
|
2017-07-24 19:24:35 +02:00
|
|
|
|
scripts: sanitycheck: If error happens accessing YAML data, go on
Extend exception handling to cover not just YAML loading, but any
error while accessing parsed data too. That may catch e.g. schema
mismatch errors (for folks who don't have pykwalify installed, which
is optional). So, now error will be logged, but processing of other
tests will continue.
For example, I had a local, uncommitted test which wasn't converted
per 23f81eeb42668e and caused:
Traceback (most recent call last):
File "./scripts/sanitycheck", line 2456, in <module>
main()
File "./scripts/sanitycheck", line 2324, in main
options.outdir, options.coverage)
File "./scripts/sanitycheck", line 1445, in __init__
for name in parsed_data.tests.keys():
AttributeError: 'list' object has no attribute 'keys'
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-03 16:19:43 +01:00
|
|
|
workdir = os.path.relpath(dirpath, testcase_root)
|
|
|
|
|
|
|
|
for name in parsed_data.tests.keys():
|
|
|
|
tc_dict = parsed_data.get_test(name, testcase_valid_keys)
|
|
|
|
tc = TestCase(testcase_root, workdir, name, tc_dict,
|
|
|
|
yaml_path)
|
2018-04-22 05:26:48 +02:00
|
|
|
tc.parse_subcases()
|
scripts: sanitycheck: If error happens accessing YAML data, go on
Extend exception handling to cover not just YAML loading, but any
error while accessing parsed data too. That may catch e.g. schema
mismatch errors (for folks who don't have pykwalify installed, which
is optional). So, now error will be logged, but processing of other
tests will continue.
For example, I had a local, uncommitted test which wasn't converted
per 23f81eeb42668e and caused:
Traceback (most recent call last):
File "./scripts/sanitycheck", line 2456, in <module>
main()
File "./scripts/sanitycheck", line 2324, in main
options.outdir, options.coverage)
File "./scripts/sanitycheck", line 1445, in __init__
for name in parsed_data.tests.keys():
AttributeError: 'list' object has no attribute 'keys'
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-03 16:19:43 +01:00
|
|
|
self.testcases[tc.name] = tc
|
2016-04-08 20:52:13 +02:00
|
|
|
|
scripts: sanitycheck: If error happens accessing YAML data, go on
Extend exception handling to cover not just YAML loading, but any
error while accessing parsed data too. That may catch e.g. schema
mismatch errors (for folks who don't have pykwalify installed, which
is optional). So, now error will be logged, but processing of other
tests will continue.
For example, I had a local, uncommitted test which wasn't converted
per 23f81eeb42668e and caused:
Traceback (most recent call last):
File "./scripts/sanitycheck", line 2456, in <module>
main()
File "./scripts/sanitycheck", line 2324, in main
options.outdir, options.coverage)
File "./scripts/sanitycheck", line 1445, in __init__
for name in parsed_data.tests.keys():
AttributeError: 'list' object has no attribute 'keys'
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-03 16:19:43 +01:00
|
|
|
except Exception as e:
|
|
|
|
error("E: %s: can't load (skipping): %s" % (yaml_path, e))
|
2018-04-10 20:32:51 +02:00
|
|
|
self.load_errors += 1
|
2017-10-09 19:19:12 +02:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-10-09 19:42:28 +02:00
|
|
|
for board_root in board_root_list:
|
|
|
|
board_root = os.path.abspath(board_root)
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
debug(
|
|
|
|
"Reading platform configuration files under %s..." %
|
|
|
|
board_root)
|
2017-11-26 23:08:47 +01:00
|
|
|
for fn in glob.glob(os.path.join(board_root, "*", "*", "*.yaml")):
|
|
|
|
verbose("Found plaform configuration " + fn)
|
|
|
|
try:
|
|
|
|
platform = Platform(fn)
|
2018-07-24 15:14:42 +02:00
|
|
|
if platform.sanitycheck:
|
|
|
|
self.platforms.append(platform)
|
2017-11-26 23:08:47 +01:00
|
|
|
except RuntimeError as e:
|
|
|
|
error("E: %s: can't load: %s" % (fn, e))
|
2018-04-10 20:32:51 +02:00
|
|
|
self.load_errors += 1
|
2017-04-05 00:47:49 +02:00
|
|
|
|
|
|
|
arches = []
|
|
|
|
for p in self.platforms:
|
|
|
|
arches.append(p.arch)
|
|
|
|
for a in list(set(arches)):
|
2017-12-05 21:28:44 +01:00
|
|
|
aplatforms = [p for p in self.platforms if p.arch == a]
|
2017-04-05 00:47:49 +02:00
|
|
|
arch = Architecture(a, aplatforms)
|
|
|
|
self.arches[a] = arch
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
self.instances = {}
|
|
|
|
|
2019-03-02 21:43:23 +01:00
|
|
|
def get_platform(self, name):
|
|
|
|
selected_platform = None
|
|
|
|
for platform in self.platforms:
|
|
|
|
if platform.name == name:
|
|
|
|
selected_platform = platform
|
|
|
|
break
|
|
|
|
return selected_platform
|
2018-08-16 00:12:28 +02:00
|
|
|
|
2019-03-02 21:43:23 +01:00
|
|
|
def get_last_failed(self):
|
2018-08-16 00:12:28 +02:00
|
|
|
try:
|
|
|
|
if not os.path.exists(LAST_SANITY):
|
|
|
|
raise SanityRuntimeError("Couldn't find last sanity run.")
|
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
|
|
|
sys.exit(2)
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
result = []
|
|
|
|
with open(LAST_SANITY, "r") as fp:
|
|
|
|
cr = csv.DictReader(fp)
|
2019-03-02 21:43:23 +01:00
|
|
|
instance_list = []
|
2015-07-17 21:03:52 +02:00
|
|
|
for row in cr:
|
|
|
|
if row["passed"] == "True":
|
|
|
|
continue
|
|
|
|
test = row["test"]
|
2019-03-02 21:43:23 +01:00
|
|
|
platform = self.get_platform(row["platform"])
|
|
|
|
instance = TestInstance(self.testcases[test], platform, self.outdir)
|
|
|
|
instance.create_overlay(platform.name)
|
|
|
|
instance_list.append(instance)
|
|
|
|
self.add_instances(instance_list)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-09-02 18:32:08 +02:00
|
|
|
def load_from_file(self, file):
|
2018-08-16 00:12:28 +02:00
|
|
|
try:
|
|
|
|
if not os.path.exists(file):
|
|
|
|
raise SanityRuntimeError(
|
|
|
|
"Couldn't find input file with list of tests.")
|
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
|
|
|
sys.exit(2)
|
|
|
|
|
2017-09-02 18:32:08 +02:00
|
|
|
with open(file, "r") as fp:
|
|
|
|
cr = csv.reader(fp)
|
|
|
|
instance_list = []
|
|
|
|
for row in cr:
|
|
|
|
name = os.path.join(row[0], row[1])
|
2019-03-02 21:43:23 +01:00
|
|
|
platform = self.get_platform(row[2])
|
|
|
|
instance = TestInstance(self.testcases[name], platform, self.outdir)
|
|
|
|
instance.create_overlay(platform.name)
|
2017-09-02 18:32:08 +02:00
|
|
|
instance_list.append(instance)
|
|
|
|
self.add_instances(instance_list)
|
|
|
|
|
2017-12-30 17:48:43 +01:00
|
|
|
def apply_filters(self):
|
2017-09-02 18:32:08 +02:00
|
|
|
|
2018-02-15 14:20:18 +01:00
|
|
|
toolchain = os.environ.get("ZEPHYR_TOOLCHAIN_VARIANT", None) or \
|
|
|
|
os.environ.get("ZEPHYR_GCC_VARIANT", None)
|
2018-08-16 00:12:28 +02:00
|
|
|
|
2018-10-12 16:03:49 +02:00
|
|
|
if toolchain == "gccarmemb":
|
|
|
|
# Remove this translation when gccarmemb is no longer supported.
|
|
|
|
toolchain = "gnuarmemb"
|
2018-08-16 00:12:28 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
if not toolchain:
|
|
|
|
raise SanityRuntimeError("E: Variable ZEPHYR_TOOLCHAIN_VARIANT is not defined")
|
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
|
|
|
sys.exit(2)
|
2018-02-15 14:20:18 +01:00
|
|
|
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
instances = []
|
|
|
|
discards = {}
|
2017-12-30 17:48:43 +01:00
|
|
|
platform_filter = options.platform
|
2018-07-12 16:25:22 +02:00
|
|
|
testcase_filter = run_individual_tests
|
2017-12-30 17:48:43 +01:00
|
|
|
arch_filter = options.arch
|
|
|
|
tag_filter = options.tag
|
|
|
|
exclude_tag = options.exclude_tag
|
|
|
|
config_filter = options.config
|
|
|
|
extra_args = options.extra_args
|
|
|
|
all_plats = options.all
|
2017-10-04 22:14:27 +02:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
verbose("platform filter: " + str(platform_filter))
|
|
|
|
verbose(" arch_filter: " + str(arch_filter))
|
|
|
|
verbose(" tag_filter: " + str(tag_filter))
|
2016-10-24 23:08:56 +02:00
|
|
|
verbose(" exclude_tag: " + str(exclude_tag))
|
2015-07-17 21:03:52 +02:00
|
|
|
verbose(" config_filter: " + str(config_filter))
|
|
|
|
|
2016-03-22 18:08:35 +01:00
|
|
|
default_platforms = False
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2016-03-22 18:08:35 +01:00
|
|
|
if all_plats:
|
2015-07-17 21:03:52 +02:00
|
|
|
info("Selecting all possible platforms per test case")
|
2016-03-22 18:08:35 +01:00
|
|
|
# When --all used, any --platform arguments ignored
|
2015-07-17 21:03:52 +02:00
|
|
|
platform_filter = []
|
2016-03-22 18:08:35 +01:00
|
|
|
elif not platform_filter:
|
|
|
|
info("Selecting default platforms per test case")
|
|
|
|
default_platforms = True
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-11-09 11:43:33 +01:00
|
|
|
mg = MakeGenerator(self.outdir)
|
2018-12-03 01:12:21 +01:00
|
|
|
defconfig_list = {}
|
|
|
|
dt_list = {}
|
2019-01-09 14:46:42 +01:00
|
|
|
cmake_list = {}
|
2016-02-22 22:28:10 +01:00
|
|
|
for tc_name, tc in self.testcases.items():
|
|
|
|
for arch_name, arch in self.arches.items():
|
2015-10-10 15:29:43 +02:00
|
|
|
for plat in arch.platforms:
|
|
|
|
instance = TestInstance(tc, plat, self.outdir)
|
|
|
|
|
2016-08-22 14:03:46 +02:00
|
|
|
if (arch_name == "unit") != (tc.type == "unit"):
|
|
|
|
continue
|
|
|
|
|
2017-06-22 15:22:24 +02:00
|
|
|
if tc.build_on_all and not platform_filter:
|
2017-04-05 00:47:49 +02:00
|
|
|
platform_filter = []
|
|
|
|
|
2015-10-12 19:10:57 +02:00
|
|
|
if tc.skip:
|
|
|
|
continue
|
|
|
|
|
2015-10-10 15:29:43 +02:00
|
|
|
if tag_filter and not tc.tags.intersection(tag_filter):
|
|
|
|
continue
|
|
|
|
|
2016-10-24 23:08:56 +02:00
|
|
|
if exclude_tag and tc.tags.intersection(exclude_tag):
|
|
|
|
continue
|
|
|
|
|
2015-10-10 15:29:43 +02:00
|
|
|
if testcase_filter and tc_name not in testcase_filter:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if arch_filter and arch_name not in arch_filter:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if tc.arch_whitelist and arch.name not in tc.arch_whitelist:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if tc.arch_exclude and arch.name in tc.arch_exclude:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if tc.platform_exclude and plat.name in tc.platform_exclude:
|
|
|
|
continue
|
|
|
|
|
2017-06-28 00:05:30 +02:00
|
|
|
if tc.toolchain_exclude and toolchain in tc.toolchain_exclude:
|
|
|
|
continue
|
|
|
|
|
2015-10-10 15:29:43 +02:00
|
|
|
if platform_filter and plat.name not in platform_filter:
|
|
|
|
continue
|
|
|
|
|
2017-08-10 05:55:53 +02:00
|
|
|
if plat.ram < tc.min_ram:
|
2017-04-05 00:47:49 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
if set(plat.ignore_tags) & tc.tags:
|
|
|
|
continue
|
|
|
|
|
2017-07-07 15:05:48 +02:00
|
|
|
if tc.depends_on:
|
2017-12-05 21:28:44 +01:00
|
|
|
dep_intersection = tc.depends_on.intersection(
|
|
|
|
set(plat.supported))
|
2017-07-07 15:05:48 +02:00
|
|
|
if dep_intersection != set(tc.depends_on):
|
|
|
|
continue
|
2017-04-05 00:47:49 +02:00
|
|
|
|
|
|
|
if plat.flash < tc.min_flash:
|
|
|
|
continue
|
|
|
|
|
2015-10-10 15:29:43 +02:00
|
|
|
if tc.platform_whitelist and plat.name not in tc.platform_whitelist:
|
|
|
|
continue
|
|
|
|
|
2017-06-28 00:05:30 +02:00
|
|
|
if tc.toolchain_whitelist and toolchain not in tc.toolchain_whitelist:
|
|
|
|
continue
|
|
|
|
|
2018-10-18 18:25:55 +02:00
|
|
|
if (plat.env_satisfied and tc.tc_filter
|
|
|
|
and (plat.default or all_plats or platform_filter)
|
2018-07-22 02:29:08 +02:00
|
|
|
and (toolchain in plat.supported_toolchains or options.force_toolchain)):
|
2015-11-10 18:24:20 +01:00
|
|
|
args = tc.extra_args[:]
|
2017-10-31 13:33:17 +01:00
|
|
|
args.append("BOARD={}".format(plat.name))
|
2016-09-01 19:41:03 +02:00
|
|
|
args.extend(extra_args)
|
2015-10-10 15:29:43 +02:00
|
|
|
# FIXME would be nice to use a common outdir for this so that
|
2016-11-03 19:58:53 +01:00
|
|
|
# conf, gen_idt, etc aren't rebuilt for every combination,
|
2017-06-16 21:32:42 +02:00
|
|
|
# need a way to avoid different Make processes from clobbering
|
2017-12-05 21:28:44 +01:00
|
|
|
# each other since they all try to build them
|
|
|
|
# simultaneously
|
2015-10-10 15:29:43 +02:00
|
|
|
|
2018-11-20 15:03:17 +01:00
|
|
|
o = os.path.join(self.outdir, plat.name, tc.name)
|
2019-01-09 14:46:42 +01:00
|
|
|
cmake_cache_path = os.path.join(o, "CMakeCache.txt")
|
2018-12-03 01:12:21 +01:00
|
|
|
generated_dt_confg = "include/generated/generated_dts_board.conf"
|
|
|
|
dt_config_path = os.path.join(o, "zephyr", generated_dt_confg)
|
|
|
|
dt_list[tc, plat, tc.name.split("/")[-1]] = dt_config_path
|
2019-01-09 14:46:42 +01:00
|
|
|
cmake_list[tc, plat, tc.name.split("/")[-1]] = cmake_cache_path
|
2018-12-03 01:12:21 +01:00
|
|
|
defconfig_list[tc, plat, tc.name.split("/")[-1]] = os.path.join(o, "zephyr", ".config")
|
2018-07-07 01:20:23 +02:00
|
|
|
goal = "_".join([plat.name, "_".join(tc.name.split("/")), "config-sanitycheck"])
|
2018-11-20 15:03:17 +01:00
|
|
|
mg.add_build_goal(goal, os.path.join(ZEPHYR_BASE, tc.test_path),
|
2018-07-07 01:20:23 +02:00
|
|
|
o, args, "config-sanitycheck.log", make_args="config-sanitycheck")
|
2015-10-10 15:29:43 +02:00
|
|
|
|
|
|
|
info("Building testcase defconfigs...")
|
|
|
|
results = mg.execute(defconfig_cb)
|
|
|
|
|
2019-04-09 21:14:59 +02:00
|
|
|
info("Filtering test cases...")
|
2016-02-22 22:28:10 +01:00
|
|
|
for name, goal in results.items():
|
2018-08-16 00:12:28 +02:00
|
|
|
try:
|
|
|
|
if goal.failed:
|
|
|
|
raise SanityRuntimeError("Couldn't build some defconfigs")
|
|
|
|
except Exception as e:
|
|
|
|
error(str(e))
|
|
|
|
sys.exit(2)
|
|
|
|
|
2015-10-10 15:29:43 +02:00
|
|
|
|
2018-12-03 01:12:21 +01:00
|
|
|
for k, out_config in defconfig_list.items():
|
2016-11-03 19:58:53 +01:00
|
|
|
test, plat, name = k
|
2015-10-10 15:29:43 +02:00
|
|
|
defconfig = {}
|
|
|
|
with open(out_config, "r") as fp:
|
|
|
|
for line in fp.readlines():
|
|
|
|
m = TestSuite.config_re.match(line)
|
|
|
|
if not m:
|
2016-03-24 22:46:00 +01:00
|
|
|
if line.strip() and not line.startswith("#"):
|
|
|
|
sys.stderr.write("Unrecognized line %s\n" % line)
|
2015-10-10 15:29:43 +02:00
|
|
|
continue
|
|
|
|
defconfig[m.group(1)] = m.group(2).strip()
|
2016-11-03 19:58:53 +01:00
|
|
|
test.defconfig[plat] = defconfig
|
2015-10-10 15:29:43 +02:00
|
|
|
|
2019-01-09 14:46:42 +01:00
|
|
|
for k, cache_file in cmake_list.items():
|
|
|
|
if not os.path.exists(out_config):
|
|
|
|
continue
|
|
|
|
|
|
|
|
test, plat, name = k
|
|
|
|
cmake_conf = {}
|
|
|
|
try:
|
|
|
|
cache = CMakeCache.from_file(cache_file)
|
|
|
|
except FileNotFoundError:
|
|
|
|
cache = {}
|
|
|
|
|
|
|
|
for k in iter(cache):
|
|
|
|
cmake_conf[k.name] = k.value
|
|
|
|
|
|
|
|
test.cmake_cache[plat] = cmake_conf
|
|
|
|
|
2018-12-03 01:12:21 +01:00
|
|
|
for k, out_config in dt_list.items():
|
|
|
|
if not os.path.exists(out_config):
|
|
|
|
continue
|
|
|
|
|
|
|
|
test, plat, name = k
|
|
|
|
dt_conf = {}
|
|
|
|
with open(out_config, "r") as fp:
|
|
|
|
for line in fp.readlines():
|
|
|
|
m = TestSuite.dt_re.match(line)
|
|
|
|
if not m:
|
|
|
|
if line.strip() and not line.startswith("#"):
|
|
|
|
sys.stderr.write("Unrecognized line %s\n" % line)
|
|
|
|
continue
|
|
|
|
dt_conf[m.group(1)] = m.group(2).strip()
|
|
|
|
test.dt_config[plat] = dt_conf
|
|
|
|
|
2016-02-22 22:28:10 +01:00
|
|
|
for tc_name, tc in self.testcases.items():
|
|
|
|
for arch_name, arch in self.arches.items():
|
2015-07-17 21:03:52 +02:00
|
|
|
instance_list = []
|
|
|
|
for plat in arch.platforms:
|
|
|
|
instance = TestInstance(tc, plat, self.outdir)
|
|
|
|
|
2016-08-22 14:03:46 +02:00
|
|
|
if (arch_name == "unit") != (tc.type == "unit"):
|
|
|
|
# Discard silently
|
|
|
|
continue
|
|
|
|
|
2015-10-12 19:10:57 +02:00
|
|
|
if tc.skip:
|
|
|
|
discards[instance] = "Skip filter"
|
|
|
|
continue
|
|
|
|
|
2017-06-22 15:22:24 +02:00
|
|
|
if tc.build_on_all and not platform_filter:
|
2017-04-05 00:47:49 +02:00
|
|
|
platform_filter = []
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
if tag_filter and not tc.tags.intersection(tag_filter):
|
|
|
|
discards[instance] = "Command line testcase tag filter"
|
|
|
|
continue
|
|
|
|
|
2016-10-24 23:08:56 +02:00
|
|
|
if exclude_tag and tc.tags.intersection(exclude_tag):
|
|
|
|
discards[instance] = "Command line testcase exclude filter"
|
|
|
|
continue
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
if testcase_filter and tc_name not in testcase_filter:
|
|
|
|
discards[instance] = "Testcase name filter"
|
|
|
|
continue
|
|
|
|
|
|
|
|
if arch_filter and arch_name not in arch_filter:
|
|
|
|
discards[instance] = "Command line testcase arch filter"
|
|
|
|
continue
|
|
|
|
|
|
|
|
if tc.arch_whitelist and arch.name not in tc.arch_whitelist:
|
|
|
|
discards[instance] = "Not in test case arch whitelist"
|
|
|
|
continue
|
|
|
|
|
2015-10-05 16:02:45 +02:00
|
|
|
if tc.arch_exclude and arch.name in tc.arch_exclude:
|
|
|
|
discards[instance] = "In test case arch exclude"
|
|
|
|
continue
|
|
|
|
|
|
|
|
if tc.platform_exclude and plat.name in tc.platform_exclude:
|
|
|
|
discards[instance] = "In test case platform exclude"
|
|
|
|
continue
|
|
|
|
|
2017-06-28 00:05:30 +02:00
|
|
|
if tc.toolchain_exclude and toolchain in tc.toolchain_exclude:
|
|
|
|
discards[instance] = "In test case toolchain exclude"
|
|
|
|
continue
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
if platform_filter and plat.name not in platform_filter:
|
|
|
|
discards[instance] = "Command line platform filter"
|
|
|
|
continue
|
|
|
|
|
|
|
|
if tc.platform_whitelist and plat.name not in tc.platform_whitelist:
|
|
|
|
discards[instance] = "Not in testcase platform whitelist"
|
|
|
|
continue
|
|
|
|
|
2017-06-28 00:05:30 +02:00
|
|
|
if tc.toolchain_whitelist and toolchain not in tc.toolchain_whitelist:
|
|
|
|
discards[instance] = "Not in testcase toolchain whitelist"
|
|
|
|
continue
|
|
|
|
|
2018-10-18 18:25:55 +02:00
|
|
|
if not plat.env_satisfied:
|
|
|
|
discards[instance] = "Environment ({}) not satisfied".format(", ".join(plat.env))
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not options.force_toolchain \
|
|
|
|
and toolchain and (toolchain not in plat.supported_toolchains) \
|
|
|
|
and tc.type != 'unit':
|
2016-08-15 20:25:33 +02:00
|
|
|
discards[instance] = "Not supported by the toolchain"
|
|
|
|
continue
|
|
|
|
|
2017-08-10 05:55:53 +02:00
|
|
|
if plat.ram < tc.min_ram:
|
2017-04-05 00:47:49 +02:00
|
|
|
discards[instance] = "Not enough RAM"
|
|
|
|
continue
|
|
|
|
|
2017-07-07 15:05:48 +02:00
|
|
|
if tc.depends_on:
|
2018-07-22 02:29:08 +02:00
|
|
|
dep_intersection = tc.depends_on.intersection(set(plat.supported))
|
2017-07-07 15:05:48 +02:00
|
|
|
if dep_intersection != set(tc.depends_on):
|
|
|
|
discards[instance] = "No hardware support"
|
|
|
|
continue
|
2017-04-05 00:47:49 +02:00
|
|
|
|
2017-08-10 05:55:53 +02:00
|
|
|
if plat.flash < tc.min_flash:
|
2017-04-05 00:47:49 +02:00
|
|
|
discards[instance] = "Not enough FLASH"
|
|
|
|
continue
|
|
|
|
|
|
|
|
if set(plat.ignore_tags) & tc.tags:
|
|
|
|
discards[instance] = "Excluded tags per platform"
|
|
|
|
continue
|
|
|
|
|
2018-01-09 15:12:15 +01:00
|
|
|
defconfig = {
|
|
|
|
"ARCH": arch.name,
|
|
|
|
"PLATFORM": plat.name
|
|
|
|
}
|
2016-08-08 19:24:59 +02:00
|
|
|
defconfig.update(os.environ)
|
2016-11-03 19:58:53 +01:00
|
|
|
for p, tdefconfig in tc.defconfig.items():
|
|
|
|
if p == plat:
|
2016-03-24 22:46:00 +01:00
|
|
|
defconfig.update(tdefconfig)
|
2015-10-10 15:29:43 +02:00
|
|
|
break
|
|
|
|
|
2018-12-03 01:12:21 +01:00
|
|
|
for p, tdefconfig in tc.dt_config.items():
|
|
|
|
if p == plat:
|
|
|
|
defconfig.update(tdefconfig)
|
|
|
|
break
|
|
|
|
|
2019-01-09 14:46:42 +01:00
|
|
|
for p, tdefconfig in tc.cmake_cache.items():
|
|
|
|
if p == plat:
|
|
|
|
defconfig.update(tdefconfig)
|
|
|
|
break
|
|
|
|
|
2016-03-24 22:46:00 +01:00
|
|
|
if tc.tc_filter:
|
|
|
|
try:
|
|
|
|
res = expr_parser.parse(tc.tc_filter, defconfig)
|
2017-04-18 20:46:07 +02:00
|
|
|
except (ValueError, SyntaxError) as se:
|
2017-12-05 21:28:44 +01:00
|
|
|
sys.stderr.write(
|
|
|
|
"Failed processing %s\n" % tc.yamlfile)
|
2016-03-24 22:46:00 +01:00
|
|
|
raise se
|
|
|
|
if not res:
|
2017-12-05 21:28:44 +01:00
|
|
|
discards[instance] = (
|
|
|
|
"defconfig doesn't satisfy expression '%s'" %
|
|
|
|
tc.tc_filter)
|
2016-03-24 22:46:00 +01:00
|
|
|
continue
|
2015-10-10 15:29:43 +02:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
instance_list.append(instance)
|
|
|
|
|
|
|
|
if not instance_list:
|
|
|
|
# Every platform in this arch was rejected already
|
|
|
|
continue
|
|
|
|
|
2017-04-05 00:47:49 +02:00
|
|
|
if default_platforms and not tc.build_on_all:
|
|
|
|
if not tc.platform_whitelist:
|
2017-12-05 21:28:44 +01:00
|
|
|
instances = list(
|
|
|
|
filter(
|
|
|
|
lambda tc: tc.platform.default,
|
|
|
|
instance_list))
|
2017-04-05 00:47:49 +02:00
|
|
|
self.add_instances(instances)
|
|
|
|
else:
|
2017-12-05 23:59:01 +01:00
|
|
|
self.add_instances(instance_list[:1])
|
2017-04-05 00:47:49 +02:00
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
for instance in list(
|
|
|
|
filter(lambda tc: not tc.platform.default, instance_list)):
|
2017-04-05 00:47:49 +02:00
|
|
|
discards[instance] = "Not a default test platform"
|
2015-07-17 21:03:52 +02:00
|
|
|
else:
|
2016-03-22 18:08:35 +01:00
|
|
|
self.add_instances(instance_list)
|
2018-04-08 15:57:48 +02:00
|
|
|
|
|
|
|
for name, case in self.instances.items():
|
2018-11-24 02:24:19 +01:00
|
|
|
case.create_overlay(case.platform.name)
|
2018-04-08 15:57:48 +02:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
self.discards = discards
|
|
|
|
return discards
|
|
|
|
|
2016-03-22 18:08:35 +01:00
|
|
|
def add_instances(self, ti_list):
|
|
|
|
for ti in ti_list:
|
|
|
|
self.instances[ti.name] = ti
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2018-02-23 15:53:46 +01:00
|
|
|
def execute(self, cb, cb_context):
|
2016-04-07 21:10:25 +02:00
|
|
|
|
|
|
|
def calc_one_elf_size(name, goal):
|
|
|
|
if not goal.failed:
|
2018-07-14 13:11:02 +02:00
|
|
|
if self.instances[name].platform.type != "native":
|
|
|
|
i = self.instances[name]
|
|
|
|
sc = i.calculate_sizes()
|
|
|
|
goal.metrics["ram_size"] = sc.get_ram_size()
|
|
|
|
goal.metrics["rom_size"] = sc.get_rom_size()
|
|
|
|
goal.metrics["unrecognized"] = sc.unrecognized_sections()
|
|
|
|
else:
|
|
|
|
goal.metrics["ram_size"] = 0
|
|
|
|
goal.metrics["rom_size"] = 0
|
|
|
|
goal.metrics["unrecognized"] = []
|
2016-04-07 21:10:25 +02:00
|
|
|
|
2018-02-23 15:53:46 +01:00
|
|
|
mg = MakeGenerator(self.outdir)
|
2015-07-17 21:03:52 +02:00
|
|
|
for i in self.instances.values():
|
2018-02-23 15:53:46 +01:00
|
|
|
mg.add_test_instance(i, options.extra_args)
|
2015-07-17 21:03:52 +02:00
|
|
|
self.goals = mg.execute(cb, cb_context)
|
2016-04-07 21:10:25 +02:00
|
|
|
|
2019-01-03 19:50:53 +01:00
|
|
|
if not options.disable_size_report:
|
|
|
|
# Parallelize size calculation
|
|
|
|
executor = concurrent.futures.ThreadPoolExecutor(JOBS)
|
|
|
|
futures = [executor.submit(calc_one_elf_size, name, goal)
|
|
|
|
for name, goal in self.goals.items()]
|
|
|
|
concurrent.futures.wait(futures)
|
|
|
|
else:
|
|
|
|
for goal in self.goals.values():
|
|
|
|
goal.metrics["ram_size"] = 0
|
|
|
|
goal.metrics["rom_size"] = 0
|
|
|
|
goal.metrics["unrecognized"] = []
|
2016-04-07 21:10:25 +02:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
return self.goals
|
|
|
|
|
2019-03-21 00:48:49 +01:00
|
|
|
def save_tests(self, filename):
|
2017-09-02 18:32:08 +02:00
|
|
|
with open(filename, "at") as csvfile:
|
|
|
|
fieldnames = ['path', 'test', 'platform', 'arch']
|
|
|
|
cw = csv.DictWriter(csvfile, fieldnames, lineterminator=os.linesep)
|
|
|
|
for instance in self.instances.values():
|
|
|
|
rowdict = {
|
2017-12-05 21:28:44 +01:00
|
|
|
"path": os.path.dirname(instance.test.name),
|
|
|
|
"test": os.path.basename(instance.test.name),
|
|
|
|
"platform": instance.platform.name,
|
|
|
|
"arch": instance.platform.arch
|
|
|
|
}
|
2017-09-02 18:32:08 +02:00
|
|
|
cw.writerow(rowdict)
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
def discard_report(self, filename):
|
2018-08-16 00:12:28 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
if self.discards is None:
|
|
|
|
raise SanityRuntimeError("apply_filters() hasn't been run!")
|
|
|
|
except Exception as e:
|
|
|
|
error(str(e))
|
|
|
|
sys.exit(2)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-09-02 18:32:08 +02:00
|
|
|
with open(filename, "wt") as csvfile:
|
2015-07-17 21:03:52 +02:00
|
|
|
fieldnames = ["test", "arch", "platform", "reason"]
|
|
|
|
cw = csv.DictWriter(csvfile, fieldnames, lineterminator=os.linesep)
|
|
|
|
cw.writeheader()
|
2019-04-05 23:14:21 +02:00
|
|
|
for instance, reason in sorted(self.discards.items()):
|
2017-12-05 21:28:44 +01:00
|
|
|
rowdict = {"test": instance.test.name,
|
|
|
|
"arch": instance.platform.arch,
|
|
|
|
"platform": instance.platform.name,
|
|
|
|
"reason": reason}
|
2015-07-17 21:03:52 +02:00
|
|
|
cw.writerow(rowdict)
|
|
|
|
|
|
|
|
def compare_metrics(self, filename):
|
|
|
|
# name, datatype, lower results better
|
|
|
|
interesting_metrics = [("ram_size", int, True),
|
|
|
|
("rom_size", int, True)]
|
|
|
|
|
2018-08-16 00:12:28 +02:00
|
|
|
try:
|
|
|
|
if self.goals is None:
|
|
|
|
raise SanityRuntimeError("execute() hasn't been run!")
|
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
|
|
|
sys.exit(2)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
if not os.path.exists(filename):
|
|
|
|
info("Cannot compare metrics, %s not found" % filename)
|
|
|
|
return []
|
|
|
|
|
|
|
|
results = []
|
|
|
|
saved_metrics = {}
|
|
|
|
with open(filename) as fp:
|
|
|
|
cr = csv.DictReader(fp)
|
|
|
|
for row in cr:
|
|
|
|
d = {}
|
|
|
|
for m, _, _ in interesting_metrics:
|
|
|
|
d[m] = row[m]
|
|
|
|
saved_metrics[(row["test"], row["platform"])] = d
|
|
|
|
|
2016-02-22 22:28:10 +01:00
|
|
|
for name, goal in self.goals.items():
|
2015-07-17 21:03:52 +02:00
|
|
|
i = self.instances[name]
|
|
|
|
mkey = (i.test.name, i.platform.name)
|
|
|
|
if mkey not in saved_metrics:
|
|
|
|
continue
|
|
|
|
sm = saved_metrics[mkey]
|
|
|
|
for metric, mtype, lower_better in interesting_metrics:
|
|
|
|
if metric not in goal.metrics:
|
|
|
|
continue
|
|
|
|
if sm[metric] == "":
|
|
|
|
continue
|
|
|
|
delta = goal.metrics[metric] - mtype(sm[metric])
|
2015-08-14 23:27:38 +02:00
|
|
|
if delta == 0:
|
|
|
|
continue
|
|
|
|
results.append((i, metric, goal.metrics[metric], delta,
|
|
|
|
lower_better))
|
2015-07-17 21:03:52 +02:00
|
|
|
return results
|
|
|
|
|
2018-02-16 03:07:24 +01:00
|
|
|
def testcase_target_report(self, report_file):
|
|
|
|
|
|
|
|
run = "Sanitycheck"
|
|
|
|
eleTestsuite = None
|
|
|
|
append = options.only_failed
|
|
|
|
|
|
|
|
errors = 0
|
|
|
|
passes = 0
|
|
|
|
fails = 0
|
|
|
|
duration = 0
|
|
|
|
skips = 0
|
|
|
|
|
|
|
|
for identifier, ti in self.instances.items():
|
|
|
|
for k in ti.results.keys():
|
|
|
|
if ti.results[k] == 'PASS':
|
|
|
|
passes += 1
|
|
|
|
elif ti.results[k] == 'BLOCK':
|
|
|
|
errors += 1
|
2018-04-08 20:30:16 +02:00
|
|
|
elif ti.results[k] == 'SKIP':
|
|
|
|
skips += 1
|
2018-02-16 03:07:24 +01:00
|
|
|
else:
|
|
|
|
fails += 1
|
|
|
|
|
|
|
|
eleTestsuites = ET.Element('testsuites')
|
|
|
|
eleTestsuite = ET.SubElement(eleTestsuites, 'testsuite',
|
|
|
|
name=run, time="%d" % duration,
|
|
|
|
tests="%d" % (errors + passes + fails),
|
|
|
|
failures="%d" % fails,
|
2018-04-08 20:30:16 +02:00
|
|
|
errors="%d" % errors, skipped="%d" %skips)
|
2018-02-16 03:07:24 +01:00
|
|
|
|
|
|
|
handler_time = "0"
|
2018-04-08 20:30:16 +02:00
|
|
|
|
2018-02-16 03:07:24 +01:00
|
|
|
# print out test results
|
|
|
|
for identifier, ti in self.instances.items():
|
|
|
|
for k in ti.results.keys():
|
|
|
|
|
|
|
|
eleTestcase = ET.SubElement(
|
|
|
|
eleTestsuite, 'testcase', classname="%s:%s" %(ti.platform.name, os.path.basename(ti.test.name)),
|
2018-04-08 20:30:16 +02:00
|
|
|
name="%s" % (k), time=handler_time)
|
2018-02-16 03:07:24 +01:00
|
|
|
if ti.results[k] in ['FAIL', 'BLOCK']:
|
|
|
|
el = None
|
|
|
|
|
|
|
|
if ti.results[k] == 'FAIL':
|
|
|
|
el = ET.SubElement(
|
|
|
|
eleTestcase,
|
|
|
|
'failure',
|
|
|
|
type="failure",
|
|
|
|
message="failed")
|
|
|
|
elif ti.results[k] == 'BLOCK':
|
|
|
|
el = ET.SubElement(
|
|
|
|
eleTestcase,
|
|
|
|
'error',
|
|
|
|
type="failure",
|
|
|
|
message="failed")
|
|
|
|
p = os.path.join(options.outdir, ti.platform.name, ti.test.name)
|
2019-04-01 02:36:30 +02:00
|
|
|
log_file = os.path.join(p, "handler.log")
|
2018-02-16 03:07:24 +01:00
|
|
|
|
2019-04-01 02:36:30 +02:00
|
|
|
if os.path.exists(log_file):
|
|
|
|
with open(log_file, "rb") as f:
|
2018-02-16 03:07:24 +01:00
|
|
|
log = f.read().decode("utf-8")
|
2019-04-01 02:36:30 +02:00
|
|
|
filtered_string = ''.join(filter(lambda x: x in string.printable, log))
|
|
|
|
el.text = filtered_string
|
2018-02-16 03:07:24 +01:00
|
|
|
|
2018-04-08 20:30:16 +02:00
|
|
|
elif ti.results[k] == 'SKIP':
|
|
|
|
el = ET.SubElement(
|
|
|
|
eleTestcase,
|
2018-09-02 19:11:19 +02:00
|
|
|
'skipped',
|
|
|
|
type="skipped",
|
|
|
|
message="Skipped")
|
2018-04-08 20:30:16 +02:00
|
|
|
|
2018-02-16 03:07:24 +01:00
|
|
|
result = ET.tostring(eleTestsuites)
|
|
|
|
f = open(report_file, 'wb')
|
|
|
|
f.write(result)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
2017-12-30 17:48:43 +01:00
|
|
|
def testcase_xunit_report(self, filename, duration):
|
2018-08-16 00:12:28 +02:00
|
|
|
try:
|
|
|
|
if self.goals is None:
|
|
|
|
raise SanityRuntimeError("execute() hasn't been run!")
|
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
|
|
|
sys.exit(2)
|
2017-04-13 20:44:48 +02:00
|
|
|
|
|
|
|
fails = 0
|
|
|
|
passes = 0
|
|
|
|
errors = 0
|
|
|
|
|
|
|
|
for name, goal in self.goals.items():
|
|
|
|
if goal.failed:
|
2018-01-29 14:42:38 +01:00
|
|
|
if goal.reason in ['build_error', 'handler_crash']:
|
2017-04-13 20:44:48 +02:00
|
|
|
errors += 1
|
|
|
|
else:
|
|
|
|
fails += 1
|
|
|
|
else:
|
|
|
|
passes += 1
|
|
|
|
|
|
|
|
run = "Sanitycheck"
|
|
|
|
eleTestsuite = None
|
2017-12-30 17:48:43 +01:00
|
|
|
append = options.only_failed
|
2017-04-13 20:44:48 +02:00
|
|
|
|
2017-05-07 14:51:02 +02:00
|
|
|
if os.path.exists(filename) and append:
|
2017-04-13 20:44:48 +02:00
|
|
|
tree = ET.parse(filename)
|
|
|
|
eleTestsuites = tree.getroot()
|
2017-12-05 21:28:44 +01:00
|
|
|
eleTestsuite = tree.findall('testsuite')[0]
|
2017-04-13 20:44:48 +02:00
|
|
|
else:
|
|
|
|
eleTestsuites = ET.Element('testsuites')
|
2017-12-05 21:28:44 +01:00
|
|
|
eleTestsuite = ET.SubElement(eleTestsuites, 'testsuite',
|
|
|
|
name=run, time="%d" % duration,
|
|
|
|
tests="%d" % (errors + passes + fails),
|
|
|
|
failures="%d" % fails,
|
|
|
|
errors="%d" % errors, skip="0")
|
2017-04-13 20:44:48 +02:00
|
|
|
|
2017-11-25 23:14:12 +01:00
|
|
|
handler_time = "0"
|
2017-04-13 20:44:48 +02:00
|
|
|
for name, goal in self.goals.items():
|
|
|
|
|
|
|
|
i = self.instances[name]
|
|
|
|
if append:
|
|
|
|
for tc in eleTestsuite.findall('testcase'):
|
2017-12-05 21:28:44 +01:00
|
|
|
if tc.get('classname') == "%s:%s" % (
|
|
|
|
i.platform.name, i.test.name):
|
2017-04-13 20:44:48 +02:00
|
|
|
eleTestsuite.remove(tc)
|
|
|
|
|
2017-11-25 23:37:17 +01:00
|
|
|
if not goal.failed and goal.handler:
|
|
|
|
handler_time = "%s" %(goal.metrics["handler_time"])
|
2017-04-13 20:44:48 +02:00
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
eleTestcase = ET.SubElement(
|
|
|
|
eleTestsuite, 'testcase', classname="%s:%s" %
|
|
|
|
(i.platform.name, i.test.name), name="%s" %
|
|
|
|
(name), time=handler_time)
|
2017-04-13 20:44:48 +02:00
|
|
|
if goal.failed:
|
2017-12-05 21:28:44 +01:00
|
|
|
failure = ET.SubElement(
|
|
|
|
eleTestcase,
|
|
|
|
'failure',
|
|
|
|
type="failure",
|
|
|
|
message=goal.reason)
|
2017-12-30 17:48:43 +01:00
|
|
|
p = ("%s/%s/%s" % (options.outdir, i.platform.name, i.test.name))
|
2017-04-13 20:44:48 +02:00
|
|
|
bl = os.path.join(p, "build.log")
|
2019-02-05 13:38:32 +01:00
|
|
|
hl = os.path.join(p, "handler.log")
|
|
|
|
log_file = bl
|
2017-05-01 22:33:43 +02:00
|
|
|
if goal.reason != 'build_error':
|
2019-02-05 13:38:32 +01:00
|
|
|
if os.path.exists(hl):
|
|
|
|
log_file = hl
|
|
|
|
else:
|
|
|
|
log_file = bl
|
2017-05-01 22:33:43 +02:00
|
|
|
|
2019-02-05 13:38:32 +01:00
|
|
|
if os.path.exists(log_file):
|
|
|
|
with open(log_file, "rb") as f:
|
2017-12-30 04:09:03 +01:00
|
|
|
log = f.read().decode("utf-8")
|
2018-10-15 15:45:59 +02:00
|
|
|
filtered_string = ''.join(filter(lambda x: x in string.printable, log))
|
|
|
|
failure.text = filtered_string
|
2018-09-23 16:41:59 +02:00
|
|
|
f.close()
|
2017-04-13 20:44:48 +02:00
|
|
|
|
|
|
|
result = ET.tostring(eleTestsuites)
|
|
|
|
f = open(filename, 'wb')
|
|
|
|
f.write(result)
|
|
|
|
f.close()
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
def testcase_report(self, filename):
|
2018-08-16 00:12:28 +02:00
|
|
|
try:
|
|
|
|
if self.goals is None:
|
|
|
|
raise SanityRuntimeError("execute() hasn't been run!")
|
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
|
|
|
sys.exit(2)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2016-02-22 22:28:10 +01:00
|
|
|
with open(filename, "wt") as csvfile:
|
2015-07-17 21:03:52 +02:00
|
|
|
fieldnames = ["test", "arch", "platform", "passed", "status",
|
2017-11-25 23:14:12 +01:00
|
|
|
"extra_args", "qemu", "handler_time", "ram_size",
|
2015-07-17 21:03:52 +02:00
|
|
|
"rom_size"]
|
|
|
|
cw = csv.DictWriter(csvfile, fieldnames, lineterminator=os.linesep)
|
|
|
|
cw.writeheader()
|
2019-04-05 23:14:21 +02:00
|
|
|
for name, goal in sorted(self.goals.items()):
|
2015-07-17 21:03:52 +02:00
|
|
|
i = self.instances[name]
|
2017-12-05 21:28:44 +01:00
|
|
|
rowdict = {"test": i.test.name,
|
|
|
|
"arch": i.platform.arch,
|
|
|
|
"platform": i.platform.name,
|
|
|
|
"extra_args": " ".join(i.test.extra_args),
|
|
|
|
"qemu": i.platform.qemu_support}
|
2015-07-17 21:03:52 +02:00
|
|
|
if goal.failed:
|
|
|
|
rowdict["passed"] = False
|
|
|
|
rowdict["status"] = goal.reason
|
|
|
|
else:
|
|
|
|
rowdict["passed"] = True
|
2017-11-25 23:37:17 +01:00
|
|
|
if goal.handler:
|
2017-11-25 23:14:12 +01:00
|
|
|
rowdict["handler_time"] = goal.metrics["handler_time"]
|
2015-07-17 21:03:52 +02:00
|
|
|
rowdict["ram_size"] = goal.metrics["ram_size"]
|
|
|
|
rowdict["rom_size"] = goal.metrics["rom_size"]
|
|
|
|
cw.writerow(rowdict)
|
|
|
|
|
|
|
|
|
|
|
|
def parse_arguments():
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description=__doc__,
|
|
|
|
formatter_class=argparse.RawDescriptionHelpFormatter)
|
2016-10-25 01:00:58 +02:00
|
|
|
parser.fromfile_prefix_chars = "+"
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2019-03-12 19:37:53 +01:00
|
|
|
case_select = parser.add_argument_group("Test case selection",
|
|
|
|
"""
|
|
|
|
Artificially long but functional example:
|
|
|
|
$ ./scripts/sanitycheck -v \\
|
|
|
|
--testcase-root tests/ \\
|
|
|
|
--testcase-root mytests/ \\
|
|
|
|
--test tests/ztest/base/testing.ztest.verbose_0 \\
|
|
|
|
--test tests/kernel/fifo/fifo_api/kernel.fifo.poll
|
|
|
|
|
|
|
|
"kernel.fifo.poll" is one of the test section names in
|
|
|
|
__/fifo_api/testcase.yaml
|
|
|
|
""")
|
2019-03-08 21:39:11 +01:00
|
|
|
|
2018-07-22 02:29:08 +02:00
|
|
|
parser.add_argument("--force-toolchain", action="store_true",
|
|
|
|
help="Do not filter based on toolchain, use the set "
|
|
|
|
" toolchain unconditionally")
|
2017-12-05 21:28:44 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"-p", "--platform", action="append",
|
|
|
|
help="Platform filter for testing. This option may be used multiple "
|
|
|
|
"times. Testcases will only be built/run on the platforms "
|
|
|
|
"specified. If this option is not used, then platforms marked "
|
|
|
|
"as default in the platform metadata file will be chosen "
|
|
|
|
"to build and test. ")
|
|
|
|
parser.add_argument(
|
|
|
|
"-a", "--arch", action="append",
|
|
|
|
help="Arch filter for testing. Takes precedence over --platform. "
|
|
|
|
"If unspecified, test all arches. Multiple invocations "
|
|
|
|
"are treated as a logical 'or' relationship")
|
|
|
|
parser.add_argument(
|
|
|
|
"-t", "--tag", action="append",
|
|
|
|
help="Specify tags to restrict which tests to run by tag value. "
|
|
|
|
"Default is to not do any tag filtering. Multiple invocations "
|
|
|
|
"are treated as a logical 'or' relationship")
|
2016-10-24 23:08:56 +02:00
|
|
|
parser.add_argument("-e", "--exclude-tag", action="append",
|
2017-12-05 21:28:44 +01:00
|
|
|
help="Specify tags of tests that should not run. "
|
|
|
|
"Default is to run all tests with all tags.")
|
2019-03-08 21:39:11 +01:00
|
|
|
case_select.add_argument(
|
2017-12-05 21:28:44 +01:00
|
|
|
"-f",
|
|
|
|
"--only-failed",
|
|
|
|
action="store_true",
|
|
|
|
help="Run only those tests that failed the previous sanity check "
|
|
|
|
"invocation.")
|
|
|
|
parser.add_argument(
|
|
|
|
"-c", "--config", action="append",
|
|
|
|
help="Specify platform configuration values filtering. This can be "
|
|
|
|
"specified two ways: <config>=<value> or just <config>. The "
|
|
|
|
"defconfig for all platforms will be "
|
|
|
|
"checked. For the <config>=<value> case, only match defconfig "
|
|
|
|
"that have that value defined. For the <config> case, match "
|
|
|
|
"defconfig that have that value assigned to any value. "
|
|
|
|
"Prepend a '!' to invert the match.")
|
2018-07-12 16:25:22 +02:00
|
|
|
|
2019-03-12 01:28:36 +01:00
|
|
|
test_xor_subtest = case_select.add_mutually_exclusive_group()
|
|
|
|
|
|
|
|
test_xor_subtest.add_argument(
|
2017-12-05 21:28:44 +01:00
|
|
|
"-s", "--test", action="append",
|
|
|
|
help="Run only the specified test cases. These are named by "
|
2019-03-12 19:37:53 +01:00
|
|
|
"path/relative/to/Zephyr/base/section.name.in.testcase.yaml>")
|
2018-07-12 16:25:22 +02:00
|
|
|
|
2019-03-12 01:28:36 +01:00
|
|
|
test_xor_subtest.add_argument(
|
2018-07-12 16:25:22 +02:00
|
|
|
"--sub-test", action="append",
|
2019-03-12 19:37:53 +01:00
|
|
|
help="""Recursively find sub-test functions and run the entire
|
|
|
|
test section where they were found, including all sibling test
|
|
|
|
functions. Sub-tests are named by:
|
|
|
|
section.name.in.testcase.yaml.function_name_without_test_prefix
|
|
|
|
Example: kernel.fifo.poll.fifo_loop
|
|
|
|
""")
|
2018-07-12 16:25:22 +02:00
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"-l", "--all", action="store_true",
|
|
|
|
help="Build/test on all platforms. Any --platform arguments "
|
|
|
|
"ignored.")
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"-o", "--testcase-report",
|
|
|
|
help="Output a CSV spreadsheet containing results of the test run")
|
|
|
|
parser.add_argument(
|
|
|
|
"-d", "--discard-report",
|
|
|
|
help="Output a CSV spreadsheet showing tests that were skipped "
|
|
|
|
"and why")
|
2016-04-08 20:07:32 +02:00
|
|
|
parser.add_argument("--compare-report",
|
2017-12-05 21:28:44 +01:00
|
|
|
help="Use this report file for size comparison")
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"-B", "--subset",
|
|
|
|
help="Only run a subset of the tests, 1/4 for running the first 25%%, "
|
|
|
|
"3/5 means run the 3rd fifth of the total. "
|
|
|
|
"This option is useful when running a large number of tests on "
|
|
|
|
"different hosts to speed up execution time.")
|
2017-12-30 19:01:06 +01:00
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"-N", "--ninja", action="store_true",
|
2018-03-06 14:15:11 +01:00
|
|
|
help="Use the Ninja generator with CMake")
|
2017-12-30 19:01:06 +01:00
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"-y", "--dry-run", action="store_true",
|
|
|
|
help="Create the filtered list of test cases, but don't actually "
|
|
|
|
"run them. Useful if you're just interested in "
|
|
|
|
"--discard-report")
|
|
|
|
|
2018-02-24 15:32:14 +01:00
|
|
|
parser.add_argument("--list-tags", action="store_true",
|
|
|
|
help="list all tags in selected tests")
|
|
|
|
|
2019-03-08 21:39:11 +01:00
|
|
|
case_select.add_argument("--list-tests", action="store_true",
|
2019-03-12 19:37:53 +01:00
|
|
|
help="""List of all sub-test functions recursively found in
|
|
|
|
all --testcase-root arguments. Note different sub-tests can share
|
|
|
|
the same section name and come from different directories.
|
|
|
|
The output is flattened and reports --sub-test names only,
|
|
|
|
not their directories. For instance net.socket.getaddrinfo_ok
|
|
|
|
and net.socket.fd_set belong to different directories.
|
|
|
|
""")
|
2018-04-15 06:12:58 +02:00
|
|
|
|
2018-06-01 16:51:08 +02:00
|
|
|
parser.add_argument("--export-tests", action="store",
|
|
|
|
metavar="FILENAME",
|
|
|
|
help="Export tests case meta-data to a file in CSV format.")
|
|
|
|
|
2018-02-16 03:07:24 +01:00
|
|
|
parser.add_argument("--detailed-report",
|
|
|
|
action="store",
|
|
|
|
metavar="FILENAME",
|
|
|
|
help="Generate a junit report with detailed testcase results.")
|
|
|
|
|
2019-04-11 14:38:21 +02:00
|
|
|
parser.add_argument("--timestamps",
|
|
|
|
action="store_true",
|
|
|
|
help="Print all messages with time stamps")
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"-r", "--release", action="store_true",
|
|
|
|
help="Update the benchmark database with the results of this test "
|
|
|
|
"run. Intended to be run by CI when tagging an official "
|
|
|
|
"release. This database is used as a basis for comparison "
|
|
|
|
"when looking for deltas in metrics such as footprint")
|
2015-07-17 21:03:52 +02:00
|
|
|
parser.add_argument("-w", "--warnings-as-errors", action="store_true",
|
2017-12-05 21:28:44 +01:00
|
|
|
help="Treat warning conditions as errors")
|
|
|
|
parser.add_argument(
|
|
|
|
"-v",
|
|
|
|
"--verbose",
|
|
|
|
action="count",
|
|
|
|
default=0,
|
|
|
|
help="Emit debugging information, call multiple times to increase "
|
|
|
|
"verbosity")
|
|
|
|
parser.add_argument(
|
|
|
|
"-i", "--inline-logs", action="store_true",
|
|
|
|
help="Upon test failure, print relevant log data to stdout "
|
|
|
|
"instead of just a path to it")
|
2016-11-29 19:43:40 +01:00
|
|
|
parser.add_argument("--log-file", metavar="FILENAME", action="store",
|
2017-12-05 21:28:44 +01:00
|
|
|
help="log also to file")
|
|
|
|
parser.add_argument(
|
|
|
|
"-m", "--last-metrics", action="store_true",
|
|
|
|
help="Instead of comparing metrics from the last --release, "
|
|
|
|
"compare with the results of the previous sanity check "
|
|
|
|
"invocation")
|
|
|
|
parser.add_argument(
|
|
|
|
"-u",
|
|
|
|
"--no-update",
|
|
|
|
action="store_true",
|
|
|
|
help="do not update the results of the last run of the sanity "
|
|
|
|
"checks")
|
2019-03-08 21:39:11 +01:00
|
|
|
case_select.add_argument(
|
2017-12-05 21:28:44 +01:00
|
|
|
"-F",
|
|
|
|
"--load-tests",
|
|
|
|
metavar="FILENAME",
|
|
|
|
action="store",
|
2019-03-12 19:37:53 +01:00
|
|
|
help="Load list of tests and platforms to be run from file.")
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2019-03-08 21:39:11 +01:00
|
|
|
case_select.add_argument(
|
2017-12-05 21:28:44 +01:00
|
|
|
"-E",
|
|
|
|
"--save-tests",
|
|
|
|
metavar="FILENAME",
|
|
|
|
action="store",
|
2019-03-21 00:48:49 +01:00
|
|
|
help="Append list of tests and platforms to be run to file.")
|
2017-12-05 21:28:44 +01:00
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"-b", "--build-only", action="store_true",
|
|
|
|
help="Only build the code, do not execute any of it in QEMU")
|
|
|
|
parser.add_argument(
|
|
|
|
"-j", "--jobs", type=int,
|
2018-08-17 17:31:38 +02:00
|
|
|
help="Number of jobs for building, defaults to number of CPU threads "
|
|
|
|
"overcommited by factor 2")
|
2018-02-19 17:57:03 +01:00
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--device-testing", action="store_true",
|
2018-05-24 21:35:33 +02:00
|
|
|
help="Test on device directly. Specify the serial device to "
|
|
|
|
"use with the --device-serial option.")
|
2018-11-14 14:46:49 +01:00
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"-X", "--fixture", action="append", default=[],
|
|
|
|
help="Specify a fixture that a board might support")
|
2018-02-19 17:57:03 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"--device-serial",
|
2018-05-24 21:35:33 +02:00
|
|
|
help="Serial device for accessing the board (e.g., /dev/ttyACM0)")
|
2018-02-20 15:37:24 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"--show-footprint", action="store_true",
|
|
|
|
help="Show footprint statistics and deltas since last release."
|
|
|
|
)
|
2017-12-05 21:28:44 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"-H", "--footprint-threshold", type=float, default=5,
|
|
|
|
help="When checking test case footprint sizes, warn the user if "
|
|
|
|
"the new app size is greater then the specified percentage "
|
|
|
|
"from the last release. Default is 5. 0 to warn on any "
|
|
|
|
"increase on app size")
|
|
|
|
parser.add_argument(
|
|
|
|
"-D", "--all-deltas", action="store_true",
|
|
|
|
help="Show all footprint deltas, positive or negative. Implies "
|
|
|
|
"--footprint-threshold=0")
|
2018-04-25 08:24:25 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"-O", "--outdir",
|
2018-11-20 17:51:34 +01:00
|
|
|
default="%s/sanity-out" % os.getcwd(),
|
2018-04-25 08:24:25 +02:00
|
|
|
help="Output directory for logs and binaries. "
|
2018-11-20 17:51:34 +01:00
|
|
|
"Default is 'sanity-out' in the current directory. "
|
2018-04-25 08:24:25 +02:00
|
|
|
"This directory will be deleted unless '--no-clean' is set.")
|
2017-12-05 21:28:44 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"-n", "--no-clean", action="store_true",
|
|
|
|
help="Do not delete the outdir before building. Will result in "
|
|
|
|
"faster compilation since builds will be incremental")
|
2019-03-08 21:39:11 +01:00
|
|
|
case_select.add_argument(
|
2017-12-05 21:28:44 +01:00
|
|
|
"-T", "--testcase-root", action="append", default=[],
|
|
|
|
help="Base directory to recursively search for test cases. All "
|
|
|
|
"testcase.yaml files under here will be processed. May be "
|
2019-03-12 19:37:53 +01:00
|
|
|
"called multiple times. Defaults to the 'samples/' and "
|
|
|
|
"'tests/' directories at the base of the Zephyr tree.")
|
2018-11-14 14:46:49 +01:00
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
board_root_list = ["%s/boards" % ZEPHYR_BASE,
|
|
|
|
"%s/scripts/sanity_chk/boards" % ZEPHYR_BASE]
|
2018-11-14 14:46:49 +01:00
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"-A", "--board-root", action="append", default=board_root_list,
|
|
|
|
help="Directory to search for board configuration files. All .yaml "
|
|
|
|
"files in the directory will be processed.")
|
|
|
|
parser.add_argument(
|
|
|
|
"-z", "--size", action="append",
|
|
|
|
help="Don't run sanity checks. Instead, produce a report to "
|
|
|
|
"stdout detailing RAM/ROM sizes on the specified filenames. "
|
|
|
|
"All other command line arguments ignored.")
|
|
|
|
parser.add_argument(
|
|
|
|
"-S", "--enable-slow", action="store_true",
|
|
|
|
help="Execute time-consuming test cases that have been marked "
|
|
|
|
"as 'slow' in testcase.yaml. Normally these are only built.")
|
2018-11-13 13:36:19 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"--disable-unrecognized-section-test", action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Skip the 'unrecognized section' test.")
|
2016-07-20 20:52:04 +02:00
|
|
|
parser.add_argument("-R", "--enable-asserts", action="store_true",
|
2018-01-26 17:22:20 +01:00
|
|
|
default=True,
|
2018-05-24 22:33:09 +02:00
|
|
|
help="deprecated, left for compatibility")
|
2018-01-26 17:22:20 +01:00
|
|
|
parser.add_argument("--disable-asserts", action="store_false",
|
|
|
|
dest="enable_asserts",
|
2018-05-24 22:33:09 +02:00
|
|
|
help="deprecated, left for compatibility")
|
2016-11-30 20:25:44 +01:00
|
|
|
parser.add_argument("-Q", "--error-on-deprecations", action="store_false",
|
2017-12-05 21:28:44 +01:00
|
|
|
help="Error on deprecation warnings.")
|
2019-01-03 19:50:53 +01:00
|
|
|
parser.add_argument("--disable-size-report", action="store_true",
|
|
|
|
help="Skip expensive computation of ram/rom segment sizes.")
|
2017-11-09 12:25:02 +01:00
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"-x", "--extra-args", action="append", default=[],
|
2018-02-10 17:40:33 +01:00
|
|
|
help="""Extra CMake cache entries to define when building test cases.
|
|
|
|
May be called multiple times. The key-value entries will be
|
2017-11-09 12:25:02 +01:00
|
|
|
prefixed with -D before being passed to CMake.
|
|
|
|
|
|
|
|
E.g
|
|
|
|
"sanitycheck -x=USE_CCACHE=0"
|
|
|
|
will translate to
|
|
|
|
"cmake -DUSE_CCACHE=0"
|
|
|
|
|
|
|
|
which will ultimately disable ccache.
|
|
|
|
"""
|
|
|
|
)
|
2019-01-25 03:50:59 +01:00
|
|
|
parser.add_argument("--gcov-tool", default="gcov",
|
|
|
|
help="Path to the gcov tool. Default is gcov in the path.")
|
2017-11-09 12:25:02 +01:00
|
|
|
|
2018-06-21 09:30:20 +02:00
|
|
|
parser.add_argument("--enable-coverage", action="store_true",
|
2018-11-08 05:05:42 +01:00
|
|
|
help="Enable code coverage using gcov.")
|
2018-06-21 09:30:20 +02:00
|
|
|
|
2016-08-31 13:17:03 +02:00
|
|
|
parser.add_argument("-C", "--coverage", action="store_true",
|
2018-11-08 05:05:42 +01:00
|
|
|
help="Generate coverage reports. Implies --enable_coverage")
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2018-11-24 02:24:19 +01:00
|
|
|
coverage_platforms = ["native_posix", "nrf52_bsim"]
|
|
|
|
parser.add_argument("--coverage-platform", action="append", default=coverage_platforms,
|
|
|
|
help="Plarforms to run coverage reports on. "
|
|
|
|
"This option may be used multiple times.")
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
return parser.parse_args()
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
def log_info(filename):
|
2017-02-04 14:32:04 +01:00
|
|
|
filename = os.path.relpath(os.path.realpath(filename))
|
2015-07-17 21:03:52 +02:00
|
|
|
if INLINE_LOGS:
|
2016-02-22 22:28:10 +01:00
|
|
|
info("{:-^100}".format(filename))
|
2017-01-10 22:15:02 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
with open(filename) as fp:
|
|
|
|
data = fp.read()
|
|
|
|
except Exception as e:
|
|
|
|
data = "Unable to read log data (%s)\n" % (str(e))
|
|
|
|
|
|
|
|
sys.stdout.write(data)
|
|
|
|
if log_file:
|
|
|
|
log_file.write(data)
|
2016-02-22 22:28:10 +01:00
|
|
|
info("{:-^100}".format(filename))
|
2015-07-17 21:03:52 +02:00
|
|
|
else:
|
2016-02-22 22:28:10 +01:00
|
|
|
info("\tsee: " + COLOR_YELLOW + filename + COLOR_NORMAL)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
def terse_test_cb(instances, goals, goal):
|
|
|
|
total_tests = len(goals)
|
|
|
|
total_done = 0
|
|
|
|
total_failed = 0
|
|
|
|
|
2016-02-22 22:28:10 +01:00
|
|
|
for k, g in goals.items():
|
2015-07-17 21:03:52 +02:00
|
|
|
if g.finished:
|
|
|
|
total_done += 1
|
|
|
|
if g.failed:
|
|
|
|
total_failed += 1
|
|
|
|
|
|
|
|
if goal.failed:
|
|
|
|
i = instances[goal.name]
|
2017-12-05 21:28:44 +01:00
|
|
|
info(
|
|
|
|
"\n\n{:<25} {:<50} {}FAILED{}: {}".format(
|
|
|
|
i.platform.name,
|
|
|
|
i.test.name,
|
|
|
|
COLOR_RED,
|
|
|
|
COLOR_NORMAL,
|
2019-04-11 14:38:21 +02:00
|
|
|
goal.reason), False)
|
2015-07-17 21:03:52 +02:00
|
|
|
log_info(goal.get_error_log())
|
2019-04-11 14:38:21 +02:00
|
|
|
info("", False)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
sys.stdout.write(
|
|
|
|
"\rtotal complete: %s%4d/%4d%s %2d%% failed: %s%4d%s" %
|
|
|
|
(COLOR_GREEN, total_done, total_tests, COLOR_NORMAL,
|
|
|
|
int((float(total_done) / total_tests) * 100),
|
|
|
|
COLOR_RED if total_failed > 0 else COLOR_NORMAL, total_failed,
|
|
|
|
COLOR_NORMAL))
|
2015-07-17 21:03:52 +02:00
|
|
|
sys.stdout.flush()
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
def chatty_test_cb(instances, goals, goal):
|
|
|
|
i = instances[goal.name]
|
|
|
|
|
|
|
|
if VERBOSE < 2 and not goal.finished:
|
|
|
|
return
|
|
|
|
|
2018-05-29 13:35:34 +02:00
|
|
|
total_tests = len(goals)
|
|
|
|
total_tests_width = len(str(total_tests))
|
|
|
|
total_done = 0
|
|
|
|
|
|
|
|
for k, g in goals.items():
|
|
|
|
if g.finished:
|
|
|
|
total_done += 1
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
if goal.failed:
|
|
|
|
status = COLOR_RED + "FAILED" + COLOR_NORMAL + ": " + goal.reason
|
|
|
|
elif goal.finished:
|
|
|
|
status = COLOR_GREEN + "PASSED" + COLOR_NORMAL
|
|
|
|
else:
|
|
|
|
status = goal.make_state
|
|
|
|
|
2018-05-29 13:35:34 +02:00
|
|
|
info("{:>{}}/{} {:<25} {:<50} {}".format(
|
|
|
|
total_done, total_tests_width, total_tests, i.platform.name,
|
|
|
|
i.test.name, status))
|
2015-07-17 21:03:52 +02:00
|
|
|
if goal.failed:
|
|
|
|
log_info(goal.get_error_log())
|
|
|
|
|
2015-08-17 22:16:11 +02:00
|
|
|
|
|
|
|
def size_report(sc):
|
|
|
|
info(sc.filename)
|
2015-10-07 20:33:22 +02:00
|
|
|
info("SECTION NAME VMA LMA SIZE HEX SZ TYPE")
|
2015-10-07 23:25:51 +02:00
|
|
|
for i in range(len(sc.sections)):
|
|
|
|
v = sc.sections[i]
|
|
|
|
|
2015-10-07 20:33:22 +02:00
|
|
|
info("%-17s 0x%08x 0x%08x %8d 0x%05x %-7s" %
|
|
|
|
(v["name"], v["virt_addr"], v["load_addr"], v["size"], v["size"],
|
|
|
|
v["type"]))
|
2015-10-07 23:25:51 +02:00
|
|
|
|
2015-10-07 20:33:22 +02:00
|
|
|
info("Totals: %d bytes (ROM), %d bytes (RAM)" %
|
2017-12-05 21:28:44 +01:00
|
|
|
(sc.rom_size, sc.ram_size))
|
2015-08-17 22:16:11 +02:00
|
|
|
info("")
|
|
|
|
|
2019-01-25 15:37:38 +01:00
|
|
|
def retrieve_gcov_data(intput_file):
|
2018-10-08 16:19:41 +02:00
|
|
|
if VERBOSE:
|
|
|
|
print("Working on %s" %intput_file)
|
|
|
|
extracted_coverage_info = {}
|
|
|
|
capture_data = False
|
2019-01-25 15:37:38 +01:00
|
|
|
capture_complete = False
|
2018-10-08 16:19:41 +02:00
|
|
|
with open(intput_file, 'r') as fp:
|
|
|
|
for line in fp.readlines():
|
|
|
|
if re.search("GCOV_COVERAGE_DUMP_START", line):
|
|
|
|
capture_data = True
|
|
|
|
continue
|
|
|
|
if re.search("GCOV_COVERAGE_DUMP_END", line):
|
2019-01-25 15:37:38 +01:00
|
|
|
capture_complete = True
|
2018-10-08 16:19:41 +02:00
|
|
|
break
|
|
|
|
# Loop until the coverage data is found.
|
|
|
|
if not capture_data:
|
|
|
|
continue
|
|
|
|
if line.startswith("*"):
|
|
|
|
sp = line.split("<")
|
|
|
|
if len(sp) > 1:
|
|
|
|
# Remove the leading delimiter "*"
|
|
|
|
file_name = sp[0][1:]
|
|
|
|
# Remove the trailing new line char
|
|
|
|
hex_dump = sp[1][:-1]
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
extracted_coverage_info.update({file_name:hex_dump})
|
2019-01-25 15:37:38 +01:00
|
|
|
if not capture_data:
|
|
|
|
capture_complete = True
|
|
|
|
return {'complete': capture_complete, 'data': extracted_coverage_info}
|
2018-10-08 16:19:41 +02:00
|
|
|
|
|
|
|
def create_gcda_files(extracted_coverage_info):
|
|
|
|
if VERBOSE:
|
|
|
|
print("Generating gcda files")
|
|
|
|
for filename, hexdump_val in extracted_coverage_info.items():
|
|
|
|
# if kobject_hash is given for coverage gcovr fails
|
|
|
|
# hence skipping it problem only in gcovr v4.1
|
|
|
|
if "kobject_hash" in filename:
|
|
|
|
filename = (filename[:-4]) +"gcno"
|
|
|
|
try:
|
|
|
|
os.remove(filename)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
continue
|
|
|
|
|
|
|
|
with open(filename, 'wb') as fp:
|
|
|
|
fp.write(bytes.fromhex(hexdump_val))
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2016-08-31 13:17:03 +02:00
|
|
|
def generate_coverage(outdir, ignores):
|
2018-10-08 16:19:41 +02:00
|
|
|
|
|
|
|
for filename in glob.glob("%s/**/handler.log" %outdir, recursive=True):
|
2019-01-25 15:37:38 +01:00
|
|
|
gcov_data = retrieve_gcov_data(filename)
|
|
|
|
capture_complete = gcov_data['complete']
|
|
|
|
extracted_coverage_info = gcov_data['data']
|
|
|
|
if capture_complete:
|
|
|
|
create_gcda_files(extracted_coverage_info)
|
|
|
|
verbose("Gcov data captured: {}".format(filename))
|
|
|
|
else:
|
|
|
|
error("Gcov data capture incomplete: {}".format(filename))
|
2018-10-08 16:19:41 +02:00
|
|
|
|
2019-01-25 03:50:59 +01:00
|
|
|
gcov_tool = options.gcov_tool
|
|
|
|
|
2016-08-31 13:17:03 +02:00
|
|
|
with open(os.path.join(outdir, "coverage.log"), "a") as coveragelog:
|
|
|
|
coveragefile = os.path.join(outdir, "coverage.info")
|
|
|
|
ztestfile = os.path.join(outdir, "ztest.info")
|
2019-01-25 03:50:59 +01:00
|
|
|
subprocess.call(["lcov", "--gcov-tool", gcov_tool,
|
|
|
|
"--capture", "--directory", outdir,
|
|
|
|
"--rc", "lcov_branch_coverage=1",
|
|
|
|
"--output-file", coveragefile], stdout=coveragelog)
|
2016-08-31 13:17:03 +02:00
|
|
|
# We want to remove tests/* and tests/ztest/test/* but save tests/ztest
|
2019-01-25 03:50:59 +01:00
|
|
|
subprocess.call(["lcov", "--gcov-tool", gcov_tool, "--extract", coveragefile,
|
2017-12-05 21:28:44 +01:00
|
|
|
os.path.join(ZEPHYR_BASE, "tests", "ztest", "*"),
|
2018-02-11 09:33:55 +01:00
|
|
|
"--output-file", ztestfile,
|
|
|
|
"--rc", "lcov_branch_coverage=1"], stdout=coveragelog)
|
|
|
|
|
2018-11-08 05:50:54 +01:00
|
|
|
if os.path.exists(ztestfile) and os.path.getsize(ztestfile) > 0:
|
2019-01-25 03:50:59 +01:00
|
|
|
subprocess.call(["lcov", "--gcov-tool", gcov_tool, "--remove", ztestfile,
|
2018-02-11 09:33:55 +01:00
|
|
|
os.path.join(ZEPHYR_BASE, "tests/ztest/test/*"),
|
|
|
|
"--output-file", ztestfile,
|
|
|
|
"--rc", "lcov_branch_coverage=1"],
|
|
|
|
stdout=coveragelog)
|
|
|
|
files = [coveragefile, ztestfile];
|
|
|
|
else:
|
|
|
|
files = [coveragefile];
|
|
|
|
|
2016-08-31 13:17:03 +02:00
|
|
|
for i in ignores:
|
2017-12-05 21:28:44 +01:00
|
|
|
subprocess.call(
|
2019-01-25 03:50:59 +01:00
|
|
|
["lcov", "--gcov-tool", gcov_tool, "--remove",
|
|
|
|
coveragefile, i, "--output-file",
|
|
|
|
coveragefile, "--rc", "lcov_branch_coverage=1"],
|
2017-12-05 21:28:44 +01:00
|
|
|
stdout=coveragelog)
|
2018-02-11 09:33:55 +01:00
|
|
|
|
2019-02-03 15:48:07 +01:00
|
|
|
#The --ignore-errors source option is added to avoid it exiting due to
|
|
|
|
#samples/application_development/external_lib/
|
2018-02-11 09:33:55 +01:00
|
|
|
ret = subprocess.call(["genhtml", "--legend", "--branch-coverage",
|
2019-02-03 15:48:07 +01:00
|
|
|
"--ignore-errors", "source",
|
2018-02-11 09:33:55 +01:00
|
|
|
"-output-directory",
|
|
|
|
os.path.join(outdir, "coverage")] + files,
|
|
|
|
stdout=coveragelog)
|
|
|
|
if ret==0:
|
|
|
|
info("HTML report generated: %s"%
|
|
|
|
os.path.join(outdir, "coverage","index.html"));
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2015-08-17 22:16:11 +02:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
def main():
|
2015-07-31 21:25:22 +02:00
|
|
|
start_time = time.time()
|
2018-08-17 14:02:28 +02:00
|
|
|
global VERBOSE, INLINE_LOGS, JOBS, log_file
|
2017-12-30 19:01:45 +01:00
|
|
|
global options
|
2018-07-12 16:25:22 +02:00
|
|
|
global run_individual_tests
|
2017-12-30 19:01:45 +01:00
|
|
|
options = parse_arguments()
|
2015-08-17 22:16:11 +02:00
|
|
|
|
2018-06-21 09:30:20 +02:00
|
|
|
if options.coverage:
|
|
|
|
options.enable_coverage = True
|
|
|
|
|
2017-12-30 19:01:45 +01:00
|
|
|
if options.size:
|
|
|
|
for fn in options.size:
|
2016-11-29 21:21:59 +01:00
|
|
|
size_report(SizeCalculator(fn, []))
|
2015-08-17 22:16:11 +02:00
|
|
|
sys.exit(0)
|
|
|
|
|
2018-02-19 17:57:03 +01:00
|
|
|
|
|
|
|
if options.device_testing:
|
|
|
|
if options.device_serial is None or len(options.platform) != 1:
|
|
|
|
sys.exit(1)
|
|
|
|
|
2017-12-30 19:01:45 +01:00
|
|
|
VERBOSE += options.verbose
|
|
|
|
INLINE_LOGS = options.inline_logs
|
|
|
|
if options.log_file:
|
|
|
|
log_file = open(options.log_file, "w")
|
2018-08-17 13:56:05 +02:00
|
|
|
|
2017-12-30 19:01:45 +01:00
|
|
|
if options.jobs:
|
2018-08-17 14:02:28 +02:00
|
|
|
JOBS = options.jobs
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2018-08-17 14:02:28 +02:00
|
|
|
# Decrease JOBS for Ninja, if jobs weren't explicitly set
|
2018-08-17 13:56:05 +02:00
|
|
|
if options.ninja and not options.jobs:
|
2018-08-17 14:02:28 +02:00
|
|
|
JOBS = int(JOBS * 0.75)
|
2018-08-17 13:56:05 +02:00
|
|
|
|
2018-08-17 14:02:28 +02:00
|
|
|
info("JOBS: %d" % JOBS);
|
2018-08-17 13:56:05 +02:00
|
|
|
|
2017-12-30 19:01:45 +01:00
|
|
|
if options.subset:
|
|
|
|
subset, sets = options.subset.split("/")
|
2017-05-14 03:31:53 +02:00
|
|
|
if int(subset) > 0 and int(sets) >= int(subset):
|
2017-12-05 21:28:44 +01:00
|
|
|
info("Running only a subset: %s/%s" % (subset, sets))
|
2017-05-14 03:31:53 +02:00
|
|
|
else:
|
2017-12-30 19:01:45 +01:00
|
|
|
error("You have provided a wrong subset value: %s." % options.subset)
|
2017-05-14 03:31:53 +02:00
|
|
|
return
|
|
|
|
|
2017-12-30 19:01:45 +01:00
|
|
|
if os.path.exists(options.outdir) and not options.no_clean:
|
|
|
|
info("Cleaning output directory " + options.outdir)
|
|
|
|
shutil.rmtree(options.outdir)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-30 19:01:45 +01:00
|
|
|
if not options.testcase_root:
|
|
|
|
options.testcase_root = [os.path.join(ZEPHYR_BASE, "tests"),
|
2016-04-08 20:52:13 +02:00
|
|
|
os.path.join(ZEPHYR_BASE, "samples")]
|
|
|
|
|
2018-02-23 15:53:46 +01:00
|
|
|
ts = TestSuite(options.board_root, options.testcase_root, options.outdir)
|
2017-09-02 18:32:08 +02:00
|
|
|
|
2018-04-10 20:32:51 +02:00
|
|
|
if ts.load_errors:
|
|
|
|
sys.exit(1)
|
|
|
|
|
2018-02-24 15:32:14 +01:00
|
|
|
if options.list_tags:
|
|
|
|
tags = set()
|
|
|
|
for n,tc in ts.testcases.items():
|
|
|
|
tags = tags.union(tc.tags)
|
|
|
|
|
|
|
|
for t in tags:
|
|
|
|
print("- {}".format(t))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
2018-06-01 16:51:08 +02:00
|
|
|
|
|
|
|
def export_tests(filename, tests):
|
|
|
|
with open(filename, "wt") as csvfile:
|
|
|
|
fieldnames = ['section', 'subsection', 'title', 'reference']
|
|
|
|
cw = csv.DictWriter(csvfile, fieldnames, lineterminator=os.linesep)
|
|
|
|
for test in tests:
|
|
|
|
data = test.split(".")
|
|
|
|
subsec = " ".join(data[1].split("_")).title()
|
|
|
|
rowdict = {
|
|
|
|
"section": data[0].capitalize(),
|
|
|
|
"subsection": subsec,
|
|
|
|
"title": test,
|
|
|
|
"reference": test
|
|
|
|
}
|
|
|
|
cw.writerow(rowdict)
|
|
|
|
|
|
|
|
if options.export_tests:
|
|
|
|
cnt = 0
|
|
|
|
unq = []
|
|
|
|
for n,tc in ts.testcases.items():
|
|
|
|
for c in tc.cases:
|
|
|
|
unq.append(c)
|
|
|
|
|
|
|
|
tests = sorted(set(unq))
|
|
|
|
export_tests(options.export_tests, tests)
|
|
|
|
return
|
|
|
|
|
2018-07-12 16:25:22 +02:00
|
|
|
run_individual_tests = []
|
2018-06-01 16:51:08 +02:00
|
|
|
|
2018-07-12 16:25:22 +02:00
|
|
|
if options.test:
|
|
|
|
run_individual_tests = options.test
|
|
|
|
|
|
|
|
if options.list_tests or options.sub_test:
|
2018-04-15 06:12:58 +02:00
|
|
|
cnt = 0
|
2018-05-06 02:10:22 +02:00
|
|
|
unq = []
|
2018-07-12 16:25:22 +02:00
|
|
|
run_individual_tests = []
|
2018-04-15 06:12:58 +02:00
|
|
|
for n,tc in ts.testcases.items():
|
|
|
|
for c in tc.cases:
|
2018-07-12 16:25:22 +02:00
|
|
|
if options.sub_test and c in options.sub_test:
|
|
|
|
if tc.name not in run_individual_tests:
|
|
|
|
run_individual_tests.append(tc.name)
|
2018-05-06 02:10:22 +02:00
|
|
|
unq.append(c)
|
2018-04-15 06:12:58 +02:00
|
|
|
|
2018-07-12 16:25:22 +02:00
|
|
|
if options.sub_test:
|
|
|
|
if run_individual_tests:
|
|
|
|
info("Running the following tests:")
|
|
|
|
for t in run_individual_tests:
|
|
|
|
print(" - {}".format(t))
|
|
|
|
else:
|
|
|
|
info("Tests not found")
|
|
|
|
return
|
|
|
|
|
|
|
|
elif options.list_tests:
|
|
|
|
for u in sorted(set(unq)):
|
|
|
|
cnt = cnt + 1
|
|
|
|
print(" - {}".format(u))
|
|
|
|
print("{} total.".format(cnt))
|
|
|
|
return
|
2018-04-15 06:12:58 +02:00
|
|
|
|
2017-09-02 18:32:08 +02:00
|
|
|
discards = []
|
2017-12-30 19:01:45 +01:00
|
|
|
if options.load_tests:
|
|
|
|
ts.load_from_file(options.load_tests)
|
2019-03-02 21:43:23 +01:00
|
|
|
elif options.only_failed:
|
|
|
|
ts.get_last_failed()
|
2017-09-02 18:32:08 +02:00
|
|
|
else:
|
2017-12-30 17:48:43 +01:00
|
|
|
discards = ts.apply_filters()
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-30 19:01:45 +01:00
|
|
|
if options.discard_report:
|
|
|
|
ts.discard_report(options.discard_report)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2018-01-13 03:56:59 +01:00
|
|
|
if VERBOSE > 1 and discards:
|
2018-01-13 13:57:42 +01:00
|
|
|
# if we are using command line platform filter, no need to list every
|
|
|
|
# other platform as excluded, we know that already.
|
|
|
|
# Show only the discards that apply to the selected platforms on the
|
|
|
|
# command line
|
|
|
|
|
2016-02-22 22:28:10 +01:00
|
|
|
for i, reason in discards.items():
|
2018-01-13 13:57:42 +01:00
|
|
|
if options.platform and i.platform.name not in options.platform:
|
|
|
|
continue
|
2017-12-05 21:28:44 +01:00
|
|
|
debug(
|
|
|
|
"{:<25} {:<50} {}SKIPPED{}: {}".format(
|
|
|
|
i.platform.name,
|
|
|
|
i.test.name,
|
|
|
|
COLOR_YELLOW,
|
|
|
|
COLOR_NORMAL,
|
|
|
|
reason))
|
2017-09-02 18:32:08 +02:00
|
|
|
|
2018-01-05 14:07:45 +01:00
|
|
|
|
2018-10-08 08:57:13 +02:00
|
|
|
def native_and_unit_first(a, b):
|
|
|
|
if a[0].startswith('unit_testing'):
|
2018-01-05 14:07:45 +01:00
|
|
|
return -1
|
2018-10-08 08:57:13 +02:00
|
|
|
if b[0].startswith('unit_testing'):
|
2018-01-05 14:07:45 +01:00
|
|
|
return 1
|
2018-10-08 08:57:13 +02:00
|
|
|
if a[0].startswith('native_posix'):
|
|
|
|
return -1
|
|
|
|
if b[0].startswith('native_posix'):
|
|
|
|
return 1
|
|
|
|
if a[0].split("/",1)[0].endswith("_bsim"):
|
|
|
|
return -1
|
|
|
|
if b[0].split("/",1)[0].endswith("_bsim"):
|
|
|
|
return 1
|
|
|
|
|
2018-01-05 14:07:45 +01:00
|
|
|
return (a > b) - (a < b)
|
|
|
|
|
|
|
|
ts.instances = OrderedDict(sorted(ts.instances.items(),
|
2018-10-08 08:57:13 +02:00
|
|
|
key=cmp_to_key(native_and_unit_first)))
|
2017-09-02 18:32:08 +02:00
|
|
|
|
2017-12-30 19:01:45 +01:00
|
|
|
if options.save_tests:
|
2019-03-21 00:48:49 +01:00
|
|
|
ts.save_tests(options.save_tests)
|
2017-09-02 18:32:08 +02:00
|
|
|
return
|
|
|
|
|
2017-12-30 19:01:45 +01:00
|
|
|
if options.subset:
|
2018-01-05 14:07:45 +01:00
|
|
|
|
2017-12-30 19:01:45 +01:00
|
|
|
subset, sets = options.subset.split("/")
|
2017-09-02 18:32:08 +02:00
|
|
|
total = len(ts.instances)
|
2017-05-14 03:31:53 +02:00
|
|
|
per_set = round(total / int(sets))
|
2017-12-05 21:28:44 +01:00
|
|
|
start = (int(subset) - 1) * per_set
|
2017-05-14 03:31:53 +02:00
|
|
|
if subset == sets:
|
|
|
|
end = total
|
|
|
|
else:
|
|
|
|
end = start + per_set
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
sliced_instances = islice(ts.instances.items(), start, end)
|
2017-05-14 03:31:53 +02:00
|
|
|
ts.instances = OrderedDict(sliced_instances)
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
info("%d tests selected, %d tests discarded due to filters" %
|
|
|
|
(len(ts.instances), len(discards)))
|
|
|
|
|
2017-12-30 19:01:45 +01:00
|
|
|
if options.dry_run:
|
2015-07-17 21:03:52 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
if VERBOSE or not TERMINAL:
|
2017-12-05 21:28:44 +01:00
|
|
|
goals = ts.execute(
|
|
|
|
chatty_test_cb,
|
2018-02-23 15:53:46 +01:00
|
|
|
ts.instances)
|
2015-07-17 21:03:52 +02:00
|
|
|
else:
|
2017-12-05 21:28:44 +01:00
|
|
|
goals = ts.execute(
|
|
|
|
terse_test_cb,
|
2018-02-23 15:53:46 +01:00
|
|
|
ts.instances)
|
2019-04-11 14:38:21 +02:00
|
|
|
info("", False)
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2018-02-16 03:07:24 +01:00
|
|
|
if options.detailed_report:
|
|
|
|
ts.testcase_target_report(options.detailed_report)
|
|
|
|
|
2016-04-08 20:07:32 +02:00
|
|
|
# figure out which report to use for size comparison
|
2017-12-30 19:01:45 +01:00
|
|
|
if options.compare_report:
|
|
|
|
report_to_use = options.compare_report
|
|
|
|
elif options.last_metrics:
|
2016-04-08 20:07:32 +02:00
|
|
|
report_to_use = LAST_SANITY
|
|
|
|
else:
|
|
|
|
report_to_use = RELEASE_DATA
|
|
|
|
|
|
|
|
deltas = ts.compare_metrics(report_to_use)
|
2015-07-17 21:03:52 +02:00
|
|
|
warnings = 0
|
2018-02-20 15:37:24 +01:00
|
|
|
if deltas and options.show_footprint:
|
2015-08-14 23:27:38 +02:00
|
|
|
for i, metric, value, delta, lower_better in deltas:
|
2017-12-30 19:01:45 +01:00
|
|
|
if not options.all_deltas and ((delta < 0 and lower_better) or
|
2015-08-14 23:27:38 +02:00
|
|
|
(delta > 0 and not lower_better)):
|
|
|
|
continue
|
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
percentage = (float(delta) / float(value - delta))
|
2017-12-30 19:01:45 +01:00
|
|
|
if not options.all_deltas and (percentage <
|
|
|
|
(options.footprint_threshold / 100.0)):
|
2015-07-17 21:03:52 +02:00
|
|
|
continue
|
|
|
|
|
2016-04-11 19:27:56 +02:00
|
|
|
info("{:<25} {:<60} {}{}{}: {} {:<+4}, is now {:6} {:+.2%}".format(
|
2015-08-14 23:27:38 +02:00
|
|
|
i.platform.name, i.test.name, COLOR_YELLOW,
|
2017-12-30 19:01:45 +01:00
|
|
|
"INFO" if options.all_deltas else "WARNING", COLOR_NORMAL,
|
2015-10-13 18:44:19 +02:00
|
|
|
metric, delta, value, percentage))
|
2015-07-17 21:03:52 +02:00
|
|
|
warnings += 1
|
|
|
|
|
|
|
|
if warnings:
|
|
|
|
info("Deltas based on metrics from last %s" %
|
2017-12-30 19:01:45 +01:00
|
|
|
("release" if not options.last_metrics else "run"))
|
2015-07-17 21:03:52 +02:00
|
|
|
|
|
|
|
failed = 0
|
2016-02-22 22:28:10 +01:00
|
|
|
for name, goal in goals.items():
|
2015-07-17 21:03:52 +02:00
|
|
|
if goal.failed:
|
|
|
|
failed += 1
|
2018-11-13 13:36:19 +01:00
|
|
|
elif goal.metrics.get("unrecognized") and not options.disable_unrecognized_section_test:
|
2015-10-07 20:33:22 +02:00
|
|
|
info("%sFAILED%s: %s has unrecognized binary sections: %s" %
|
|
|
|
(COLOR_RED, COLOR_NORMAL, goal.name,
|
|
|
|
str(goal.metrics["unrecognized"])))
|
|
|
|
failed += 1
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-30 19:01:45 +01:00
|
|
|
if options.coverage:
|
2016-08-31 13:17:03 +02:00
|
|
|
info("Generating coverage files...")
|
2018-11-08 01:29:04 +01:00
|
|
|
generate_coverage(options.outdir, ["*generated*", "tests/*", "samples/*"])
|
2016-08-31 13:17:03 +02:00
|
|
|
|
2017-05-07 14:51:02 +02:00
|
|
|
duration = time.time() - start_time
|
2015-07-31 21:25:22 +02:00
|
|
|
info("%s%d of %d%s tests passed with %s%d%s warnings in %d seconds" %
|
2017-12-05 21:28:44 +01:00
|
|
|
(COLOR_RED if failed else COLOR_GREEN, len(goals) - failed,
|
|
|
|
len(goals), COLOR_NORMAL, COLOR_YELLOW if warnings else COLOR_NORMAL,
|
|
|
|
warnings, COLOR_NORMAL, duration))
|
2015-07-17 21:03:52 +02:00
|
|
|
|
2017-12-30 19:01:45 +01:00
|
|
|
if options.testcase_report:
|
|
|
|
ts.testcase_report(options.testcase_report)
|
|
|
|
if not options.no_update:
|
2017-12-30 17:48:43 +01:00
|
|
|
ts.testcase_xunit_report(LAST_SANITY_XUNIT, duration)
|
2015-07-17 21:03:52 +02:00
|
|
|
ts.testcase_report(LAST_SANITY)
|
2017-12-30 19:01:45 +01:00
|
|
|
if options.release:
|
2015-07-17 21:03:52 +02:00
|
|
|
ts.testcase_report(RELEASE_DATA)
|
2016-11-29 19:43:40 +01:00
|
|
|
if log_file:
|
|
|
|
log_file.close()
|
2017-12-30 19:01:45 +01:00
|
|
|
if failed or (warnings and options.warnings_as_errors):
|
2015-07-17 21:03:52 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2017-12-05 21:28:44 +01:00
|
|
|
|
2015-07-17 21:03:52 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|