libhal / libhal-mock

Mocks, fakes, simulation and other testing utilities for libhal
Apache License 2.0
0 stars 1 forks source link

Add `hal::mock::stall_detector` #14

Open kammce opened 2 months ago

kammce commented 2 months ago

It should look like this:

hal::mock::stall_detector detector(10ms);

// Do the actions that may cause a stall to occur like polling a register or waiting a duration of time.
detector.operation_finished();

The stall detector should spawn a thread that waits the amount of time specified in the constructor. That thread should throw an exception if the operation_finished() has not been called in the amount of time specified. That thrown exception object is not accessible by the rest of the code ensuring that it terminates the test. It would also be good to take a std::source_location as well in order for the developer to know where the deadlock occurred in the code. Maybe even a stack trace as well from the termination site. The destructor should join the thread.

kammce commented 2 months ago

Should replace the kind of code hand written here:

https://github.com/libhal/libhal-soft/blob/main/tests/atomic_spin_lock.test.cpp#L132-L162