Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] Creating CADMIN 1.19 python3 test module #35611

Merged
merged 17 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 0 additions & 127 deletions src/app/tests/suites/certification/Test_TC_CADMIN_1_19.yaml

This file was deleted.

175 changes: 175 additions & 0 deletions src/python_testing/TC_CADMIN_1_19.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
#
# Copyright (c) 2024 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# === BEGIN CI TEST ARGUMENTS ===
# test-runner-runs:
# run1:
# app: ${ALL_CLUSTERS_APP}
# app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
# script-args: >
# --storage-path admin_storage.json
# --commissioning-method on-network
# --discriminator 1234
# --passcode 20202021
# --trace-to json:${TRACE_TEST_JSON}.json
# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
# --PICS src/app/tests/suites/certification/ci-pics-values
# factory-reset: true
# quiet: true
# === END CI TEST ARGUMENTS ===

import random

import chip.clusters as Clusters
from chip import ChipDeviceCtrl
from chip.exceptions import ChipStackError
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
from mobly import asserts


class TC_CADMIN_1_19(MatterBaseTest):
def generate_unique_random_value(self, value):
while True:
random_value = random.randint(10000000, 99999999)
if random_value != value:
return random_value

async def get_fabrics(self, th: ChipDeviceCtrl) -> int:
OC_cluster = Clusters.OperationalCredentials
fabrics = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics)
return fabrics

def steps_TC_CADMIN_1_19(self) -> list[TestStep]:
return [
TestStep(1, "Commissioning, already done", is_commissioning=True),
TestStep(
2, "TH_CR1 reads the BasicCommissioningInfo attribute from the General Commissioning cluster and saves the MaxCumulativeFailsafeSeconds field as max_window_duration."),
TestStep(3, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a non-fabric-filtered read. Save the number of fabrics in the list as initial_number_of_fabrics"),
TestStep(4, "TH_CR1 reads the SupportedFabrics attribute from the Node Operational Credentials cluster. Save max_fabrics"),
TestStep(5, "Repeat the following steps (5a and 5b) max_fabrics - initial_number_of_fabrics times"),
TestStep(
"5a", "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"),
TestStep("5b", "TH creates a controller on a new fabric and commissions DUT_CE using that controller",
"Commissioning is successful"),
TestStep(6, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.",
"Verify this is equal to max_fabrics"),
TestStep(
7, "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"),
TestStep(8, "TH creates a controller on a new fabric and commissions DUT_CE using that controller",
"Verify DUT_CE responds with NOCResponse with a StatusCode field value of TableFull(5)"),
TestStep(9, "Repeat the following steps (9a and 9b) for each controller (TH_CRn) created by this test"),
TestStep("9a", "The controller reads the CurrentFabricIndex from the Node Operational Credentials cluster. Save as fabric_index."),
TestStep("9b", "TH_CR1 sends the RemoveFabric command to DUT_CE", "{resDutSuccess}"),
TestStep(10, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.",
"Verify this is equal to initial_number_of_fabrics."),
]

def pics_TC_CADMIN_1_19(self) -> list[str]:
return ["CADMIN.S"]

@async_test_body
async def test_TC_CADMIN_1_19(self):
self.step(1)

# Establishing TH1 and TH2
self.th1 = self.default_controller

self.step(2)
GC_cluster = Clusters.GeneralCommissioning
cecille marked this conversation as resolved.
Show resolved Hide resolved
attribute = GC_cluster.Attributes.BasicCommissioningInfo
duration = await self.read_single_attribute_check_success(endpoint=0, cluster=GC_cluster, attribute=attribute)
self.max_window_duration = duration.maxCumulativeFailsafeSeconds

self.step(3)
fabrics = await self.get_fabrics(th=self.th1)
initial_number_of_fabrics = len(fabrics)

self.step(4)
OC_cluster = Clusters.OperationalCredentials
max_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics)

self.step(5)
fids_ca_dir = {}
fids_fa_dir = {}
fids = {}
j-ororke marked this conversation as resolved.
Show resolved Hide resolved
self.print_step("total fabrics", max_fabrics - initial_number_of_fabrics)
for fid in range(1, max_fabrics - initial_number_of_fabrics):
tehampson marked this conversation as resolved.
Show resolved Hide resolved
# Make sure that current test step is 5, resets here after each loop
self.current_step_index = 5

