1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/cpp11_condition_variable: Use ztimer64_usec instead of xtimer

This commit is contained in:
MrKevinWeiss 2023-03-09 14:00:31 +01:00
parent 4f6448ed05
commit 8e7407e5f6
No known key found for this signature in database
GPG Key ID: 4B69974722CBEEAE
3 changed files with 14 additions and 14 deletions

View File

@ -7,7 +7,6 @@ ifneq (,$(filter nucleo-f303k8 nucleo-f334r8,$(BOARD)))
endif
USEMODULE += cpp11-compat
USEMODULE += xtimer
USEMODULE += timex
USEMODULE += ztimer64_usec
include $(RIOTBASE)/Makefile.include

View File

@ -1,3 +1,2 @@
CONFIG_MODULE_CPP11-COMPAT=y
CONFIG_MODULE_TIMEX=y
CONFIG_MODULE_XTIMER=y
CONFIG_ZTIMER64_USEC=y

View File

@ -22,6 +22,8 @@
#include <cstdio>
#include <system_error>
#include "time_units.h"
#include "ztimer64.h"
#include "riot/mutex.hpp"
#include "riot/chrono.hpp"
#include "riot/thread.hpp"
@ -95,13 +97,13 @@ int main() {
constexpr unsigned timeout = 1;
mutex m;
condition_variable cv;
timex_t before, after;
uint64_t before, after;
unique_lock<mutex> lk(m);
xtimer_now_timex(&before);
before = ztimer64_now(ZTIMER64_USEC);
cv.wait_for(lk, chrono::seconds(timeout));
xtimer_now_timex(&after);
auto diff = timex_sub(after, before);
expect(diff.seconds >= timeout);
after = ztimer64_now(ZTIMER64_USEC);
auto diff = after - before;
expect(diff >= timeout * US_PER_SEC);
}
puts("Done\n");
@ -111,14 +113,14 @@ int main() {
constexpr unsigned timeout = 1;
mutex m;
condition_variable cv;
timex_t before, after;
uint64_t before, after;
unique_lock<mutex> lk(m);
xtimer_now_timex(&before);
before = ztimer64_now(ZTIMER64_USEC);
auto time = riot::now() += chrono::seconds(timeout);
cv.wait_until(lk, time);
xtimer_now_timex(&after);
auto diff = timex_sub(after, before);
expect(diff.seconds >= timeout);
after = ztimer64_now(ZTIMER64_USEC);
auto diff = after - before;
expect(diff >= timeout * US_PER_SEC);
}
puts("Done\n");