Skip to content

Commit

Permalink
[YAML] Add TestDiscovery.yaml (#14598)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vivien-apple authored and pull[bot] committed Dec 20, 2023
1 parent 9df12c2 commit 2515820
Show file tree
Hide file tree
Showing 16 changed files with 2,767 additions and 81 deletions.
1 change: 1 addition & 0 deletions examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static_library("chip-tool-utils") {

public_deps = [
"${chip_root}/src/app/server",
"${chip_root}/src/app/tests/suites/commands/discovery",
"${chip_root}/src/app/tests/suites/commands/log",
"${chip_root}/src/app/tests/suites/commands/system",
"${chip_root}/src/app/tests/suites/pics",
Expand Down
6 changes: 4 additions & 2 deletions examples/chip-tool/commands/tests/TestCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ CHIP_ERROR TestCommand::RunCommand()

CHIP_ERROR TestCommand::WaitForCommissionee()
{
CurrentCommissioner().ReleaseOperationalDevice(mNodeId);
return CurrentCommissioner().GetConnectedDevice(mNodeId, &mOnDeviceConnectedCallback, &mOnDeviceConnectionFailureCallback);
}

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

command->NextTest();
command->ContinueOnChipMainThread();
}

void TestCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error)
Expand All @@ -51,7 +52,8 @@ void TestCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHI
peerId.GetNodeId(), error.Format());
auto * command = static_cast<TestCommand *>(context);
VerifyOrReturn(command != nullptr, ChipLogError(chipTool, "Test command context is null"));
command->SetCommandExitStatus(error);

command->ContinueOnChipMainThread();
}

