Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
watchdog_tests.cpp
Go to the documentation of this file.
1#include <sysio/vm/watchdog.hpp>
2#include <atomic>
3#include <chrono>
4
5#include <catch2/catch.hpp>
6
8
9TEST_CASE("watchdog interrupt", "[watchdog_interrupt]") {
10 std::atomic<bool> okay = false;
11 watchdog w{std::chrono::milliseconds(50)};
12 {
13 auto g = w.scoped_run([&]() { okay = true; });
14 std::this_thread::sleep_for(std::chrono::milliseconds(100));
15 }
16 CHECK(okay);
17}
18
19TEST_CASE("watchdog no interrupt", "[watchdog_no_interrupt]") {
20 std::atomic<bool> okay = true;
21 watchdog w{std::chrono::milliseconds(50)};
22 {
23 auto g = w.scoped_run([&]() { okay = false; });
24 } // the guard goes out of scope here, cancelling the timer
25 std::this_thread::sleep_for(std::chrono::milliseconds(100));
26 CHECK(okay);
27}
Triggers a callback after a given time elapses.
Definition watchdog.hpp:13
#define CHECK(cond)
Definition util.h:80
#define TEST_CASE(...)
Definition catch.hpp:222