Skip to content

Commit

Permalink
Switch yaml tests to use ClusterBase::WriteAttribute for attribute wr…
Browse files Browse the repository at this point in the history
…ite.

The changes to test_cluster.zapt are the actual change we care about.

The change to WriteClient.h is to fix a pre-existing bug: it calls
Encode() without including all the headers that declare various
signatures of Encode().

The change to ClusterTestGeneration.js fixes a bug with the signature
of the success callback for writes: it had an extra arg with the type
of the attribute, whereas it should have no arg at all.

The change to CHIPClusters-src.zapt is to instantiate WriteAttribute
for all the non-writable attributes when compiling tests, because we
actually issue writes for those non-writable attributes (and test that
they fail).
  • Loading branch information
bzbarsky-apple committed Nov 5, 2021
1 parent 64ffda0 commit 645f948
Show file tree
Hide file tree
Showing 6 changed files with 2,939 additions and 1,559 deletions.
21 changes: 19 additions & 2 deletions examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,31 @@ class {{filename}}: public TestCommand
{{#unless (isTestOnlyCluster cluster)}}
{{#unless isWait}}
{{#unless isCommand}}
{{#unless isWriteAttribute}}
chip::Callback::Callback<void (*) ({{>failureArguments}})> {{>failureCallback}} { {{>failureResponse}}, this };
chip::Callback::Callback<void (*) ({{>successArguments}})> {{>successCallback}} { {{>successResponse}}, this };
{{/unless}}
{{/unless}}
{{/unless}}
{{/unless}}
{{/chip_tests_items}}

{{#chip_tests_items}}
{{#unless (isTestOnlyCluster cluster)}}
{{#unless isWait}}
{{#unless isCommand}}
{{#if isWriteAttribute}}
static void {{>failureResponse}}(void * context, EmberAfStatus status)
{
(static_cast<{{filename}} *>(context))->OnFailureResponse_{{index}}(chip::to_underlying(status));
}
{{else}}
static void {{>failureResponse}}({{> failureArguments}})
{
(static_cast<{{filename}} *>(context))->OnFailureResponse_{{index}}(status);
}
{{/if}}


static void {{>successResponse}}({{> successArguments}})
{
Expand Down Expand Up @@ -156,8 +166,15 @@ class {{filename}}: public TestCommand
{{/if}};
{{/chip_tests_item_parameters}}

{{~#*inline "commandName"}}{{asUpperCamelCase commandName}}{{#if isAttribute}}Attribute{{asUpperCamelCase attribute}}{{/if}}{{/inline}}
{{#if async}}ReturnErrorOnFailure({{else}}return {{/if}}cluster.{{>commandName}}({{>successCallback}}.Cancel(){{#unless isWaitForReport}}, {{>failureCallback}}.Cancel(){{/unless}}{{#chip_tests_item_parameters}}, {{asLowerCamelCase name}}Argument{{/chip_tests_item_parameters}}){{#if async}}){{/if}};
{{#if isWriteAttribute}}
{{#*inline "failureResponse"}}OnFailureCallback_{{index}}{{/inline}}
{{#*inline "successResponse"}}OnSuccessCallback_{{index}}{{/inline}}
{{#if async}}ReturnErrorOnFailure({{else}}return {{/if}}cluster.WriteAttribute<chip::app::Clusters::{{asUpperCamelCase cluster}}::Attributes::{{asUpperCamelCase attribute}}::TypeInfo>({{#chip_tests_item_parameters}}{{asLowerCamelCase name}}Argument, {{/chip_tests_item_parameters}}this, {{>successResponse}}, {{>failureResponse}}){{#if async}}){{/if}};
{{else}}
{{~#*inline "commandName"}}{{asUpperCamelCase commandName}}{{#if isAttribute}}Attribute{{asUpperCamelCase attribute}}{{/if}}{{/inline}}
{{#if async}}ReturnErrorOnFailure({{else}}return {{/if}}cluster.{{>commandName}}({{>successCallback}}.Cancel(){{#unless isWaitForReport}}, {{>failureCallback}}.Cancel(){{/unless}}{{#chip_tests_item_parameters}}, {{asLowerCamelCase name}}Argument{{/chip_tests_item_parameters}}){{#if async}}){{/if}};
{{/if}}

{{/if}}
{{#if async}}return WaitForMs(0);{{/if}}
}
Expand Down
1 change: 1 addition & 0 deletions src/app/WriteClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <app/MessageDef/AttributeStatusIB.h>
#include <app/MessageDef/WriteRequestMessage.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <lib/core/CHIPCore.h>
#include <lib/core/CHIPTLVDebug.hpp>
#include <lib/support/CodeUtils.h>
Expand Down
3 changes: 3 additions & 0 deletions src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@ function chip_tests_item_response_parameters(options)
const responseValues = this.response.values.slice();

const promise = assertCommandOrAttribute(this).then(item => {
if (this.isWriteAttribute) {
return [];
}
const responseArgs = item.response.arguments;

const responses = responseArgs.map(responseArg => {
Expand Down
30 changes: 30 additions & 0 deletions src/app/zap-templates/templates/app/tests/CHIPClusters-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ namespace Controller {

{{#chip_server_cluster_attributes}}
{{#unless isWritableAttribute}}
{{#*inline "attributeTypeInfo"}}chip::app::Clusters::{{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::TypeInfo{{/inline}}
template CHIP_ERROR ClusterBase::WriteAttribute<{{>attributeTypeInfo}}>(const {{>attributeTypeInfo}}::Type & requestData, void *context,
WriteResponseSuccessCallback successCb, WriteResponseFailureCallback failureCb);

{{#unless isList}}
{{#unless isStruct}}
CHIP_ERROR {{asUpperCamelCase parent.name}}ClusterTest::WriteAttribute{{asUpperCamelCase name}}(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback, {{chipType}} value)
Expand All @@ -36,6 +40,32 @@ CHIP_ERROR {{asUpperCamelCase parent.name}}ClusterTest::WriteAttribute{{asUpperC
{{/chip_server_cluster_attributes}}
{{/chip_client_clusters}}

template <typename AttributeInfo>
CHIP_ERROR ClusterBase::WriteAttribute(const typename AttributeInfo::Type & requestData, void * context,
WriteResponseSuccessCallback successCb, WriteResponseFailureCallback failureCb)
{
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
ReturnErrorOnFailure(mDevice->LoadSecureSessionParametersIfNeeded());

auto onSuccessCb = [context, successCb](const app::ConcreteAttributePath & commandPath) {
if (successCb != nullptr)
{
successCb(context);
}
};

auto onFailureCb = [context, failureCb](const app::ConcreteAttributePath * commandPath, app::StatusIB status,
CHIP_ERROR aError) {
if (failureCb != nullptr)
{
failureCb(context, app::ToEmberAfStatus(status.mStatus));
}
};

return chip::Controller::WriteAttribute<AttributeInfo>(mDevice->GetExchangeManager(), mDevice->GetSecureSession().Value(),
mEndpoint, requestData, onSuccessCb, onFailureCb);
}

} // namespace Controller
} // namespace chip
{{/if}}
Loading

0 comments on commit 645f948

Please sign in to comment.