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

[CI] Add TestLogCommands.yaml and an helper to log a custom message #10516

Merged
merged 2 commits into from
Oct 21, 2021
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
7 changes: 7 additions & 0 deletions examples/chip-tool/commands/tests/TestCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ CHIP_ERROR TestCommand::WaitForMs(uint32_t ms)
return chip::DeviceLayer::SystemLayer().StartTimer(ms, OnWaitForMsFn, this);
}

CHIP_ERROR TestCommand::Log(const char * message)
{
ChipLogDetail(chipTool, "%s", message);
WaitForMs(0);
return CHIP_NO_ERROR;
}

void TestCommand::Exit(std::string message)
{
ChipLogError(chipTool, " ***** Test Failure: %s\n", message.c_str());
Expand Down
1 change: 1 addition & 0 deletions examples/chip-tool/commands/tests/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class TestCommand : public CHIPCommand

/////////// GlobalCommands Interface /////////
CHIP_ERROR WaitForMs(uint32_t ms);
CHIP_ERROR Log(const char * message);

protected:
ChipDevice * mDevice;
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class {{filename}}: public TestCommand
{{#if (isTestOnlyCluster cluster)}}
CHIP_ERROR {{>testCommand}}()
{
return {{command}}({{#chip_tests_item_parameters}}{{#not_first}}, {{/not_first}}{{definedValue}}{{/chip_tests_item_parameters}});
return {{command}}({{#chip_tests_item_parameters}}{{#not_first}}, {{/not_first}}{{#if (isString type)}}"{{/if}}{{definedValue}}{{#if (isString type)}}"{{/if}}{{/chip_tests_item_parameters}});
}
{{else}}
{{#*inline "failureResponse"}}OnFailureResponse_{{index}}{{/inline}}
Expand Down
1 change: 1 addition & 0 deletions examples/chip-tool/templates/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function getTests()
'TestClusterComplexTypes',
'TestConstraints',
'TestDelayCommands',
'TestLogCommands',
'TestDescriptorCluster',
'TestOperationalCredentialsCluster',
];
Expand Down
28 changes: 28 additions & 0 deletions src/app/tests/suites/TestLogCommands.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Log Commands Tests

config:
cluster: "Test Cluster"
endpoint: 1

tests:
- label: "Log a simple message"
cluster: "LogCommands"
command: "Log"
arguments:
values:
- name: "message"
value: "This is a simple message"
28 changes: 23 additions & 5 deletions src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const path = require('path');
const templateUtil = require(zapPath + 'dist/src-electron/generator/template-util.js')

const { DelayCommands } = require('./simulated-clusters/TestDelayCommands.js');
const { LogCommands } = require('./simulated-clusters/TestLogCommands.js');
const { Clusters, asBlocks, asPromise } = require('./ClustersHelper.js');
const { asUpperCamelCase } = require(basePath + 'src/app/zap-templates/templates/app/helper.js');

Expand Down Expand Up @@ -263,18 +264,31 @@ 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(DelayCommands, LogCommands));
}

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

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

function assertCommandOrAttribute(context)
Expand Down Expand Up @@ -341,7 +355,11 @@ function chip_tests_items(options)

function isTestOnlyCluster(name)
{
return name == DelayCommands.name;
const testOnlyClusters = [
DelayCommands.name,
LogCommands.name,
];
return testOnlyClusters.includes(name);
}

function chip_tests_item_response_type(options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

const WaitForMs = {
name : 'WaitForMs',
arguments : [ { name : 'ms' } ],
arguments : [ { type : 'INT32U', name : 'ms' } ],
response : { arguments : [] }
};

Expand Down
41 changes: 41 additions & 0 deletions src/app/zap-templates/common/simulated-clusters/TestLogCommands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* This file declares test suite utility methods for logging.
*
* Each method declared in this file needs to be implemented on a per-language
* basis and allows exposing methods to the test suites that are not part
* of the regular cluster set of APIs.
*
*/

const Log = {
name : 'Log',
arguments : [ { type : 'CHAR_STRING', name : 'message' } ],
response : { arguments : [] }
};

const LogCommands = {
name : 'LogCommands',
commands : [ Log ],
};

//
// Module exports
//
exports.LogCommands = LogCommands;
55 changes: 55 additions & 0 deletions zzz_generated/chip-tool/zap-generated/test/Commands.h

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