self.step("5a")
tehampson marked this conversation as resolved.
Show resolved Hide resolved
params = await self.openCommissioningWindow(dev_ctrl=self.th1, timeout=self.max_window_duration, node_id=self.dut_node_id)

self.step("5b")
fids_ca_dir[fid] = self.certificate_authority_manager.NewCertificateAuthority()
fids_fa_dir[fid] = fids_ca_dir[fid].NewFabricAdmin(vendorId=0xFFF1, fabricId=fid)
fids[fid] = fids_fa_dir[fid].NewController(nodeId=fid)

await fids[fid].CommissionOnNetwork(
nodeId=self.dut_node_id, setupPinCode=params.commissioningParameters.setupPinCode,
filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator)

self.print_step("commissioning iteration", fid)
j-ororke marked this conversation as resolved.
Show resolved Hide resolved

self.step(6)
# TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster
current_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics)
if current_fabrics != max_fabrics:
asserts.fail(f"Expected number of fabrics not correct, instead was {current_fabrics}")

self.step(7)
params = await self.openCommissioningWindow(dev_ctrl=self.th1, node_id=self.dut_node_id)

self.step(8)
# TH creates a controller on a new fabric and commissions DUT_CE using that controller
fids_ca_dir[current_fabrics + 1] = self.certificate_authority_manager.NewCertificateAuthority()
tehampson marked this conversation as resolved.
Show resolved Hide resolved
fids_fa_dir[current_fabrics + 1] = fids_ca_dir[current_fabrics +
1].NewFabricAdmin(vendorId=0xFFF1, fabricId=current_fabrics + 1)
try:
fids[current_fabrics + 1] = fids_fa_dir[current_fabrics + 1].NewController(nodeId=current_fabrics + 1)
await fids[current_fabrics + 1].CommissionOnNetwork(
nodeId=self.dut_node_id, setupPinCode=params.commissioningParameters.setupPinCode,
filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator)

except ChipStackError as e:
self.print_step("err", e.err)
j-ororke marked this conversation as resolved.
Show resolved Hide resolved
# When attempting to create a new controller we are expected to get the following response:
# src/credentials/FabricTable.cpp:833: CHIP Error 0x0000000B: No memory
# Since the FabricTable is full and unable to create any new fabrics
asserts.assert_equal(e.err, 0x0000000B,
"Expected to return table is full since max number of fabrics has been created already")

self.step(9)
for thc in fids.keys():
# Make sure that current test step is 11 (9 + 2 since 5a and 5b test steps included in count), resets here after each loop
self.current_step_index = 11

self.step("9a")
fabric_index = await self.read_single_attribute_check_success(dev_ctrl=fids[thc], endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.CurrentFabricIndex)

self.step("9b")
removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(fabric_index)
await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd)

self.step(10)
# TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.
current_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.CommissionedFabrics)
if current_fabrics != initial_number_of_fabrics:
tehampson marked this conversation as resolved.
Show resolved Hide resolved
asserts.fail(f"Found more than expected fabrics: {str(current_fabrics)}")


if __name__ == "__main__":
default_matter_test_main()
Original file line number Diff line number Diff line change
Expand Up @@ -1136,10 +1136,10 @@ def check_pics(self, pics_key: str) -> bool:
def is_pics_sdk_ci_only(self) -> bool:
return self.check_pics('PICS_SDK_CI_ONLY')

async def openCommissioningWindow(self, dev_ctrl: ChipDeviceCtrl, node_id: int) -> CustomCommissioningParameters:
async def openCommissioningWindow(self, dev_ctrl: ChipDeviceCtrl, node_id: int, timeout: int = 900) -> CustomCommissioningParameters:
rnd_discriminator = random.randint(0, 4095)
try:
commissioning_params = await dev_ctrl.OpenCommissioningWindow(nodeid=node_id, timeout=900, iteration=1000,
commissioning_params = await dev_ctrl.OpenCommissioningWindow(nodeid=node_id, timeout=timeout, iteration=1000,
discriminator=rnd_discriminator, option=1)
params = CustomCommissioningParameters(commissioning_params, rnd_discriminator)
return params
Expand Down
Loading