void TestCommand::OnWaitForMsFn(chip::System::Layer * systemLayer, void * context)
Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/commands/tests/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include "../common/CHIPCommand.h"
#include <app/tests/suites/commands/discovery/DiscoveryCommands.h>
#include <app/tests/suites/commands/log/LogCommands.h>
#include <app/tests/suites/commands/system/SystemCommands.h>
#include <app/tests/suites/include/ConstraintsChecker.h>
Expand All @@ -34,6 +35,7 @@ class TestCommand : public CHIPCommand,
public ConstraintsChecker,
public PICSChecker,
public LogCommands,
public DiscoveryCommands,
public SystemCommands
{
public:
Expand Down
59 changes: 58 additions & 1 deletion examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,57 @@ class {{filename}}: public TestCommand
{{/chip_tests_item_response_parameters}}
{{/chip_tests_items}}

void OnDiscoveryCommandsResults(const DiscoveryCommandResult & nodeData) override
{
bool isExpectedDnssdResult = false;
{{#chip_tests_items}}
{{#if (isStrEqual cluster "DiscoveryCommands")}}
if ((mTestIndex - 1) == {{index}})
{
isExpectedDnssdResult = true;
{{#chip_tests_item_response_parameters}}
{{#*inline "itemValue"}}nodeData.{{name}}{{#if isOptional}}.Value(){{/if}}{{/inline}}
{{~#if hasExpectedValue}}
{{#if isOptional}}VerifyOrReturn(CheckValuePresent("{{name}}", nodeData.{{name}}));{{/if}}
VerifyOrReturn(CheckValue("{{name}}", {{>itemValue}},
{{#if (chip_tests_config_has expectedValue)}}
m{{asUpperCamelCase expectedValue}}.HasValue() ? m{{asUpperCamelCase expectedValue}}.Value() : {{asTypedLiteral (chip_tests_config_get_default_value expectedValue) (chip_tests_config_get_type expectedValue)}}
{{else}}
{{expectedValue}}
{{/if}}
));
{{/if}}
{{#if hasExpectedConstraints}}
{{#if isOptional}}VerifyOrReturn(CheckValuePresent("{{name}}", nodeData.{{name}}));{{/if}}
{{#if (hasProperty expectedConstraints "minLength")}}VerifyOrReturn(CheckConstraintMinLength("{{name}}", {{>itemValue}}.size(), {{expectedConstraints.minLength}}));{{/if}}
{{#if (hasProperty expectedConstraints "maxLength")}}VerifyOrReturn(CheckConstraintMaxLength("{{name}}", {{>itemValue}}.size(), {{expectedConstraints.maxLength}}));{{/if}}
{{#if (hasProperty expectedConstraints "minValue")}}VerifyOrReturn(CheckConstraintMinValue<{{chipType}}>("{{name}}", {{>itemValue}}, {{asTypedLiteral expectedConstraints.minValue type}}));{{/if}}
{{#if (hasProperty expectedConstraints "maxValue")}}VerifyOrReturn(CheckConstraintMaxValue<{{chipType}}>("{{name}}", {{>itemValue}}, {{asTypedLiteral expectedConstraints.maxValue type}}));{{/if}}
{{#if (hasProperty expectedConstraints "notValue")}}VerifyOrReturn(CheckConstraintNotValue("{{name}}", {{>itemValue}}, {{asTypedLiteral expectedConstraints.notValue type}}));{{/if}}
{{/if}}

{{#if saveAs}}
{{#if (isString type)}}
if ({{saveAs}}Buffer != nullptr)
{
chip::Platform::MemoryFree({{saveAs}}Buffer);
}
{{saveAs}}Buffer = static_cast<{{#if (isOctetString type)}}uint8_t{{else}}char{{/if}} *>(chip::Platform::MemoryAlloc({{>itemValue}}.size()));
memcpy({{saveAs}}Buffer, {{>itemValue}}.data(), {{>itemValue}}.size());
{{saveAs}} = {{chipType}}({{saveAs}}Buffer, {{>itemValue}}.size());
{{else}}
{{saveAs}} = {{>itemValue}};
{{/if}}
{{/if}}
{{/chip_tests_item_response_parameters}}
}
{{/if}}
{{/chip_tests_items}}

VerifyOrReturn(isExpectedDnssdResult, Exit("An unexpected dnssd result has been received"));
NextTest();
}

{{! Helper around zapTypeToDecodableClusterObjectType that lets us set the
array/nullable/etc context appropriately.}}
{{~#*inline "subscribeResponseDataArgument"~}}
Expand Down Expand Up @@ -194,7 +245,13 @@ class {{filename}}: public TestCommand
CHIP_ERROR {{>testCommand}}()
{
SetIdentity(kIdentity{{asUpperCamelCase identity}});
return {{command}}({{#chip_tests_item_parameters}}{{#not_first}}, {{/not_first}}{{#if (isString type)}}"{{/if}}{{definedValue}}{{#if (isString type)}}"{{/if}}{{/chip_tests_item_parameters}});
return {{command}}({{#chip_tests_item_parameters}}{{#not_first}}, {{/not_first}}{{#if (isString type)}}"{{/if~}}
{{~#if (chip_tests_config_has definedValue)~}}
m{{asUpperCamelCase definedValue}}.HasValue() ? m{{asUpperCamelCase definedValue}}.Value() : {{asTypedLiteral (chip_tests_config_get_default_value definedValue) (chip_tests_config_get_type definedValue)}}
{{else}}
{{definedValue}}
{{~/if~}}
{{~#if (isString type)}}"{{/if}}{{/chip_tests_item_parameters}});
}
{{else if isWait}}
CHIP_ERROR {{>testCommand}}()
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 @@ -241,6 +241,7 @@ function getTests()
'TestClusterComplexTypes',
'TestConstraints',
'TestDelayCommands',
'TestDiscovery',
'TestLogCommands',
'TestSaveAs',
'TestConfigVariables',
Expand Down
1 change: 1 addition & 0 deletions examples/placeholder/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ executable("chip-${chip_tests_zap_config}") {
deps = [
":configuration",
"${chip_root}/examples/platform/linux:app-main",
"${chip_root}/src/app/tests/suites/commands/discovery",
"${chip_root}/src/app/tests/suites/commands/log",
"${chip_root}/src/app/tests/suites/pics",
"${chip_root}/src/lib",
Expand Down
9 changes: 8 additions & 1 deletion examples/placeholder/linux/include/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <app/ConcreteAttributePath.h>
#include <app/ConcreteCommandPath.h>

#include <app/tests/suites/commands/discovery/DiscoveryCommands.h>
#include <app/tests/suites/commands/log/LogCommands.h>
#include <app/tests/suites/include/PICSChecker.h>

Expand All @@ -34,7 +35,7 @@ constexpr const char kIdentityAlpha[] = "";
constexpr const char kIdentityBeta[] = "";
constexpr const char kIdentityGamma[] = "";

class TestCommand : public PICSChecker, public LogCommands
class TestCommand : public PICSChecker, public LogCommands, public DiscoveryCommands
{
public:
TestCommand(const char * commandName) : mCommandPath(0, 0, 0), mAttributePath(0, 0, 0) {}
Expand Down Expand Up @@ -70,6 +71,12 @@ class TestCommand : public PICSChecker, public LogCommands
return CHIP_NO_ERROR;
}

void Exit(std::string message)
{
ChipLogError(chipTool, " ***** Test Failure: %s\n", message.c_str());
SetCommandExitStatus(CHIP_ERROR_INTERNAL);
}

static void ScheduleNextTest(intptr_t context)
{
TestCommand * command = reinterpret_cast<TestCommand *>(context);
Expand Down
Loading

0 comments on commit 2515820

Please sign in to comment.