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

[YAML] Add min commissioning timeout parameters to the start command of the SystemCommand simulated cluster #18038

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
2 changes: 2 additions & 0 deletions examples/chip-tool-darwin/commands/common/CHIPCommandBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class CHIPCommandBridge : public Command
// This method returns the commissioner instance to be used for running the command.
CHIPDeviceController * CurrentCommissioner();

CHIPDeviceController * GetCommissioner(const char * identity);

private:
CHIP_ERROR InitializeCommissioner(std::string key, chip::FabricId fabricId,
const chip::Credentials::AttestationTrustStore * trustStore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@

CHIPDeviceController * CHIPCommandBridge::CurrentCommissioner() { return mCurrentController; }

CHIPDeviceController * CHIPCommandBridge::GetCommissioner(const char * identity) { return mControllers[identity]; }

CHIP_ERROR CHIPCommandBridge::ShutdownCommissioner()
{
ChipLogProgress(chipTool, "Shutting down controller");
Expand Down
61 changes: 35 additions & 26 deletions examples/chip-tool-darwin/commands/tests/TestCommandBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,62 +98,80 @@ class TestCommandBridge : public CHIPCommandBridge,
SetCommandExitStatus(err);
}

void Log(NSString * _Nonnull message)
void Log(const char * _Nullable identity, const chip::app::Clusters::LogCommands::Commands::Log::Type & value)
{
NSLog(@"%@", message);
NSLog(@"%.*s", static_cast<int>(value.message.size()), value.message.data());
NextTest();
}

/////////// DelayCommands-like Interface /////////
void WaitForMs(unsigned int ms)
vivien-apple marked this conversation as resolved.
Show resolved Hide resolved
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, ms * NSEC_PER_MSEC), mCallbackQueue, ^{
chip::app::Clusters::DelayCommands::Commands::WaitForMs::Type value;
value.ms = ms;
WaitForMs(nil, value);
}

void WaitForMs(const char * _Nullable identity, const chip::app::Clusters::DelayCommands::Commands::WaitForMs::Type & value)
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, value.ms * NSEC_PER_MSEC), mCallbackQueue, ^{
NextTest();
});
}

void UserPrompt(NSString * _Nonnull message, NSString * _Nullable expectedValue = nil) { NextTest(); }
void UserPrompt(const char * _Nullable identity, const chip::app::Clusters::LogCommands::Commands::UserPrompt::Type & value)
{
NextTest();
}

