Skip to content

Commit 5323840

Browse files
vivien-applepull[bot]
authored andcommitted
[matter_yamltests] Add timeout argument supports for the chip-tool/python yaml runner (#27934)
1 parent 0e02eea commit 5323840

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

examples/chip-tool/commands/interactive/InteractiveCommands.cpp

+47-3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct InteractiveServerResult
6565
{
6666
bool mEnabled = false;
6767
bool mIsAsyncReport = false;
68+
uint16_t mTimeout = 0;
6869
int mStatus = EXIT_SUCCESS;
6970
std::vector<std::string> mResults;
7071
std::vector<InteractiveServerResultLog> mLogs;
@@ -92,18 +93,31 @@ struct InteractiveServerResult
9293
// protected by a mutex.
9394
std::mutex mMutex;
9495

95-
void Setup(bool isAsyncReport)
96+
void Setup(bool isAsyncReport, uint16_t timeout)
9697
{
9798
auto lock = ScopedLock(mMutex);
9899
mEnabled = true;
99100
mIsAsyncReport = isAsyncReport;
101+
mTimeout = timeout;
102+
103+
if (mIsAsyncReport && mTimeout)
104+
{
105+
chip::DeviceLayer::PlatformMgr().ScheduleWork(StartAsyncTimeout, reinterpret_cast<intptr_t>(this));
106+
}
100107
}
101108

102109
void Reset()
103110
{
104-
auto lock = ScopedLock(mMutex);
111+
auto lock = ScopedLock(mMutex);
112+
113+
if (mIsAsyncReport && mTimeout)
114+
{
115+
chip::DeviceLayer::PlatformMgr().ScheduleWork(StopAsyncTimeout, reinterpret_cast<intptr_t>(this));
116+
}
117+
105118
mEnabled = false;
106119
mIsAsyncReport = false;
120+
mTimeout = 0;
107121
mStatus = EXIT_SUCCESS;
108122
mResults.clear();
109123
mLogs.clear();
@@ -204,6 +218,24 @@ struct InteractiveServerResult
204218
content << "}";
205219
return content.str();
206220
}
221+
222+
static void StartAsyncTimeout(intptr_t arg)
223+
{
224+
auto self = reinterpret_cast<InteractiveServerResult *>(arg);
225+
auto timeout = chip::System::Clock::Seconds16(self->mTimeout);
226+
chip::DeviceLayer::SystemLayer().StartTimer(timeout, OnAsyncTimeout, self);
227+
}
228+
229+
static void StopAsyncTimeout(intptr_t arg)
230+
{
231+
auto self = reinterpret_cast<InteractiveServerResult *>(arg);
232+
chip::DeviceLayer::SystemLayer().CancelTimer(OnAsyncTimeout, self);
233+
}
234+
235+
static void OnAsyncTimeout(chip::System::Layer *, void * appState)
236+
{
237+
RemoteDataModelLogger::LogErrorAsJSON(CHIP_ERROR_TIMEOUT);
238+
}
207239
};
208240

209241
InteractiveServerResult gInteractiveServerResult;
@@ -263,7 +295,19 @@ CHIP_ERROR InteractiveServerCommand::RunCommand()
263295
bool InteractiveServerCommand::OnWebSocketMessageReceived(char * msg)
264296
{
265297
bool isAsyncReport = strlen(msg) == 0;
266-
gInteractiveServerResult.Setup(isAsyncReport);
298+
uint16_t timeout = 0;
299+
if (!isAsyncReport && strlen(msg) <= 5 /* Only look for numeric values <= 65535 */)
300+
{
301+
std::stringstream ss;
302+
ss << msg;
303+
ss >> timeout;
304+
if (!ss.fail())
305+
{
306+
isAsyncReport = true;
307+
}
308+
}
309+
310+
gInteractiveServerResult.Setup(isAsyncReport, timeout);
267311
VerifyOrReturnValue(!isAsyncReport, true);
268312

269313
auto shouldStop = ParseCommand(msg, &gInteractiveServerResult.mStatus);

examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/encoder.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def encode(self, request):
197197
command, command_specifier = self.__get_command_name(request)
198198

199199
if command == 'wait-for-report':
200-
return ''
200+
return str(request.timeout) if request.timeout is not None else ''
201201

202202
arguments = self.__get_arguments(request)
203203
base64_arguments = base64.b64encode(
@@ -270,6 +270,8 @@ def __get_arguments(self, request):
270270
arguments, request.max_interval, "max-interval")
271271
arguments = self.__maybe_add(arguments, request.timed_interaction_timeout_ms,
272272
"timedInteractionTimeoutMs")
273+
arguments = self.__maybe_add(
274+
arguments, request.timeout, "timeout")
273275
arguments = self.__maybe_add(
274276
arguments, request.event_number, "event-min")
275277
arguments = self.__maybe_add(

scripts/py_matter_yamltests/matter_yamltests/parser.py

+5
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def __init__(self, test: dict, config: dict, definitions: SpecDefinitions, pics_
201201
self.max_interval = _value_or_none(test, 'maxInterval')
202202
self.timed_interaction_timeout_ms = _value_or_none(
203203
test, 'timedInteractionTimeoutMs')
204+
self.timeout = _value_or_none(test, 'timeout')
204205
self.data_version = _value_or_none(
205206
test, 'dataVersion')
206207
self.busy_wait_ms = _value_or_none(test, 'busyWaitMs')
@@ -661,6 +662,10 @@ def max_interval(self):
661662
def timed_interaction_timeout_ms(self):
662663
return self._test.timed_interaction_timeout_ms
663664

665+
@property
666+
def timeout(self):
667+
return self._test.timeout
668+
664669
@property
665670
def data_version(self):
666671
return self._test.data_version

scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __check_test_step(self, config: dict, content):
105105
'response': (dict, list, str), # Can be a variable
106106
'minInterval': int,
107107
'maxInterval': int,
108+
'timeout': int,
108109
'timedInteractionTimeoutMs': int,
109110
'dataVersion': (list, int, str), # Can be a variable
110111
'busyWaitMs': int,

0 commit comments

Comments
 (0)