Skip to content

Commit

Permalink
Make attribute-write yaml tests play nicer with complex types. (#11457)
Browse files Browse the repository at this point in the history
The key change is using zapTypeToEncodableClusterObjectType to declare
the type and the "commandValue" partial to set it to the given value,
which is more similar to how we handle command arguments.  That makes
things work for lists and nullables at the very least.

The ignore="true" bit is probably not very well named, but it means
"just use the 'container' value as-is, instead of treating it as a
struct with member that stores the value".

The fix in ClusterTestGeneration.js is just fixing a typo in the
"type" values there that started to matter because we pass "type" to
zapTypeToEncodableClusterObjectType.

The fix in ClustersHelper.js is to give our synthetic "argument" to
writeAttribute the same nullability as the actual attribute, so the
types we get are right, and to set isArray for lists, because our
templates key off of that (especially the "commandValue" partial).
The "commandValue" partial also uses the "label" when dealing with
lists, so we define that for attributes to just be the attribute name.

The generated code changes are all no-ops so far, because we are not
actually using any types that would be affected by this yet.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Mar 18, 2023
1 parent d2b37ca commit 3037129
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 162 deletions.
14 changes: 2 additions & 12 deletions examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,8 @@ class {{filename}}: public TestCommand
{{#if async}}ReturnErrorOnFailure({{else}}return {{/if}}cluster.InvokeCommand<requestType, responseType>(request, this, success, failure){{#if async}}){{/if}};
{{else}}
{{#chip_tests_item_parameters}}
{{chipType}} {{asLowerCamelCase name}}Argument =
{{#if (isOctetString type)}}
chip::ByteSpan(chip::Uint8::from_const_char("{{definedValue}}"), strlen("{{definedValue}}"))
{{else if (isCharString type)}}
chip::CharSpan("{{definedValue}}", strlen("{{definedValue}}"))
{{else}}
{{#if_chip_enum type}}
static_cast<{{chipType}}>({{definedValue}}{{asTypeLiteralSuffix type}})
{{else}}
{{definedValue}}{{asTypeLiteralSuffix type}}
{{/if_chip_enum}}
{{/if}};
{{zapTypeToEncodableClusterObjectType type ns=parent.cluster}} {{asLowerCamelCase name}}Argument;
{{>commandValue ns=parent.cluster ignore=true container=(concat (asLowerCamelCase name) "Argument") definedValue=definedValue}}
{{/chip_tests_item_parameters}}

{{~#*inline "commandName"}}{{asUpperCamelCase commandName}}{{#if isAttribute}}Attribute{{asUpperCamelCase attribute}}{{/if}}{{/inline}}
Expand Down
4 changes: 2 additions & 2 deletions src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ function chip_tests_item_parameters(options)
const promise = assertCommandOrAttribute(this).then(item => {
if (this.isAttribute && !this.isWriteAttribute) {
if (this.isSubscribeAttribute) {
const minInterval = { name : 'minInterval', type : 'in16u', chipType : 'uint16_t', definedValue : this.minInterval };
const maxInterval = { name : 'maxInterval', type : 'in16u', chipType : 'uint16_t', definedValue : this.maxInterval };
const minInterval = { name : 'minInterval', type : 'int16u', chipType : 'uint16_t', definedValue : this.minInterval };
const maxInterval = { name : 'maxInterval', type : 'int16u', chipType : 'uint16_t', definedValue : this.maxInterval };
return [ minInterval, maxInterval ];
}
return [];
Expand Down
5 changes: 4 additions & 1 deletion src/app/zap-templates/common/ClustersHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,11 @@ function enhancedAttributes(attributes, globalAttributes, types)
type : attribute.type,
size : attribute.size,
isList : attribute.isList,
isArray : attribute.isList,
isNullable : attribute.isNullable,
chipType : attribute.chipType,
chipCallback : attribute.chipCallback
chipCallback : attribute.chipCallback,
label : attribute.name,
};
attribute.arguments = [ argument ];
attribute.response = { arguments : [ argument ] };
Expand Down
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIPTests/CHIPClustersTests.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3037129

Please sign in to comment.