Skip to content

Commit 2f785f4

Browse files
authored
[YAML] Add TestDiscovery.yaml (project-chip#14598)
* Add DiscoveryCommands interface to src/app/tests/suites/commands/discovery * [YAML] Add additional PICS code to PICS.yaml * [YAML] Add TestDiscovery.yaml * Workaround the colliding mdns advertisment on CI * Update generated content
1 parent bed61c3 commit 2f785f4

File tree

16 files changed

+2767
-81
lines changed

16 files changed

+2767
-81
lines changed

examples/chip-tool/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static_library("chip-tool-utils") {
6969

7070
public_deps = [
7171
"${chip_root}/src/app/server",
72+
"${chip_root}/src/app/tests/suites/commands/discovery",
7273
"${chip_root}/src/app/tests/suites/commands/log",
7374
"${chip_root}/src/app/tests/suites/commands/system",
7475
"${chip_root}/src/app/tests/suites/pics",

examples/chip-tool/commands/tests/TestCommand.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ CHIP_ERROR TestCommand::RunCommand()
3232

3333
CHIP_ERROR TestCommand::WaitForCommissionee()
3434
{
35+
CurrentCommissioner().ReleaseOperationalDevice(mNodeId);
3536
return CurrentCommissioner().GetConnectedDevice(mNodeId, &mOnDeviceConnectedCallback, &mOnDeviceConnectionFailureCallback);
3637
}
3738

@@ -42,7 +43,7 @@ void TestCommand::OnDeviceConnectedFn(void * context, chip::OperationalDevicePro
4243
VerifyOrReturn(command != nullptr, ChipLogError(chipTool, "Device connected, but cannot run the test, as the context is null"));
4344
command->mDevices[command->GetIdentity()] = device;
4445

45-
command->NextTest();
46+
command->ContinueOnChipMainThread();
4647
}
4748

4849
void TestCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error)
@@ -51,7 +52,8 @@ void TestCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHI
5152
peerId.GetNodeId(), error.Format());
5253
auto * command = static_cast<TestCommand *>(context);
5354
VerifyOrReturn(command != nullptr, ChipLogError(chipTool, "Test command context is null"));
54-
command->SetCommandExitStatus(error);
55+
56+
command->ContinueOnChipMainThread();
5557
}
5658

5759
void TestCommand::OnWaitForMsFn(chip::System::Layer * systemLayer, void * context)

examples/chip-tool/commands/tests/TestCommand.h

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#pragma once
2020

