1
1
#include < lockstep_scheduler/lockstep_scheduler.h>
2
- #include < cassert >
2
+ #include < gtest/gtest.h >
3
3
#include < thread>
4
4
#include < atomic>
5
5
#include < random>
@@ -48,7 +48,7 @@ void test_absolute_time()
48
48
{
49
49
LockstepScheduler ls;
50
50
ls.set_absolute_time (some_time_us);
51
- assert (ls.get_absolute_time () == some_time_us);
51
+ EXPECT_EQ (ls.get_absolute_time (), some_time_us);
52
52
}
53
53
54
54
void test_condition_timing_out ()
@@ -70,10 +70,10 @@ void test_condition_timing_out()
70
70
// Use a thread to wait for condition while we already have the lock.
71
71
// This ensures the synchronization happens in the right order.
72
72
TestThread thread ([&ls, &cond, &lock, &should_have_timed_out]() {
73
- assert (ls.cond_timedwait (&cond, &lock, some_time_us + 1000 ) == ETIMEDOUT);
74
- assert (should_have_timed_out);
73
+ EXPECT_EQ (ls.cond_timedwait (&cond, &lock, some_time_us + 1000 ), ETIMEDOUT);
74
+ EXPECT_TRUE (should_have_timed_out);
75
75
// It should be re-locked afterwards, so we should be able to unlock it.
76
- assert (pthread_mutex_unlock (&lock) == 0 );
76
+ EXPECT_EQ (pthread_mutex_unlock (&lock), 0 );
77
77
});
78
78
79
79
ls.set_absolute_time (some_time_us + 500 );
@@ -106,9 +106,9 @@ void test_locked_semaphore_getting_unlocked()
106
106
TestThread thread ([&ls, &cond, &lock]() {
107
107
108
108
ls.set_absolute_time (some_time_us + 500 );
109
- assert (ls.cond_timedwait (&cond, &lock, some_time_us + 1000 ) == 0 );
109
+ EXPECT_EQ (ls.cond_timedwait (&cond, &lock, some_time_us + 1000 ), 0 );
110
110
// It should be re-locked afterwards, so we should be able to unlock it.
111
- assert (pthread_mutex_unlock (&lock) == 0 );
111
+ EXPECT_EQ (pthread_mutex_unlock (&lock), 0 );
112
112
});
113
113
114
114
pthread_mutex_lock (&lock);
@@ -135,7 +135,7 @@ class TestCase
135
135
136
136
~TestCase ()
137
137
{
138
- assert (_is_done);
138
+ EXPECT_TRUE (_is_done);
139
139
pthread_mutex_destroy (&_lock);
140
140
pthread_cond_destroy (&_cond);
141
141
}
@@ -168,13 +168,13 @@ class TestCase
168
168
_is_done = true ;
169
169
// We can be sure that this triggers.
170
170
_thread->join (_ls);
171
- assert (_result == 0 );
171
+ EXPECT_EQ (_result, 0 );
172
172
}
173
173
174
174
else if (timeout_reached) {
175
175
_is_done = true ;
176
176
_thread->join (_ls);
177
- assert (_result == ETIMEDOUT);
177
+ EXPECT_EQ (_result, ETIMEDOUT);
178
178
}
179
179
}
180
180
private:
@@ -302,21 +302,19 @@ void test_usleep()
302
302
303
303
step = Step::BeforeUsleep;
304
304
305
- assert (ls.usleep_until (some_time_us + 1000 ) == 0 );
306
- assert (step == Step::UsleepTriggered);
305
+ EXPECT_EQ (ls.usleep_until (some_time_us + 1000 ), 0 );
306
+ EXPECT_EQ (step, Step::UsleepTriggered);
307
307
thread.join (ls);
308
308
}
309
309
310
- int main ( int /* argc */ , char ** /* argv */ )
310
+ TEST (LockstepScheduler, All )
311
311
{
312
- for (unsigned iteration = 1 ; iteration <= 10000 ; ++iteration) {
313
- std::cout << " Test iteration: " << iteration << " \n " ;
312
+ for (unsigned iteration = 1 ; iteration <= 100 ; ++iteration) {
313
+ // std::cout << "Test iteration: " << iteration << "\n";
314
314
test_absolute_time ();
315
315
test_condition_timing_out ();
316
316
test_locked_semaphore_getting_unlocked ();
317
317
test_usleep ();
318
318
test_multiple_semaphores_waiting ();
319
319
}
320
-
321
- return 0 ;
322
320
}
0 commit comments