Skip to content

Commit

Permalink
cyclic: Add a simple test
Browse files Browse the repository at this point in the history
Add a test for cyclic function registration and activation.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
  • Loading branch information
stroese authored and trini committed Sep 13, 2022
1 parent 00275f5 commit af042c2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/common/Makefile
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions test/common/cyclic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2022 Stefan Roese <sr@denx.de>
*/

#include <common.h>
#include <cyclic.h>
#include <dm.h>
#include <test/common.h>
#include <test/test.h>
#include <test/ut.h>
#include <watchdog.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;
ut_assertnonnull(cyclic_register(cyclic_test, 10 * 1000, "cyclic_demo",
NULL));

/* Execute all registered cyclic functions */
WATCHDOG_RESET();
ut_asserteq(true, cyclic_active);

return 0;
}
COMMON_TEST(dm_test_cyclic_running, 0);
3 changes: 3 additions & 0 deletions test/test-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <common.h>
#include <console.h>
#include <cyclic.h>
#include <dm.h>
#include <event.h>
#include <dm/root.h>
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit af042c2

Please sign in to comment.