Skip to content

Commit

Permalink
Updated TC_OCC_2_3.py (#35296)
Browse files Browse the repository at this point in the history
* Update TC_OCC_2_3.py

Test script update based on test plan TC_OCC 2.3 change

* Update TC_OCC_2_3.py

restyled

* Update TC_OCC_2_3.py

* Update TC_OCC_2_3.py

* Update TC_OCC_2_3.py

* Update TC_OCC_2_3.py

fixed python bugs.

* Update TC_OCC_2_3.py

* Update TC_OCC_2_3.py

* Update TC_OCC_2_3.py

lint update
  • Loading branch information
jaehs6sam authored and pull[bot] committed Oct 3, 2024
1 parent 5d9893d commit 1263579
Showing 1 changed file with 113 additions and 64 deletions.
177 changes: 113 additions & 64 deletions src/python_testing/TC_OCC_2_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments
# for details about the block below.
#
# === BEGIN CI TEST ARGUMENTS ===
# test-runner-runs: run1
# test-runner-run/run1/app: ${ALL_CLUSTERS_APP}
# test-runner-run/run1/factoryreset: True
# test-runner-run/run1/quiet: True
# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto --endpoint 1
# test-runner-run/run1/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 --endpoint 1 --bool-arg simulate_occupancy:true
# === END CI TEST ARGUMENTS ===
# There are CI issues to be followed up for the test cases below that implements manually controlling sensor device for
# the occupancy state ON/OFF change.
# [TC-OCC-3.1] test procedure step 3, 4
# [TC-OCC-3.2] test precedure step 3a, 3c

import logging

Expand All @@ -35,21 +35,27 @@


class TC_OCC_2_3(MatterBaseTest):
async def read_occ_attribute_expect_success(self, endpoint, attribute):
async def read_occ_attribute_expect_success(self, attribute):
cluster = Clusters.Objects.OccupancySensing
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute)
endpoint_id = self.matter_test_config.endpoint
return await self.read_single_attribute_check_success(endpoint=endpoint_id, cluster=cluster, attribute=attribute)

def desc_TC_OCC_2_3(self) -> str:
return "[TC-OCC-2.3] HoldTime Backward Compatibility Test with server as DUT"

def steps_TC_OCC_2_3(self) -> list[TestStep]:
steps = [
TestStep(1, "Commission DUT to TH", is_commissioning=True),
TestStep(2, "DUT supports HoldTime attribute. If DUT doesn’t support it, then stop and exit this test case."),
TestStep(3, "Based on the feature flag value table, read OccupancySensorType attribute from DUT"),
TestStep(4, "If TH reads 0 - PIR, TH reads PIROccupiedToUnoccupiedDelay attribute and its value should be same as HoldTime"),
TestStep(5, "If TH reads 1 - Ultrasonic, TH reads UltrasonicOccupiedToUnoccupiedDelay attribute and its value should be same as HoldTime"),
TestStep(6, "If TH reads 2 - PHY, TH reads PhysicalContactOccupiedToUnoccupiedDelay attribute and its value should be same as HoldTime")
TestStep(2, "TH reads the FeatureMap attribute on the endpoint for use in later steps."),
TestStep(3, "TH checks DUT HoldTime attribute support in the AttributeList attribute. If DUT doesn't support HoldTime attribute, skip the rest of this test case."),
TestStep(4, "TH writes DUT HoldTime attribute with HoldTimeMin and afterwards reads the attribute."),
TestStep(5, "TH writes DUT HoldTime attribute with HoldTimeMax and afterwards reads the attribute."),
TestStep("6a", "If DUT FeatureMap has PIR or (!PIR & !US & !PHY), and PIROccupiedToUnoccupiedDelay is supported, then TH writes HoldTimeMin to DUT's HoldTime attribute, otherwise skip 6a, 6b."),
TestStep("6b", "TH writes DUT's PIROccupiedToUnoccupiedDelay attribute with HoldTimeMax, then TH reads DUT's PIROccupiedToUnoccupiedDelay and HoldTime attributes."),
TestStep("7a", "If DUT FeatureMap has US, and UltrasonicOccupiedToUnoccupiedDelay is supported, then TH writes HoldTimeMin to DUT's HoldTime attribute, otherwise skip 7a, 7b."),
TestStep("7b", "TH writes DUT UltrasonicOccupiedToUnoccupiedDelay attribute with HoldTimeMax, then TH reads DUT UltrasonicOccupiedToUnoccupiedDelay and HoldTime attributes."),
TestStep("8a", "If DUT FeatureMap has PHY, and PhysicalContactOccupiedToUnoccupiedDelay is supported, then TH writes HoldTimeMin to HoldTime attribute, otherwise skip 8a, 8b."),
TestStep("8b", "TH writes DUT PhysicalContactOccupiedToUnoccupiedDelay attribute with HoldTimeMax, then TH reads DUT PhysicalContactOccupiedToUnoccupiedDelay and HoldTime attributes."),
]
return steps

Expand All @@ -61,67 +67,110 @@ def pics_TC_OCC_2_3(self) -> list[str]:

