Skip to content

Commit e139dee

Browse files
YAML checker for CI - ensure no unit testing cluster (#33261)
* YAML: add checker to run in CI * DNS: make a small change to a yaml test to see the CI run * Use python3, fix name * I have no idea what I'm doing * seriously, cecille... * maybe? * trial and error is just like knowing what you're doing * Restyled by prettier-yaml * Restyled by isort * Revert "Restyled by prettier-yaml" This reverts commit fc1825b. * Revert "DNS: make a small change to a yaml test to see the CI run" This reverts commit e3b66ec. * lint * Wrong default --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 4319ab1 commit e139dee

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Certification test checks
16+
17+
on:
18+
pull_request:
19+
paths:
20+
- "src/app/tests/suites/certification/**"
21+
22+
jobs:
23+
check-certification-tests:
24+
name: Check for common problems in certification tests
25+
runs-on: ubuntu-latest
26+
27+
container:
28+
image: ghcr.io/project-chip/chip-build
29+
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
- name: Run checks
34+
run: |
35+
python3 scripts/tests/matter_yaml_linter.py

scripts/tests/chiptest/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ def AllReplYamlTests():
420420
yield test
421421

422422

423-
def AllChipToolYamlTests():
424-
for test in _AllFoundYamlTests(treat_repl_unsupported_as_in_development=False, treat_dft_unsupported_as_in_development=False, treat_chip_tool_unsupported_as_in_development=True, use_short_run_name=True):
423+
def AllChipToolYamlTests(use_short_run_name: bool = True):
424+
for test in _AllFoundYamlTests(treat_repl_unsupported_as_in_development=False, treat_dft_unsupported_as_in_development=False, treat_chip_tool_unsupported_as_in_development=True, use_short_run_name=use_short_run_name):
425425
yield test
426426

427427

scripts/tests/matter_yaml_linter.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright (c) 2024 Project CHIP Authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
import os
17+
import re
18+
import sys
19+
from pathlib import Path
20+
21+
from chiptest import AllChipToolYamlTests
22+
23+
DEFAULT_CHIP_ROOT = os.path.abspath(
24+
os.path.join(os.path.dirname(__file__), '..', '..'))
25+
26+
# TODO: These tests need to be re-written. Please see https://github.com/project-chip/connectedhomeip/issues/32620
27+
KNOWN_BAD_UNIT_TESTING = set(('Test_TC_S_2_2.yaml', 'Test_TC_S_2_3.yaml'))
28+
29+
30+
def _is_cert_test(path):
31+
return "certification" in os.path.dirname(path)
32+
33+
34+
def main():
35+
bad_tests = set()
36+
for test in AllChipToolYamlTests(use_short_run_name=False):
37+
with open(test.run_name, "r") as f:
38+
# Unit testing cluster is disallowed in cert tests, but permissible in general integration tests
39+
unit_test_lines = {}
40+
if _is_cert_test(test.run_name):
41+
unit_test_lines = {lineno: line.strip() for lineno, line in enumerate(
42+
f) if re.search('cluster: "Unit Testing"', line)}
43+
if unit_test_lines:
44+
print(
45+
f'Found certification test using Unit Testing cluster: {test.name}')
46+
for line, val in unit_test_lines.items():
47+
print(f'\t{line+1}: {val}')
48+
bad_tests.add(Path(test.run_name).name)
49+
50+
if bad_tests - KNOWN_BAD_UNIT_TESTING:
51+
return 1
52+
return 0
53+
54+
55+
if __name__ == '__main__':
56+
sys.exit(main())

0 commit comments

Comments
 (0)