Skip to content

Commit 9632eb4

Browse files
authored
Merge branch 'master' into lib_dnssd_mmdns_responders
2 parents e6d76fe + e62bc1c commit 9632eb4

25 files changed

+320
-494
lines changed

.github/workflows/qemu.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ jobs:
6060
build \
6161
"
6262
- name: Run all tests
63-
# Disabled being tracked here: https://github.com/project-chip/connectedhomeip/issues/32587
64-
if: false
6563
run: |
6664
src/test_driver/esp32/run_qemu_image.py \
6765
--verbose \

scripts/setup/requirements.nxp.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
jsonschema>=4.17.0
2+
pycrypto>=2.6.1
3+
pycryptodome>=3.20.0

src/app/CommandHandler.cpp

+12-13
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ CHIP_ERROR CommandHandler::ValidateInvokeRequestMessageAndBuildRegistry(InvokeRe
158158

159159
// Grab the CommandRef if there is one, and validate that it's there when it
160160
// has to be.
161-
Optional<uint16_t> commandRef;
161+
std::optional<uint16_t> commandRef;
162162
uint16_t ref;
163163
err = commandData.GetRef(&ref);
164164
VerifyOrReturnError(err == CHIP_NO_ERROR || err == CHIP_END_OF_TLV, err);
@@ -168,7 +168,7 @@ CHIP_ERROR CommandHandler::ValidateInvokeRequestMessageAndBuildRegistry(InvokeRe
168168
}
169169
if (err == CHIP_NO_ERROR)
170170
{
171-
commandRef.SetValue(ref);
171+
commandRef.emplace(ref);
172172
}
173173

174174
// Adding can fail if concretePath is not unique, or if commandRef is a value
@@ -590,10 +590,9 @@ CHIP_ERROR CommandHandler::PrepareInvokeResponseCommand(const ConcreteCommandPat
590590
const CommandHandler::InvokeResponseParameters & aPrepareParameters)
591591
{
592592
auto commandPathRegistryEntry = GetCommandPathRegistry().Find(aPrepareParameters.mRequestCommandPath);
593-
VerifyOrReturnValue(commandPathRegistryEntry.HasValue(), CHIP_ERROR_INCORRECT_STATE);
593+
VerifyOrReturnValue(commandPathRegistryEntry.has_value(), CHIP_ERROR_INCORRECT_STATE);
594594

595-
return PrepareInvokeResponseCommand(commandPathRegistryEntry.Value(), aResponseCommandPath,
596-
aPrepareParameters.mStartOrEndDataStruct);
595+
return PrepareInvokeResponseCommand(*commandPathRegistryEntry, aResponseCommandPath, aPrepareParameters.mStartOrEndDataStruct);
597596
}
598597

599598
CHIP_ERROR CommandHandler::PrepareCommand(const ConcreteCommandPath & aResponseCommandPath, bool aStartDataStruct)
@@ -610,9 +609,9 @@ CHIP_ERROR CommandHandler::PrepareCommand(const ConcreteCommandPath & aResponseC
610609
"Seemingly device supports batch commands, but is calling the deprecated PrepareCommand API");
611610

612611
auto commandPathRegistryEntry = GetCommandPathRegistry().GetFirstEntry();
613-
VerifyOrReturnValue(commandPathRegistryEntry.HasValue(), CHIP_ERROR_INCORRECT_STATE);
612+
VerifyOrReturnValue(commandPathRegistryEntry.has_value(), CHIP_ERROR_INCORRECT_STATE);
614613

615-
return PrepareInvokeResponseCommand(commandPathRegistryEntry.Value(), aResponseCommandPath, aStartDataStruct);
614+
return PrepareInvokeResponseCommand(*commandPathRegistryEntry, aResponseCommandPath, aStartDataStruct);
616615
}
617616

