Skip to content

Commit

Permalink
Change the test app for subscription resumption test to lit-icd-app
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 committed Jan 9, 2024
1 parent 27d76ac commit 0c8057b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,7 @@ endpoint 0 {
ram attribute clusterRevision default = 1;

handle command OpenCommissioningWindow;
handle command OpenBasicCommissioningWindow;
handle command RevokeCommissioning;
}

Expand Down
8 changes: 8 additions & 0 deletions examples/lit-icd-app/lit-icd-common/lit-icd-server-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -2549,6 +2549,14 @@
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "OpenBasicCommissioningWindow",
"code": 1,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "RevokeCommissioning",
"code": 2,
Expand Down
90 changes: 7 additions & 83 deletions src/controller/python/test/test_scripts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1373,10 +1373,10 @@ def run(self):

try:
desiredPath = Clusters.Attribute.AttributePath(
EndpointId=1, ClusterId=6, AttributeId=0)
# OnOff Cluster, OnOff Attribute
EndpointId=0, ClusterId=0x28, AttributeId=5)
# Basic Information Cluster, NodeLabel Attribute
subscription = self.devCtrl.ZCLSubscribeAttribute(
"OnOff", "OnOff", nodeid, endpoint, 1, 50, keepSubscriptions=True, autoResubscribe=False)
"BasicInformation", "NodeLabel", nodeid, endpoint, 1, 50, keepSubscriptions=True, autoResubscribe=False)
subscription.SetAttributeUpdateCallback(OnValueReport)

self.logger.info("Restart remote deivce")
Expand All @@ -1386,12 +1386,12 @@ def run(self):
# the update
with updateCv:
while receivedUpdate is False:
if not updateCv.wait(30.0):
if not updateCv.wait(10.0):
self.logger.error(
"Failed to receive subscription resumption report")
break

restartRemoteThread.join(30.0)
restartRemoteThread.join(10.0)

#
# Clean-up by shutting down the sub. Otherwise, we're going to get callbacks through
Expand All @@ -1412,88 +1412,12 @@ def run(self):

return True

def TestSubscriptionResumptionCapacity(self, nodeid: int, endpoint: int, remote_ip: str, ssh_port: int,
remote_server_app: str, subscription_capacity: int):

class _restartRemoteDevice(threading.Thread):
def __init__(self, remote_ip: str, ssh_port: int, remote_server_app: str, subscription_capacity: int):
super(_restartRemoteDevice, self).__init__()
self.remote_ip = remote_ip
self.ssh_port = ssh_port
self.remote_server_app = remote_server_app
self.subscription_capacity = subscription_capacity

def run(self):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(self.remote_ip, self.ssh_port, "root", "admin")
client.exec_command(
("kill \"$(ps aux | grep -E \'out/debug/standalone/{}\' | grep -v grep | grep -v gdb | "
"awk \'{{print $2}}\')\"").format(self.remote_server_app))
time.sleep(1)
stdin, stdout, stderr = client.exec_command(
("ps aux | grep -E \'out/debug/standalone/{}\' | grep -v grep | grep -v gdb | "
"awk \'{{print $2}}\'").format(self.remote_server_app))
if not stdout.read().decode().strip():
logger.info(f"Succeed to kill remote process {self.remote_server_app}")
else:
logger.error(f"Failed to kill remote process {self.remote_server_app}")

client.exec_command("systemctl restart avahi-deamon.service")
client.exec_command(
("CHIPCirqueDaemon.py -- run gdb -batch -return-child-result -q -ex \"set pagination off\" "
"-ex run -ex \"thread apply all bt\" --args {} --thread --discriminator 3840 "
"--subscription-capacity {}").format(
os.path.join(CHIP_REPO, "out/debug/standalone", self.remote_server_app),
self.subscription_capacity))

finally:
client.close()

try:
desiredPath = Clusters.Attribute.AttributePath(
EndpointId=1, ClusterId=6, AttributeId=0)
# OnOff Cluster, OnOff Attribute
for i in range(subscription_capacity):
self.devCtrl.ZCLSubscribeAttribute(
"OnOff", "OnOff", nodeid, endpoint, 1, 50, keepSubscriptions=True, autoResubscribe=False)