@async_test_body
async def test_TC_OCC_2_3(self):
endpoint = self.matter_test_config.endpoint

self.step(1) # Already done, immediately go to step 2
cluster = Clusters.Objects.OccupancySensing
attributes = cluster.Attributes

self.step(1) # Commissioning already done

self.step(2)

attributes = Clusters.OccupancySensing.Attributes
attribute_list = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.AttributeList)
feature_map = await self.read_occ_attribute_expect_success(attribute=attributes.FeatureMap)
has_feature_pir = (feature_map & cluster.Bitmaps.Feature.kPassiveInfrared) != 0
has_feature_ultrasonic = (feature_map & cluster.Bitmaps.Feature.kUltrasonic) != 0
has_feature_contact = (feature_map & cluster.Bitmaps.Feature.kPhysicalContact) != 0
has_no_legacy_features = ((not has_feature_pir) and (not has_feature_ultrasonic) and (not has_feature_contact))

if attributes.HoldTime.attribute_id in attribute_list:
occupancy_hold_time_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.HoldTime)
else:
logging.info("No HoldTime attribute supports. Terminate this test case")
logging.info(
f"Feature map: 0x{feature_map:x}. PIR: {has_feature_pir}, US:{has_feature_ultrasonic}, PHY:{has_feature_contact}")

self.step(3)
if attributes.OccupancySensorType.attribute_id in attribute_list:
occupancy_sensor_type_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.OccupancySensorType)

asserts.assert_less_equal(occupancy_sensor_type_dut, 3, "OccupancySensorType attribute is out of range")
asserts.assert_greater_equal(occupancy_sensor_type_dut, 0, "OccupancySensorType attribute is out of range")
attribute_list = await self.read_occ_attribute_expect_success(attribute=attributes.AttributeList)
if attributes.HoldTime.attribute_id not in attribute_list:
logging.info("No HoldTime attribute supports. Terminate this test case")
self.skip_all_remaining_steps(4)
holdtime_dut = await self.read_occ_attribute_expect_success(attribute=attributes.HoldTime)

self.step(4)
hold_time_limits_dut = await self.read_occ_attribute_expect_success(attribute=attributes.HoldTimeLimits)
asserts.assert_greater_equal(hold_time_limits_dut.holdTimeMin, 1, "HoldTimeMin has to be greater or equal to 1.")
await self.write_single_attribute(attributes.HoldTime(hold_time_limits_dut.holdTimeMin))
holdtime_dut = await self.read_occ_attribute_expect_success(attribute=attributes.HoldTime)
asserts.assert_equal(holdtime_dut, hold_time_limits_dut.holdTimeMin, "HoldTimeMin to HoldTime writing failure")

self.step(5)
await self.write_single_attribute(attributes.HoldTime(hold_time_limits_dut.holdTimeMax))
asserts.assert_greater_equal(hold_time_limits_dut.holdTimeMax, 10, "HoldTimeMax has to be greater or equal to 10.")
holdtime_dut = await self.read_occ_attribute_expect_success(attribute=attributes.HoldTime)
asserts.assert_equal(holdtime_dut, hold_time_limits_dut.holdTimeMax, "HoldTimeMax to HoldTime writing failure")

has_pir_timing_attrib = attributes.PIROccupiedToUnoccupiedDelay.attribute_id in attribute_list
has_no_legacy_features = ((not has_feature_pir) and (not has_feature_ultrasonic) and (not has_feature_contact))

if (has_feature_pir or has_no_legacy_features) and has_pir_timing_attrib:
self.step("6a")
await self.write_single_attribute(attributes.HoldTime(hold_time_limits_dut.holdTimeMin))
holdtime_dut = await self.read_occ_attribute_expect_success(attribute=attributes.HoldTime)
occupancy_pir_otou_delay_dut = await self.read_occ_attribute_expect_success(attribute=attributes.PIROccupiedToUnoccupiedDelay)
asserts.assert_equal(occupancy_pir_otou_delay_dut, holdtime_dut,
"PIROccupiedToUnoccupiedDelay has a different value from HoldTime.")

self.step("6b")
# perform reverse
await self.write_single_attribute(attributes.PIROccupiedToUnoccupiedDelay(hold_time_limits_dut.holdTimeMax))
occupancy_pir_otou_delay_dut = await self.read_occ_attribute_expect_success(
attribute=attributes.PIROccupiedToUnoccupiedDelay)
holdtime_dut = await self.read_occ_attribute_expect_success(attribute=attributes.HoldTime)
asserts.assert_equal(occupancy_pir_otou_delay_dut, holdtime_dut,
"PIROccupiedToUnoccupiedDelay has a different value from HoldTime in reverse testing.")
# self.skip_all_remaining_steps("7a")
else:
logging.info("OccupancySensorType attribute doesn't exist. Test step skipped")

if occupancy_sensor_type_dut == Clusters.OccupancySensing.Enums.OccupancySensorTypeEnum.kPir:
self.step(4)
occupancy_pir_otou_delay_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.PIROccupiedToUnoccupiedDelay)

