MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/platforms/coroutine.cpp:23–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21#include "fl/system/engine_events.h"
22
23FL_TEST_FILE(FL_FILEPATH) {
24
25using namespace fl;
26using fl::task::CoroutineConfig;
27using fl::task::run;
28using fl::task::Scheduler;
29
30// ============================================================
31// Level 1: Binary semaphore tests
32// ============================================================
33
34FL_TEST_CASE("coroutine - binary semaphore basic signal") {
35 fl::binary_semaphore sem(0);
36 FL_CHECK_FALSE(sem.try_acquire());
37 sem.release();
38 FL_CHECK(sem.try_acquire());
39 FL_CHECK_FALSE(sem.try_acquire());
40}
41
42FL_TEST_CASE("coroutine - binary semaphore thread handoff") {
43 fl::binary_semaphore sem(0);
44 fl::atomic<bool> thread_ran(false);
45
46 fl::thread t([&]() {
47 sem.acquire();
48 thread_ran.store(true);
49 });
50
51 fl::this_thread::sleep_for(fl::chrono::milliseconds(10)); // ok sleep for
52 FL_CHECK_FALSE(thread_ran.load());
53
54 sem.release();
55 t.join();
56 FL_CHECK(thread_ran.load());
57}
58
59FL_TEST_CASE("coroutine - counting semaphore two-phase handoff") {
60 fl::counting_semaphore<2> sem(0);
61 fl::atomic<int> phase(0);
62
63 fl::thread t([&]() {
64 phase.store(1);
65 sem.release(); // Signal "started"
66
67 // Simulate work
68 fl::this_thread::sleep_for(fl::chrono::milliseconds(5)); // ok sleep for
69
70 phase.store(2);
71 sem.release(); // Signal "done"
72 });
73
74 sem.acquire(); // Wait for "started"
75 FL_CHECK_EQ(phase.load(), 1);
76
77 sem.acquire(); // Wait for "done"
78 FL_CHECK_EQ(phase.load(), 2);
79
80 t.join();

Callers

nothing calls this directly

Calls 11

coroutineFunction · 0.85
isCoroutineMethod · 0.80
sleep_forFunction · 0.50
runFunction · 0.50
delayFunction · 0.50
try_acquireMethod · 0.45
releaseMethod · 0.45
acquireMethod · 0.45
storeMethod · 0.45
loadMethod · 0.45
fetch_addMethod · 0.45

Tested by

no test coverage detected