diff --git a/repos/os/src/test/timeout/main.cc b/repos/os/src/test/timeout/main.cc index 864253652c..d3b5cfb1f5 100644 --- a/repos/os/src/test/timeout/main.cc +++ b/repos/os/src/test/timeout/main.cc @@ -95,6 +95,51 @@ struct Test }; +struct Lock_test : Test +{ + static constexpr char const *brief = "Test locks in handlers"; + + bool stop { false }; + Microseconds us { 1000 }; + Lock lock { }; + Timer::One_shot_timeout ot1 { timer, *this, &Lock_test::handle_ot1 }; + Timer::One_shot_timeout ot2 { timer, *this, &Lock_test::handle_ot2 }; + Timer::One_shot_timeout ot3 { timer, *this, &Lock_test::handle_ot3 }; + + Lock_test(Env &env, + unsigned &error_cnt, + Signal_context_capability done, + unsigned id) + : + Test(env, error_cnt, done, id, brief) + { + ot1.schedule(us); + ot2.schedule(us); + ot3.schedule(us); + } + + void handle(Timer::One_shot_timeout &ot) + { + if (stop) + return; + + if (!us.value) { + log("good"); + done.submit(); + stop = true; + return; + } + Lock_guard lock_guard(lock); + us.value--; + ot.schedule(us); + } + + void handle_ot1(Duration) { handle(ot1); } + void handle_ot2(Duration) { handle(ot2); } + void handle_ot3(Duration) { handle(ot3); } +}; + + struct Duration_test : Test { static constexpr char const *brief = "Test operations on durations"; @@ -776,15 +821,23 @@ struct Main { Env &env; unsigned error_cnt { 0 }; + Constructible test_0 { }; Constructible test_1 { }; Constructible test_2 { }; Constructible test_3 { }; + Signal_handler
test_0_done { env.ep(), *this, &Main::handle_test_0_done }; Signal_handler
test_1_done { env.ep(), *this, &Main::handle_test_1_done }; Signal_handler
test_2_done { env.ep(), *this, &Main::handle_test_2_done }; Signal_handler
test_3_done { env.ep(), *this, &Main::handle_test_3_done }; Main(Env &env) : env(env) { + test_0.construct(env, error_cnt, test_0_done, 0); + } + + void handle_test_0_done() + { + test_0.destruct(); test_1.construct(env, error_cnt, test_1_done, 1); }