Skip to content

Commit 8fe3a01

Browse files
Allow test event loop dispatch time adjustment for slow VMs (#37210)
* Allow event loop dispatch time adjustment for slow VMs * Restyled by clang-format --------- Co-authored-by: Restyled.io <[email protected]>
1 parent 2521405 commit 8fe3a01

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/system/tests/TestEventLoopHandler.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17+
#include <cstdlib>
18+
#include <functional>
19+
#include <string>
20+
1721
#include <pw_unit_test/framework.h>
1822
#include <system/SystemConfig.h>
1923

@@ -25,9 +29,6 @@
2529
#include <lib/support/CodeUtils.h>
2630
#include <platform/CHIPDeviceLayer.h>
2731

28-
#include <functional>
29-
#include <string>
30-
3132
using namespace chip;
3233
using namespace chip::System::Clock;
3334
using namespace chip::System::Clock::Literals;
@@ -139,9 +140,20 @@ TEST_F(TestEventLoopHandler, EventLoopHandlerWake)
139140
SystemLayer().RemoveLoopHandler(loopHandler);
140141
cancelFallback(); // avoid leaking the fallback timer
141142

143+
// Get the upper bound of the sleep duration from the environment, so we can
144+
// adjust it if the test machine is under heavy load, e.g. in CI or on a slow VM.
145+
// By default, we expect the sleep duration to be close to the requested 400ms.
146+
unsigned int expectedMaxDuration = 500u; // allow some slack for test machine load
147+
const char * maxDurationEnv = std::getenv("CHIP_TEST_EVENT_LOOP_HANDLER_MAX_DURATION_MS");
148+
if (maxDurationEnv != nullptr)
149+
{
150+
ChipLogDetail(Test, "CHIP_TEST_EVENT_LOOP_HANDLER_MAX_DURATION_MS=%s", maxDurationEnv);
151+
expectedMaxDuration = static_cast<unsigned int>(std::stoul(maxDurationEnv));
152+
}
153+
142154
Timestamp sleepDuration = loopHandler.wakeTimestamp - loopHandler.startTimestamp;
143155
EXPECT_GE(sleepDuration.count(), 400u); // loopHandler requested wake-up after 400ms
144-
EXPECT_LE(sleepDuration.count(), 500u); // allow some slack for test machine load
156+
EXPECT_LE(sleepDuration.count(), expectedMaxDuration);
145157
}
146158

147159
#endif // !CHIP_DEVICE_LAYER_TARGET_FAKE

src/test_driver/tizen/chip_tests/runner.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ set -e
2121
# Print CHIP logs on stdout
2222
dlogutil CHIP &
2323

24+
# Override the default value to account for slower execution on QEMU.
25+
export CHIP_TEST_EVENT_LOOP_HANDLER_MAX_DURATION_MS=1000
26+
2427
# Set the correct path for .gcda files
2528
export GCOV_PREFIX=/mnt/chip
2629
export GCOV_PREFIX_STRIP=5

0 commit comments

Comments
 (0)