Skip to content

Commit e338404

Browse files
erjiaqingandy31415
andauthored
[cirque] Add tests for re-registration for ICD devices (project-chip#36335)
* Update Linux app main * [cirque] Add tests for re-registration for ICD devices * Fix test --------- Co-authored-by: Andrei Litvin <andy314@gmail.com>
1 parent 78f399d commit e338404

File tree

6 files changed

+42
-12
lines changed

6 files changed

+42
-12
lines changed

examples/platform/linux/AppMain.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
#if CHIP_DEVICE_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER
9797
#include <app/clusters/device-energy-management-server/DeviceEnergyManagementTestEventTriggerHandler.h>
9898
#endif
99+
#if CHIP_CONFIG_ENABLE_ICD_SERVER
100+
#include <app/icd/server/ICDManager.h>
101+
#endif
99102
#include <app/TestEventTriggerDelegate.h>
100103

101104
#include <signal.h>
@@ -593,6 +596,9 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)
593596
static DeviceEnergyManagementTestEventTriggerHandler sDeviceEnergyManagementTestEventTriggerHandler;
594597
sTestEventTriggerDelegate.AddHandler(&sDeviceEnergyManagementTestEventTriggerHandler);
595598
#endif
599+
#if CHIP_CONFIG_ENABLE_ICD_SERVER
600+
sTestEventTriggerDelegate.AddHandler(&Server::GetInstance().GetICDManager());
601+
#endif
596602

597603
initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate;
598604

examples/platform/linux/BUILD.gn

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import("//build_overrides/chip.gni")
1616
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
1717
import("${chip_root}/src/app/common_flags.gni")
18+
import("${chip_root}/src/app/icd/icd.gni")
1819
import("${chip_root}/src/lib/core/core.gni")
1920
import("${chip_root}/src/lib/lib.gni")
2021
import("${chip_root}/src/tracing/tracing_args.gni")
@@ -133,6 +134,9 @@ source_set("app-main") {
133134
"${chip_root}/src/tracing",
134135
]
135136
}
137+
if (chip_enable_icd_server) {
138+
deps += [ "${chip_root}/src/app/icd/server:manager" ]
139+
}
136140

137141
defines += [
138142
"CHIP_DEVICE_CONFIG_ENABLE_SMOKE_CO_TRIGGER=${chip_enable_smoke_co_trigger}",

scripts/tests/cirque_tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ CIRQUE_TESTS=(
4848
"FailsafeTest"
4949
"MobileDeviceTest"
5050
"CommissioningTest"
51-
"IcdWaitForActiveTest"
51+
"IcdDeviceTest"
5252
"SplitCommissioningTest"
5353
"CommissioningFailureTest"
5454
"CommissioningFailureOnReportTest"

src/controller/python/test/test_scripts/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1159,18 +1159,18 @@ def TestResolve(self, nodeid):
11591159
return False
11601160

11611161
async def TestTriggerTestEventHandler(self, nodeid, enable_key, event_trigger):
1162-
self.logger.info("Test trigger test event handler for device = %08x", nodeid)
1162+
self.logger.info("Test trigger test event handler for device = %08x trigger = %016x", nodeid, event_trigger)
11631163
try:
11641164
await self.devCtrl.SendCommand(nodeid, 0, Clusters.GeneralDiagnostics.Commands.TestEventTrigger(enableKey=enable_key, eventTrigger=event_trigger))
11651165
return True
11661166
except Exception as ex:
11671167
self.logger.exception("Failed to trigger test event handler {}".format(ex))
11681168
return False
11691169

1170-
async def TestWaitForActive(self, nodeid):
1170+
async def TestWaitForActive(self, nodeid, stayActiveDurationMs=30000):
11711171
self.logger.info("Test wait for device = %08x", nodeid)
11721172
try:
1173-
await self.devCtrl.WaitForActive(nodeid)
1173+
await self.devCtrl.WaitForActive(nodeid, stayActiveDurationMs=stayActiveDurationMs)
11741174
return True
11751175
except Exception as ex:
11761176
self.logger.exception("Failed to wait for active. {}".format(ex))

src/controller/python/test/test_scripts/icd_wait_for_device_test.py src/controller/python/test/test_scripts/icd_device_test.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@
3535

3636

3737
async def waitForActiveAndTriggerCheckIn(test, nodeid):
38-
coro = test.TestWaitForActive(nodeid=nodeid)
39-
await test.TestTriggerTestEventHandler(nodeid, bytes.fromhex("00112233445566778899aabbccddeeff"), 0x0046 << 48)
38+
coro = test.TestWaitForActive(nodeid=nodeid, stayActiveDurationMs=10)
4039
return await coro
4140

4241

42+
async def invalidateHalfCounterValuesAndWaitForCheckIn(test, nodeid, testEventKey):
43+
await test.TestTriggerTestEventHandler(nodeid, bytes.fromhex(testEventKey), 0x0046_0000_0000_0003)
44+
return await waitForActiveAndTriggerCheckIn(test, nodeid)
45+
46+
4347
async def main():
4448
optParser = OptionParser()
4549
optParser.add_option(
@@ -108,6 +112,15 @@ async def main():
108112
help="Discovery type of commissioning. (0: networkOnly 1: networkOnlyWithoutPASEAutoRetry 2: All<Ble & Network>)",
109113
metavar="<discovery-type>"
110114
)
115+
optParser.add_option(
116+
"--test-event-key",
117+
action="store",
118+
dest="testEventKey",
119+
default="00112233445566778899aabbccddeeff",
120+
type=str,
121+
help="Enable key of Test event trigger.",
122+
metavar="<test-event-key>"
123+
)
111124

112125
(options, remainingArgs) = optParser.parse_args(sys.argv[1:])
113126

@@ -125,9 +138,14 @@ async def main():
125138
nodeid=options.nodeid),
126139
"Failed to finish key exchange")
127140
logger.info("Commissioning completed")
141+
128142
logger.info("Testing wait for active")
129143
FailIfNot(await waitForActiveAndTriggerCheckIn(test, nodeid=options.nodeid), "Failed to test wait for active")
130-
logger.info('Successfully handled wait-for-active')
144+
logger.info("Successfully handled wait-for-active")
145+
146+
logger.info("Testing InvalidateHalfCounterValues for refresh key")
147+
FailIfNot(await invalidateHalfCounterValuesAndWaitForCheckIn(test, nodeid=options.nodeid, testEventKey=options.testEventKey), "Failed to test wait for active")
148+
logger.info("Successfully handled key refresh")
131149

