| 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 |
no test coverage detected