self.logger.info("Shutdown Controller 1")
self.devCtrl.Shutdown()

self.logger.info("Restart remote deivce")
restartRemoteThread = _restartRemoteDevice(remote_ip, ssh_port, remote_server_app, subscription_capacity)
restartRemoteThread.start()
time.sleep(6)

self.logger.info("Send a new subscription request from the second controller")
# Close previous session so that the controller 2 will res-establish the session to the remote device
self.devCtrl2.CloseSession(nodeid)
self.devCtrl2.ZCLSubscribeAttribute(
"OnOff", "OnOff", nodeid, endpoint, 1, 50, keepSubscriptions=True, autoResubscribe=False)
restartRemoteThread.join(10.0)

if restartRemoteThread.is_alive():
# Thread join timed out
self.logger.error("Failed to join change thread")
return False

return True

except Exception as ex:
self.logger.exception(f"Failed to finish API test: {ex}")
return False

return True

def TestSubscriptionResumptionCapacityStep1(self, nodeid: int, endpoint: int, subscription_capacity: int):

try:
# OnOff Cluster, OnOff Attribute
for i in range(subscription_capacity):
self.devCtrl.ZCLSubscribeAttribute(
"OnOff", "OnOff", nodeid, endpoint, 1, 50, keepSubscriptions=True, autoResubscribe=False)
"BasicInformation", "NodeLabel", nodeid, endpoint, 1, 50, keepSubscriptions=True, autoResubscribe=False)

logger.info("Send OpenBasicCommissioningWindow command on fist controller")
asyncio.run(
Expand Down Expand Up @@ -1573,7 +1497,7 @@ def run(self):
# Close previous session so that the second controller will res-establish the session with the remote device
self.devCtrl.CloseSession(nodeid)
self.devCtrl.ZCLSubscribeAttribute(
"OnOff", "OnOff", nodeid, endpoint, 1, 50, keepSubscriptions=True, autoResubscribe=False)
"BasicInformation", "NodeLabel", nodeid, endpoint, 1, 50, keepSubscriptions=True, autoResubscribe=False)
restartRemoteThread.join(10.0)

if restartRemoteThread.is_alive():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
TEST_DISCRIMINATOR = 3840
TEST_SETUPPIN = 20202021

TEST_ENDPOINT_ID = 1
TEST_ENDPOINT_ID = 0

def ethernet_commissioning(test: BaseTestHelper, discriminator: int, setup_pin: int, address_override: str, device_nodeid: int):
logger.info("Testing discovery")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
TEST_DISCRIMINATOR = 3840
TEST_SETUPPIN = 20202021

TEST_ENDPOINT_ID = 1
TEST_ENDPOINT_ID = 0

TEST_SSH_PORT=2222

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
TEST_DISCRIMINATOR = 3840
TEST_SETUPPIN = 20202021

TEST_ENDPOINT_ID = 1
TEST_ENDPOINT_ID = 0

TEST_SSH_PORT=2222

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from helper.CHIPTestBase import CHIPVirtualHome

logger = logging.getLogger('SubscriptionResumptionTest')
logger = logging.getLogger('SubscriptionResumptionCapacityTest')
logger.setLevel(logging.INFO)

sh = logging.StreamHandler()
Expand All @@ -38,7 +38,7 @@
TEST_EXTPANID = "fedcba9876543210"
TEST_DISCRIMINATOR = 3840
MATTER_DEVELOPMENT_PAA_ROOT_CERTS = "credentials/development/paa-root-certs"
TEST_END_DEVICE_APP="chip-lighting-app"
TEST_END_DEVICE_APP="lit-icd-app"
TEST_SUBSCRIPTION_CAPACITY=3


Expand Down
2 changes: 1 addition & 1 deletion src/test_driver/linux-cirque/SubscriptionResumptionTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
TEST_EXTPANID = "fedcba9876543210"
TEST_DISCRIMINATOR = 3840
MATTER_DEVELOPMENT_PAA_ROOT_CERTS = "credentials/development/paa-root-certs"
TEST_END_DEVICE_APP="chip-lighting-app"
TEST_END_DEVICE_APP="lit-icd-app"

DEVICE_CONFIG = {
'device0': {
Expand Down

0 comments on commit 0c8057b

Please sign in to comment.