Skip to content
Permalink
Browse files

scripts/sanitycheck: fix ZEPHYR_BASE subdir check edge case

There is a case where using startswith to determine if a path is a
subdirectory of another path can erroneously match. When using a
testcase root outside of ZEPHYR_BASE, an erroneous match will cause the
relative path containing ".." to get prepended to the test output
directory.

Example:

$HOME/zephyr/zephyr # ZEPHYR_BASE
$HOME/zephyr/zephyr-rust/tests # testcase root

The relative path prepended to the testcase name is ../zephyr-rust/tests
and an example test output dir is
./sanity-out/qemu_x86/../zephyr-rust/tests/rust/rust.main

In this case, the build directory escapes the board directory and is no
longer unique. Parallel tests then clobber each other.

Use pathlib instead of string matching to cover this case.

Signed-off-by: Tyler Hall <tylerwhall@gmail.com>
  • Loading branch information...
tylerwhall authored and nashif committed Jun 19, 2019
1 parent 6cbc0e0 commit bb359257bfcf82e86d074ce4e196b00ca7ac7cac
Showing with 1 addition and 1 deletion.
  1. +1 −1 scripts/sanitycheck
@@ -1740,7 +1740,7 @@ class TestCase:
def get_unique(self, testcase_root, workdir, name):

canonical_testcase_root = os.path.realpath(testcase_root)
if canonical_testcase_root.startswith(canonical_zephyr_base):
if Path(canonical_zephyr_base) in Path(canonical_testcase_root).parents:
# This is in ZEPHYR_BASE, so include path in name for uniqueness
# FIXME: We should not depend on path of test for unique names.
relative_tc_root = os.path.relpath(canonical_testcase_root,

0 comments on commit bb35925

Please sign in to comment.
You can’t perform that action at this time.