Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestCluster: Add attribute resets during Test cmd. #13673

Merged
merged 1 commit into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
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