618617
CHIP_ERROR CommandHandler::PrepareInvokeResponseCommand(const CommandPathRegistryEntry & apCommandPathRegistryEntry,
@@ -675,9 +674,9 @@ CHIP_ERROR CommandHandler::FinishCommand(bool aStartDataStruct)
675674
ReturnErrorOnFailure(commandData.GetWriter()->EndContainer(mDataElementContainerType));
676675
}
677676

678-
if (mRefForResponse.HasValue())
677+
if (mRefForResponse.has_value())
679678
{
680-
ReturnErrorOnFailure(commandData.Ref(mRefForResponse.Value()));
679+
ReturnErrorOnFailure(commandData.Ref(*mRefForResponse));
681680
}
682681

683682
ReturnErrorOnFailure(commandData.EndOfCommandDataIB());
@@ -699,8 +698,8 @@ CHIP_ERROR CommandHandler::PrepareStatus(const ConcreteCommandPath & aCommandPat
699698
}
700699

701700
auto commandPathRegistryEntry = GetCommandPathRegistry().Find(aCommandPath);
702-
VerifyOrReturnError(commandPathRegistryEntry.HasValue(), CHIP_ERROR_INCORRECT_STATE);
703-
mRefForResponse = commandPathRegistryEntry.Value().ref;
701+
VerifyOrReturnError(commandPathRegistryEntry.has_value(), CHIP_ERROR_INCORRECT_STATE);
702+
mRefForResponse = commandPathRegistryEntry->ref;
704703

705704
MoveToState(State::Preparing);
706705
InvokeResponseIBs::Builder & invokeResponses = mInvokeResponseBuilder.GetInvokeResponses();
@@ -720,9 +719,9 @@ CHIP_ERROR CommandHandler::FinishStatus()
720719
VerifyOrReturnError(mState == State::AddingCommand, CHIP_ERROR_INCORRECT_STATE);
721720

722721
CommandStatusIB::Builder & commandStatus = mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().GetStatus();
723-
if (mRefForResponse.HasValue())
722+
if (mRefForResponse.has_value())
724723
{
725-
ReturnErrorOnFailure(commandStatus.Ref(mRefForResponse.Value()));
724+
ReturnErrorOnFailure(commandStatus.Ref(*mRefForResponse));
726725
}
727726

728727
ReturnErrorOnFailure(mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().GetStatus().EndOfCommandStatusIB());

src/app/CommandHandler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ class CommandHandler
686686
// TODO Allow flexibility in registration.
687687
BasicCommandPathRegistry<CHIP_CONFIG_MAX_PATHS_PER_INVOKE> mBasicCommandPathRegistry;
688688
CommandPathRegistry * mCommandPathRegistry = &mBasicCommandPathRegistry;
689-
Optional<uint16_t> mRefForResponse;
689+
std::optional<uint16_t> mRefForResponse;
690690

691691
CommandHandlerExchangeInterface * mpResponder = nullptr;
692692

src/app/CommandPathRegistry.h

+15-13
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,27 @@
2424
#include <lib/core/CHIPError.h>
2525
#include <lib/core/Optional.h>
2626

