-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* TC-TMP-2.1: Fix The constraints here are actually relatively complex because the min and max can be null and fall back to default values. Updated the automation to python so we can do the appropriate tests, added tests for the various scenarios becuase there are a LOT and we don't cover any of them with our current examples. Please see https://github.com/CHIP-Specifications/chip-test-plans/pull/4096 for test plan updates * remove yaml * missed a change * Restyled by autopep8 * remove unused import * Apply suggestions from code review --------- Co-authored-by: Restyled.io <[email protected]>
- Loading branch information
Showing
5 changed files
with
352 additions
and
83 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# | ||
# 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. | ||
|
||
import chip.clusters as Clusters | ||
from chip.clusters.Types import NullValue | ||
from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main | ||
from mobly import asserts | ||
|
||
|
||
class TC_TMP_2_1(MatterBaseTest): | ||
def desc_TC_TMP_2_1(self) -> str: | ||
return "[TC-TMP-2.1] Attributes with Server as DUT" | ||
|
||
def pics_TC_TMP_2_1(self): | ||
return ["TMP.S"] | ||
|
||
def steps_TC_TMP_2_1(self) -> list[TestStep]: | ||
return [ | ||
TestStep(1, "Commissioning, already done", is_commissioning=True), | ||
TestStep( | ||
2, "Set default bounds `min_bound` = -27315, `max_bound` = 32767"), | ||
TestStep(3, "TH reads the MinMeasuredValue attribute from the DUT and saves as `min_measured_value`. If `min_measured_value` is not null, set `min_bound` to `min_measured_value`"), | ||
TestStep(4, "TH reads the MaxMeasuredValue attribute from the DUT and saves as `max_measured_value`. If `max_measured_value` is not null, set `max_bound` to `max_measured_value", | ||
"Verify that `max_measured_value` is either null or an int16 where min_bound < `max_measured_value` ≤ 32767."), | ||
TestStep(5, "If `min_measured_value` is not null, verify min measured value range", | ||
"Verify that -27315 ≤ `min_measured_value` < `max_bound`"), | ||
TestStep(6, "TH reads the MeasuredValue attribute from the DUT", | ||
"Verify that the DUT response contains either null or a int16 where `min_bound` ≤ MeasuredValue ≤ `max_bound`."), | ||
TestStep(7, "TH reads the Tolerance attribute from the DUT", | ||
"Verify that Tolerance is in the range of 0 to 2048"), | ||
] | ||
|
||
@async_test_body | ||
async def test_TC_TMP_2_1(self): | ||
cluster = Clusters.TemperatureMeasurement | ||
attr = Clusters.TemperatureMeasurement.Attributes | ||
|
||
# Commission DUT - already done | ||
self.step(1) | ||
|
||
self.step(2) | ||
min_bound = -27315 | ||
max_bound = 32767 | ||
|
||
self.step(3) | ||
min_measured_value = await self.read_single_attribute_check_success(cluster=cluster, attribute=attr.MinMeasuredValue) | ||
if min_measured_value != NullValue: | ||
min_bound = min_measured_value | ||
|
||
self.step(4) | ||
max_measured_value = await self.read_single_attribute_check_success(cluster=cluster, attribute=attr.MaxMeasuredValue) | ||
if max_measured_value != NullValue: | ||
max_bound = max_measured_value | ||
asserts.assert_greater(max_measured_value, min_bound, | ||
"MaxMeasuredValue is not greater than the minimum bound") | ||
asserts.assert_less_equal( | ||
max_measured_value, 32767, "MaxMeasuredValue is not less than or equal to than 32767") | ||
|
||
self.step(5) | ||
if min_measured_value != NullValue: | ||
asserts.assert_greater_equal(min_measured_value, -27315, "MinMeasuredValue is out of range") | ||
asserts.assert_less(min_measured_value, max_bound, "MinMeasuredValue is out of range") | ||
else: | ||
self.mark_current_step_skipped() | ||
|
||
self.step(6) | ||
measured_value = await self.read_single_attribute_check_success(cluster=cluster, attribute=attr.MeasuredValue) | ||
if measured_value != NullValue: | ||
print(measured_value) | ||
print(min_bound) | ||
asserts.assert_greater_equal( | ||
measured_value, min_bound, "Measured value is less than min bound") | ||
asserts.assert_less_equal( | ||
measured_value, max_bound, "Measured value is greater than max bound") | ||
|
||
self.step(7) | ||
tolerance = await self.read_single_attribute_check_success(cluster=cluster, attribute=attr.Tolerance) | ||
asserts.assert_greater_equal(tolerance, 0, "Tolerance is less than 0") | ||
asserts.assert_less_equal( | ||
tolerance, 2048, "Tolerance is greater than 2048") | ||
|
||
|
||
if __name__ == "__main__": | ||
default_matter_test_main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
import importlib | ||
import os | ||
import sys | ||
from pathlib import Path | ||
from unittest.mock import MagicMock | ||
|
||
from chip.clusters import Attribute | ||
|
||
try: | ||
from matter_testing_support import MatterStackState, MatterTestConfig, run_tests_no_exit | ||
except ImportError: | ||
sys.path.append(os.path.abspath( | ||
os.path.join(os.path.dirname(__file__), '..'))) | ||
from matter_testing_support import MatterStackState, MatterTestConfig, run_tests_no_exit | ||
|
||
|
||
class AsyncMock(MagicMock): | ||
async def __call__(self, *args, **kwargs): | ||
return super(AsyncMock, self).__call__(*args, **kwargs) | ||
|
||
|
||
class MockTestRunner(): | ||
def __init__(self, filename: str, classname: str, test: str): | ||
self.config = MatterTestConfig( | ||
tests=[test], endpoint=1, dut_node_ids=[1]) | ||
self.stack = MatterStackState(self.config) | ||
self.default_controller = self.stack.certificate_authorities[0].adminList[0].NewController( | ||
nodeId=self.config.controller_node_id, | ||
paaTrustStorePath=str(self.config.paa_trust_store_path), | ||
catTags=self.config.controller_cat_tags | ||
) | ||
module = importlib.import_module(Path(os.path.basename(filename)).stem) | ||
self.test_class = getattr(module, classname) | ||
|
||
def Shutdown(self): | ||
self.stack.Shutdown() | ||
|
||
def run_test_with_mock_read(self, read_cache: Attribute.AsyncReadTransaction.ReadResponse): | ||
self.default_controller.Read = AsyncMock(return_value=read_cache) | ||
return run_tests_no_exit(self.test_class, self.config, None, self.default_controller, self.stack) |
Oops, something went wrong.