void WaitForCommissionee(chip::NodeId nodeId)
void WaitForCommissionee(
const char * _Nullable identity, const chip::app::Clusters::DelayCommands::Commands::WaitForCommissionee::Type & value)
{
CHIPDeviceController * controller = CurrentCommissioner();
CHIPDeviceController * controller = GetCommissioner(identity);
VerifyOrReturn(controller != nil, SetCommandExitStatus(CHIP_ERROR_INCORRECT_STATE));

SetIdentity(identity);

// Disconnect our existing device; otherwise getConnectedDevice will
// just hand it right back to us without establishing a new CASE
// session.
if (GetConnectedDevice() != nil) {
auto device = [GetConnectedDevice() internalDevice];
if (GetDevice(identity) != nil) {
auto device = [GetDevice(identity) internalDevice];
if (device != nullptr) {
device->Disconnect();
}
mConnectedDevices[mCurrentIdentity] = nil;
mConnectedDevices[identity] = nil;
}

[controller getConnectedDevice:nodeId
[controller getConnectedDevice:value.nodeId
queue:mCallbackQueue
completionHandler:^(CHIPDevice * _Nullable device, NSError * _Nullable error) {
CHIP_ERROR err = [CHIPError errorToCHIPErrorCode:error];
VerifyOrReturn(CHIP_NO_ERROR == err, SetCommandExitStatus(err));

mConnectedDevices[mCurrentIdentity] = device;
mConnectedDevices[identity] = device;
NextTest();
}];
}

/////////// CommissionerCommands-like Interface /////////
CHIP_ERROR PairWithQRCode(chip::NodeId nodeId, const chip::CharSpan payload)
CHIP_ERROR PairWithQRCode(
const char * _Nullable identity, const chip::app::Clusters::CommissionerCommands::Commands::PairWithQRCode::Type & value)
{
CHIPDeviceController * controller = CurrentCommissioner();
CHIPDeviceController * controller = GetCommissioner(identity);
VerifyOrReturnError(controller != nil, CHIP_ERROR_INCORRECT_STATE);

SetIdentity(identity);

[controller setPairingDelegate:mPairingDelegate queue:mCallbackQueue];
[mPairingDelegate setDeviceId:nodeId];
[mPairingDelegate setDeviceId:value.nodeId];
[mPairingDelegate setActive:YES];

NSString * payloadStr = [[NSString alloc] initWithBytes:payload.data() length:payload.size() encoding:NSUTF8StringEncoding];
NSString * payloadStr = [[NSString alloc] initWithBytes:value.payload.data()
length:value.payload.size()
encoding:NSUTF8StringEncoding];
NSError * err;
BOOL ok = [controller pairDevice:nodeId onboardingPayload:payloadStr error:&err];
BOOL ok = [controller pairDevice:value.nodeId onboardingPayload:payloadStr error:&err];
if (ok == YES) {
return CHIP_NO_ERROR;
}
Expand All @@ -173,7 +191,7 @@ class TestCommandBridge : public CHIPCommandBridge,
return CHIP_NO_ERROR;
}

CHIPDevice * _Nullable GetConnectedDevice(void) { return mConnectedDevices[mCurrentIdentity]; }
CHIPDevice * _Nullable GetDevice(const char * _Nullable identity) { return mConnectedDevices[identity]; }

// PairingDeleted and PairingComplete need to be public so our pairing
// delegate can call them.
Expand Down Expand Up @@ -203,12 +221,6 @@ class TestCommandBridge : public CHIPCommandBridge,
}
}

void SetIdentity(const char * _Nonnull name)
{
mCurrentIdentity = name;
CHIPCommandBridge::SetIdentity(name);
}

protected:
dispatch_queue_t _Nullable mCallbackQueue;

Expand Down Expand Up @@ -372,9 +384,6 @@ class TestCommandBridge : public CHIPCommandBridge,
private:
TestPairingDelegate * _Nonnull mPairingDelegate;

// Currently selected identity ("alpha", "beta", "gamma").
std::string mCurrentIdentity;

