| 14 | #include "platforms/stub/isr_stub.hpp" |
| 15 | |
| 16 | FL_TEST_FILE(FL_FILEPATH) { |
| 17 | |
| 18 | using namespace fl; |
| 19 | // Test counters |
| 20 | static fl::atomic<int> g_isr_call_count{0}; |
| 21 | static 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 |
| 30 | template<typename Predicate> |
| 31 | static 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 | |
| 61 | static 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 | |
| 73 | FL_TEST_CASE("test_isr_platform_info") { |
nothing calls this directly
no test coverage detected