twister: extend searching src directory

Extend scope of searching src directory with defined test source code.
In some cases for optimization reason src direcotry is placed in parent
directory (in relation to testcase.yaml file placement). This changes
allow to detect such situations.

Signed-off-by: Piotr Golyzniak <piotr.golyzniak@nordicsemi.no>
This commit is contained in:
Piotr Golyzniak 2022-02-04 13:13:44 +01:00 committed by Anas Nashif
commit e2d903fe31

View file

@ -1928,7 +1928,8 @@ Tests should reference the category and subsystem with a dot as a separator.
has_test_main = False
ztest_suite_names = []
for filename in glob.glob(os.path.join(path, "src", "*.c*")):
src_dir_path = self._find_src_dir_path(path)
for filename in glob.glob(os.path.join(src_dir_path, "*.c*")):
try:
result: ScanPathResult = self.scan_file(filename)
if result.warnings:
@ -1982,6 +1983,21 @@ Tests should reference the category and subsystem with a dot as a separator.
self.ztest_suite_names = ztest_suite_names
@staticmethod
def _find_src_dir_path(test_dir_path):
"""
Try to find src directory with test source code. Sometimes due to the
optimization reasons it is placed in upper directory.
"""
src_dir_name = "src"
src_dir_path = os.path.join(test_dir_path, src_dir_name)
if os.path.isdir(src_dir_path):
return src_dir_path
src_dir_path = os.path.join(test_dir_path, "..", src_dir_name)
if os.path.isdir(src_dir_path):
return src_dir_path
return ""
def __str__(self):
return self.name