27+
#include <optional>
28+
2729
namespace chip {
2830
namespace app {
2931

3032
struct CommandPathRegistryEntry
3133
{
3234
ConcreteCommandPath requestPath = ConcreteCommandPath(0, 0, 0);
33-
Optional<uint16_t> ref;
35+
std::optional<uint16_t> ref;
3436
};
3537

3638
class CommandPathRegistry
3739
{
3840
public:
3941
virtual ~CommandPathRegistry() = default;
4042

41-
virtual Optional<CommandPathRegistryEntry> Find(const ConcreteCommandPath & requestPath) const = 0;
42-
virtual Optional<CommandPathRegistryEntry> GetFirstEntry() const = 0;
43-
virtual CHIP_ERROR Add(const ConcreteCommandPath & requestPath, const Optional<uint16_t> & ref) = 0;
44-
virtual size_t Count() const = 0;
45-
virtual size_t MaxSize() const = 0;
43+
virtual std::optional<CommandPathRegistryEntry> Find(const ConcreteCommandPath & requestPath) const = 0;
44+
virtual std::optional<CommandPathRegistryEntry> GetFirstEntry() const = 0;
45+
virtual CHIP_ERROR Add(const ConcreteCommandPath & requestPath, const std::optional<uint16_t> & ref) = 0;
46+
virtual size_t Count() const = 0;
47+
virtual size_t MaxSize() const = 0;
4648
};
4749

4850
/**
@@ -59,28 +61,28 @@ template <size_t N>
5961
class BasicCommandPathRegistry : public CommandPathRegistry
6062
{
6163
public:
62-
Optional<CommandPathRegistryEntry> Find(const ConcreteCommandPath & requestPath) const override
64+
std::optional<CommandPathRegistryEntry> Find(const ConcreteCommandPath & requestPath) const override
6365
{
6466
for (size_t i = 0; i < mCount; i++)
6567
{
6668
if (mTable[i].requestPath == requestPath)
6769
{
68-
return MakeOptional(mTable[i]);
70+
return std::make_optional(mTable[i]);
6971
}
7072
}
71-
return NullOptional;
73+
return std::nullopt;
7274
}
7375

74-
Optional<CommandPathRegistryEntry> GetFirstEntry() const override
76+
std::optional<CommandPathRegistryEntry> GetFirstEntry() const override
7577
{
7678
if (mCount > 0)
7779
{
78-
return MakeOptional(mTable[0]);
80+
return std::make_optional(mTable[0]);
7981
}
80-
return NullOptional;
82+
return std::nullopt;
8183
}
8284

83-
CHIP_ERROR Add(const ConcreteCommandPath & requestPath, const Optional<uint16_t> & ref) override
85+
CHIP_ERROR Add(const ConcreteCommandPath & requestPath, const std::optional<uint16_t> & ref) override
8486
{
8587
if (mCount >= N)
8688
{

src/app/tests/TestBasicCommandPathRegistry.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ void TestAddingSameConcretePath(nlTestSuite * apSuite, void * apContext)
3636
BasicCommandPathRegistry<kQuickTestSize> basicCommandPathRegistry;
3737

3838
ConcreteCommandPath concretePath(0, 0, 0);
39-
Optional<uint16_t> commandRef;
39+
std::optional<uint16_t> commandRef;
4040
uint16_t commandRefValue = 0;
4141

4242
size_t idx = 0;
4343
for (idx = 0; idx < kQuickTestSize && err == CHIP_NO_ERROR; idx++)
4444
{
45-
commandRef.SetValue(commandRefValue);
45+
commandRef.emplace(commandRefValue);
4646
commandRefValue++;
4747
err = basicCommandPathRegistry.Add(concretePath, commandRef);
4848
}
@@ -56,8 +56,8 @@ void TestAddingSameCommandRef(nlTestSuite * apSuite, void * apContext)
5656
CHIP_ERROR err = CHIP_NO_ERROR;
5757
BasicCommandPathRegistry<kQuickTestSize> basicCommandPathRegistry;
5858

59-
Optional<uint16_t> commandRef;
60-
commandRef.SetValue(0);
59+
std::optional<uint16_t> commandRef;
60+
commandRef.emplace(0);
6161

6262
uint16_t endpointValue = 0;
6363

@@ -78,14 +78,14 @@ void TestAddingMaxNumberOfEntries(nlTestSuite * apSuite, void * apContext)
7878
CHIP_ERROR err = CHIP_NO_ERROR;
7979
BasicCommandPathRegistry<kQuickTestSize> basicCommandPathRegistry;
8080

81-
Optional<uint16_t> commandRef;
81+
std::optional<uint16_t> commandRef;
8282
uint16_t commandRefAndEndpointValue = 0;
8383

8484
size_t idx = 0;
8585
for (idx = 0; idx < kQuickTestSize && err == CHIP_NO_ERROR; idx++)
8686
{
8787
ConcreteCommandPath concretePath(commandRefAndEndpointValue, 0, 0);
88-
commandRef.SetValue(commandRefAndEndpointValue);
88+
commandRef.emplace(commandRefAndEndpointValue);
8989
commandRefAndEndpointValue++;
9090
err = basicCommandPathRegistry.Add(concretePath, commandRef);
9191
}
@@ -100,14 +100,14 @@ void TestAddingTooManyEntries(nlTestSuite * apSuite, void * apContext)
100100
BasicCommandPathRegistry<kQuickTestSize> basicCommandPathRegistry;
101101
size_t maxPlusOne = kQuickTestSize + 1;
102102

103-
Optional<uint16_t> commandRef;
103+
std::optional<uint16_t> commandRef;
104104
uint16_t commandRefAndEndpointValue = 0;
105105

106106
size_t idx = 0;
107107
for (idx = 0; idx < maxPlusOne && err == CHIP_NO_ERROR; idx++)
108108
{
109109
ConcreteCommandPath concretePath(commandRefAndEndpointValue, 0, 0);
110-
commandRef.SetValue(commandRefAndEndpointValue);
110+
commandRef.emplace(commandRefAndEndpointValue);
111111
commandRefAndEndpointValue++;
112112
err = basicCommandPathRegistry.Add(concretePath, commandRef);
113113
}

src/app/tests/TestCommandInteraction.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <messaging/ExchangeContext.h>
4141
#include <messaging/ExchangeMgr.h>
4242
#include <messaging/Flags.h>
43+
#include <optional>
4344
#include <platform/CHIPDeviceLayer.h>
4445
#include <protocols/interaction_model/Constants.h>
4546
#include <system/SystemPacketBuffer.h>
@@ -392,7 +393,7 @@ class TestCommandInteraction
392393
const Optional<uint16_t> & aRef) :
393394
CommandHandler(apCallback)
394395
{
395-
GetCommandPathRegistry().Add(aRequestCommandPath, aRef);
396+
GetCommandPathRegistry().Add(aRequestCommandPath, aRef.std_optional());
396397
SetExchangeInterface(&mMockCommandResponder);
397398
}
398399
MockCommandResponder mMockCommandResponder;
@@ -407,7 +408,8 @@ class TestCommandInteraction
407408
// payload will be included. Otherwise no payload will be included.
408409
static void GenerateInvokeResponse(nlTestSuite * apSuite, void * apContext, System::PacketBufferHandle & aPayload,
409410
CommandId aCommandId, ClusterId aClusterId = kTestClusterId,
410-
EndpointId aEndpointId = kTestEndpointId, Optional<uint16_t> aCommandRef = NullOptional);
411+
EndpointId aEndpointId = kTestEndpointId,
412+
std::optional<uint16_t> aCommandRef = std::nullopt);
411413
static void AddInvokeRequestData(nlTestSuite * apSuite, void * apContext, CommandSender * apCommandSender,
412414
CommandId aCommandId = kTestCommandIdWithData);
413415
static void AddInvalidInvokeRequestData(nlTestSuite * apSuite, void * apContext, CommandSender * apCommandSender,
@@ -494,7 +496,7 @@ void TestCommandInteraction::GenerateInvokeRequest(nlTestSuite * apSuite, void *
494496

495497
void TestCommandInteraction::GenerateInvokeResponse(nlTestSuite * apSuite, void * apContext, System::PacketBufferHandle & aPayload,
496498
CommandId aCommandId, ClusterId aClusterId, EndpointId aEndpointId,
497-
Optional<uint16_t> aCommandRef)
499+
std::optional<uint16_t> aCommandRef)
498500

499501
{
500502
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -536,9 +538,9 @@ void TestCommandInteraction::GenerateInvokeResponse(nlTestSuite * apSuite, void
536538
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
537539
}
538540

539-
if (aCommandRef.HasValue())
541+
if (aCommandRef.has_value())
540542
{
541-
NL_TEST_ASSERT(apSuite, commandDataIBBuilder.Ref(aCommandRef.Value()) == CHIP_NO_ERROR);
543+
NL_TEST_ASSERT(apSuite, commandDataIBBuilder.Ref(*aCommandRef) == CHIP_NO_ERROR);
542544
}
543545

544546
commandDataIBBuilder.EndOfCommandDataIB();
@@ -633,9 +635,9 @@ uint32_t TestCommandInteraction::GetAddResponseDataOverheadSizeForPath(nlTestSui
633635
ConcreteCommandPath requestCommandPath1 = { kTestEndpointId, kTestClusterId, kTestCommandIdFillResponseMessage };
634636
ConcreteCommandPath requestCommandPath2 = { kTestEndpointId, kTestClusterId, kTestCommandIdCommandSpecificResponse };
635637

636-
CHIP_ERROR err = basicCommandPathRegistry.Add(requestCommandPath1, MakeOptional<uint16_t>(static_cast<uint16_t>(1)));
638+
CHIP_ERROR err = basicCommandPathRegistry.Add(requestCommandPath1, std::make_optional<uint16_t>(static_cast<uint16_t>(1)));
637639
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
638-
err = basicCommandPathRegistry.Add(requestCommandPath2, MakeOptional<uint16_t>(static_cast<uint16_t>(2)));
640+
err = basicCommandPathRegistry.Add(requestCommandPath2, std::make_optional<uint16_t>(static_cast<uint16_t>(2)));
639641
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
640642

641643
err = commandHandler.AllocateBuffer();
@@ -823,7 +825,7 @@ void TestCommandInteraction::TestCommandSenderExtendableApiWithProcessReceivedMs
823825

824826
uint16_t invalidResponseCommandRef = 2;
825827
GenerateInvokeResponse(apSuite, apContext, buf, kTestCommandIdWithData, kTestClusterId, kTestEndpointId,
826-
MakeOptional(invalidResponseCommandRef));
828+
std::make_optional(invalidResponseCommandRef));
827829
bool moreChunkedMessages = false;
828830
err = commandSender.ProcessInvokeResponse(std::move(buf), moreChunkedMessages);
829831
NL_TEST_ASSERT(apSuite, err == CHIP_ERROR_KEY_NOT_FOUND);
@@ -1948,9 +1950,9 @@ void TestCommandInteraction::TestCommandHandler_FillUpInvokeResponseMessageWhere
19481950
ConcreteCommandPath requestCommandPath1 = { kTestEndpointId, kTestClusterId, kTestCommandIdFillResponseMessage };
19491951
ConcreteCommandPath requestCommandPath2 = { kTestEndpointId, kTestClusterId, kTestCommandIdCommandSpecificResponse };
19501952

1951-
CHIP_ERROR err = basicCommandPathRegistry.Add(requestCommandPath1, MakeOptional<uint16_t>(static_cast<uint16_t>(1)));
1953+
CHIP_ERROR err = basicCommandPathRegistry.Add(requestCommandPath1, std::make_optional<uint16_t>(static_cast<uint16_t>(1)));
19521954
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
1953-
err = basicCommandPathRegistry.Add(requestCommandPath2, MakeOptional<uint16_t>(static_cast<uint16_t>(2)));
1955+
err = basicCommandPathRegistry.Add(requestCommandPath2, std::make_optional<uint16_t>(static_cast<uint16_t>(2)));
19541956
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
19551957

19561958
uint32_t sizeToLeave = 0;
@@ -1977,9 +1979,9 @@ void TestCommandInteraction::TestCommandHandler_FillUpInvokeResponseMessageWhere
19771979
ConcreteCommandPath requestCommandPath1 = { kTestEndpointId, kTestClusterId, kTestCommandIdFillResponseMessage };
19781980
ConcreteCommandPath requestCommandPath2 = { kTestEndpointId, kTestClusterId, kTestCommandIdCommandSpecificResponse };
19791981

1980-
CHIP_ERROR err = basicCommandPathRegistry.Add(requestCommandPath1, MakeOptional<uint16_t>(static_cast<uint16_t>(1)));
1982+
CHIP_ERROR err = basicCommandPathRegistry.Add(requestCommandPath1, std::make_optional<uint16_t>(static_cast<uint16_t>(1)));
19811983
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
1982-
err = basicCommandPathRegistry.Add(requestCommandPath2, MakeOptional<uint16_t>(static_cast<uint16_t>(2)));
1984+
err = basicCommandPathRegistry.Add(requestCommandPath2, std::make_optional<uint16_t>(static_cast<uint16_t>(2)));
19831985
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
19841986

19851987
uint32_t sizeToLeave = 0;
@@ -2005,9 +2007,9 @@ void TestCommandInteraction::TestCommandHandler_FillUpInvokeResponseMessageWhere
20052007
ConcreteCommandPath requestCommandPath1 = { kTestEndpointId, kTestClusterId, kTestCommandIdFillResponseMessage };
20062008
ConcreteCommandPath requestCommandPath2 = { kTestEndpointId, kTestClusterId, kTestCommandIdCommandSpecificResponse };
20072009

2008-
CHIP_ERROR err = basicCommandPathRegistry.Add(requestCommandPath1, MakeOptional<uint16_t>(static_cast<uint16_t>(1)));
2010+
CHIP_ERROR err = basicCommandPathRegistry.Add(requestCommandPath1, std::make_optional<uint16_t>(static_cast<uint16_t>(1)));
20092011
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
2010-
err = basicCommandPathRegistry.Add(requestCommandPath2, MakeOptional<uint16_t>(static_cast<uint16_t>(2)));
2012+
err = basicCommandPathRegistry.Add(requestCommandPath2, std::make_optional<uint16_t>(static_cast<uint16_t>(2)));
20112013
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
20122014

20132015
uint32_t sizeToLeave = 0;

src/darwin/Framework/CHIP/MTRError.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ typedef NS_ERROR_ENUM(MTRInteractionErrorDomain, MTRInteractionErrorCode){
138138
MTRInteractionErrorCodePathsExhausted = 0xc8,
139139
MTRInteractionErrorCodeTimedRequestMismatch = 0xc9,
140140
MTRInteractionErrorCodeFailsafeRequired = 0xca,
141-
MTRInteractionErrorInvalidInState MTR_NEWLY_AVAILABLE = 0xcb,
142-
MTRInteractionErrorNoCommandResponse MTR_NEWLY_AVAILABLE = 0xcc,
141+
MTRInteractionErrorCodeInvalidInState MTR_NEWLY_AVAILABLE = 0xcb,
142+
MTRInteractionErrorCodeNoCommandResponse MTR_NEWLY_AVAILABLE = 0xcc,
143143
};
144144
// clang-format on
145145

src/lib/address_resolve/tests/BUILD.gn

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414

1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
17-
import("//build_overrides/nlunit_test.gni")
1817

1918
import("${chip_root}/src/lib/address_resolve/address_resolve.gni")
2019

2120
import("${chip_root}/build/chip/chip_test_suite.gni")
2221

23-
chip_test_suite_using_nltest("tests") {
22+
chip_test_suite("tests") {
2423
output_name = "libAddressResolveTests"
2524

2625
if (chip_address_resolve_strategy == "default") {
@@ -29,8 +28,6 @@ chip_test_suite_using_nltest("tests") {
2928

3029
public_deps = [
3130
"${chip_root}/src/lib/address_resolve",
32-
"${chip_root}/src/lib/support:testing_nlunit",
3331
"${chip_root}/src/protocols",
34-
"${nlunit_test_root}:nlunit-test",
3532
]
3633
}

0 commit comments

Comments
 (0)