blob: 51a07c576b6dae9bae847392d589b6952b8fe6ac [file] [log] [blame]
Stefan Roese5be8f372022-09-02 13:57:54 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2022 Stefan Roese <sr@denx.de>
4 */
5
Stefan Roese5be8f372022-09-02 13:57:54 +02006#include <cyclic.h>
7#include <dm.h>
8#include <test/common.h>
9#include <test/test.h>
10#include <test/ut.h>
11#include <watchdog.h>
12#include <linux/delay.h>
13
14/* Test that cyclic function is called */
Rasmus Villemoesea36ada2024-05-21 10:46:52 +020015static struct cyclic_test {
16 struct cyclic_info cyclic;
17 bool called;
18} cyclic_test;
Stefan Roese5be8f372022-09-02 13:57:54 +020019
Rasmus Villemoesea36ada2024-05-21 10:46:52 +020020static void test_cb(struct cyclic_info *c)
Stefan Roese5be8f372022-09-02 13:57:54 +020021{
Rasmus Villemoesea36ada2024-05-21 10:46:52 +020022 struct cyclic_test *t = container_of(c, struct cyclic_test, cyclic);
23 t->called = true;
Stefan Roese5be8f372022-09-02 13:57:54 +020024}
25
26static int dm_test_cyclic_running(struct unit_test_state *uts)
27{
Rasmus Villemoesea36ada2024-05-21 10:46:52 +020028 cyclic_test.called = false;
29 cyclic_register(&cyclic_test.cyclic, test_cb, 10 * 1000, "cyclic_test");
Stefan Roese5be8f372022-09-02 13:57:54 +020030
31 /* Execute all registered cyclic functions */
Stefan Roese80877fa2022-09-02 14:10:46 +020032 schedule();
Rasmus Villemoesea36ada2024-05-21 10:46:52 +020033 ut_asserteq(true, cyclic_test.called);
34
35 cyclic_unregister(&cyclic_test.cyclic);
Stefan Roese5be8f372022-09-02 13:57:54 +020036
37 return 0;
38}
39COMMON_TEST(dm_test_cyclic_running, 0);