sanitycheck: support exporting instances

Enable exporting tests per platform.

sanitycheck --export-tests out.txt  -p qemu_x86 -T tests/

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2020-05-07 12:02:48 -04:00 committed by Carles Cufí
commit bb28035a82
3 changed files with 37 additions and 5 deletions

View file

@ -103,9 +103,9 @@ identifier:
``cmake``:: ``cmake``::
# with west # with west
west build -b tinytile west build -b reel_board
# with cmake # with cmake
cmake -DBOARD=tinytile .. cmake -DBOARD=reel_board ..
name: name:
The actual name of the board as it appears in marketing material. The actual name of the board as it appears in marketing material.

View file

@ -2214,6 +2214,10 @@ class TestSuite(DisablePyTestCollectionMixin):
# hardcoded for now # hardcoded for now
self.connected_hardware = [] self.connected_hardware = []
def get_platform_instances(self, platform):
filtered_dict = {k:v for k,v in self.instances.items() if k.startswith(platform + "/")}
return filtered_dict
def config(self): def config(self):
logger.info("coverage platform: {}".format(self.coverage_platform)) logger.info("coverage platform: {}".format(self.coverage_platform))

View file

@ -170,6 +170,7 @@ import argparse
import sys import sys
import logging import logging
import time import time
import itertools
import shutil import shutil
from collections import OrderedDict from collections import OrderedDict
import multiprocessing import multiprocessing
@ -178,6 +179,7 @@ import csv
from colorama import Fore from colorama import Fore
from pathlib import Path from pathlib import Path
ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
if not ZEPHYR_BASE: if not ZEPHYR_BASE:
# This file has been zephyr/scripts/sanitycheck for years, # This file has been zephyr/scripts/sanitycheck for years,
@ -391,7 +393,10 @@ Artificially long but functional example:
parser.add_argument("--export-tests", action="store", parser.add_argument("--export-tests", action="store",
metavar="FILENAME", metavar="FILENAME",
help="Export tests case meta-data to a file in CSV format.") help="Export tests case meta-data to a file in CSV format."
"Test instances can be exported per target by supplying "
"the platform name using --platform option. (tests for only "
" one platform can be exported at a time)")
parser.add_argument("--timestamps", parser.add_argument("--timestamps",
action="store_true", action="store_true",
@ -837,8 +842,8 @@ def main():
return return
if options.list_tests or options.test_tree or options.list_test_duplicates \ if not options.platform and (options.list_tests or options.test_tree or options.list_test_duplicates \
or options.sub_test or options.export_tests: or options.sub_test or options.export_tests):
cnt = 0 cnt = 0
all_tests = suite.get_all_tests() all_tests = suite.get_all_tests()
@ -945,6 +950,29 @@ def main():
) )
if (options.export_tests or options.list_tests) and options.platform:
if len(options.platform) > 1:
logger.error("When exporting tests, only one platform "
"should be specified.")
return
for p in options.platform:
inst = suite.get_platform_instances(p)
if options.export_tests:
tests = [x.testcase.cases for x in inst.values()]
merged = list(itertools.chain(*tests))
export_tests(options.export_tests, merged)
return
count = 0
for i in inst.values():
for c in i.testcase.cases:
print(f"- {c}")
count += 1
print(f"Tests found: {count}")
return
if VERBOSE > 1 and discards: if VERBOSE > 1 and discards:
# if we are using command line platform filter, no need to list every # if we are using command line platform filter, no need to list every
# other platform as excluded, we know that already. # other platform as excluded, we know that already.