On Tue, 16 Aug 2022 at 04:28, Stefan Roese <s...@denx.de> wrote: > > Add a test for cyclic function registration and activation. > > Signed-off-by: Stefan Roese <s...@denx.de> > --- > v4: > - New patch > > test/common/Makefile | 1 + > test/common/cyclic.c | 31 +++++++++++++++++++++++++++++++ > test/test-main.c | 3 +++ > 3 files changed, 35 insertions(+) > create mode 100644 test/common/cyclic.c
Reviewed-by: Simon Glass <s...@chromium.org> > > diff --git a/test/common/Makefile b/test/common/Makefile > index 9087788ba6a8..cc918f64e544 100644 > --- a/test/common/Makefile > +++ b/test/common/Makefile > @@ -1,4 +1,5 @@ > # SPDX-License-Identifier: GPL-2.0+ > obj-y += cmd_ut_common.o > obj-$(CONFIG_AUTOBOOT) += test_autoboot.o > +obj-$(CONFIG_CYCLIC) += cyclic.o > obj-$(CONFIG_EVENT) += event.o > diff --git a/test/common/cyclic.c b/test/common/cyclic.c > new file mode 100644 > index 000000000000..58f1603137e9 > --- /dev/null > +++ b/test/common/cyclic.c > @@ -0,0 +1,31 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Copyright (C) 2022 Stefan Roese <s...@denx.de> > + */ > + > +#include <common.h> > +#include <cyclic.h> > +#include <dm.h> > +#include <dm/test.h> > +#include <test/test.h> > +#include <test/ut.h> > +#include <linux/delay.h> > + > +/* Test that cyclic function is called */ > +static bool cyclic_active = false; > + > +static void cyclic_test(void *ctx) > +{ > + cyclic_active = true; > +} > + > +static int dm_test_cyclic_running(struct unit_test_state *uts) > +{ cyclic_active = false; (since tests can be re-run) > + ut_assertnonnull(cyclic_register(cyclic_test, 10 * 1000, > "cyclic_demo", > + NULL)); > + mdelay(100); Instead of the delay, can you use WATCHDOG_RESET() ? This is the first think udelay() does, after all. It doesn't test as much code, but it does avoid a delay in the tests (which slows them down). > + ut_asserteq(true, cyclic_active); > + > + return 0; > +} > +DM_TEST(dm_test_cyclic_running, 0); For this directory it should be COMMON_TEST() - see event.c > diff --git a/test/test-main.c b/test/test-main.c > index 31837e57a8fb..8a609a8a2fce 100644 > --- a/test/test-main.c > +++ b/test/test-main.c > @@ -6,6 +6,7 @@ > > #include <common.h> > #include <console.h> > +#include <cyclic.h> > #include <dm.h> > #include <event.h> > #include <dm/root.h> > @@ -220,6 +221,7 @@ static int dm_test_restore(struct device_node *of_root) > static int test_pre_run(struct unit_test_state *uts, struct unit_test *test) > { > ut_assertok(event_init()); > + ut_assertok(cyclic_init()); > > if (test->flags & UT_TESTF_DM) > ut_assertok(dm_test_pre_run(uts)); > @@ -265,6 +267,7 @@ static int test_post_run(struct unit_test_state *uts, > struct unit_test *test) > ut_unsilence_console(uts); > if (test->flags & UT_TESTF_DM) > ut_assertok(dm_test_post_run(uts)); > + ut_assertok(cyclic_uninit()); > ut_assertok(event_uninit()); > > return 0; > -- > 2.37.2 > Regards, Simon