Skip to content

Commit

Permalink
[YAML] Make busyWait a dedicated method instead of always generating …
Browse files Browse the repository at this point in the history
…it (#15416)

* [YAML] Make busyWait a dedicated method instead of always generating it

* Update generated tests content
  • Loading branch information
vivien-apple authored and pull[bot] committed Dec 21, 2023
1 parent 1e03d44 commit 1006315
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 39 deletions.
9 changes: 2 additions & 7 deletions examples/chip-tool/templates/tests/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,8 @@ class {{filename}}: public TestCommand

{{~#*inline "maybeWait"}}
{{#if busyWaitMs}}
{
using namespace chip::System::Clock::Literals;
// Busy-wait for {{busyWaitMs}} milliseconds.
auto & clock = chip::System::SystemClock();
auto start = clock.GetMonotonicTimestamp();
while (clock.GetMonotonicTimestamp() - start < {{busyWaitMs}}_ms);
}
using namespace chip::System::Clock::Literals;
BusyWaitFor({{busyWaitMs}}_ms);
{{/if}}
{{/inline~}}

Expand Down
11 changes: 11 additions & 0 deletions src/app/tests/suites/commands/delay/DelayCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,14 @@ CHIP_ERROR DelayCommands::RunInternal(const char * command)
VerifyOrReturnError(system(command) == 0, CHIP_ERROR_INTERNAL);
return ContinueOnChipMainThread(CHIP_NO_ERROR);
}

CHIP_ERROR DelayCommands::BusyWaitFor(chip::System::Clock::Milliseconds32 durationInMs)
{
auto & clock = chip::System::SystemClock();
auto start = clock.GetMonotonicTimestamp();
while (clock.GetMonotonicTimestamp() - start < durationInMs)
{
// nothing to do.
};
return CHIP_NO_ERROR;
}
3 changes: 3 additions & 0 deletions src/app/tests/suites/commands/delay/DelayCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class DelayCommands
CHIP_ERROR WaitForCommissionableAdvertisement();
CHIP_ERROR WaitForOperationalAdvertisement();

// Busy-wait for a given duration in milliseconds
CHIP_ERROR BusyWaitFor(chip::System::Clock::Milliseconds32 durationInMs);

private:
static void OnWaitForMsFn(chip::System::Layer * systemLayer, void * context);
CHIP_ERROR RunInternal(const char * command);
Expand Down
40 changes: 8 additions & 32 deletions zzz_generated/chip-tool/zap-generated/test/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1006315

Please sign in to comment.