// Set of our connected devices, keyed by identity.
std::map<std::string, CHIPDevice *> mConnectedDevices;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,15 @@ class {{filename}}: public TestCommandBridge
{{#*inline "testCommand"}}Test{{asUpperCamelCase label}}_{{index}}{{/inline}}
CHIP_ERROR {{>testCommand}}()
{
SetIdentity("{{identity}}");
vivien-apple marked this conversation as resolved.
Show resolved Hide resolved
{{#if (isTestOnlyCluster cluster)}}
{{command}}(
{{#if (chip_tests_item_has_list)}}ListFreer listFreer;{{/if~}}
{{asEncodableType}} value;
{{#chip_tests_item_parameters}}
{{~#not_first}}, {{/not_first~}}
{{#*inline "defaultValue"}}{{asTypedLiteral (chip_tests_config_get_default_value definedValue) (chip_tests_config_get_type definedValue)}}{{/inline}}
{{~#if (chip_tests_config_has definedValue)~}}
m{{asUpperCamelCase definedValue}}.HasValue() ? m{{asUpperCamelCase definedValue}}.Value() : {{~#if (isString type)}}chip::CharSpan::fromCharString("{{>defaultValue}}"){{else}}{{>defaultValue}}{{/if~}}
{{else}}
{{#if (isString type)}}@"{{/if}}{{definedValue}}{{#if (isString type)}}"{{/if}}
{{~/if~}}
{{/chip_tests_item_parameters}});
{{>commandValue ns=parent.cluster container=(asPropertyValue dontUnwrapValue=true) definedValue=definedValue depth=0}}
{{/chip_tests_item_parameters}}
{{command}}("{{identity}}", value);
{{else}}
CHIPDevice * device = GetConnectedDevice();
CHIPDevice * device = GetDevice("{{identity}}");
CHIPTest{{asUpperCamelCase cluster}} * cluster = [[CHIPTest{{asUpperCamelCase cluster}} alloc] initWithDevice:device endpoint:{{endpoint}} queue:mCallbackQueue];
VerifyOrReturnError(cluster != nil, CHIP_ERROR_INCORRECT_STATE);

Expand Down
5 changes: 5 additions & 0 deletions examples/chip-tool-darwin/templates/tests/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "chip-v1",
"helpers": [
"../../../../examples/chip-tool/templates/helper.js",
"../../../../examples/chip-tool/templates/tests/helper.js",
"../../../../src/app/zap-templates/partials/helper.js",
"../../../../src/app/zap-templates/common/StringHelper.js",
"../../../../src/app/zap-templates/templates/app/helper.js",
Expand All @@ -22,6 +23,10 @@
"name": "encode_value",
"path": "../../../../src/darwin/Framework/CHIP/templates/partials/encode_value.zapt"
},
{
"name": "commandValue",
"path": "../../../../examples/chip-tool/templates/tests/partials/command_value.zapt"
},
{
"name": "test_cluster",
"path": "partials/test_cluster.zapt"
Expand Down
1 change: 1 addition & 0 deletions examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ assert(chip_build_tools)
config("config") {
include_dirs = [
".",
"${chip_root}/zzz_generated/app-common/app-common",
"${chip_root}/zzz_generated/chip-tool",
"${chip_root}/src/lib",
]
Expand Down
6 changes: 6 additions & 0 deletions examples/chip-tool/commands/common/CHIPCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ chip::Controller::DeviceCommissioner & CHIPCommand::CurrentCommissioner()
return *item->second;
}

chip::Controller::DeviceCommissioner & CHIPCommand::GetCommissioner(const char * identity)
{
auto item = mCommissioners.find(identity);
return *item->second;
}

CHIP_ERROR CHIPCommand::ShutdownCommissioner(std::string key)
{
return mCommissioners[key].get()->Shutdown();
Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/commands/common/CHIPCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class CHIPCommand : public Command
// --identity "instance name" when running a command.
ChipDeviceCommissioner & CurrentCommissioner();

ChipDeviceCommissioner & GetCommissioner(const char * identity);

private:
CHIP_ERROR MaybeSetUpStack();
CHIP_ERROR MaybeTearDownStack();
Expand Down
15 changes: 10 additions & 5 deletions examples/chip-tool/commands/tests/TestCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,23 @@ CHIP_ERROR TestCommand::RunCommand()
return CHIP_NO_ERROR;
}

CHIP_ERROR TestCommand::WaitForCommissionee(chip::NodeId nodeId)
CHIP_ERROR TestCommand::WaitForCommissionee(const char * identity,
const chip::app::Clusters::DelayCommands::Commands::WaitForCommissionee::Type & value)
{
chip::FabricIndex fabricIndex;

ReturnErrorOnFailure(CurrentCommissioner().GetFabricIndex(&fabricIndex));
ReturnErrorOnFailure(GetCommissioner(identity).GetFabricIndex(&fabricIndex));

//
// There's a chance the commissionee may have rebooted before this call here as part of a test flow
// or is just starting out fresh outright. Let's make sure we're not re-using any cached CASE sessions
// that will now be stale and mismatched with the peer, causing subsequent interactions to fail.
//
CurrentCommissioner().SessionMgr()->ExpireAllPairings(chip::ScopedNodeId(nodeId, fabricIndex));
GetCommissioner(identity).SessionMgr()->ExpireAllPairings(chip::ScopedNodeId(value.nodeId, fabricIndex));

return CurrentCommissioner().GetConnectedDevice(nodeId, &mOnDeviceConnectedCallback, &mOnDeviceConnectionFailureCallback);
SetIdentity(identity);
return GetCommissioner(identity).GetConnectedDevice(value.nodeId, &mOnDeviceConnectedCallback,
&mOnDeviceConnectionFailureCallback);
}

void TestCommand::OnDeviceConnectedFn(void * context, chip::OperationalDeviceProxy * device)
Expand Down Expand Up @@ -99,7 +102,9 @@ CHIP_ERROR TestCommand::ContinueOnChipMainThread(CHIP_ERROR err)

if (CHIP_NO_ERROR == err)
{
return WaitForMs(0);
chip::app::Clusters::DelayCommands::Commands::WaitForMs::Type value;
value.ms = 0;
return WaitForMs(GetIdentity().c_str(), value);
}

Exit(chip::ErrorStr(err), err);
Expand Down
10 changes: 7 additions & 3 deletions examples/chip-tool/commands/tests/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <app/tests/suites/include/PICSChecker.h>
#include <app/tests/suites/include/TestRunner.h>
#include <app/tests/suites/include/ValueChecker.h>
#include <zap-generated/tests/CHIPClustersTest.h>
#include <zap-generated/tests/simulated-cluster-objects.h>

constexpr uint16_t kTimeoutInSeconds = 90;

Expand Down Expand Up @@ -61,7 +61,8 @@ class TestCommand : public TestRunner,

protected:
/////////// DelayCommands Interface /////////
CHIP_ERROR WaitForCommissionee(chip::NodeId nodeId) override;
CHIP_ERROR WaitForCommissionee(const char * identity,
const chip::app::Clusters::DelayCommands::Commands::WaitForCommissionee::Type & value) override;
void OnWaitForMs() override { NextTest(); };

/////////// Interaction Model Interface /////////
Expand All @@ -73,7 +74,10 @@ class TestCommand : public TestRunner,

CHIP_ERROR ContinueOnChipMainThread(CHIP_ERROR err) override;

chip::Controller::DeviceCommissioner & GetCurrentCommissioner() override { return CurrentCommissioner(); };
chip::Controller::DeviceCommissioner & GetCommissioner(const char * identity) override
{
return CHIPCommand::GetCommissioner(identity);
vivien-apple marked this conversation as resolved.
Show resolved Hide resolved
};

static void ExitAsync(intptr_t context);
void Exit(std::string message, CHIP_ERROR err = CHIP_ERROR_INTERNAL) override;
Expand Down
43 changes: 28 additions & 15 deletions examples/chip-tool/templates/tests/partials/command_value.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,36 @@
{{else}}
{{container}} =
{{~#if (chip_tests_variables_has definedValue)~}}
{{definedValue}};
{{definedValue}};
{{else if (chip_tests_config_has definedValue)}}
m{{asUpperCamelCase definedValue}}.HasValue() ? m{{asUpperCamelCase definedValue}}.Value() :
{{~#if_chip_enum type~}}
static_cast<{{zapTypeToEncodableClusterObjectType type ns=ns}}>({{chip_tests_config_get_default_value definedValue}});
{{else if (isCharString type)}}
chip::Span<const char>("{{chip_tests_config_get_default_value definedValue}}", {{utf8StringLength (chip_tests_config_get_default_value definedValue)}});
{{else if (isOctetString type)}}
{{!-- TODO Extract the length of the default value for ByteSpan--}}
{{else}}
{{#if_is_bitmap type}}
static_cast<{{zapTypeToEncodableClusterObjectType type ns=ns}}>({{asTypedLiteral (chip_tests_config_get_default_value definedValue) type}});
{{else}}
{{asTypedExpression (chip_tests_config_get_default_value definedValue) type}};
{{/if_is_bitmap}}
{{/if_chip_enum~}}
{{else~}}
{{~#if_chip_enum type~}}
static_cast<{{zapTypeToEncodableClusterObjectType type ns=ns}}>({{definedValue}});
{{else if (isCharString type)}}
chip::Span<const char>("{{definedValue}}garbage: not in length on purpose", {{utf8StringLength definedValue}});
{{else if (isOctetString type)}}
chip::ByteSpan(chip::Uint8::from_const_char("{{octetStringEscapedForCLiteral definedValue}}garbage: not in length on purpose"), {{definedValue.length}});
{{else}}
{{#if_is_bitmap type}}
static_cast<{{zapTypeToEncodableClusterObjectType type ns=ns}}>({{asTypedLiteral definedValue type}});
{{else 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)}};
{{~#if_chip_enum type~}}
static_cast<{{zapTypeToEncodableClusterObjectType type ns=ns}}>({{definedValue}});
{{else if (isCharString type)}}
chip::Span<const char>("{{definedValue}}garbage: not in length on purpose", {{utf8StringLength definedValue}});
{{else if (isOctetString type)}}
chip::ByteSpan(chip::Uint8::from_const_char("{{octetStringEscapedForCLiteral definedValue}}garbage: not in length on purpose"), {{definedValue.length}});
{{else}}
{{asTypedExpression definedValue type}};
{{/if_is_bitmap}}
{{/if_chip_enum~}}
{{#if_is_bitmap type}}
static_cast<{{zapTypeToEncodableClusterObjectType type ns=ns}}>({{asTypedLiteral definedValue type}});
{{else}}
{{asTypedExpression definedValue type}};
{{/if_is_bitmap}}
{{/if_chip_enum~}}
{{~/if~}}

{{/if_is_struct}}
Expand Down
21 changes: 3 additions & 18 deletions examples/chip-tool/templates/tests/partials/test_step.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

{{~#*inline "maybePrepareArguments"}}
{{#unless isWait}}
{{#if (isTestOnlyCluster cluster)}}
SetIdentity({{>kIdentity}});
{{else if hasSpecificArguments}}
{{#if hasSpecificArguments}}
{{#if (chip_tests_item_has_list)}}ListFreer listFreer;{{/if~}}
{{asEncodableType}} value;
{{#chip_tests_item_parameters}}
Expand All @@ -26,20 +24,6 @@
{{/unless}}
{{/inline~}}

{{~#*inline "testOnlyClusterArguments"}}
{{#chip_tests_item_parameters}}{{#not_first}},{{/not_first}}
{{#*inline "defaultValue"}}{{asTypedLiteral (chip_tests_config_get_default_value definedValue) (chip_tests_config_get_type definedValue)}}{{/inline}}
{{~#if (chip_tests_config_has definedValue)~}}
m{{asUpperCamelCase definedValue}}.HasValue() ? m{{asUpperCamelCase definedValue}}.Value() : {{~#if (isString type)}}chip::CharSpan::fromCharString("{{>defaultValue}}"){{else}}{{>defaultValue}}{{/if~}}
{{~else if (isString type)}}
"{{definedValue}}"
{{else}}
{{definedValue}}
{{~/if~}}
{{/chip_tests_item_parameters}}
{{/inline~}}


{{~#*inline "maybeFabricFiltered"}}
{{#unless isWait}}
{{#unless fabricFiltered}}
Expand All @@ -66,6 +50,7 @@
{{~#*inline "eventId"}}{{>clusterName}}::Events::{{asUpperCamelCase event}}::Id{{/inline~}}
{{~#*inline "commandId"}}{{>clusterName}}::Commands::{{asUpperCamelCase command}}::Id{{/inline~}}

{{~#*inline "testOnlyClusterArguments"}}{{>kIdentity}}{{/inline~}}
{{~#*inline "attributeArguments"}}{{>kIdentity}}, {{>endpointId}}, {{>clusterId}}, {{>attributeId}}{{/inline~}}
{{~#*inline "eventArguments"}}{{>kIdentity}}, {{>endpointId}}, {{>clusterId}}, {{>eventId}}{{/inline~}}
{{~#*inline "commandArguments"}}{{>kIdentity}}, {{>endpointId}}, {{>clusterId}}, {{>commandId}}{{/inline~}}
Expand All @@ -86,7 +71,7 @@
{{/inline~}}

{{~#*inline "arguments"}}
{{#if (isTestOnlyCluster cluster)}}{{>testOnlyClusterArguments}}
{{#if (isTestOnlyCluster cluster)}}{{>testOnlyClusterArguments}}, value
{{else if isWait}} {{>waitArguments}}
{{else if isReadAttribute}} {{>attributeArguments}}{{>maybeFabricFiltered~}}
{{else if isSubscribeAttribute}} {{>attributeArguments}}, {{minInterval}}, {{maxInterval}}{{>maybeFabricFiltered~}}
Expand Down
Loading