Skip to content

Commit

Permalink
[YAML] Add a test for eventNumber (#18466)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple authored May 19, 2022
1 parent fdc9af2 commit e04564c
Show file tree
Hide file tree
Showing 9 changed files with 5,791 additions and 2,878 deletions.
4 changes: 2 additions & 2 deletions examples/chip-tool/commands/clusters/ClusterCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return InteractionModelCommands::SendCommand(device, endpointIds.at(0), mClusterId, mCommandId, mPayload,
mTimedInteractionTimeoutMs, mRepeatCount, mRepeatDelayInMs, mSuppressResponse);
mTimedInteractionTimeoutMs, mSuppressResponse, mRepeatCount, mRepeatDelayInMs);
}

template <class T>
CHIP_ERROR SendCommand(chip::DeviceProxy * device, chip::EndpointId endpointId, chip::ClusterId clusterId,
chip::CommandId commandId, const T & value)
{
return InteractionModelCommands::SendCommand(device, endpointId, clusterId, commandId, value, mTimedInteractionTimeoutMs,
mRepeatCount, mRepeatDelayInMs, mSuppressResponse);
mSuppressResponse, mRepeatCount, mRepeatDelayInMs);
}

CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex) override
Expand Down
34 changes: 21 additions & 13 deletions examples/chip-tool/commands/clusters/ReportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,17 @@ class ReadAttribute : public ReportCommand
{
AddArgument("cluster-id", 0, UINT32_MAX, &mClusterIds);
AddArgument("attribute-id", 0, UINT32_MAX, &mAttributeIds);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
ReportCommand::AddArguments();
}

ReadAttribute(chip::ClusterId clusterId, CredentialIssuerCommands * credsIssuerConfig) :
ReportCommand("read-by-id", credsIssuerConfig), mClusterIds(1, clusterId)
{
AddArgument("attribute-id", 0, UINT32_MAX, &mAttributeIds);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
ReportCommand::AddArguments();
}

Expand All @@ -142,8 +142,8 @@ class ReadAttribute : public ReportCommand
mClusterIds(1, clusterId), mAttributeIds(1, attributeId)
{
AddArgument("attr-name", attributeName);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
ReportCommand::AddArguments();
}

Expand All @@ -170,8 +170,8 @@ class SubscribeAttribute : public ReportCommand
AddArgument("attribute-id", 0, UINT32_MAX, &mAttributeIds);
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval);
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions);
ReportCommand::AddArguments();
}
Expand All @@ -182,8 +182,8 @@ class SubscribeAttribute : public ReportCommand
AddArgument("attribute-id", 0, UINT32_MAX, &mAttributeIds);
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval);
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions);
ReportCommand::AddArguments();
}
Expand All @@ -196,8 +196,8 @@ class SubscribeAttribute : public ReportCommand
AddArgument("attr-name", attributeName);
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval);
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions);
ReportCommand::AddArguments();
}
Expand Down Expand Up @@ -245,6 +245,7 @@ class ReadEvent : public ReportCommand
{
AddArgument("cluster-id", 0, UINT32_MAX, &mClusterIds);
AddArgument("event-id", 0, UINT32_MAX, &mEventIds);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
ReportCommand::AddArguments();
}
Expand All @@ -253,6 +254,7 @@ class ReadEvent : public ReportCommand
ReportCommand("read-event-by-id", credsIssuerConfig), mClusterIds(1, clusterId)
{
AddArgument("event-id", 0, UINT32_MAX, &mEventIds);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
ReportCommand::AddArguments();
}
Expand All @@ -263,6 +265,7 @@ class ReadEvent : public ReportCommand
mClusterIds(1, clusterId), mEventIds(1, eventId)
{
AddArgument("event-name", eventName);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
ReportCommand::AddArguments();
}
Expand All @@ -271,12 +274,13 @@ class ReadEvent : public ReportCommand

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return ReportCommand::ReadEvent(device, endpointIds, mClusterIds, mEventIds, mEventNumber);
return ReportCommand::ReadEvent(device, endpointIds, mClusterIds, mEventIds, mFabricFiltered, mEventNumber);
}