asserts.assert_equal(occupancy_pir_otou_delay_dut, occupancy_hold_time_dut,
"HoldTime attribute value is not equal to PIROccupiedToUnoccupiedDelay")
self.skip_step(5)
self.skip_step(6)

elif occupancy_sensor_type_dut == Clusters.OccupancySensing.Enums.OccupancySensorTypeEnum.kUltrasonic:
self.step(4)
occupancy_pir_otou_delay_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.PIROccupiedToUnoccupiedDelay)

asserts.assert_equal(occupancy_pir_otou_delay_dut, occupancy_hold_time_dut,
"HoldTime attribute value is not equal to PIROccupiedToUnoccupiedDelay")
self.step(5)
occupancy_us_otou_delay_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.UltrasonicOccupiedToUnoccupiedDelay)

asserts.assert_equal(occupancy_us_otou_delay_dut, occupancy_hold_time_dut,
"HoldTime attribute value is not equal to UltrasonicOccupiedToUnoccupiedDelay")
self.skip_step(6)

elif occupancy_sensor_type_dut == Clusters.OccupancySensing.Enums.OccupancySensorTypeEnum.kPIRAndUltrasonic:
occupancy_pirus_otou_delay_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.PIROccupiedToUnoccupiedDelay)

asserts.assert_equal(occupancy_pirus_otou_delay_dut, occupancy_hold_time_dut,
"HoldTime attribute value is not equal to PIROccupiedToUnoccupiedDelay")

elif occupancy_sensor_type_dut == Clusters.OccupancySensing.Enums.OccupancySensorTypeEnum.kPhysicalContact:
self.skip_step(4)
self.skip_step(5)
self.step(6)
occupancy_phy_otou_delay_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.PhysicalContactOccupiedToUnoccupiedDelay)

asserts.assert_equal(occupancy_phy_otou_delay_dut, occupancy_hold_time_dut,
"HoldTime attribute value is not equal to PhysicalContactOccupiedToUnoccupiedDelay")
self.skip_step("6a")
self.skip_step("6b")

has_ultrasonic_timing_attrib = attributes.UltrasonicOccupiedToUnoccupiedDelay.attribute_id in attribute_list
if has_feature_ultrasonic and has_ultrasonic_timing_attrib:
self.step("7a")
await self.write_single_attribute(attributes.HoldTime(hold_time_limits_dut.holdTimeMin))
holdtime_dut = await self.read_occ_attribute_expect_success(attribute=attributes.HoldTime)
occupancy_us_otou_delay_dut = await self.read_occ_attribute_expect_success(attribute=attributes.UltrasonicOccupiedToUnoccupiedDelay)
asserts.assert_equal(occupancy_us_otou_delay_dut, holdtime_dut,
"UltrasonicOccupiedToUnoccupiedDelay has a different value from HoldTime.")

self.step("7b")
# perform reverse
await self.write_single_attribute(
attributes.UltrasonicOccupiedToUnoccupiedDelay(hold_time_limits_dut.holdTimeMax))
occupancy_us_otou_delay_dut = await self.read_occ_attribute_expect_success(
attribute=attributes.UltrasonicOccupiedToUnoccupiedDelay)
holdtime_dut = await self.read_occ_attribute_expect_success(attribute=attributes.HoldTime)
asserts.assert_equal(occupancy_us_otou_delay_dut, holdtime_dut,
"UltrasonicOccupiedToUnoccupiedDelay has a different value from HoldTime in reverse testing.")
else:
self.skip_step("7a")
self.skip_step("7b")

has_contact_timing_attrib = attributes.PhysicalContactOccupiedToUnoccupiedDelay.attribute_id in attribute_list
if has_feature_contact and has_contact_timing_attrib:
self.step("8a")
await self.write_single_attribute(attributes.HoldTime(hold_time_limits_dut.holdTimeMin))
holdtime_dut = await self.read_occ_attribute_expect_success(attribute=attributes.HoldTime)
occupancy_phy_otou_delay_dut = await self.read_occ_attribute_expect_success(attribute=attributes.PhysicalContactOccupiedToUnoccupiedDelay)
asserts.assert_equal(occupancy_phy_otou_delay_dut, holdtime_dut,
"PhysicalContactOccupiedToUnoccupiedDelay has a different value from HoldTime.")

self.step("8b")
# perform reverse
await self.write_single_attribute(
attributes.PhysicalContactOccupiedToUnoccupiedDelay(hold_time_limits_dut.holdTimeMin))
occupancy_phy_otou_delay_dut = await self.read_occ_attribute_expect_success(
attribute=attributes.PhysicalContactOccupiedToUnoccupiedDelay)
holdtime_dut = await self.read_occ_attribute_expect_success(attribute=attributes.HoldTime)
asserts.assert_equal(occupancy_phy_otou_delay_dut, holdtime_dut,
"PhysicalContactOccupiedToUnoccupiedDelay has a different value from HoldTime in reverse testing.")
else:
logging.info("OccupancySensorType attribute value is out of range")
self.skip_step("8a")
self.skip_step("8b")


if __name__ == "__main__":
Expand Down

0 comments on commit 1263579

Please sign in to comment.