watchdog: add

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman
2023-10-01 23:05:54 +02:00
parent 06a896ccf6
commit 67d328a550
6 changed files with 132 additions and 1 deletions

32
UnitTests/watchdog.cpp Normal file
View File

@@ -0,0 +1,32 @@
/*
SPDX-License-Identifier: MIT
Copyright © 2023 Amebis
*/
#include "pch.hpp"
using namespace std;
#ifdef _WIN32
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
#endif
namespace UnitTests
{
TEST_CLASS(watchdog)
{
public:
TEST_METHOD(test)
{
volatile bool wd_called = false;
stdex::watchdog<std::chrono::steady_clock> wd(
std::chrono::milliseconds(100), [&] { wd_called = true; });
for (int i = 0; i < 100; ++i) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
Assert::IsFalse(wd_called);
wd.reset();
}
std::this_thread::sleep_for(std::chrono::milliseconds(300));
Assert::IsTrue(wd_called);
}
};
}