Stefan Roese | 5be8f37 | 2022-09-02 13:57:54 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2022 Stefan Roese <sr@denx.de> |
| 4 | */ |
| 5 | |
Stefan Roese | 5be8f37 | 2022-09-02 13:57:54 +0200 | [diff] [blame] | 6 | #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 Villemoes | ea36ada | 2024-05-21 10:46:52 +0200 | [diff] [blame] | 15 | static struct cyclic_test { |
| 16 | struct cyclic_info cyclic; |
| 17 | bool called; |
| 18 | } cyclic_test; |
Stefan Roese | 5be8f37 | 2022-09-02 13:57:54 +0200 | [diff] [blame] | 19 | |
Rasmus Villemoes | ea36ada | 2024-05-21 10:46:52 +0200 | [diff] [blame] | 20 | static void test_cb(struct cyclic_info *c) |
Stefan Roese | 5be8f37 | 2022-09-02 13:57:54 +0200 | [diff] [blame] | 21 | { |
Rasmus Villemoes | ea36ada | 2024-05-21 10:46:52 +0200 | [diff] [blame] | 22 | struct cyclic_test *t = container_of(c, struct cyclic_test, cyclic); |
| 23 | t->called = true; |
Stefan Roese | 5be8f37 | 2022-09-02 13:57:54 +0200 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | static int dm_test_cyclic_running(struct unit_test_state *uts) |
| 27 | { |
Rasmus Villemoes | ea36ada | 2024-05-21 10:46:52 +0200 | [diff] [blame] | 28 | cyclic_test.called = false; |
| 29 | cyclic_register(&cyclic_test.cyclic, test_cb, 10 * 1000, "cyclic_test"); |
Stefan Roese | 5be8f37 | 2022-09-02 13:57:54 +0200 | [diff] [blame] | 30 | |
| 31 | /* Execute all registered cyclic functions */ |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 32 | schedule(); |
Rasmus Villemoes | ea36ada | 2024-05-21 10:46:52 +0200 | [diff] [blame] | 33 | ut_asserteq(true, cyclic_test.called); |
| 34 | |
| 35 | cyclic_unregister(&cyclic_test.cyclic); |
Stefan Roese | 5be8f37 | 2022-09-02 13:57:54 +0200 | [diff] [blame] | 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | COMMON_TEST(dm_test_cyclic_running, 0); |