From a375131500ac758d27ff68a79f6228be10fb4969 Mon Sep 17 00:00:00 2001 From: Nivedita Sarkar Date: Mon, 26 Aug 2024 07:25:59 -0700 Subject: [PATCH] Modify the number of presets supported test case to read the number of presets supported and build a preset list whose size exceeds that to test --- .../include/thermostat-delegate-impl.h | 4 ++ .../src/thermostat-delegate-impl.cpp | 5 ++- src/python_testing/TC_TSTAT_4_2.py | 39 +++++++++++++------ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/examples/thermostat/thermostat-common/include/thermostat-delegate-impl.h b/examples/thermostat/thermostat-common/include/thermostat-delegate-impl.h index 2e8b8da73683b3..dea3816d29e186 100644 --- a/examples/thermostat/thermostat-common/include/thermostat-delegate-impl.h +++ b/examples/thermostat/thermostat-common/include/thermostat-delegate-impl.h @@ -39,6 +39,10 @@ static constexpr uint8_t kMaxNumberOfPresetTypes = 7; // We will support only one preset of each preset type. static constexpr uint8_t kMaxNumberOfPresetsOfEachType = 1; +// For testing the use case where number of presets added exceed the number of presets supported, we will have the value of +// kMaxNumberOfPresetsSupported < kMaxNumberOfPresetTypes * kMaxNumberOfPresetsOfEachType +static constexpr uint8_t kMaxNumberOfPresetsSupported = kMaxNumberOfPresetTypes * kMaxNumberOfPresetsOfEachType - 1; + class ThermostatDelegate : public Delegate { public: diff --git a/examples/thermostat/thermostat-common/src/thermostat-delegate-impl.cpp b/examples/thermostat/thermostat-common/src/thermostat-delegate-impl.cpp index 81b3221eaa1a31..5cd982c45c6d18 100644 --- a/examples/thermostat/thermostat-common/src/thermostat-delegate-impl.cpp +++ b/examples/thermostat/thermostat-common/src/thermostat-delegate-impl.cpp @@ -31,7 +31,7 @@ ThermostatDelegate ThermostatDelegate::sInstance; ThermostatDelegate::ThermostatDelegate() { - mNumberOfPresets = kMaxNumberOfPresetTypes * kMaxNumberOfPresetsOfEachType; + mNumberOfPresets = kMaxNumberOfPresetsSupported; mNextFreeIndexInPresetsList = 0; mNextFreeIndexInPendingPresetsList = 0; @@ -87,6 +87,9 @@ CHIP_ERROR ThermostatDelegate::GetPresetTypeAtIndex(size_t index, PresetTypeStru { .presetScenario = PresetScenarioEnum::kVacation, .numberOfPresets = kMaxNumberOfPresetsOfEachType, .presetTypeFeatures = to_underlying(PresetTypeFeaturesBitmap::kSupportsNames) }, + { .presetScenario = PresetScenarioEnum::kGoingToSleep, + .numberOfPresets = kMaxNumberOfPresetsOfEachType, + .presetTypeFeatures = to_underlying(PresetTypeFeaturesBitmap::kSupportsNames) }, { .presetScenario = PresetScenarioEnum::kUserDefined, .numberOfPresets = kMaxNumberOfPresetsOfEachType, .presetTypeFeatures = to_underlying(PresetTypeFeaturesBitmap::kSupportsNames) }, diff --git a/src/python_testing/TC_TSTAT_4_2.py b/src/python_testing/TC_TSTAT_4_2.py index acfc29e28e72dc..2d186fe6570831 100644 --- a/src/python_testing/TC_TSTAT_4_2.py +++ b/src/python_testing/TC_TSTAT_4_2.py @@ -482,30 +482,45 @@ async def test_TC_TSTAT_4_2(self): self.step("18") 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")): - # Read the numberOfPresets supported to get the maximum number of presets supported. + # Read the numberOfPresets supported. numberOfPresetsSupported = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=cluster.Attributes.NumberOfPresets) - logger.info(f"Rx'd NumberOfPresets: {numberOfPresetsSupported}") - # Read the presetTypes supported to get the preset types supported + # Read the PresetTypes to get the preset scenarios to build the Presets list. presetTypes = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=cluster.Attributes.PresetTypes) - logger.info(f"Rx'd PresetTypes: {presetTypes}") - # Since we currently support one preset of each type, run the test only if we have enough preset types to exceed maximum number of presets supported. - if sizeof(presetTypes) > numberOfPresetsSupported: - for preset in presetTypes: + # Read the Presets to copy the existing presets into our testPresets list below. + presets = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=cluster.Attributes.Presets) + + # Since we currently support one preset of each type, run the test only if we have enough preset types to create a preset list whose length exceeds the + # maximum number of presets supported. + if len(presetTypes) > numberOfPresetsSupported: + didCopyPreset = False + testPresets = [] + for presetType in presetTypes: scenario = presetType.presetScenario - isBuiltIn = (scenario == cluster.Enums.PresetScenarioEnum.kOccupied or scenario == cluster.Enums.PresetScenarioEnum.kUnoccupied) - test_presets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=presetType.presetScenario, - name="Preset", coolingSetpoint=2500, heatingSetpoint=1700, builtIn=isBuiltIn)) + + # For each scenario, check if there is a preset in the Presets attribute matching the scenario. iif so, copy the preset into testPresets. + # Otherwide, add a new entry. + for preset in presets: + if scenario == preset.presetScenario: + testPresets.append(preset) + didCopyPreset = True + break + else: + didCopyPreset = False + if not didCopyPreset: + testPresets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=presetType.presetScenario, + name="Preset", coolingSetpoint=2500, heatingSetpoint=1700, builtIn=False)) # Send the AtomicRequest begin command await self.send_atomic_request_begin_command() - await self.write_presets(endpoint=endpoint, presets=test_presets, expected_status=Status.ResourceExhausted) + await self.write_presets(endpoint=endpoint, presets=testPresets, expected_status=Status.ResourceExhausted) # Clear state for next test. await self.send_atomic_request_rollback_command() - + else: + logger.info(f"Couldn't run test step 18 since there are not enough preset types to build a Presets list that exceeds the number of presets supported"); if __name__ == "__main__": default_matter_test_main()