diff --git a/common/tests/CMakeLists.txt b/common/tests/CMakeLists.txt index 27a190988..9c5dd56b3 100644 --- a/common/tests/CMakeLists.txt +++ b/common/tests/CMakeLists.txt @@ -22,7 +22,6 @@ add_executable(unit-tests-common logging.cpp - advio.cpp json_buffer.cpp bitset.cpp @@ -31,7 +30,6 @@ add_executable(unit-tests-common hist.cpp kernel.cpp list.cpp - log.cpp task.cpp timing.cpp tsc.cpp diff --git a/common/tests/list.cpp b/common/tests/list.cpp index b5c503aba..cf2cd16af 100644 --- a/common/tests/list.cpp +++ b/common/tests/list.cpp @@ -118,10 +118,6 @@ Test(list, destructor) cr_assert_eq(elm.destroyed, 1); } -static int compare(const void *a, const void *b) { - return (intptr_t) b - (intptr_t) a; -} - Test(list, basics) { uintptr_t i; @@ -147,13 +143,13 @@ Test(list, basics) cr_assert_eq(k, (void *) i++); } - list_sort(&l, compare); /* Reverse list */ + list_sort(&l, (cmp_cb_t) [](const void *a, const void *b) -> int { + return (intptr_t) b - (intptr_t) a; + }); - for (size_t j = 0, i = 99; j < list_length(&l); j++) { - void *k = list_at(&l, j); - - cr_assert_eq(k, (void *) i, "Is %#zx, expected %p", i, k); - i--; + for (size_t j = 0, i = 99; j <= 99; j++, i--) { + uintptr_t k = (uintptr_t) list_at(&l, j); + cr_assert_eq(k, i, "Is %zu, expected %zu", k, i); } ret = list_contains(&l, (void *) 55); @@ -164,7 +160,8 @@ Test(list, basics) ret = list_contains(&l, (void *) 55); cr_assert(!ret); - list_destroy(&l, nullptr, false); + ret = list_destroy(&l, nullptr, false); + cr_assert(!ret); ret = list_length(&l); cr_assert_eq(ret, -1, "List not properly destroyed: l.length = %zd", l.length); diff --git a/common/tests/timing.cpp b/common/tests/timing.cpp index 1d989eb2d..fd0d58f08 100644 --- a/common/tests/timing.cpp +++ b/common/tests/timing.cpp @@ -33,10 +33,7 @@ Test(timing, time_now) struct timespec now1 = time_now(); struct timespec now2 = time_now(); - double delta = time_delta(&now1, &now2); - - cr_assert_float_eq(delta, 0, 1e-5, "time_now() shows large variance!"); - cr_assert_gt(delta, 0, "time_now() was reordered!"); + cr_assert(time_cmp(&now1, &now2) <= 0, "time_now() was reordered!"); } Test(timing, time_diff)