| 58 | static fl::atomic<bool> g_should_exit{false}; |
| 59 | |
| 60 | inline DWORD WINAPI watchdog_timer_thread(LPVOID param) { |
| 61 | double timeout_s = *static_cast<double*>(param); |
| 62 | DWORD sleep_time = static_cast<DWORD>(timeout_s * 1000.0); |
| 63 | |
| 64 | // Sleep for the timeout duration |
| 65 | // Note: WaitForSingleObject(GetCurrentThread(), ...) is incorrect here because |
| 66 | // GetCurrentThread() returns a pseudo-handle to the calling thread itself, |
| 67 | // so a thread waiting on itself never completes meaningfully. |
| 68 | Sleep(sleep_time); |
| 69 | |
| 70 | { |
| 71 | if (g_watchdog_active.load() && !g_should_exit.load()) { |
| 72 | // Timeout occurred! |
| 73 | g_watchdog_triggered.store(true); |
| 74 | |
| 75 | fprintf(stderr, "\n"); |
| 76 | fprintf(stderr, "================================================================================\n"); |
| 77 | fprintf(stderr, "INTERNAL TIMEOUT WATCHDOG TRIGGERED\n"); |
| 78 | fprintf(stderr, "================================================================================\n"); |
| 79 | fprintf(stderr, "Test exceeded internal timeout of %.1f seconds\n", g_timeout_seconds); |
| 80 | fprintf(stderr, "Dumping main thread stack trace...\n"); |
| 81 | fprintf(stderr, "================================================================================\n"); |
| 82 | fprintf(stderr, "\n"); |
| 83 | fflush(stderr); |
| 84 | |
| 85 | // Suspend main thread to get accurate stack trace |
| 86 | if (g_main_thread != nullptr) { |
| 87 | SuspendThread(g_main_thread); |
| 88 | } |
| 89 | |
| 90 | // Dump stack trace from main thread context |
| 91 | print_stacktrace(); |
| 92 | |
| 93 | // Resume and exit |
| 94 | if (g_main_thread != nullptr) { |
| 95 | ResumeThread(g_main_thread); |
| 96 | } |
| 97 | |
| 98 | fprintf(stderr, "\n"); |
| 99 | fprintf(stderr, "================================================================================\n"); |
| 100 | fprintf(stderr, "END TIMEOUT WATCHDOG\n"); |
| 101 | fprintf(stderr, "Exiting with code 1\n"); |
| 102 | fprintf(stderr, "================================================================================\n"); |
| 103 | fprintf(stderr, "\n"); |
| 104 | fflush(stderr); |
| 105 | |
| 106 | // Exit with code 1 |
| 107 | _exit(1); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | inline void setup(double timeout_seconds = 20.0) { |
| 115 | // Check if watchdog should be disabled |
nothing calls this directly
no test coverage detected