Skip to content

Commit

Permalink
[testsuite] Refactor test suite simulated cluster command
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing committed Sep 13, 2021
1 parent 987a2d3 commit 8390956
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 29 deletions.
7 changes: 1 addition & 6 deletions examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ class {{filename}}: public TestCommand

{{#chip_tests_items}}
{{#if (isTestOnlyCluster cluster)}}
CHIP_ERROR TestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}()
{
ChipLogProgress(chipTool, "{{cluster}} - {{label}}");

return {{command}}({{#chip_tests_item_parameters}}{{#not_first}}, {{/not_first}}{{definedValue}}{{/chip_tests_item_parameters}});
}
{{> (asTestSuiteSimulatedClusterCommandPartial command) }}
{{else}}
// Test {{label}}
{{#if isSubscribeAttribute}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CHIP_ERROR TestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}()
{
ChipLogProgress(chipTool, "{{cluster}} - {{asUpperCamelCase command}} - {{label}}");

return {{command}}({{#chip_tests_item_parameters}}{{#not_first}}, {{/not_first}}{{definedValue}}{{/chip_tests_item_parameters}});
}
4 changes: 4 additions & 0 deletions examples/chip-tool/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
{
"name": "test_cluster",
"path": "partials/test_cluster.zapt"
},
{
"name": "TestSuiteHelper_WaitForMs",
"path": "partials/testsuite/WaitForMs.zapt"
}
],
"templates": [
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/suites/TestDelayCommands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ config:

tests:
- label: "Wait 100ms"
cluster: "DelayCommands"
cluster: "TestSuite"
command: "WaitForMs"
arguments:
values:
Expand Down
13 changes: 7 additions & 6 deletions src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const path = require('path');
// Import helpers from zap core
const templateUtil = require(zapPath + 'dist/src-electron/generator/template-util.js')

const { DelayCommands } = require('./simulated-clusters/TestDelayCommands.js');
const { TestSuiteHelperCluster } = require('./TestSuiteHelperCluster.js');
const { Clusters, asBlocks, asPromise } = require('./ClustersHelper.js');

const kClusterName = 'cluster';
Expand Down Expand Up @@ -219,18 +219,19 @@ function getClusters()
{
// Create a new array to merge the configured clusters list and test
// simulated clusters.
return Clusters.getClusters().then(clusters => clusters.concat(DelayCommands));
return Clusters.getClusters().then(clusters => clusters.concat(TestSuiteHelperCluster));
}

function getCommands(clusterName)
{
return (clusterName == DelayCommands.name) ? Promise.resolve(DelayCommands.commands) : Clusters.getClientCommands(clusterName);
return (clusterName == TestSuiteHelperCluster.name) ? Promise.resolve(TestSuiteHelperCluster.commands)
: Clusters.getClientCommands(clusterName);
}

function getAttributes(clusterName)
{
return (clusterName == DelayCommands.name) ? Promise.resolve(DelayCommands.attributes)
: Clusters.getServerAttributes(clusterName);
return (clusterName == TestSuiteHelperCluster.name) ? Promise.resolve(TestSuiteHelperCluster.attributes)
: Clusters.getServerAttributes(clusterName);
}

function assertCommandOrAttribute(context)
Expand Down Expand Up @@ -296,7 +297,7 @@ function chip_tests_items(options)

function isTestOnlyCluster(name)
{
return name == DelayCommands.name;
return name == TestSuiteHelperCluster.name;
}

function chip_tests_with_command_attribute_info(options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

/*
* This file declare test suites utilities methods for delayed commands.
* This file declare test suites utilities methods for test suite.
*
* Each method declared in this file needs to be implemented on a per-language
* basis and permits to exposes methods to the test suites that are not part
Expand All @@ -30,12 +30,12 @@ const WaitForMs = {
response : { arguments : [] }
};

const DelayCommands = {
name : 'DelayCommands',
const TestSuiteHelperCluster = {
name : 'TestSuite',
commands : [ WaitForMs ],
};

//
// Module exports
//
exports.DelayCommands = DelayCommands;
exports.TestSuiteHelperCluster = TestSuiteHelperCluster;
26 changes: 16 additions & 10 deletions src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,22 @@ function asMEI(prefix, suffix)
return cHelper.asHex((prefix << 16) + suffix, 8);
}

function asTestSuiteSimulatedClusterCommandPartial(label)
{
return "TestSuiteHelper_" + asUpperCamelCase(label)
}

//
// Module exports
//
exports.asPrintFormat = asPrintFormat;
exports.asReadType = asReadType;
exports.asReadTypeLength = asReadTypeLength;
exports.chip_endpoint_generated_functions = chip_endpoint_generated_functions
exports.chip_endpoint_cluster_list = chip_endpoint_cluster_list
exports.asTypeLiteralSuffix = asTypeLiteralSuffix;
exports.asLowerCamelCase = asLowerCamelCase;
exports.asUpperCamelCase = asUpperCamelCase;
exports.hasSpecificAttributes = hasSpecificAttributes;
exports.asMEI = asMEI;
exports.asPrintFormat = asPrintFormat;
exports.asReadType = asReadType;
exports.asReadTypeLength = asReadTypeLength;
exports.chip_endpoint_generated_functions = chip_endpoint_generated_functions
exports.chip_endpoint_cluster_list = chip_endpoint_cluster_list
exports.asTypeLiteralSuffix = asTypeLiteralSuffix;
exports.asLowerCamelCase = asLowerCamelCase;
exports.asUpperCamelCase = asUpperCamelCase;
exports.hasSpecificAttributes = hasSpecificAttributes;
exports.asMEI = asMEI;
exports.asTestSuiteSimulatedClusterCommandPartial = asTestSuiteSimulatedClusterCommandPartial;
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
{
XCTestExpectation * expectation = [self expectationWithDescription:@"{{label}}"];
{{#if (isTestOnlyCluster cluster)}}
dispatch_queue_t queue = dispatch_get_main_queue();
{{command}}(expectation, queue{{#chip_tests_item_parameters}}, {{definedValue}}{{/chip_tests_item_parameters}});
{{> (asTestSuiteSimulatedClusterCommandPartial command)}}
{{else}}
CHIPDevice * device = GetPairedDevice(kDeviceId);
dispatch_queue_t queue = dispatch_get_main_queue();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dispatch_queue_t queue = dispatch_get_main_queue();
{{command}}(expectation, queue{{#chip_tests_item_parameters}}, {{definedValue}}{{/chip_tests_item_parameters}});
4 changes: 4 additions & 0 deletions src/darwin/Framework/CHIP/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
{
"name": "CHIPCallbackBridge",
"path": "partials/CHIPCallbackBridge.zapt"
},
{
"name": "TestSuiteHelper_WaitForMs",
"path": "partials/testsuite/WaitForMs.zapt"
}
],
"templates": [
Expand Down

0 comments on commit 8390956

Please sign in to comment.