Skip to content

Commit

Permalink
twister: Add support for GTEST_SKIP()
Browse files Browse the repository at this point in the history
Calling GTEST_SKIP will print the test as DISABLED, add support and unit
tests for this.

(cherry picked from commit c2a207b)

Original-Signed-off-by: Yuval Peress <peress@google.com>
GitOrigin-RevId: c2a207b
Change-Id: I5cb1db7038a594b7d885f543c252bf45cb8b35d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5299375
Tested-by: Fabio Baltieri <fabiobaltieri@google.com>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
Commit-Queue: Fabio Baltieri <fabiobaltieri@google.com>
  • Loading branch information
yperess authored and Chromeos LUCI committed Feb 15, 2024
1 parent f6ad5a6 commit 47a63c9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scripts/pylib/twister/twisterlib/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ class Gtest(Harness):
ANSI_ESCAPE = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
TEST_START_PATTERN = r".*\[ RUN \] (?P<suite_name>.*)\.(?P<test_name>.*)$"
TEST_PASS_PATTERN = r".*\[ OK \] (?P<suite_name>.*)\.(?P<test_name>.*)$"
TEST_SKIP_PATTERN = r".*\[ DISABLED \] (?P<suite_name>.*)\.(?P<test_name>.*)$"
TEST_FAIL_PATTERN = r".*\[ FAILED \] (?P<suite_name>.*)\.(?P<test_name>.*)$"
FINISHED_PATTERN = r".*\[==========\] Done running all tests\.$"

Expand Down Expand Up @@ -594,6 +595,9 @@ def _check_result(self, line):
test_pass_match = re.search(self.TEST_PASS_PATTERN, line)
if test_pass_match:
return "passed", "{}.{}.{}".format(self.id, test_pass_match.group("suite_name"), test_pass_match.group("test_name"))
test_skip_match = re.search(self.TEST_SKIP_PATTERN, line)
if test_skip_match:
return "skipped", "{}.{}.{}".format(self.id, test_skip_match.group("suite_name"), test_skip_match.group("test_name"))
test_fail_match = re.search(self.TEST_FAIL_PATTERN, line)
if test_fail_match:
return "failed", "{}.{}.{}".format(self.id, test_fail_match.group("suite_name"), test_fail_match.group("test_name"))
Expand Down
50 changes: 50 additions & 0 deletions scripts/tests/twister/test_harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

GTEST_START_STATE = " RUN "
GTEST_PASS_STATE = " OK "
GTEST_SKIP_STATE = " DISABLED "
GTEST_FAIL_STATE = " FAILED "
SAMPLE_GTEST_START = (
"[00:00:00.000,000] <inf> label: [==========] Running all tests."
Expand Down Expand Up @@ -525,6 +526,26 @@ def test_gtest_failed(gtest):
assert gtest.instance.get_case_by_name("id.suite_name.test_name").status == "failed"


def test_gtest_skipped(gtest):
process_logs(
gtest,
[
SAMPLE_GTEST_START,
SAMPLE_GTEST_FMT.format(
state=GTEST_START_STATE, suite="suite_name", test="test_name"
),
SAMPLE_GTEST_FMT.format(
state=GTEST_SKIP_STATE, suite="suite_name", test="test_name"
),
],
)
assert gtest.state is None
assert len(gtest.detected_suite_names) == 1
assert gtest.detected_suite_names[0] == "suite_name"
assert gtest.instance.get_case_by_name("id.suite_name.test_name") is not None
assert gtest.instance.get_case_by_name("id.suite_name.test_name").status == "skipped"


def test_gtest_all_pass(gtest):
process_logs(
gtest,
Expand All @@ -546,6 +567,35 @@ def test_gtest_all_pass(gtest):
assert gtest.instance.get_case_by_name("id.suite_name.test_name").status == "passed"


def test_gtest_one_skipped(gtest):
process_logs(
gtest,
[
SAMPLE_GTEST_START,
SAMPLE_GTEST_FMT.format(
state=GTEST_START_STATE, suite="suite_name", test="test_name"
),
SAMPLE_GTEST_FMT.format(
state=GTEST_PASS_STATE, suite="suite_name", test="test_name"
),
SAMPLE_GTEST_FMT.format(
state=GTEST_START_STATE, suite="suite_name", test="test_name1"
),
SAMPLE_GTEST_FMT.format(
state=GTEST_SKIP_STATE, suite="suite_name", test="test_name1"
),
SAMPLE_GTEST_END,
],
)
assert gtest.state == "passed"
assert len(gtest.detected_suite_names) == 1
assert gtest.detected_suite_names[0] == "suite_name"
assert gtest.instance.get_case_by_name("id.suite_name.test_name") is not None
assert gtest.instance.get_case_by_name("id.suite_name.test_name").status == "passed"
assert gtest.instance.get_case_by_name("id.suite_name.test_name1") is not None
assert gtest.instance.get_case_by_name("id.suite_name.test_name1").status == "skipped"


def test_gtest_one_fail(gtest):
process_logs(
gtest,
Expand Down

0 comments on commit 47a63c9

Please sign in to comment.