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

Function FL_TEST_FILE

tests/fl/stl/semaphore.cpp:16–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14#include "fl/stl/vector.h"
15
16FL_TEST_FILE(FL_FILEPATH) {
17
18
19#if FASTLED_MULTITHREADED
20
21FL_TEST_CASE("fl::counting_semaphore basic operations") {
22 FL_SUBCASE("acquire and release single resource") {
23 fl::counting_semaphore<5> sem(1);
24
25 // Acquire the resource
26 sem.acquire();
27
28 // Try acquire should fail (count is 0)
29 FL_CHECK(sem.try_acquire() == false);
30
31 // Release the resource
32 sem.release();
33
34 // Now try_acquire should succeed
35 FL_CHECK(sem.try_acquire() == true);
36 }
37
38 FL_SUBCASE("multiple acquire and release") {
39 fl::counting_semaphore<10> sem(3);
40
41 // Acquire all 3 resources
42 sem.acquire();
43 sem.acquire();
44 sem.acquire();
45
46 // Try acquire should fail (count is 0)
47 FL_CHECK(sem.try_acquire() == false);
48
49 // Release 2 resources
50 sem.release(2);
51
52 // Now we should be able to acquire 2
53 FL_CHECK(sem.try_acquire() == true);
54 FL_CHECK(sem.try_acquire() == true);
55 FL_CHECK(sem.try_acquire() == false);
56 }
57
58 FL_SUBCASE("max() returns correct value") {
59 fl::counting_semaphore<42> sem(0);
60 FL_CHECK(sem.max() == 42);
61 }
62}
63
64FL_TEST_CASE("fl::binary_semaphore basic operations") {
65 FL_SUBCASE("binary semaphore as simple flag") {
66 fl::binary_semaphore sem(0);
67
68 // Initially unavailable
69 FL_CHECK(sem.try_acquire() == false);
70
71 // Signal
72 sem.release();
73

Callers

nothing calls this directly

Calls 14

sleep_forFunction · 0.50
delayFunction · 0.50
acquireMethod · 0.45
try_acquireMethod · 0.45
releaseMethod · 0.45
maxMethod · 0.45
fetch_addMethod · 0.45
loadMethod · 0.45
push_backMethod · 0.45
compare_exchange_weakMethod · 0.45
fetch_subMethod · 0.45
try_acquire_forMethod · 0.45

Tested by

no test coverage detected