-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[TC_CLTRL-3.1] Added new python test case for Calibrate based on test plan #38299
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
Changes from all commits
7902086
f752816
ffccc86
701bc62
3dd2de4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,271 @@ | ||
# | ||
# Copyright (c) 2023 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 | ||
# factory-reset: true | ||
# quiet: true | ||
# === END CI TEST ARGUMENTS === | ||
|
||
import logging | ||
from random import choice | ||
|
||
import chip.clusters as Clusters | ||
from chip.clusters.Types import NullValue | ||
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main, type_matches | ||
from mobly import asserts | ||
|
||
|
||
class TC_CLCTRL_3_1(MatterBaseTest): | ||
async def read_clctrl_attribute_expect_success(self, endpoint, attribute): | ||
cluster = Clusters.Objects.ClosureControl | ||
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute) | ||
|
||
def desc_TC_CLCTRL_3_1(self) -> str: | ||
return "[TC_CLCTRL_3_1] Calibrate Command Primary Functionality with DUT as Server" | ||
|
||
def steps_TC_CLCTRL_3_1(self) -> list[TestStep]: | ||
steps = [ | ||
TestStep(1, "Commission DUT to TH (can be skipped if done in a preceding test).", is_commissioning=True), | ||
TestStep("2a", "TH sends command Calibrate to DUT"), | ||
TestStep("2b", "after 1 seconds, TH reads from the DUT the MainState attribute"), | ||
TestStep("2c", "TH waits for PIXIT.CLCTRL.CalibrationDuration seconds"), | ||
TestStep("2d", "TH reads from the DUT the MainState attribute"), | ||
TestStep("3a", "TH sends command Calibrate to DUT"), | ||
TestStep("3b", "after 1 seconds, TH reads from the DUT the MainState attribute"), | ||
TestStep("3c", "TH sends command Calibrate to DUT"), | ||
TestStep("3d", "TH waits for PIXIT.CLCTRL.CalibrationDuration seconds"), | ||
TestStep("3e", "TH reads from the DUT the MainState attribute"), | ||
TestStep("4a", "TH sends command MoveTo to DUT with Position = CloseInFull(0)"), | ||
TestStep("4b", "after 1 seconds, TH reads from the DUT the MainState attribute"), | ||
TestStep("4c", "TH sends command Calibrate to DUT"), | ||
] | ||
return steps | ||
|
||
def pics_TC_CLCTRL_3_1(self) -> list[str]: | ||
pics = [ | ||
"CLCTRL.S", | ||
"CLCTRL.S.C02.Rsp(Calibrate)" | ||
] | ||
return pics | ||
|
||
@async_test_body | ||
async def test_TC_CLCTRL_3_1(self): | ||
endpoint = self.get_endpoint(default=1) | ||
|
||
# STEP 1: Commission DUT to TH (can be skipped if done in a preceding test) | ||
self.step(1) | ||
10000 attributes = Clusters.ClosureControl.Attributes | ||
|
||
# Read the FeatureMap attribute | ||
feature_map = await self.read_clctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.FeatureMap) | ||
|
||
logging.info(f"FeatureMap: {feature_map}") | ||
is_CL_feature_supported = feature_map & Clusters.ClosureControl.Bitmaps.Feature.kCalibrate | ||
if not is_CL_feature_supported: | ||
logging.info("The feature Calibration is not supported by the DUT") | ||
for step in self.get_test_steps(self.current_test_info.name)[self.current_step.index:]: | ||
# Skip the test steps that are not relevant | ||
self.step(step.test_plan_number) | ||
logging.info(f"Skipping test step {step.test_plan_number}") | ||
return | ||
|
||
# STEP 2a: TH sends command Calibrate to DUT | ||
self.step("2a") | ||
|
||
try: | ||
await self.send_command(endpoint=endpoint, cluster=Clusters.Objects.ClosureControl, command=Clusters.ClosureControl.Commands.Calibrate) | ||
except InteractionModelError as e: | ||
asserts.assert_equal( | ||
e.status, Status.Success, "Unexpected error returned") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. success is not an exception - this will never happen. the logic below is off: the This test needs to be actually executed before being placed as a PR |
||
pass | ||
# Check if the command was sent successfully | ||
if not type_matches(e.status, Status.SUCCESS): | ||
logging.error(f"Failed to send command Calibrate: {e.status}") | ||
return | ||
else: | ||
logging.info("Command Calibrate sent successfully") | ||
|
||
# STEP 2b: after 1 seconds, TH reads from the DUT the MainState attribute | ||
self.step("2b") | ||
|
||
sleep(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the sleep? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its written in the testplan. See Draft for Testplan change. |
||
mainstate = await self.read_clctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MainState) | ||
asserts.assert_not_equal(mainstate, NullValue, "MainState attribute is NullValue") | ||
# Check if the MainState attribute has the expected values | ||
is_calibrating = mainstate == Clusters.ClosureControl.Bitmaps.MainState.kCalibrating | ||
asserts.assert_true(is_calibrating, "MainState is not in the expected state") | ||
if is_calibrating: | ||
logging.info("MainState is in the calibrating state") | ||
|
||
# STEP 2c: TH waits for PIXIT.CLCTRL.CalibrationDuration seconds | ||
self.step("2c") | ||
|
||
calibration_duration = self.matter_test_config.global_test_params['PIXIT.CLCTRL.CalibrationDuration'] | ||
if calibration_duration is None: | ||
logging.error("PIXIT.CLCTRL.CalibrationDuration is not defined") | ||
return | ||
if calibration_duration < 0: | ||
logging.error("PIXIT.CLCTRL.CalibrationDuration is negative") | ||
return | ||
if calibration_duration > 0: | ||
sleep(calibration_duration) | ||
else: | ||
logging.info("Calibration duration is 0, skipping wait") | ||
|
||
# STEP 2d: TH reads from the DUT the MainState attribute | ||
self.step("2d") | ||
|
||
mainstate = await self.read_clctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MainState) | ||
asserts.assert_not_equal(mainstate, NullValue, "MainState attribute is NullValue") | ||
# Check if the MainState attribute has the expected values | ||
is_stopped = mainstate == Clusters.ClosureControl.Bitmaps.MainState.kStopped | ||
asserts.assert_true(is_stopped, "MainState is not in the expected state") | ||
if is_stopped: | ||
logging.info("MainState is in the stopped state") | ||
|
||
# STEP 3a: TH sends command Calibrate to DUT | ||
self.step("3a") | ||
|
||
try: | ||
await self.send_command(endpoint=endpoint, cluster=Clusters.Objects.ClosureControl, command=Clusters.ClosureControl.Commands.Calibrate) | ||
except InteractionModelError as e: | ||
asserts.assert_equal( | ||
e.status, Status.Success, "Unexpected error returned") | ||
pass | ||
|
||
# Check if the command was sent successfully | ||
if not type_matches(e.status, Status.SUCCESS): | ||
logging.error(f"Failed to send command Calibrate: {e.status}") | ||
return | ||
else: | ||
logging.info("Command Calibrate sent successfully") | ||
|
||
# STEP 3b: after 1 seconds, TH reads from the DUT the MainState attribute | ||
self.step("3b") | ||
|
||
sleep(1) | ||
mainstate = await self.read_clctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MainState) | ||
asserts.assert_not_equal(mainstate, NullValue, "MainState attribute is NullValue") | ||
# Check if the MainState attribute has the expected values | ||
is_calibrating = mainstate == Clusters.ClosureControl.Bitmaps.MainState.kCalibrating | ||
asserts.assert_true(is_calibrating, "MainState is not in the expected state") | ||
if is_calibrating: | ||
logging.info("MainState is in the calibrating state") | ||
|
||
# STEP 3c: TH sends command Calibrate to DUT | ||
self.step("3c") | ||
|
||
try: | ||
await self.send_command(endpoint=endpoint, cluster=Clusters.Objects.ClosureControl, command=Clusters.ClosureControl.Commands.Calibrate) | ||
except InteractionModelError as e: | ||
asserts.assert_equal( | ||
e.status, Status.Success, "Unexpected error returned") | ||
pass | ||
# Check if the command was sent successfully | ||
if not type_matches(e.status, Status.SUCCESS): | ||
logging.error(f"Failed to send command Calibrate: {e.status}") | ||
return | ||
else: | ||
logging.info("Command Calibrate sent successfully") | ||
|
||
# STEP 3d: TH waits for PIXIT.CLCTRL.CalibrationDuration seconds | ||
self.step("3d") | ||
calibration_duration = self.matter_test_config.global_test_params['PIXIT.CLCTRL.CalibrationDuration'] | ||
if calibration_duration is None: | ||
logging.error("PIXIT.CLCTRL.CalibrationDuration is not defined") | ||
return | ||
if calibration_duration < 0: | ||
logging.error("PIXIT.CLCTRL.CalibrationDuration is negative") | ||
return | ||
if calibration_duration > 0: | ||
sleep(calibration_duration) | ||
else: | ||
logging.info("Calibration duration is 0, skipping wait") | ||
|
||
# STEP 3e: TH reads from the DUT the MainState attribute | ||
self.step("3e") | ||
|
||
mainstate = await self.read_clctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MainState) | ||
asserts.assert_not_equal(mainstate, NullValue, "MainState attribute is NullValue") | ||
# Check if the MainState attribute has the expected values | ||
is_stopped = mainstate == Clusters.ClosureControl.Bitmaps.MainState.kStopped | ||
asserts.assert_true(is_stopped, "MainState is not in the expected state") | ||
if is_stopped: | ||
logging.info("MainState is in the stopped state") | ||
|
||
# STEP 4a: TH sends command MoveTo to DUT with Position = CloseInFull(0) | ||
self.step("4a") | ||
|
||
try: | ||
await self.send_command(endpoint=endpoint, cluster=Clusters.Objects.ClosureControl, | ||
command=Clusters.ClosureControl.Commands.MoveTo, arguments=Clusters.ClosureControl.MoveToRequest( | ||
position=Clusters.ClosureControl.Bitmaps.Position.kCloseInFull | ||
)) | ||
except InteractionModelError as e: | ||
asserts.assert_equal( | ||
e.status, Status.Success, "Unexpected error returned") | ||
pass | ||
# Check if the command was sent successfully | ||
if not type_matches(e.status, Status.SUCCESS): | ||
logging.error(f"Failed to send command MoveTo: {e.status}") | ||
return | ||
else: | ||
logging.info("Command MoveTo sent successfully") | ||
|
||
# STEP 4b: after 1 seconds, TH reads from the DUT the MainState attribute | ||
self.step("4b") | ||
|
||
sleep(1) | ||
mainstate = await self.read_clctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MainState) | ||
asserts.assert_not_equal(mainstate, NullValue, "MainState attribute is NullValue") | ||
# Check if the MainState attribute has the expected values | ||
is_moving = mainstate == Clusters.ClosureControl.Bitmaps.MainState.kMoving | ||
asserts.assert_true(is_moving, "MainState is not in the expected state") | ||
if is_moving: | ||
logging.info("MainState is in the moving state") | ||
|
||
# STEP 4c: TH sends command Calibrate to DUT | ||
self.step("4c") | ||
|
||
try: | ||
await self.send_command(endpoint=endpoint, cluster=Clusters.Objects.ClosureControl, command=Clusters.ClosureControl.Commands.Calibrate) | ||
except InteractionModelError as e: | ||
asserts.assert_equal( | ||
e.status, Status.Success, "Unexpected error returned") | ||
pass | ||
# Check if the command was sent invalid state | ||
if e.status == Status.INVALID_IN_STATE: | ||
logging.info("Command Calibrate is invalid while moving") | ||
return | ||
else: | ||
logging.error(f"Failed to send command Calibrate: {e.status}") | ||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
default_matter_test_main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test plan has a requirements to set the
MainState
to eitherSetupRequired
orStop
. How is this translated to the test steps?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkardous-silabs I did this draft as solution for missing steps. Please check this and then I change the script like this.
https://github.com/CHIP-Specifications/chip-test-plans/pull/5110