132150
timeoutTicker.stop()
133151

src/test_driver/linux-cirque/IcdWaitForActiveTest.py src/test_driver/linux-cirque/IcdDeviceTest.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
TEST_DISCOVERY_TYPE = [0, 1, 2]
4444
MATTER_DEVELOPMENT_PAA_ROOT_CERTS = "credentials/development/paa-root-certs"
4545

46+
TEST_EVENT_KEY_HEX = "00112233445566778899aabbccddeeff"
47+
4648
DEVICE_CONFIG = {
4749
'device0': {
4850
'type': 'MobileDevice',
@@ -88,8 +90,8 @@ def run_controller_test(self):
8890
self.execute_device_cmd(
8991
server,
9092
("CHIPCirqueDaemon.py -- run gdb -batch -return-child-result -q -ex \"set pagination off\" "
91-
"-ex run -ex \"thread apply all bt\" --args {} --thread --discriminator {}").format(
92-
os.path.join(CHIP_REPO, "out/debug/lit_icd/lit-icd-app"), TEST_DISCRIMINATOR))
93+
"-ex run -ex \"thread apply all bt\" --args {} --thread --discriminator {} --enable-key {}").format(
94+
os.path.join(CHIP_REPO, "out/debug/lit_icd/lit-icd-app"), TEST_DISCRIMINATOR, TEST_EVENT_KEY_HEX))
9395

9496
self.reset_thread_devices(server_ids)
9597

@@ -103,10 +105,10 @@ def run_controller_test(self):
103105
CHIP_REPO, "out/debug/linux_x64_gcc/controller/python/chip_repl-0.0-py3-none-any.whl")))
104106

105107
command = ("gdb -batch -return-child-result -q -ex run -ex \"thread apply all bt\" "
106-
"--args python3 {} -t 300 -a {} --paa-trust-store-path {}").format(
108+
"--args python3 {} -t 300 -a {} --paa-trust-store-path {} --test-event-key {}").format(
107109
os.path.join(
108-
CHIP_REPO, "src/controller/python/test/test_scripts/icd_wait_for_device_test.py"), ethernet_ip,
109-
os.path.join(CHIP_REPO, MATTER_DEVELOPMENT_PAA_ROOT_CERTS))
110+
CHIP_REPO, "src/controller/python/test/test_scripts/icd_device_test.py"), ethernet_ip,
111+
os.path.join(CHIP_REPO, MATTER_DEVELOPMENT_PAA_ROOT_CERTS), TEST_EVENT_KEY_HEX)
110112
ret = self.execute_device_cmd(req_device_id, command)
111113

112114
self.assertEqual(ret['return_code'], '0',

0 commit comments

Comments
 (0)