Skip to content

Commit

Permalink
Add checks for correct DEM feature map for test
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterC1965 committed Aug 19, 2024
1 parent f9ad5bf commit a71bb17
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 4 deletions.
28 changes: 28 additions & 0 deletions src/python_testing/TC_DEMTestBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@

logger = logging.getLogger(__name__)

s_feature_strs = {Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment: "kPowerAdjustment",
Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting: "kPowerForecastReporting",
Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting: "kStateForecastReporting",
Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment: "kStartTimeAdjustment",
Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable: "kPausable",
Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment: "kForecastAdjustment",
Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment: "kConstraintBasedAdjustment"}


class DEMTestBase:

Expand All @@ -38,6 +46,26 @@ async def check_dem_attribute(self, attribute, expected_value, endpoint: int = N
asserts.assert_equal(value, expected_value,
f"Unexpected '{attribute}' value - expected {expected_value}, was {value}")

async def validate_feature_map(self, must_have_features, must_not_have_features):
feature_map = await self.read_dem_attribute_expect_success(attribute="FeatureMap")
for must_have_feature in must_have_features:
asserts.assert_true(feature_map & must_have_feature,
f"{s_feature_strs[must_have_feature]} must be set but is not. feature_map 0x{feature_map:x}")

for must_not_have_feature in must_not_have_features:
asserts.assert_false(feature_map & must_not_have_feature,
f"{s_feature_strs[must_not_have_feature]} is not allowed to be set. feature_map 0x{feature_map:x}")

async def validate_pfr_or_sfr_in_feature_map(self):
feature_map = await self.read_dem_attribute_expect_success(attribute="FeatureMap")

illegal_combination = Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting | Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting
asserts.assert_not_equal(feature_map & illegal_combination, illegal_combination,
f"Cannot have kPowerForecastReporting and kStateForecastReporting both set. feature_map 0x{feature_map:x}")

asserts.assert_not_equal(feature_map & illegal_combination, 0,
f"Must have one of kPowerForecastReporting and kStateForecastReporting set. feature_map 0x{feature_map:x}")

async def send_power_adjustment_command(self, power: int, duration: int,
cause: Clusters.Objects.DeviceEnergyManagement.Enums.CauseEnum,
endpoint: int = None, timedRequestTimeoutMs: int = 3000,
Expand Down
2 changes: 2 additions & 0 deletions src/python_testing/TC_DEM_2_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ async def test_TC_DEM_2_2(self):
self.step("1")
# Commission DUT - already done

await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerAdjustment], [])

# Subscribe to Events and when they are sent push them to a queue for checking later
events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement)
await events_callback.start(self.default_controller,
Expand Down
5 changes: 4 additions & 1 deletion src/python_testing/TC_DEM_2_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# test-runner-run/run1/app: ${ENERGY_MANAGEMENT_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 --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7a
# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0xa
# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
# === END CI TEST ARGUMENTS ===

Expand Down Expand Up @@ -138,6 +138,9 @@ async def test_TC_DEM_2_3(self):
self.step("1")
# Commission DUT - already done

await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStartTimeAdjustment], [])
await self.validate_pfr_or_sfr_in_feature_map()

# Subscribe to Events and when they are sent push them to a queue for checking later
events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement)
await events_callback.start(self.default_controller,
Expand Down
5 changes: 4 additions & 1 deletion src/python_testing/TC_DEM_2_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# test-runner-run/run1/app: ${ENERGY_MANAGEMENT_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 --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7a
# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x12
# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
# === END CI TEST ARGUMENTS ===

Expand Down Expand Up @@ -159,6 +159,9 @@ async def test_TC_DEM_2_4(self):
self.step("1")
# Commission DUT - already done

await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPausable], [])
await self.validate_pfr_or_sfr_in_feature_map()

# Subscribe to Events and when they are sent push them to a queue for checking later
events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement)
await events_callback.start(self.default_controller,
Expand Down
6 changes: 5 additions & 1 deletion src/python_testing/TC_DEM_2_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# test-runner-run/run1/app: ${ENERGY_MANAGEMENT_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 --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7a
# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x22
# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
# === END CI TEST ARGUMENTS ===

Expand Down Expand Up @@ -144,6 +144,10 @@ async def test_TC_DEM_2_5(self):
self.step("1")
# Commission DUT - already done

await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment,
Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting],
[])

# Subscribe to Events and when they are sent push them to a queue for checking later
events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement)
await events_callback.start(self.default_controller,
Expand Down
4 changes: 4 additions & 0 deletions src/python_testing/TC_DEM_2_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ async def test_TC_DEM_2_6(self):
self.step("1")
# Commission DUT - already done

await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kForecastAdjustment,
Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting],
[Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting])

# Subscribe to Events and when they are sent push them to a queue for checking later
events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement)
await events_callback.start(self.default_controller,
Expand Down
4 changes: 4 additions & 0 deletions src/python_testing/TC_DEM_2_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ async def test_TC_DEM_2_7(self):
self.step("1")
# Commission DUT - already done

await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment,
Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting],
[Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting])

# Subscribe to Events and when they are sent push them to a queue for checking later
events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement)
await events_callback.start(self.default_controller,
Expand Down
4 changes: 4 additions & 0 deletions src/python_testing/TC_DEM_2_8.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ async def test_TC_DEM_2_8(self):
self.step("1")
# Commission DUT - already done

await self.validate_feature_map([Clusters.DeviceEnergyManagement.Bitmaps.Feature.kConstraintBasedAdjustment,
Clusters.DeviceEnergyManagement.Bitmaps.Feature.kStateForecastReporting],
[Clusters.DeviceEnergyManagement.Bitmaps.Feature.kPowerForecastReporting])

# Subscribe to Events and when they are sent push them to a queue for checking later
events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement)
await events_callback.start(self.default_controller,
Expand Down
4 changes: 3 additions & 1 deletion src/python_testing/TC_DEM_2_9.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# test-runner-run/run1/app: ${ENERGY_MANAGEMENT_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 --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7e
# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f --featureSet 0x7c
# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
# === END CI TEST ARGUMENTS ===

Expand Down Expand Up @@ -81,6 +81,8 @@ async def test_TC_DEM_2_9(self):
self.step("1")
# Commission DUT - already done

await self.validate_pfr_or_sfr_in_feature_map()

# Subscribe to Events and when they are sent push them to a queue for checking later
events_callback = EventChangeCallback(Clusters.DeviceEnergyManagement)
await events_callback.start(self.default_controller,
Expand Down

0 comments on commit a71bb17

Please sign in to comment.