Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[matter_yamltests] Add timeout argument supports for the chip-tool/py… #27934

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions examples/chip-tool/commands/interactive/InteractiveCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct InteractiveServerResult
{
bool mEnabled = false;
bool mIsAsyncReport = false;
uint16_t mTimeout = 0;
int mStatus = EXIT_SUCCESS;
std::vector<std::string> mResults;
std::vector<InteractiveServerResultLog> mLogs;
Expand Down Expand Up @@ -92,18 +93,31 @@ struct InteractiveServerResult
// protected by a mutex.
std::mutex mMutex;

void Setup(bool isAsyncReport)
void Setup(bool isAsyncReport, uint16_t timeout)
{
auto lock = ScopedLock(mMutex);
mEnabled = true;
mIsAsyncReport = isAsyncReport;
mTimeout = timeout;

if (mIsAsyncReport && mTimeout)
{
chip::DeviceLayer::PlatformMgr().ScheduleWork(StartAsyncTimeout, reinterpret_cast<intptr_t>(this));
}
}

void Reset()
{
auto lock = ScopedLock(mMutex);
auto lock = ScopedLock(mMutex);

if (mIsAsyncReport && mTimeout)
{
chip::DeviceLayer::PlatformMgr().ScheduleWork(StopAsyncTimeout, reinterpret_cast<intptr_t>(this));
}

mEnabled = false;
mIsAsyncReport = false;
mTimeout = 0;
mStatus = EXIT_SUCCESS;
mResults.clear();
mLogs.clear();
Expand Down Expand Up @@ -204,6 +218,24 @@ struct InteractiveServerResult
content << "}";
return content.str();
}

static void StartAsyncTimeout(intptr_t arg)
{
auto self = reinterpret_cast<InteractiveServerResult *>(arg);
auto timeout = chip::System::Clock::Seconds16(self->mTimeout);
chip::DeviceLayer::SystemLayer().StartTimer(timeout, OnAsyncTimeout, self);
}

static void StopAsyncTimeout(intptr_t arg)
{
auto self = reinterpret_cast<InteractiveServerResult *>(arg);
chip::DeviceLayer::SystemLayer().CancelTimer(OnAsyncTimeout, self);
}

static void OnAsyncTimeout(chip::System::Layer *, void * appState)
{
RemoteDataModelLogger::LogErrorAsJSON(CHIP_ERROR_TIMEOUT);
}
};

InteractiveServerResult gInteractiveServerResult;
Expand Down Expand Up @@ -263,7 +295,19 @@ CHIP_ERROR InteractiveServerCommand::RunCommand()
bool InteractiveServerCommand::OnWebSocketMessageReceived(char * msg)
{
bool isAsyncReport = strlen(msg) == 0;
gInteractiveServerResult.Setup(isAsyncReport);
uint16_t timeout = 0;
if (!isAsyncReport && strlen(msg) <= 5 /* Only look for numeric values <= 65535 */)
{
std::stringstream ss;
ss << msg;
ss >> timeout;
if (!ss.fail())
{
isAsyncReport = true;
}
}

gInteractiveServerResult.Setup(isAsyncReport, timeout);
VerifyOrReturnValue(!isAsyncReport, true);

auto shouldStop = ParseCommand(msg, &gInteractiveServerResult.mStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def encode(self, request):
command, command_specifier = self.__get_command_name(request)

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

arguments = self.__get_arguments(request)
base64_arguments = base64.b64encode(
Expand Down Expand Up @@ -270,6 +270,8 @@ def __get_arguments(self, request):
arguments, request.max_interval, "max-interval")
arguments = self.__maybe_add(arguments, request.timed_interaction_timeout_ms,
"timedInteractionTimeoutMs")
arguments = self.__maybe_add(
arguments, request.timeout, "timeout")
arguments = self.__maybe_add(
arguments, request.event_number, "event-min")
arguments = self.__maybe_add(
Expand Down
5 changes: 5 additions & 0 deletions scripts/py_matter_yamltests/matter_yamltests/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def __init__(self, test: dict, config: dict, definitions: SpecDefinitions, pics_
self.max_interval = _value_or_none(test, 'maxInterval')
self.timed_interaction_timeout_ms = _value_or_none(
test, 'timedInteractionTimeoutMs')
self.timeout = _value_or_none(test, 'timeout')
self.data_version = _value_or_none(
test, 'dataVersion')
self.busy_wait_ms = _value_or_none(test, 'busyWaitMs')
Expand Down Expand Up @@ -661,6 +662,10 @@ def max_interval(self):
def timed_interaction_timeout_ms(self):
return self._test.timed_interaction_timeout_ms

@property
def timeout(self):
return self._test.timeout

@property
def data_version(self):
return self._test.data_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def __check_test_step(self, config: dict, content):
'response': (dict, list, str), # Can be a variable
'minInterval': int,
'maxInterval': int,
'timeout': int,
'timedInteractionTimeoutMs': int,
'dataVersion': (list, int, str), # Can be a variable
'busyWaitMs': int,
Expand Down