diff --git a/tests/unittests/main.c b/tests/unittests/main.c index 23399752d5e7..8c6092b80bde 100644 --- a/tests/unittests/main.c +++ b/tests/unittests/main.c @@ -31,7 +31,7 @@ int main(void) ztimer_init(); #endif -#ifdef MODULE_XTIMER +#if IS_USED(MODULE_XTIMER) && !IS_USED(MODULE_ZTIMER_XTIMER_COMPAT) /* auto_init is disabled, but some modules depends on this module being initialized */ xtimer_init(); #endif diff --git a/tests/unittests/tests-zt/Makefile b/tests/unittests/tests-zt/Makefile new file mode 100644 index 000000000000..6c572ed15c17 --- /dev/null +++ b/tests/unittests/tests-zt/Makefile @@ -0,0 +1,6 @@ +# avoid clang warning in tests-ztimer/tests-ztimer-extend.c:141 +ifeq (llvm,$(TOOLCHAIN)) + CFLAGS += -Wno-gnu-folding-constant +endif + +include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/tests-zt/Makefile.include b/tests/unittests/tests-zt/Makefile.include new file mode 100644 index 000000000000..320a2283c268 --- /dev/null +++ b/tests/unittests/tests-zt/Makefile.include @@ -0,0 +1,2 @@ +USEMODULE += ztimer_core +USEMODULE += ztimer_msec diff --git a/tests/unittests/tests-zt/tests-zt.c b/tests/unittests/tests-zt/tests-zt.c new file mode 100644 index 000000000000..78fb61e720e9 --- /dev/null +++ b/tests/unittests/tests-zt/tests-zt.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2022 K F + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @{ + * + * @file + * @brief Unittest entry point for the zt test group + * + * @author kfessel + */ +#include +#include +#include +#include "embUnit/embUnit.h" + +#include "tests-zt.h" + +void zt_sleep(void){ + uint32_t start = ztimer_now(ZTIMER_MSEC); + puts( "will sleep"); + ztimer_sleep(ZTIMER_MSEC,2000); + puts( "done sleep"); + uint32_t end = ztimer_now(ZTIMER_MSEC); + TEST_ASSERT_EQUAL_INT(2000, end - start); + +} + +Test * tests_zt_test(void){ + + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture(zt_sleep) + }; + + EMB_UNIT_TESTCALLER(zt_tests, NULL, NULL, fixtures); + + return (Test *)&zt_tests; +} + +void tests_zt(void) +{ + TESTS_RUN(tests_zt_test()); + +} +/** @} */ diff --git a/tests/unittests/tests-zt/tests-zt.h b/tests/unittests/tests-zt/tests-zt.h new file mode 100644 index 000000000000..1f2718f2893a --- /dev/null +++ b/tests/unittests/tests-zt/tests-zt.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 K F + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @addtogroup unittests + * @{ + * + * @file + * @brief Unittests for zt + * + * @author kfessel + */ +#ifndef TESTS_ZT_H +#define TESTS_ZT_H + +#include "embUnit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The entry point of this test suite. + */ +void tests_zt(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TESTS_ZT_H */ +/** @} */