Skip to content

Commit

Permalink
TestCluster: Add attribute resets during Test cmd. (#13673)
Browse files Browse the repository at this point in the history
The test assumes that we start with the default values, which means
the test will fail the second time around. This fixes that.
  • Loading branch information
cecille authored Jan 19, 2022
1 parent 8eb0c21 commit 55e9a47
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
37 changes: 37 additions & 0 deletions src/app/clusters/test-cluster-server/test-cluster-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,43 @@ CHIP_ERROR TestAttrAccess::WriteStructAttribute(AttributeValueDecoder & aDecoder
bool emberAfTestClusterClusterTestCallback(app::CommandHandler *, const app::ConcreteCommandPath & commandPath,
const Test::DecodableType & commandData)
{
// Setup the test variables
emAfLoadAttributeDefaults(commandPath.mEndpointId, true, MakeOptional(commandPath.mClusterId));
for (int i = 0; i < kAttributeListLength; ++i)
{
gListUint8Data[i] = 0;
gListOctetStringData[i].SetLength(0);
gListOperationalCert[i].SetLength(0);
listStructOctetStringData[i].fabricIndex = 0;
listStructOctetStringData[i].operationalCert = ByteSpan();
gSimpleEnums[i] = SimpleEnum::kUnspecified;
}
gSimpleEnumCount = 0;

gStructAttributeValue.a = 0;
gStructAttributeValue.b = false;
gStructAttributeValue.c = SimpleEnum::kValueA;
gStructAttributeValue.d = ByteSpan();
gStructAttributeValue.e = CharSpan();
gStructAttributeValue.f = BitFlags<SimpleBitmap>();
gStructAttributeValue.g = 0;
gStructAttributeValue.h = 0;

gNullableStructAttributeValue.SetNull();

gNullablesAndOptionalsStruct.nullableInt.SetNull();
gNullablesAndOptionalsStruct.optionalInt = NullOptional;
gNullablesAndOptionalsStruct.nullableOptionalInt = NullOptional;
gNullablesAndOptionalsStruct.nullableString.SetNull();
gNullablesAndOptionalsStruct.optionalString = NullOptional;
gNullablesAndOptionalsStruct.nullableOptionalString = NullOptional;
gNullablesAndOptionalsStruct.nullableStruct.SetNull();
gNullablesAndOptionalsStruct.optionalStruct = NullOptional;
gNullablesAndOptionalsStruct.nullableOptionalStruct = NullOptional;
gNullablesAndOptionalsStruct.nullableList.SetNull();
gNullablesAndOptionalsStruct.optionalList = NullOptional;
gNullablesAndOptionalsStruct.nullableOptionalList = NullOptional;

emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
return true;
}
Expand Down
9 changes: 8 additions & 1 deletion src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ void emberAfResetAttributes(EndpointId endpoint)
emAfLoadAttributeDefaults(endpoint, true);
}

void emAfLoadAttributeDefaults(EndpointId endpoint, bool ignoreStorage)
void emAfLoadAttributeDefaults(EndpointId endpoint, bool ignoreStorage, Optional<ClusterId> clusterId)
{
uint16_t ep;
uint8_t clusterI, curNetwork = 0 /* emberGetCurrentNetwork() */;
Expand Down Expand Up @@ -1142,6 +1142,13 @@ void emAfLoadAttributeDefaults(EndpointId endpoint, bool ignoreStorage)
for (clusterI = 0; clusterI < de->endpointType->clusterCount; clusterI++)
{
EmberAfCluster * cluster = &(de->endpointType->cluster[clusterI]);
if (clusterId.HasValue())
{
if (clusterId.Value() != cluster->clusterId)
{
continue;
}
}

// when the attributeCount is high, the loop takes too long to run and a
// watchdog kicks in causing a reset. As a workaround, we'll
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/attribute-storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void emberAfResetAttributes(chip::EndpointId endpoint);
// Loads the attributes from built-in default and / or storage. If
// ignoreStorage is true, only defaults will be read, and the storage for
// non-volatile attributes will be overwritten with those defaults.
void emAfLoadAttributeDefaults(chip::EndpointId endpoint, bool ignoreStorage);
void emAfLoadAttributeDefaults(chip::EndpointId endpoint, bool ignoreStorage, chip::Optional<chip::ClusterId> = chip::NullOptional);

// After the RAM value has changed, code should call this function. If this
// attribute has been tagged as non-volatile, its value will be stored.
Expand Down

0 comments on commit 55e9a47

Please sign in to comment.