| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | /* | |||
| 2 | * @file test_periodic_thread_controller.cpp | |||
| 3 | * | |||
| 4 | * May 14, 2021 | |||
| 5 | * @author Andrey Belomutskiy, (c) 2012-2021 | |||
| 6 | */ | |||
| 7 | ||||
| 8 | #include "pch.h" | |||
| 9 | ||||
| 10 | #include "periodic_thread_controller.h" | |||
| 11 | #include <thread> | |||
| 12 | ||||
| 13 | class TestPeriodicController : public PeriodicController<111> { | |||
| 14 | public: | |||
| 15 | 1 | TestPeriodicController() : PeriodicController("test") { } | ||
| 16 | private: | |||
| 17 | ✗ | void PeriodicTask(efitick_t nowNt) override { | ||
| 18 | UNUSED(nowNt); | |||
| 19 | ✗ | } | ||
| 20 | }; | |||
| 21 | ||||
| 22 | static TestPeriodicController instance; | |||
| 23 | ||||
| 24 | ✗ | systime_t chVTGetSystemTime(void) { | ||
| 25 | ✗ | return getTimeNowUs(); | ||
| 26 | } | |||
| 27 | ||||
| 28 | ✗ | systime_t chThdSleepUntilWindowed(systime_t prev, systime_t next) { | ||
| 29 | ✗ | return 0; | ||
| 30 | } | |||
| 31 | ||||
| 32 | ✗ | bool chThdShouldTerminateX(void) { | ||
| 33 | ✗ | return false; | ||
| 34 | } | |||
| 35 | ||||
| 36 | class taskq { | |||
| 37 | public: | |||
| 38 | // int trigger(taskq &tq); | |||
| 39 | // mutex mtx; | |||
| 40 | }; | |||
| 41 | ||||
| 42 | ||||
| 43 | ✗ | void func_wrapper(taskq &tq) { | ||
| 44 | ||||
| 45 | ✗ | } | ||
| 46 | ||||
| 47 | ✗ | thread_t *chThdCreateStatic(void *wsp, size_t size, | ||
| 48 | tprio_t prio, tfunc_t funcp, void *arg) { | |||
| 49 | ||||
| 50 | ✗ | taskq insta; | ||
| 51 | ||||
| 52 | ✗ | taskq &tq = insta; | ||
| 53 | /** | |||
| 54 | * I do not understand what's going on here. Do allocate thread on stack and that would crash once method is over? | |||
| 55 | * how do we dynamically create new std::thread? | |||
| 56 | */ | |||
| 57 | ||||
| 58 | ✗ | std::thread thr(func_wrapper, std::ref(tq)); | ||
| 59 | ||||
| 60 | ✗ | thread_t *thread = new thread_t(); | ||
| 61 | ✗ | thread->funcp = funcp; | ||
| 62 | ✗ | thread->arg = arg; | ||
| 63 | ✗ | return thread; | ||
| 64 | ||||
| 65 | ✗ | } | ||
| 66 | ||||
| 67 | /* this test was comented on 2021 for this error: | |||
| 68 | * ../firmware/controllers/system/thread_controller.h:53:29: error: no match for ‘operator=’ (operand types are ‘chibios_rt::ThreadReference’ and ‘void’) | |||
| 69 | * ref = chibios_rt::BaseStaticThread<TStackSize>::start(m_prio); | |||
| 70 | */ | |||
| 71 | 4 | TEST(system, periodic) { | ||
| 72 | // instance.Start(); | |||
| 73 | 1 | } | ||
| 74 |