Skip to content

Commit

Permalink
[cirque] Add tests for re-registration for ICD devices (#36335)
Browse files Browse the repository at this point in the history
* Update Linux app main

* [cirque] Add tests for re-registration for ICD devices

* Fix test

---------

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
erjiaqing and andy31415 authored Nov 7, 2024
1 parent 78f399d commit e338404
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12 deletions.
6 changes: 6 additions & 0 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
#if CHIP_DEVICE_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER
#include <app/clusters/device-energy-management-server/DeviceEnergyManagementTestEventTriggerHandler.h>
#endif
#if CHIP_CONFIG_ENABLE_ICD_SERVER
#include <app/icd/server/ICDManager.h>
#endif
#include <app/TestEventTriggerDelegate.h>

#include <signal.h>
Expand Down Expand Up @@ -593,6 +596,9 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)
static DeviceEnergyManagementTestEventTriggerHandler sDeviceEnergyManagementTestEventTriggerHandler;
sTestEventTriggerDelegate.AddHandler(&sDeviceEnergyManagementTestEventTriggerHandler);
#endif
#if CHIP_CONFIG_ENABLE_ICD_SERVER
sTestEventTriggerDelegate.AddHandler(&Server::GetInstance().GetICDManager());
#endif

initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate;

Expand Down
4 changes: 4 additions & 0 deletions examples/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import("//build_overrides/chip.gni")
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
import("${chip_root}/src/app/common_flags.gni")
import("${chip_root}/src/app/icd/icd.gni")
import("${chip_root}/src/lib/core/core.gni")
import("${chip_root}/src/lib/lib.gni")
import("${chip_root}/src/tracing/tracing_args.gni")
Expand Down Expand Up @@ -133,6 +134,9 @@ source_set("app-main") {
"${chip_root}/src/tracing",
]
}
if (chip_enable_icd_server) {
deps += [ "${chip_root}/src/app/icd/server:manager" ]
}

defines += [
"CHIP_DEVICE_CONFIG_ENABLE_SMOKE_CO_TRIGGER=${chip_enable_smoke_co_trigger}",
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/cirque_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CIRQUE_TESTS=(
"FailsafeTest"
"MobileDeviceTest"
"CommissioningTest"
"IcdWaitForActiveTest"
"IcdDeviceTest"
"SplitCommissioningTest"
"CommissioningFailureTest"
"CommissioningFailureOnReportTest"
Expand Down
6 changes: 3 additions & 3 deletions src/controller/python/test/test_scripts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,18 +1159,18 @@ def TestResolve(self, nodeid):
return False

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

async def TestWaitForActive(self, nodeid):
async def TestWaitForActive(self, nodeid, stayActiveDurationMs=30000):
self.logger.info("Test wait for device = %08x", nodeid)
try:
await self.devCtrl.WaitForActive(nodeid)
await self.devCtrl.WaitForActive(nodeid, stayActiveDurationMs=stayActiveDurationMs)
return True
except Exception as ex:
self.logger.exception("Failed to wait for active. {}".format(ex))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@


async def waitForActiveAndTriggerCheckIn(test, nodeid):
coro = test.TestWaitForActive(nodeid=nodeid)
await test.TestTriggerTestEventHandler(nodeid, bytes.fromhex("00112233445566778899aabbccddeeff"), 0x0046 << 48)
coro = test.TestWaitForActive(nodeid=nodeid, stayActiveDurationMs=10)
return await coro


async def invalidateHalfCounterValuesAndWaitForCheckIn(test, nodeid, testEventKey):
await test.TestTriggerTestEventHandler(nodeid, bytes.fromhex(testEventKey), 0x0046_0000_0000_0003)
return await waitForActiveAndTriggerCheckIn(test, nodeid)


async def main():
optParser = OptionParser()
optParser.add_option(
Expand Down Expand Up @@ -108,6 +112,15 @@ async def main():
help="Discovery type of commissioning. (0: networkOnly 1: networkOnlyWithoutPASEAutoRetry 2: All<Ble & Network>)",
metavar="<discovery-type>"
)
optParser.add_option(
"--test-event-key",
action="store",
dest="testEventKey",
default="00112233445566778899aabbccddeeff",
type=str,
help="Enable key of Test event trigger.",
metavar="<test-event-key>"
)

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

Expand All @@ -125,9 +138,14 @@ async def main():
nodeid=options.nodeid),
"Failed to finish key exchange")
logger.info("Commissioning completed")

logger.info("Testing wait for active")
FailIfNot(await waitForActiveAndTriggerCheckIn(test, nodeid=options.nodeid), "Failed to test wait for active")
logger.info('Successfully handled wait-for-active')
logger.info("Successfully handled wait-for-active")

logger.info("Testing InvalidateHalfCounterValues for refresh key")
FailIfNot(await invalidateHalfCounterValuesAndWaitForCheckIn(test, nodeid=options.nodeid, testEventKey=options.testEventKey), "Failed to test wait for active")
logger.info("Successfully handled key refresh")

timeoutTicker.stop()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
TEST_DISCOVERY_TYPE = [0, 1, 2]
MATTER_DEVELOPMENT_PAA_ROOT_CERTS = "credentials/development/paa-root-certs"

TEST_EVENT_KEY_HEX = "00112233445566778899aabbccddeeff"

DEVICE_CONFIG = {
'device0': {
'type': 'MobileDevice',
Expand Down Expand Up @@ -88,8 +90,8 @@ def run_controller_test(self):
self.execute_device_cmd(
server,
("CHIPCirqueDaemon.py -- run gdb -batch -return-child-result -q -ex \"set pagination off\" "
"-ex run -ex \"thread apply all bt\" --args {} --thread --discriminator {}").format(
os.path.join(CHIP_REPO, "out/debug/lit_icd/lit-icd-app"), TEST_DISCRIMINATOR))
"-ex run -ex \"thread apply all bt\" --args {} --thread --discriminator {} --enable-key {}").format(
os.path.join(CHIP_REPO, "out/debug/lit_icd/lit-icd-app"), TEST_DISCRIMINATOR, TEST_EVENT_KEY_HEX))

self.reset_thread_devices(server_ids)

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

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

self.assertEqual(ret['return_code'], '0',
Expand Down

0 comments on commit e338404

Please sign in to comment.