Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 02e3453

Browse files
committedAug 21, 2024··
Add test cases for testing additional Presets write and commit constraints
- Add a test for adding a preset with a preset scenario not present in PresetTypes - Add a test for testing addition of presets such that the total number of presets added is greater than the total number of presets supported
1 parent 68f0407 commit 02e3453

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed
 

‎examples/thermostat/linux/include/thermostat-delegate-impl.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ namespace Thermostat {
3333
*
3434
*/
3535

36-
static constexpr uint8_t kMaxNumberOfPresetTypes = 6;
36+
static constexpr uint8_t kMaxNumberOfPresetTypes = 7;
3737

3838
// TODO: #34556 Support multiple presets of each type.
3939
// We will support only one preset of each preset type.
4040
static constexpr uint8_t kMaxNumberOfPresetsOfEachType = 1;
4141

42+
// The number of presets supported is set to a value equal to than (kMaxNumberOfPresetTypes * kMaxNumberOfPresetsOfEachType) - 1
43+
// for testing purposes.
44+
static constexpr uint8_t kMaxNumberOfPresets = kMaxNumberOfPresetTypes * kMaxNumberOfPresetsOfEachType - 1;
45+
4246
class ThermostatDelegate : public Delegate
4347
{
4448
public:
@@ -90,7 +94,11 @@ class ThermostatDelegate : public Delegate
9094
uint8_t mNumberOfPresets;
9195

9296
Structs::PresetTypeStruct::Type mPresetTypes[kMaxNumberOfPresetTypes];
93-
PresetStructWithOwnedMembers mPresets[kMaxNumberOfPresetTypes * kMaxNumberOfPresetsOfEachType];
97+
PresetStructWithOwnedMembers mPresets[kMaxNumberOfPresets];
98+
99+
// For testing purposes, we have a pending presets array that matches the size of PresetTypes so it can
100+
// accomodate a preset of each type including UserDefined for the case where total number of presets
101+
// exceeds number of presets supported.
94102
PresetStructWithOwnedMembers mPendingPresets[kMaxNumberOfPresetTypes * kMaxNumberOfPresetsOfEachType];
95103

96104
uint8_t mNextFreeIndexInPendingPresetsList;

‎examples/thermostat/linux/thermostat-delegate-impl.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ ThermostatDelegate ThermostatDelegate::sInstance;
3232

3333
ThermostatDelegate::ThermostatDelegate()
3434
{
35-
mNumberOfPresets = kMaxNumberOfPresetTypes * kMaxNumberOfPresetsOfEachType;
35+
static_assert(kMaxNumberOfPresets <= kMaxNumberOfPresetTypes * kMaxNumberOfPresetsOfEachType);
36+
mNumberOfPresets = kMaxNumberOfPresets;
3637
mNextFreeIndexInPresetsList = 0;
3738
mNextFreeIndexInPendingPresetsList = 0;
3839

@@ -47,7 +48,8 @@ void ThermostatDelegate::InitializePresetTypes()
4748
{
4849
PresetScenarioEnum presetScenarioEnumArray[kMaxNumberOfPresetTypes] = {
4950
PresetScenarioEnum::kOccupied, PresetScenarioEnum::kUnoccupied, PresetScenarioEnum::kSleep,
50-
PresetScenarioEnum::kWake, PresetScenarioEnum::kVacation, PresetScenarioEnum::kGoingToSleep
51+
PresetScenarioEnum::kWake, PresetScenarioEnum::kVacation, PresetScenarioEnum::kGoingToSleep,
52+
PresetScenarioEnum::kUserDefined
5153
};
5254
static_assert(ArraySize(presetScenarioEnumArray) <= ArraySize(mPresetTypes));
5355

‎src/python_testing/TC_TSTAT_4_2.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ def steps_TC_TSTAT_4_2(self) -> list[TestStep]:
186186
"Verify that the write request is rejected"),
187187
TestStep("16", "TH starts an atomic write, and before it's complete, TH2 removes TH's fabric; TH2 then opens an atomic write",
188188
"Verify that the atomic request is successful"),
189+
TestStep("17", "TH writes to the Presets attribute with a preset that has a presetScenario not present in PresetTypes attribute",
190+
"Verify that the write request returned CONSTRAINT_ERROR (0x87)."),
191+
TestStep("18", "TH writes to the Presets attribute such that the total number of presets is greater than the number of presets supported",
192+
"Verify that the AtomicRequest commit returned RESOURCE_EXHAUSTED (0x89)."),
189193
]
190194

191195
return steps
@@ -441,8 +445,44 @@ async def test_TC_TSTAT_4_2(self):
441445
# Roll back
442446
await self.send_atomic_request_rollback_command()
443447

444-
# TODO: Add tests for the total number of Presets exceeds the NumberOfPresets supported. Also Add tests for adding presets with preset scenario not present in PresetTypes.
448+
self.step("17")
449+
if self.pics_guard(self.check_pics("TSTAT.S.F08") and self.check_pics("TSTAT.S.A0050") and self.check_pics("TSTAT.S.Cfe.Rsp")):
450+
test_presets = new_presets_with_handle.copy()
451+
test_presets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=9,
452+
name="Wake", coolingSetpoint=2500, heatingSetpoint=1700, builtIn=False))
453+
454+
# Send the AtomicRequest begin command
455+
await self.send_atomic_request_begin_command()
456+
457+
await self.write_presets(endpoint=endpoint, presets=test_presets, expected_status=Status.ConstraintError)
458+
459+
# Clear state for next test.
460+
await self.send_atomic_request_rollback_command()
461+
462+
self.step("18")
463+
if self.pics_guard(self.check_pics("TSTAT.S.F08") and self.check_pics("TSTAT.S.A0050") and self.check_pics("TSTAT.S.Cfe.Rsp")):
464+
465+
# Read the active preset handle attribute and verify it was updated to preset handle
466+
presetTypes = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=cluster.Attributes.PresetTypes)
467+
logger.info(f"Rx'd PresetTypes: {presetTypes}")
468+
469+
test_presets = copy.deepcopy(new_presets_with_handle)
470+
test_presets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=cluster.Enums.PresetScenarioEnum.kWake,
471+
name="Wake", coolingSetpoint=2500, heatingSetpoint=1700, builtIn=False))
472+
test_presets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=cluster.Enums.PresetScenarioEnum.kVacation,
473+
name="Vacation", coolingSetpoint=2400, heatingSetpoint=1800, builtIn=False))
474+
test_presets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=cluster.Enums.PresetScenarioEnum.kGoingToSleep,
475+
name="GoingToSleep", coolingSetpoint=2300, heatingSetpoint=1900, builtIn=False))
476+
test_presets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=cluster.Enums.PresetScenarioEnum.kUserDefined,
477+
name="UserDefined", coolingSetpoint=2300, heatingSetpoint=1900, builtIn=False))
478+
479+
# Send the AtomicRequest begin command
480+
await self.send_atomic_request_begin_command()
481+
482+
await self.write_presets(endpoint=endpoint, presets=test_presets)
445483

484+
# Send the AtomicRequest commit command and expect ResourceExhausted for presets.
485+
await self.send_atomic_request_commit_command(expected_overall_status=Status.Failure, expected_preset_status=Status.ResourceExhausted)
446486

447487
if __name__ == "__main__":
448488
default_matter_test_main()

0 commit comments

Comments
 (0)
Please sign in to comment.