Skip to content

Commit

Permalink
Add GenerateEventPathList and test (project-chip#8014)
Browse files Browse the repository at this point in the history
Summary of Changes:
-- Add GenerateEventPathList function in ReadClinet
-- Add one event path test and two event path test
-- Fix im e2e cirque test in chip_im_responder from PR 7634 since cirque test is not
enabled
  • Loading branch information
yunhanw-google authored and Nikita committed Sep 23, 2021
1 parent 59213d7 commit 7fad80c
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 62 deletions.
1 change: 1 addition & 0 deletions src/app/EventPathParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct EventPathParams
EventPathParams(NodeId aNodeId, EndpointId aEndpointId, ClusterId aClusterId, EventId aEventId, bool aIsUrgent) :
mNodeId(aNodeId), mEndpointId(aEndpointId), mClusterId(aClusterId), mEventId(aEventId), mIsUrgent(aIsUrgent)
{}
EventPathParams() {}
bool IsSamePath(const EventPathParams & other) const
{
return other.mNodeId == mNodeId && other.mEndpointId == mEndpointId && other.mClusterId == mClusterId &&
Expand Down
54 changes: 33 additions & 21 deletions src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,8 @@ CHIP_ERROR ReadClient::SendReadRequest(NodeId aNodeId, Transport::AdminId aAdmin

if (aEventPathParamsListSize != 0 && apEventPathParamsList != nullptr)
{
EventPathList::Builder & eventPathListBuilder = request.CreateEventPathListBuilder();
EventPath::Builder eventPathBuilder = eventPathListBuilder.CreateEventPathBuilder();
for (size_t eventIndex = 0; eventIndex < aEventPathParamsListSize; ++eventIndex)
{
EventPathParams eventPath = apEventPathParamsList[eventIndex];
eventPathBuilder.NodeId(eventPath.mNodeId)
.EventId(eventPath.mEventId)
.EndpointId(eventPath.mEndpointId)
.ClusterId(eventPath.mClusterId)
.EndOfEventPath();
SuccessOrExit(err = eventPathBuilder.GetError());
}

eventPathListBuilder.EndOfEventPathList();
SuccessOrExit(err = eventPathListBuilder.GetError());

if (aEventNumber != 0)
{
// EventNumber is optional
request.EventNumber(aEventNumber);
}
err = GenerateEventPathList(request, apEventPathParamsList, aEventPathParamsListSize, aEventNumber);
SuccessOrExit(err);
}

if (aAttributePathParamsListSize != 0 && apAttributePathParamsList != nullptr)
Expand Down Expand Up @@ -174,6 +155,37 @@ CHIP_ERROR ReadClient::SendReadRequest(NodeId aNodeId, Transport::AdminId aAdmin
return err;
}

CHIP_ERROR ReadClient::GenerateEventPathList(ReadRequest::Builder & aRequest, EventPathParams * apEventPathParamsList,
size_t aEventPathParamsListSize, EventNumber & aEventNumber)
{
CHIP_ERROR err = CHIP_NO_ERROR;
EventPathList::Builder & eventPathListBuilder = aRequest.CreateEventPathListBuilder();
for (size_t eventIndex = 0; eventIndex < aEventPathParamsListSize; ++eventIndex)
{
EventPath::Builder eventPathBuilder = eventPathListBuilder.CreateEventPathBuilder();
EventPathParams eventPath = apEventPathParamsList[eventIndex];
eventPathBuilder.NodeId(eventPath.mNodeId)
.EventId(eventPath.mEventId)
.EndpointId(eventPath.mEndpointId)
.ClusterId(eventPath.mClusterId)
.EndOfEventPath();
SuccessOrExit(err = eventPathBuilder.GetError());
}

eventPathListBuilder.EndOfEventPathList();
SuccessOrExit(err = eventPathListBuilder.GetError());

if (aEventNumber != 0)
{
// EventNumber is optional
aRequest.EventNumber(aEventNumber);
}

exit:
ChipLogFunctError(err);
return err;
}

CHIP_ERROR ReadClient::GenerateAttributePathList(ReadRequest::Builder & aRequest, AttributePathParams * apAttributePathParamsList,
size_t aAttributePathParamsListSize)
{
Expand Down
2 changes: 2 additions & 0 deletions src/app/ReadClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class ReadClient : public Messaging::ExchangeDelegate
*/
bool IsFree() const { return mState == ClientState::Uninitialized; };

CHIP_ERROR GenerateEventPathList(ReadRequest::Builder & aRequest, EventPathParams * apEventPathParamsList,
size_t aEventPathParamsListSize, EventNumber & aEventNumber);
CHIP_ERROR GenerateAttributePathList(ReadRequest::Builder & aRequest, AttributePathParams * apAttributePathParamsList,
size_t aAttributePathParamsListSize);
CHIP_ERROR ProcessAttributeDataList(TLV::TLVReader & aAttributeDataListReader);
Expand Down
107 changes: 106 additions & 1 deletion src/app/tests/TestReadInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class TestReadInteraction
static void TestReadHandler(nlTestSuite * apSuite, void * apContext);
static void TestReadClientGenerateAttributePathList(nlTestSuite * apSuite, void * apContext);
static void TestReadClientGenerateInvalidAttributePathList(nlTestSuite * apSuite, void * apContext);
static void TestReadClientGenerateOneEventPathList(nlTestSuite * apSuite, void * apContext);
static void TestReadClientGenerateTwoEventPathList(nlTestSuite * apSuite, void * apContext);
static void TestReadClientInvalidReport(nlTestSuite * apSuite, void * apContext);
static void TestReadHandlerInvalidAttributePath(nlTestSuite * apSuite, void * apContext);

Expand Down Expand Up @@ -224,8 +226,9 @@ void TestReadInteraction::TestReadClientGenerateAttributePathList(nlTestSuite *
writer.Init(std::move(msgBuf));
err = request.Init(&writer);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = readClient.Init(&gExchangeManager, &delegate, 0 /* application identifier */);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

AttributePathParams attributePathParams[2];
attributePathParams[0].mFlags.Set(AttributePathParams::Flags::kFieldIdValid);
Expand Down Expand Up @@ -326,6 +329,106 @@ void TestReadInteraction::TestReadHandlerInvalidAttributePath(nlTestSuite * apSu
NL_TEST_ASSERT(apSuite, err == CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH);
}

void TestReadInteraction::TestReadClientGenerateOneEventPathList(nlTestSuite * apSuite, void * apContext)
{
CHIP_ERROR err = CHIP_NO_ERROR;
app::ReadClient readClient;
chip::app::InteractionModelDelegate delegate;
System::PacketBufferHandle msgBuf;
System::PacketBufferTLVWriter writer;
ReadRequest::Builder request;
chip::EventNumber eventNumber = 0;
msgBuf = System::PacketBufferHandle::New(kMaxSecureSduLengthBytes);
NL_TEST_ASSERT(apSuite, !msgBuf.IsNull());
writer.Init(std::move(msgBuf));
err = request.Init(&writer);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = readClient.Init(&gExchangeManager, &delegate, 0 /* application identifier */);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

chip::app::EventPathParams eventPathParams[2];
eventPathParams[0].mNodeId = 1;
eventPathParams[0].mEndpointId = 2;
eventPathParams[0].mClusterId = 3;
eventPathParams[0].mEventId = 4;

err = readClient.GenerateEventPathList(request, eventPathParams, 1 /*aEventPathParamsListSize*/, eventNumber);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

request.EndOfReadRequest();
NL_TEST_ASSERT(apSuite, CHIP_NO_ERROR == request.GetError());

err = writer.Finalize(&msgBuf);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

chip::System::PacketBufferTLVReader reader;
ReadRequest::Parser readRequestParser;

reader.Init(msgBuf.Retain());
reader.Next();

err = readRequestParser.Init(reader);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
err = readRequestParser.CheckSchemaValidity();
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
#endif
}

void TestReadInteraction::TestReadClientGenerateTwoEventPathList(nlTestSuite * apSuite, void * apContext)
{
CHIP_ERROR err = CHIP_NO_ERROR;
app::ReadClient readClient;
chip::app::InteractionModelDelegate delegate;
System::PacketBufferHandle msgBuf;
System::PacketBufferTLVWriter writer;
ReadRequest::Builder request;
chip::EventNumber eventNumber = 0;
msgBuf = System::PacketBufferHandle::New(kMaxSecureSduLengthBytes);
NL_TEST_ASSERT(apSuite, !msgBuf.IsNull());
writer.Init(std::move(msgBuf));
err = request.Init(&writer);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = readClient.Init(&gExchangeManager, &delegate, 0 /* application identifier */);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

chip::app::EventPathParams eventPathParams[2];
eventPathParams[0].mNodeId = 1;
eventPathParams[0].mEndpointId = 2;
eventPathParams[0].mClusterId = 3;
eventPathParams[0].mEventId = 4;

eventPathParams[1].mNodeId = 1;
eventPathParams[1].mEndpointId = 2;
eventPathParams[1].mClusterId = 3;
eventPathParams[1].mEventId = 5;
err = readClient.GenerateEventPathList(request, eventPathParams, 2 /*aEventPathParamsListSize*/, eventNumber);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

request.EndOfReadRequest();
NL_TEST_ASSERT(apSuite, CHIP_NO_ERROR == request.GetError());

err = writer.Finalize(&msgBuf);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

chip::System::PacketBufferTLVReader reader;
ReadRequest::Parser readRequestParser;

reader.Init(msgBuf.Retain());
reader.Next();

err = readRequestParser.Init(reader);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
err = readRequestParser.CheckSchemaValidity();
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
#endif
}

} // namespace app
} // namespace chip

Expand Down Expand Up @@ -367,6 +470,8 @@ const nlTest sTests[] =
NL_TEST_DEF("CheckReadHandler", chip::app::TestReadInteraction::TestReadHandler),
NL_TEST_DEF("TestReadClientGenerateAttributePathList", chip::app::TestReadInteraction::TestReadClientGenerateAttributePathList),
NL_TEST_DEF("TestReadClientGenerateInvalidAttributePathList", chip::app::TestReadInteraction::TestReadClientGenerateInvalidAttributePathList),
NL_TEST_DEF("TestReadClientGenerateOneEventPathList", chip::app::TestReadInteraction::TestReadClientGenerateOneEventPathList),
NL_TEST_DEF("TestReadClientGenerateTwoEventPathList", chip::app::TestReadInteraction::TestReadClientGenerateTwoEventPathList),
NL_TEST_DEF("TestReadClientInvalidReport", chip::app::TestReadInteraction::TestReadClientInvalidReport),
NL_TEST_DEF("TestReadHandlerInvalidAttributePath", chip::app::TestReadInteraction::TestReadHandlerInvalidAttributePath),
NL_TEST_SENTINEL()
Expand Down
37 changes: 23 additions & 14 deletions src/app/tests/integration/MockEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,43 +53,53 @@ void LivenessEventGenerator::Generate(void)
switch (mState)
{
case 0:
LogLiveness(chip::kTestDeviceNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE);
LogLiveness(kTestNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE, kTestChangeEvent1,
chip::app::PriorityLevel::Critical);
break;

case 1:
LogLiveness(chip::kTestDeviceNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE);
LogLiveness(kTestNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE, kTestChangeEvent2,
chip::app::PriorityLevel::Debug);
break;

case 2:
LogLiveness(chip::kTestDeviceNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE);
LogLiveness(kTestNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE, kTestChangeEvent1,
chip::app::PriorityLevel::Critical);
break;

case 3:
LogLiveness(chip::kTestDeviceNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_UNREACHABLE);
LogLiveness(kTestNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_UNREACHABLE, kTestChangeEvent2,
chip::app::PriorityLevel::Debug);
break;

case 4:
LogLiveness(chip::kTestDeviceNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE);
LogLiveness(kTestNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE, kTestChangeEvent1,
chip::app::PriorityLevel::Critical);
break;

case 5:
LogLiveness(chip::kTestDeviceNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_REBOOTING);
LogLiveness(kTestNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_REBOOTING, kTestChangeEvent2,
chip::app::PriorityLevel::Debug);
break;

case 6:
LogLiveness(chip::kTestDeviceNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE);
LogLiveness(kTestNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE, kTestChangeEvent1,
chip::app::PriorityLevel::Critical);
break;

case 7:
LogLiveness(chip::kTestDeviceNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE);
LogLiveness(kTestNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE, kTestChangeEvent2,
chip::app::PriorityLevel::Debug);
break;

case 8:
LogLiveness(chip::kTestDeviceNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE);
LogLiveness(kTestNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE, kTestChangeEvent1,
chip::app::PriorityLevel::Critical);
break;

case 9:
LogLiveness(chip::kTestDeviceNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE);
LogLiveness(kTestNodeId, kTestEndpointId, LIVENESS_DEVICE_STATUS_ONLINE, kTestChangeEvent2,
chip::app::PriorityLevel::Debug);
break;

default:
Expand All @@ -107,13 +117,12 @@ CHIP_ERROR LivenessEventGenerator::WriteEvent(chip::TLV::TLVWriter & aWriter)
}

chip::EventNumber LivenessEventGenerator::LogLiveness(chip::NodeId aNodeId, chip::EndpointId aEndpointId,
LivenessDeviceStatus aStatus)
LivenessDeviceStatus aStatus, chip::EventId aEventId,
chip::app::PriorityLevel aPriorityLevel)
{
chip::app::EventManagement & logManager = chip::app::EventManagement::GetInstance();
chip::EventNumber number = 0;
chip::app::EventSchema schema = {
aNodeId, aEndpointId, kTestClusterId, kLivenessChangeEvent, chip::app::PriorityLevel::Critical,
};
chip::app::EventSchema schema = { aNodeId, aEndpointId, kTestClusterId, aEventId, aPriorityLevel };
chip::app::EventOptions options;
mStatus = static_cast<int32_t>(aStatus);
options.mpEventSchema = &schema;
Expand Down
3 changes: 2 additions & 1 deletion src/app/tests/integration/MockEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class LivenessEventGenerator : public EventGenerator
public:
LivenessEventGenerator(void);
void Generate(void);
chip::EventNumber LogLiveness(chip::NodeId aNodeId, chip::EndpointId aEndpointId, LivenessDeviceStatus aStatus);
chip::EventNumber LogLiveness(chip::NodeId aNodeId, chip::EndpointId aEndpointId, LivenessDeviceStatus aStatus,
chip::EventId aEventId, chip::app::PriorityLevel aPriorityLevel);
CHIP_ERROR WriteEvent(chip::TLV::TLVWriter & aWriter);

private:
Expand Down
14 changes: 11 additions & 3 deletions src/app/tests/integration/chip_im_initiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,24 @@ CHIP_ERROR SendReadRequest()
{
CHIP_ERROR err = CHIP_NO_ERROR;
chip::EventNumber number = 0;
chip::app::EventPathParams eventPathParams(kTestNodeId, kTestEndpointId, kTestClusterId, kLivenessChangeEvent,
false /*not urgent*/);
chip::app::EventPathParams eventPathParams[2];
eventPathParams[0].mNodeId = kTestNodeId;
eventPathParams[0].mEndpointId = kTestEndpointId;
eventPathParams[0].mClusterId = kTestClusterId;
eventPathParams[0].mEventId = kTestChangeEvent1;

eventPathParams[1].mNodeId = kTestNodeId;
eventPathParams[1].mEndpointId = kTestEndpointId;
eventPathParams[1].mClusterId = kTestClusterId;
eventPathParams[1].mEventId = kTestChangeEvent2;

chip::app::AttributePathParams attributePathParams(chip::kTestDeviceNodeId, kTestEndpointId, kTestClusterId, 1, 0,
chip::app::AttributePathParams::Flags::kFieldIdValid);

printf("\nSend read request message to Node: %" PRIu64 "\n", chip::kTestDeviceNodeId);

err = chip::app::InteractionModelEngine::GetInstance()->SendReadRequest(chip::kTestDeviceNodeId, gAdminId, nullptr,
&eventPathParams, 1, &attributePathParams, 1, number);
eventPathParams, 2, &attributePathParams, 1, number);
SuccessOrExit(err);

exit:
Expand Down
16 changes: 5 additions & 11 deletions src/app/tests/integration/chip_im_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,15 @@ void DispatchSingleClusterCommand(chip::ClusterId aClusterId, chip::CommandId aC

CHIP_ERROR ReadSingleClusterData(ClusterInfo & aClusterInfo, TLV::TLVWriter * apWriter, bool * apDataExists)
{
CHIP_ERROR err = CHIP_NO_ERROR;
CHIP_ERROR err = CHIP_NO_ERROR;
uint64_t version = 0;
VerifyOrExit(aClusterInfo.mClusterId == kTestClusterId && aClusterInfo.mEndpointId == kTestEndpointId,
err = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(apWriter != nullptr, /* no op */);

if (aClusterInfo.mFieldId == kRootFieldId || aClusterInfo.mFieldId == 1)
{
err = apWriter->Put(TLV::ContextTag(kTestFieldId1), kTestFieldValue1);
SuccessOrExit(err);
}
if (aClusterInfo.mFieldId == kRootFieldId || aClusterInfo.mFieldId == 2)
{
err = apWriter->Put(TLV::ContextTag(kTestFieldId2), kTestFieldValue2);
SuccessOrExit(err);
}
err = apWriter->Put(TLV::ContextTag(AttributeDataElement::kCsTag_Data), kTestFieldValue1);
SuccessOrExit(err);
err = apWriter->Put(TLV::ContextTag(AttributeDataElement::kCsTag_DataVersion), version);

exit:
ChipLogFunctError(err);
Expand Down
23 changes: 12 additions & 11 deletions src/app/tests/integration/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ extern chip::Messaging::ExchangeManager gExchangeManager;
extern chip::SecureSessionMgr gSessionManager;
extern chip::secure_channel::MessageCounterManager gMessageCounterManager;

constexpr chip::NodeId kTestNodeId = 0x1ULL;
constexpr chip::NodeId kTestNodeId1 = 0x2ULL;
constexpr chip::ClusterId kTestClusterId = 6;
constexpr chip::CommandId kTestCommandId = 40;
constexpr chip::EndpointId kTestEndpointId = 1;
constexpr chip::GroupId kTestGroupId = 0;
constexpr chip::FieldId kTestFieldId1 = 1;
constexpr chip::FieldId kTestFieldId2 = 2;
constexpr uint8_t kTestFieldValue1 = 1;
constexpr uint8_t kTestFieldValue2 = 2;
constexpr chip::EventId kLivenessChangeEvent = 1;
constexpr chip::NodeId kTestNodeId = 0x1ULL;
constexpr chip::NodeId kTestNodeId1 = 0x2ULL;
constexpr chip::ClusterId kTestClusterId = 6;
constexpr chip::CommandId kTestCommandId = 40;
constexpr chip::EndpointId kTestEndpointId = 1;
constexpr chip::GroupId kTestGroupId = 0;
constexpr chip::FieldId kTestFieldId1 = 1;
constexpr chip::FieldId kTestFieldId2 = 2;
constexpr uint8_t kTestFieldValue1 = 1;
constexpr uint8_t kTestFieldValue2 = 2;
constexpr chip::EventId kTestChangeEvent1 = 1;
constexpr chip::EventId kTestChangeEvent2 = 2;
void InitializeChip(void);
void ShutdownChip(void);
void TLVPrettyPrinter(const char * aFormat, ...);

0 comments on commit 7fad80c

Please sign in to comment.