private:
std::vector<chip::ClusterId> mClusterIds;
std::vector<chip::EventId> mEventIds;
chip::Optional<bool> mFabricFiltered;
chip::Optional<chip::EventNumber> mEventNumber;
};

Expand All @@ -289,8 +293,9 @@ class SubscribeEvent : public ReportCommand
AddArgument("event-id", 0, UINT32_MAX, &mEventIds);
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval);
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions);
ReportCommand::AddArguments();
}

Expand All @@ -300,8 +305,9 @@ class SubscribeEvent : public ReportCommand
AddArgument("event-id", 0, UINT32_MAX, &mEventIds);
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval);
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions);
ReportCommand::AddArguments();
}

Expand All @@ -315,18 +321,19 @@ class SubscribeEvent : public ReportCommand
"The requested minimum interval between reports. Sets MinIntervalFloor in the Subscribe Request.");
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval,
"The requested maximum interval between reports. Sets MaxIntervalCeiling in the Subscribe Request.");
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions,
"false - Terminate existing subscriptions from initiator.\n true - Leave existing subscriptions in place.");
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
ReportCommand::AddArguments();
}

~SubscribeEvent() {}

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return ReportCommand::SubscribeEvent(device, endpointIds, mClusterIds, mEventIds, mMinInterval, mMaxInterval, mEventNumber,
mKeepSubscriptions);
return ReportCommand::SubscribeEvent(device, endpointIds, mClusterIds, mEventIds, mMinInterval, mMaxInterval,
mFabricFiltered, mEventNumber, mKeepSubscriptions);
}

void OnSubscription() override
Expand All @@ -352,6 +359,7 @@ class SubscribeEvent : public ReportCommand

uint16_t mMinInterval;
uint16_t mMaxInterval;
chip::Optional<bool> mKeepSubscriptions;
chip::Optional<bool> mFabricFiltered;
chip::Optional<chip::EventNumber> mEventNumber;
chip::Optional<bool> mKeepSubscriptions;
};
58 changes: 45 additions & 13 deletions examples/chip-tool/templates/tests/partials/test_step.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,30 @@
{{/inline~}}

