19 #include <condition_variable>
24 #include <gtest/gtest.h>
34 TEST(AlarmTest, RegularExpiry) {
36 void* junk =
reinterpret_cast<void*
>(1618033);
50 TEST(AlarmTest, RegularExpiryMultiSet) {
52 void* junk =
reinterpret_cast<void*
>(1618033);
55 for (
int i = 0;
i < 3;
i++) {
69 TEST(AlarmTest, RegularExpiryMultiSetMultiCQ) {
70 void* junk =
reinterpret_cast<void*
>(1618033);
73 for (
int i = 0;
i < 3;
i++) {
89 bool completed =
false;
91 std::condition_variable
cv;
94 TEST(AlarmTest, CallbackRegularExpiry) {
97 auto c = std::make_shared<Completion>();
101 std::lock_guard<std::mutex>
l(
c->mu);
106 std::unique_lock<std::mutex>
l(
c->mu);
109 [c] { return c->completed; }));
112 TEST(AlarmTest, CallbackZeroExpiry) {
115 auto c = std::make_shared<Completion>();
118 std::lock_guard<std::mutex>
l(
c->mu);
123 std::unique_lock<std::mutex>
l(
c->mu);
126 [c] { return c->completed; }));
129 TEST(AlarmTest, CallbackNegativeExpiry) {
132 auto c = std::make_shared<Completion>();
136 std::lock_guard<std::mutex>
l(
c->mu);
141 std::unique_lock<std::mutex>
l(
c->mu);
144 [c] { return c->completed; }));
147 TEST(AlarmTest, MultithreadedRegularExpiry) {
149 void* junk =
reinterpret_cast<void*
>(1618033);
171 TEST(AlarmTest, DeprecatedRegularExpiry) {
173 void* junk =
reinterpret_cast<void*
>(1618033);
186 TEST(AlarmTest, MoveConstructor) {
188 void* junk =
reinterpret_cast<void*
>(1618033);
201 TEST(AlarmTest, MoveAssignment) {
203 void* junk =
reinterpret_cast<void*
>(1618033);
219 TEST(AlarmTest, RegularExpiryChrono) {
221 void* junk =
reinterpret_cast<void*
>(1618033);
225 alarm.Set(&
cq, one_sec_deadline, junk);
237 TEST(AlarmTest, ZeroExpiry) {
239 void* junk =
reinterpret_cast<void*
>(1618033);
253 TEST(AlarmTest, NegativeExpiry) {
255 void* junk =
reinterpret_cast<void*
>(1618033);
269 TEST(AlarmTest, Cancellation) {
271 void* junk =
reinterpret_cast<void*
>(1618033);
286 TEST(AlarmTest, CallbackCancellation) {
289 auto c = std::make_shared<Completion>();
293 std::lock_guard<std::mutex>
l(
c->mu);
299 std::unique_lock<std::mutex>
l(
c->mu);
302 [c] { return c->completed; }));
305 TEST(AlarmTest, CallbackCancellationLocked) {
308 auto c = std::make_shared<Completion>();
312 std::lock_guard<std::mutex>
l(
c->mu);
316 std::unique_lock<std::mutex>
l(
c->mu);
321 [c] { return c->completed; }));
324 TEST(AlarmTest, SetDestruction) {
326 void* junk =
reinterpret_cast<void*
>(1618033);
342 TEST(AlarmTest, CallbackSetDestruction) {
343 auto c = std::make_shared<Completion>();
349 std::lock_guard<std::mutex>
l(
c->mu);
355 std::unique_lock<std::mutex>
l(
c->mu);
358 [c] { return c->completed; }));
361 TEST(AlarmTest, UnsetDestruction) {
369 int main(
int argc,
char** argv) {