Skip to content

Commit

Permalink
[YAML] Remove unused list freer (#15415)
Browse files Browse the repository at this point in the history
* [YAML] Add chip_tests_item_has_list in order to not generate a useless ListFreer if it it not needed

* Update generated tests content
  • Loading branch information
vivien-apple authored and pull[bot] committed Jan 23, 2024
1 parent d66e635 commit 1678740
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3,107 deletions.
4 changes: 2 additions & 2 deletions examples/chip-tool/templates/tests/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class {{filename}}: public TestCommand
{{#if isCommand}}
using RequestType = chip::app::Clusters::{{asUpperCamelCase cluster}}::Commands::{{asUpperCamelCase command}}::Type;

ListFreer listFreer;
{{#if (chip_tests_item_has_list)}} ListFreer listFreer;{{/if}}
RequestType request;
{{#chip_tests_item_parameters}}
{{>commandValue ns=parent.cluster container=(concat "request." (asLowerCamelCase label)) definedValue=definedValue depth=0}}
Expand Down Expand Up @@ -335,7 +335,7 @@ class {{filename}}: public TestCommand
cluster.Associate({{>device}}, endpoint);
{{/if}}

ListFreer listFreer;
{{#if (chip_tests_item_has_list)}} ListFreer listFreer;{{/if}}
{{#chip_tests_item_parameters}}
{{zapTypeToEncodableClusterObjectType type ns=parent.cluster}} {{asLowerCamelCase name}}Argument;
{{>commandValue ns=parent.cluster container=(concat (asLowerCamelCase name) "Argument") definedValue=definedValue depth=0}}
Expand Down
27 changes: 27 additions & 0 deletions src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,11 +768,38 @@ function ensureIsArray(value, options)
}
}

function chip_tests_item_has_list(options)
{
function hasList(args)
{
for (let i = 0; i < args.length; i++) {
if (args[i].isArray) {
return true;
}

if (args[i].isStruct && hasList(args[i].items)) {
return true;
}
}

return false;
}

return assertCommandOrAttributeOrEvent(this).then(item => {
if (this.isWriteAttribute || this.isCommand) {
return hasList(item.arguments);
}

return false;
});
}

//
// Module exports
//
exports.chip_tests = chip_tests;
exports.chip_tests_items = chip_tests_items;
exports.chip_tests_item_has_list = chip_tests_item_has_list;
exports.chip_tests_item_parameters = chip_tests_item_parameters;
exports.chip_tests_item_response_parameters = chip_tests_item_response_parameters;
exports.chip_tests_pics = chip_tests_pics;
Expand Down
Loading

0 comments on commit 1678740

Please sign in to comment.