{{~#*inline "maybeFabricFiltered"}}
{{#unless isWait}}
{{#unless fabricFiltered}}
{{#if fabricFiltered}}
, true
{{else}}
, false
{{/unless}}
{{/unless}}
{{/if}}
{{/inline~}}

{{~#*inline "maybeTimedInteractionTimeout"}}
{{~#*inline "maybeSuppressResponse"}}
{{#if suppressResponse}}
, chip::Optional<bool>({{suppressResponse}})
{{else}}
, chip::NullOptional
{{/if}}
{{/inline~}}

{{~#*inline "maybeDataVersion"}}
{{#if dataVersion}}
, chip::Optional<chip::DataVersion>({{dataVersion}})
{{else}}
, chip::NullOptional
{{/if}}
{{/inline~}}

{{~#*inline "maybeTimedInteractionTimeoutMs"}}
{{#if timedInteractionTimeoutMs}}
, chip::Optional<uint16_t>({{timedInteractionTimeoutMs}})
{{else if commandObject.mustUseTimedInvoke}}
Expand All @@ -42,6 +58,22 @@
{{/if}}
{{/inline~}}

{{~#*inline "maybeEventNumber"}}
{{#if eventNumber}}
, chip::Optional<chip::EventNumber>({{eventNumber}})
{{else}}
, chip::NullOptional
{{/if}}
{{/inline~}}

{{~#*inline "maybeKeepSubscriptions"}}
{{#if keepSubscriptions}}
, chip::Optional<bool>({{keepSubscriptions}})
{{else}}
, chip::NullOptional
{{/if}}
{{/inline~}}

{{~#*inline "kIdentity"}}kIdentity{{asUpperCamelCase identity}}{{/inline~}}
{{~#*inline "groupId"}}{{groupId}}{{/inline~}}
{{~#*inline "endpointId"}}GetEndpoint({{endpoint}}){{/inline~}}
Expand Down Expand Up @@ -73,14 +105,14 @@
{{~#*inline "arguments"}}
{{#if (isTestOnlyCluster cluster)}}{{>testOnlyClusterArguments}}, value
{{else if isWait}} {{>waitArguments}}
{{else if isReadAttribute}} {{>attributeArguments}}{{>maybeFabricFiltered~}}
{{else if isSubscribeAttribute}} {{>attributeArguments}}, {{minInterval}}, {{maxInterval}}{{>maybeFabricFiltered~}}
{{else if isWriteGroupAttribute}} {{>groupAttributeArguments}}, value{{>maybeTimedInteractionTimeout~}}
{{else if isWriteAttribute}} {{>attributeArguments}}, value{{>maybeTimedInteractionTimeout~}}
{{else if isReadEvent}} {{>eventArguments~}}
{{else if isSubscribeEvent}} {{>eventArguments}}, {{minInterval}}, {{maxInterval~}}
{{else if isGroupCommand}} {{>groupCommandArguments}}, value{{>maybeTimedInteractionTimeout~}}
{{else if isCommand}} {{>commandArguments}}, value{{>maybeTimedInteractionTimeout~}}
{{else if isReadAttribute}} {{>attributeArguments}}{{>maybeFabricFiltered}}{{>maybeDataVersion~}}
{{else if isSubscribeAttribute}} {{>attributeArguments}}, {{minInterval}}, {{maxInterval}}{{>maybeFabricFiltered}}{{>maybeDataVersion}}{{>maybeKeepSubscriptions~}}
{{else if isWriteGroupAttribute}} {{>groupAttributeArguments}}, value{{>maybeDataVersion~}}
{{else if isWriteAttribute}} {{>attributeArguments}}, value{{>maybeTimedInteractionTimeoutMs}}{{>maybeSuppressResponse}}{{>maybeDataVersion~}}
{{else if isReadEvent}} {{>eventArguments}}{{>maybeFabricFiltered}}{{>maybeEventNumber~}}
{{else if isSubscribeEvent}} {{>eventArguments}}, {{minInterval}}, {{maxInterval}}{{>maybeFabricFiltered}}{{>maybeEventNumber}}{{>maybeKeepSubscriptions~}}
{{else if isGroupCommand}} {{>groupCommandArguments}}, value
{{else if isCommand}} {{>commandArguments}}, value{{>maybeTimedInteractionTimeoutMs}}{{>maybeSuppressResponse}}
{{/if}}
{{/inline~}}

Expand Down
16 changes: 12 additions & 4 deletions src/app/tests/suites/TestEvents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,11 @@ tests:
- label: "Check there is no event on the target endpoint"
command: "readEvent"
event: "TestEvent"
response:
value: {}

- label: "Check reading events from an invalid endpoint"
command: "readEvent"
event: "TestEvent"
endpoint: 0
response:
value: {}

- label: "Generate an event on the accessory"
command: "TestEmitTestEventRequest"
Expand All @@ -62,6 +58,18 @@ tests:
response:
value: { arg1: 1, arg2: 2, arg3: true }

- label: "Read the event with eventNumber set to the event value"
command: "readEvent"
event: "TestEvent"
eventNumber: eventNumber
response:
value: { arg1: 1, arg2: 2, arg3: true }

- label: "Read the event with eventNumber set to the event value + 1"
command: "readEvent"
event: "TestEvent"
eventNumber: eventNumber + 1

- label: "Generate a second event on the accessory"
command: "TestEmitTestEventRequest"
arguments:
Expand Down
Loading

0 comments on commit e04564c

Please sign in to comment.