22
22
#include < app/tests/suites/commands/commissioner/CommissionerCommands.h>
23
23
#include < app/tests/suites/commands/delay/DelayCommands.h>
24
24
#include < app/tests/suites/commands/discovery/DiscoveryCommands.h>
25
+ #include < app/tests/suites/commands/interaction_model/InteractionModel.h>
25
26
#include < app/tests/suites/commands/log/LogCommands.h>
26
27
#include < app/tests/suites/commands/system/SystemCommands.h>
27
28
#include < app/tests/suites/include/ConstraintsChecker.h>
28
29
#include < app/tests/suites/include/PICSChecker.h>
30
+ #include < app/tests/suites/include/TestRunner.h>
29
31
#include < app/tests/suites/include/ValueChecker.h>
30
- #include < lib/support/UnitTestUtils.h>
31
32
#include < zap-generated/tests/CHIPClustersTest.h>
32
33
33
34
constexpr uint16_t kTimeoutInSeconds = 90 ;
34
35
35
- class TestCommand : public CHIPCommand ,
36
+ class TestCommand : public TestRunner ,
37
+ public CHIPCommand,
36
38
public ValueChecker,
37
39
public ConstraintsChecker,
38
40
public PICSChecker,
39
41
public LogCommands,
40
42
public CommissionerCommands,
41
43
public DiscoveryCommands,
42
44
public SystemCommands,
43
- public DelayCommands
45
+ public DelayCommands,
46
+ public InteractionModel
44
47
{
45
48
public:
46
- TestCommand (const char * commandName, CredentialIssuerCommands * credsIssuerConfig) :
47
- CHIPCommand (commandName, credsIssuerConfig ), mOnDeviceConnectedCallback (OnDeviceConnectedFn, this ),
48
- mOnDeviceConnectionFailureCallback (OnDeviceConnectionFailureFn, this )
49
+ TestCommand (const char * commandName, uint16_t testsCount, CredentialIssuerCommands * credsIssuerConfig) :
50
+ TestRunner (commandName, testsCount ), CHIPCommand(commandName, credsIssuerConfig ),
51
+ mOnDeviceConnectedCallback (OnDeviceConnectedFn, this ), mOnDeviceConnectionFailureCallback (OnDeviceConnectionFailureFn, this )
49
52
{
50
53
AddArgument (" delayInMs" , 0 , UINT64_MAX, &mDelayInMs );
51
54
AddArgument (" PICS" , &mPICSFilePath );
@@ -55,33 +58,25 @@ class TestCommand : public CHIPCommand,
55
58
56
59
// ///////// CHIPCommand Interface /////////
57
60
CHIP_ERROR RunCommand () override ;
58
- virtual void NextTest () = 0;
59
61
60
62
protected:
61
63
// ///////// DelayCommands Interface /////////
62
64
CHIP_ERROR WaitForCommissionee (chip::NodeId nodeId) override ;
63
65
void OnWaitForMs () override { NextTest (); };
64
66
65
- std::map<std::string, ChipDevice *> mDevices ;
67
+ // ///////// Interaction Model Interface /////////
68
+ chip::DeviceProxy * GetDevice (const char * identity) override { return mDevices [identity]; }
69
+ void OnResponse (const chip::app::StatusIB & status, chip::TLV::TLVReader * data) override {};
66
70
67
71
static void OnDeviceConnectedFn (void * context, chip::OperationalDeviceProxy * device);
68
72
static void OnDeviceConnectionFailureFn (void * context, PeerId peerId, CHIP_ERROR error);
69
73
70
- CHIP_ERROR ContinueOnChipMainThread (CHIP_ERROR err) override
71
- {
72
- if (CHIP_NO_ERROR == err)
73
- {
74
- return WaitForMs (0 );
75
- }
76
- Exit (chip::ErrorStr (err));
77
- return CHIP_NO_ERROR;
78
- }
74
+ CHIP_ERROR ContinueOnChipMainThread (CHIP_ERROR err) override ;
79
75
80
76
chip::Controller::DeviceCommissioner & GetCurrentCommissioner () override { return CurrentCommissioner (); };
81
77
82
- void Exit (std::string message) override ;
83
- void ThrowFailureResponse (CHIP_ERROR error);
84
- void ThrowSuccessResponse ();
78
+ static void ExitAsync (intptr_t context);
79
+ void Exit (std::string message, CHIP_ERROR err = CHIP_ERROR_INTERNAL) override ;
85
80
86
81
chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback ;
87
82
chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback ;
@@ -92,14 +87,14 @@ class TestCommand : public CHIPCommand,
92
87
status.mStatus == chip::Protocols::InteractionModel::Status::UnsupportedCommand;
93
88
}
94
89
95
- void Wait ()
96
- {
97
- if (mDelayInMs .HasValue ())
98
- {
99
- chip::test_utils::SleepMillis (mDelayInMs .Value ());
100
- }
101
- };
102
- chip::Optional<uint64_t > mDelayInMs ;
103
90
chip::Optional<char *> mPICSFilePath ;
104
91
chip::Optional<uint16_t > mTimeout ;
92
+ std::map<std::string, ChipDevice *> mDevices ;
93
+
94
+ // When set to false, prevents interaction model events from affecting the current test status.
95
+ // This flag exists because if an error happens while processing a response the allocated
96
+ // command client/sender (ReadClient/WriteClient/CommandSender) can not be deallocated
97
+ // as it still used by the stack afterward. So a task is scheduled to run to close the
98
+ // test suite as soon as possible, and pending events are ignored in between.
99
+ bool mContinueProcessing = true ;
105
100
};
0 commit comments