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

Function FL_TEST_FILE

tests/fl/stl/isr.cpp:16–380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14#include "platforms/stub/isr_stub.hpp"
15
16FL_TEST_FILE(FL_FILEPATH) {
17
18using namespace fl;
19// Test counters
20static fl::atomic<int> g_isr_call_count{0};
21static fl::atomic<uint32_t> g_isr_user_data_value{0};
22
23// =============================================================================
24// Helper Functions for Timing-Dependent Tests
25// =============================================================================
26
27// Wait for a condition to become true with timeout using condition variables
28// This is more efficient and reliable than sleep polling under heavy load
29// Returns true if condition met, false if timeout
30template<typename Predicate>
31static bool wait_for_condition(Predicate pred, std::chrono::milliseconds timeout) { // okay std namespace
32 if (pred()) {
33 return true; // Already satisfied
34 }
35
36 // Get access to the test synchronization primitives from the timer manager
37 auto& manager = fl::isr::TimerThreadManager::instance();
38 fl::unique_lock<fl::mutex> lock(manager.get_test_sync_mutex());
39
40 auto deadline = std::chrono::steady_clock::now() + timeout; // okay std namespace
41
42 while (!pred()) {
43 auto now = std::chrono::steady_clock::now(); // okay std namespace
44 if (now >= deadline) {
45 return false; // Timeout
46 }
47
48 // Wait on condition variable with remaining timeout
49 // This will be notified whenever an ISR executes
50 auto remaining = std::chrono::duration_cast<std::chrono::milliseconds>(deadline - now); // okay std namespace
51 manager.get_test_sync_cv().wait_for(lock, remaining);
52 }
53
54 return true; // Condition met
55}
56
57// =============================================================================
58// Test Handlers
59// =============================================================================
60
61static void test_isr_handler(void* user_data) {
62 ++g_isr_call_count;
63 if (user_data) {
64 uint32_t* value = static_cast<uint32_t*>(user_data);
65 g_isr_user_data_value = *value;
66 }
67}
68
69// =============================================================================
70// Test Cases
71// =============================================================================
72
73FL_TEST_CASE("test_isr_platform_info") {

Callers

nothing calls this directly

Calls 15

wait_for_conditionFunction · 0.85
interruptsEnabledFunction · 0.85
interruptsDisabledFunction · 0.85
get_platform_nameFunction · 0.50
get_max_timer_frequencyFunction · 0.50
get_min_timer_frequencyFunction · 0.50
get_max_priorityFunction · 0.50
attach_timer_handlerFunction · 0.50
detach_handlerFunction · 0.50
disable_handlerFunction · 0.50
is_handler_enabledFunction · 0.50

Tested by

no test coverage detected