2121
#include "../common/CHIPCommand.h"
22+
#include <app/tests/suites/commands/discovery/DiscoveryCommands.h>
2223
#include <app/tests/suites/commands/log/LogCommands.h>
2324
#include <app/tests/suites/commands/system/SystemCommands.h>
2425
#include <app/tests/suites/include/ConstraintsChecker.h>
@@ -34,6 +35,7 @@ class TestCommand : public CHIPCommand,
3435
public ConstraintsChecker,
3536
public PICSChecker,
3637
public LogCommands,
38+
public DiscoveryCommands,
3739
public SystemCommands
3840
{
3941
public:

examples/chip-tool/templates/partials/test_cluster.zapt

+58-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,57 @@ class {{filename}}: public TestCommand
102102
{{/chip_tests_item_response_parameters}}
103103
{{/chip_tests_items}}
104104

105+
void OnDiscoveryCommandsResults(const DiscoveryCommandResult & nodeData) override
106+
{
107+
bool isExpectedDnssdResult = false;
108+
{{#chip_tests_items}}
109+
{{#if (isStrEqual cluster "DiscoveryCommands")}}
110+
if ((mTestIndex - 1) == {{index}})
111+
{
112+
isExpectedDnssdResult = true;
113+
{{#chip_tests_item_response_parameters}}
114+
{{#*inline "itemValue"}}nodeData.{{name}}{{#if isOptional}}.Value(){{/if}}{{/inline}}
115+
{{~#if hasExpectedValue}}
116+
{{#if isOptional}}VerifyOrReturn(CheckValuePresent("{{name}}", nodeData.{{name}}));{{/if}}
117+
VerifyOrReturn(CheckValue("{{name}}", {{>itemValue}},
118+
{{#if (chip_tests_config_has expectedValue)}}
119+
m{{asUpperCamelCase expectedValue}}.HasValue() ? m{{asUpperCamelCase expectedValue}}.Value() : {{asTypedLiteral (chip_tests_config_get_default_value expectedValue) (chip_tests_config_get_type expectedValue)}}
120+
{{else}}
121+
{{expectedValue}}
122+
{{/if}}
123+
));
124+
{{/if}}
125+
{{#if hasExpectedConstraints}}
126+
{{#if isOptional}}VerifyOrReturn(CheckValuePresent("{{name}}", nodeData.{{name}}));{{/if}}
127+
{{#if (hasProperty expectedConstraints "minLength")}}VerifyOrReturn(CheckConstraintMinLength("{{name}}", {{>itemValue}}.size(), {{expectedConstraints.minLength}}));{{/if}}
128+
{{#if (hasProperty expectedConstraints "maxLength")}}VerifyOrReturn(CheckConstraintMaxLength("{{name}}", {{>itemValue}}.size(), {{expectedConstraints.maxLength}}));{{/if}}
129+
{{#if (hasProperty expectedConstraints "minValue")}}VerifyOrReturn(CheckConstraintMinValue<{{chipType}}>("{{name}}", {{>itemValue}}, {{asTypedLiteral expectedConstraints.minValue type}}));{{/if}}
130+
{{#if (hasProperty expectedConstraints "maxValue")}}VerifyOrReturn(CheckConstraintMaxValue<{{chipType}}>("{{name}}", {{>itemValue}}, {{asTypedLiteral expectedConstraints.maxValue type}}));{{/if}}
131+
{{#if (hasProperty expectedConstraints "notValue")}}VerifyOrReturn(CheckConstraintNotValue("{{name}}", {{>itemValue}}, {{asTypedLiteral expectedConstraints.notValue type}}));{{/if}}
132+
{{/if}}
133+
134+
{{#if saveAs}}
135+
{{#if (isString type)}}
136+
if ({{saveAs}}Buffer != nullptr)
137+
{
138+
chip::Platform::MemoryFree({{saveAs}}Buffer);
139+
}
140+
{{saveAs}}Buffer = static_cast<{{#if (isOctetString type)}}uint8_t{{else}}char{{/if}} *>(chip::Platform::MemoryAlloc({{>itemValue}}.size()));
141+
memcpy({{saveAs}}Buffer, {{>itemValue}}.data(), {{>itemValue}}.size());
142+
{{saveAs}} = {{chipType}}({{saveAs}}Buffer, {{>itemValue}}.size());
143+
{{else}}
144+
{{saveAs}} = {{>itemValue}};
145+
{{/if}}
146+
{{/if}}
147+
{{/chip_tests_item_response_parameters}}
148+
}
149+
{{/if}}
150+
{{/chip_tests_items}}
151+
152+
VerifyOrReturn(isExpectedDnssdResult, Exit("An unexpected dnssd result has been received"));
153+
NextTest();
154+
}
155+
105156
{{! Helper around zapTypeToDecodableClusterObjectType that lets us set the
106157
array/nullable/etc context appropriately.}}
107158
{{~#*inline "subscribeResponseDataArgument"~}}
@@ -194,7 +245,13 @@ class {{filename}}: public TestCommand
194245
CHIP_ERROR {{>testCommand}}()
195246
{
196247
SetIdentity(kIdentity{{asUpperCamelCase identity}});
197-
return {{command}}({{#chip_tests_item_parameters}}{{#not_first}}, {{/not_first}}{{#if (isString type)}}"{{/if}}{{definedValue}}{{#if (isString type)}}"{{/if}}{{/chip_tests_item_parameters}});
248+
return {{command}}({{#chip_tests_item_parameters}}{{#not_first}}, {{/not_first}}{{#if (isString type)}}"{{/if~}}
249+
{{~#if (chip_tests_config_has definedValue)~}}
250+
m{{asUpperCamelCase definedValue}}.HasValue() ? m{{asUpperCamelCase definedValue}}.Value() : {{asTypedLiteral (chip_tests_config_get_default_value definedValue) (chip_tests_config_get_type definedValue)}}
251+
{{else}}
252+
{{definedValue}}
253+
{{~/if~}}
254+
{{~#if (isString type)}}"{{/if}}{{/chip_tests_item_parameters}});
198255
}
199256
{{else if isWait}}
200257
CHIP_ERROR {{>testCommand}}()

examples/chip-tool/templates/tests.js

+1
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ function getTests()
241241
'TestClusterComplexTypes',
242242
'TestConstraints',
243243
'TestDelayCommands',
244+
'TestDiscovery',
244245
'TestLogCommands',
245246
'TestSaveAs',
246247
'TestConfigVariables',

examples/placeholder/linux/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ executable("chip-${chip_tests_zap_config}") {
4141
deps = [
4242
":configuration",
4343
"${chip_root}/examples/platform/linux:app-main",
44+
"${chip_root}/src/app/tests/suites/commands/discovery",
4445
"${chip_root}/src/app/tests/suites/commands/log",
4546
"${chip_root}/src/app/tests/suites/pics",
4647
"${chip_root}/src/lib",

examples/placeholder/linux/include/TestCommand.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <app/ConcreteAttributePath.h>
2424
#include <app/ConcreteCommandPath.h>
2525

26+
#include <app/tests/suites/commands/discovery/DiscoveryCommands.h>
2627
#include <app/tests/suites/commands/log/LogCommands.h>
2728
#include <app/tests/suites/include/PICSChecker.h>
2829

@@ -34,7 +35,7 @@ constexpr const char kIdentityAlpha[] = "";
3435
constexpr const char kIdentityBeta[] = "";
3536
constexpr const char kIdentityGamma[] = "";
3637

37-
class TestCommand : public PICSChecker, public LogCommands
38+
class TestCommand : public PICSChecker, public LogCommands, public DiscoveryCommands
3839
{
3940
public:
4041
TestCommand(const char * commandName) : mCommandPath(0, 0, 0), mAttributePath(0, 0, 0) {}
@@ -70,6 +71,12 @@ class TestCommand : public PICSChecker, public LogCommands
7071
return CHIP_NO_ERROR;
7172
}
7273

74+
void Exit(std::string message)
75+
{
76+
ChipLogError(chipTool, " ***** Test Failure: %s\n", message.c_str());
77+
SetCommandExitStatus(CHIP_ERROR_INTERNAL);
78+
}
79+
7380
static void ScheduleNextTest(intptr_t context)
7481
{
7582
TestCommand * command = reinterpret_cast<TestCommand *>(context);

0 commit comments

Comments
 (0)