Skip to content

Commit

Permalink
Merge branch 'add_c2_pytest' into 'main'
Browse files Browse the repository at this point in the history
add esp32c2 pytest

See merge request app-frameworks/esp-matter!716
  • Loading branch information
chshu committed Apr 25, 2024
2 parents 0aac1d3 + 190af4c commit 9aef5f4
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 4 deletions.
33 changes: 33 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,28 @@ build_esp_matter_examples_pytest_H2_idf_v5_1:
- pip install -r tools/ci/requirements-build.txt
- python tools/ci/build_apps.py ./examples --pytest_h2

build_esp_matter_examples_pytest_C2_idf_v5_1:
extends:
- .build_examples_template
artifacts:
paths:
- "examples/**/build*/size.json"
- "examples/**/build*/build_log.txt"
- "examples/**/build*/*.bin"
- "examples/**/build*/flasher_args.json"
- "examples/**/build*/config/sdkconfig.json"
- "examples/**/build*/bootloader/*.bin"
- "examples/**/build*/partition_table/*.bin"
- "connectedhomeip/connectedhomeip/out/host/chip-tool"
when: always
expire_in: 4 days
variables:
IDF_VERSION: "v5.2.1"
script:
- cd ${ESP_MATTER_PATH}
- pip install -r tools/ci/requirements-build.txt
- python tools/ci/build_apps.py ./examples --pytest_c2

build_esp_matter_examples_non_pytest_idf_v5_1:
extends:
- .build_examples_template
Expand Down Expand Up @@ -307,6 +329,17 @@ pytest_esp32c6_esp_matter_dut:
- pytest examples/ --target esp32c6 -m esp_matter_dut --junitxml=XUNIT_RESULT.xml
tags: ["esp32c6", "esp_matter_dut"]

pytest_esp32c2_esp_matter_dut:
stage: target_test
image: ${TARGET_TEST_ENV}
needs:
- build_esp_matter_examples_pytest_C2_idf_v5_1
script:
- cd ${ESP_MATTER_PATH}
- pip install -r tools/ci/requirements-pytest.txt
- pytest examples/ --target esp32c2 -m esp_matter_dut --junitxml=XUNIT_RESULT.xml
tags: ["esp32c2", "esp_matter_dut"]

pytest_esp32h2_esp_matter_dut:
stage: target_test
image: ${TARGET_TEST_ENV}
Expand Down
43 changes: 41 additions & 2 deletions examples/pytest_esp_matter_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,46 @@ def test_matter_commissioning_c3(dut:Dut) -> None:
print(out_str)
result = re.findall(r'Run command failure', str(out_str))
if len(result) != 0:
assert False
assert False

@pytest.mark.esp32c2
@pytest.mark.esp_matter_dut
@pytest.mark.parametrize(
' count, app_path, target, erase_all', [
( 1, pytest_build_dir, 'esp32c2', 'y'),
],
indirect=True,
)

# Matter over wifi commissioning
def test_matter_commissioning_c2(dut:Dut) -> None:
light = dut
# BLE start advertising
light.expect(r'chip\[DL\]\: Configuring CHIPoBLE advertising', timeout=20)
# Start commissioning
time.sleep(5)
command = CHIP_TOOL_EXE + ' pairing ble-wifi 1 ChipTEH2 chiptest123 20202021 3840'
out_str = subprocess.getoutput(command)
print(out_str)
result = re.findall(r'Run command failure', str(out_str))
if len(result) != 0:
assert False
# Use toggle command to turn-off the light
time.sleep(3)
command = CHIP_TOOL_EXE + ' onoff toggle 1 1'
out_str = subprocess.getoutput(command)
print(out_str)
result = re.findall(r'Run command failure', str(out_str))
if len(result) != 0:
assert False
# Use toggle command to turn-on the light
time.sleep(5)
command = CHIP_TOOL_EXE + ' onoff toggle 1 1'
out_str = subprocess.getoutput(command)
print(out_str)
result = re.findall(r'Run command failure', str(out_str))
if len(result) != 0:
assert False

@pytest.mark.esp32c6
@pytest.mark.esp_matter_dut
Expand Down Expand Up @@ -93,7 +132,7 @@ def test_matter_commissioning_c6(dut:Dut) -> None:
print(out_str)
result = re.findall(r'Run command failure', str(out_str))
if len(result) != 0:
assert False
assert False


# get the host interface name
Expand Down
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ filterwarnings =
markers =
# target markers
esp32c3: support esp32c3 target
esp32c2: support esp32c2 target
esp32c6: support esp32c6 target
esp32h2: support esp32h2 target
esp32s3: support esp32s3 target
# env markers
esp_matter_dut: esp matter runner which have single dut

# log related
log_cli = True
log_cli_level = INFO
Expand Down
22 changes: 21 additions & 1 deletion tools/ci/build_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
str(PROJECT_ROOT / 'examples' / '.build-rules.yml'),
]

PYTEST_C2_APPS = [
{"target": "esp32c2", "name": "light"},
]
MAINFEST_FILES = [
str(PROJECT_ROOT / 'examples' / '.build-rules.yml'),
]

def _is_c6_pytest_app(app: App) -> bool:
print(app.name, app.target)
for pytest_app in PYTEST_C6_APPS:
Expand All @@ -60,6 +67,12 @@ def _is_c3_pytest_app(app: App) -> bool:
return True
return False

def _is_c2_pytest_app(app: App) -> bool:
for pytest_app in PYTEST_C2_APPS:
if app.name == pytest_app["name"] and app.target == pytest_app["target"]:
return True
return False

def get_cmake_apps(
paths: List[str],
target: str,
Expand All @@ -83,7 +96,7 @@ def main(args: argparse.Namespace) -> None:
apps = get_cmake_apps(args.paths, args.target, args.config)

# no_pytest and only_pytest can not be both True
assert not (args.no_pytest and args.pytest_c6 and args.pytest_h2 and args.pytest_c3)
assert not (args.no_pytest and args.pytest_c6 and args.pytest_h2 and args.pytest_c3 and args.pytest_c2)
if args.no_pytest:
apps_for_build = [app for app in apps if not (_is_c6_pytest_app(app) or _is_h2_pytest_app(app))]
elif args.pytest_c6:
Expand All @@ -92,6 +105,8 @@ def main(args: argparse.Namespace) -> None:
apps_for_build = [app for app in apps if _is_h2_pytest_app(app)]
elif args.pytest_c3:
apps_for_build = [app for app in apps if _is_c3_pytest_app(app)]
elif args.pytest_c2:
apps_for_build = [app for app in apps if _is_c2_pytest_app(app)]
else:
apps_for_build = apps[:]

Expand Down Expand Up @@ -167,6 +182,11 @@ def main(args: argparse.Namespace) -> None:
action="store_true",
help='Only build pytest apps, definded in PYTEST_C3_APPS',
)
parser.add_argument(
'--pytest_c2',
action="store_true",
help='Only build pytest apps, definded in PYTEST_C2_APPS',
)
parser.add_argument(
'--collect-size-info',
type=argparse.FileType('w'),
Expand Down

0 comments on commit 9aef5f4

Please sign in to comment.