2016-02-22 03:25:02 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
2017-01-20 13:41:41 +08:00
|
|
|
#define BILLION UINT64_C(1000000000)
|
2016-02-22 03:25:02 +08:00
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_nstime_init) {
|
2016-02-22 03:25:02 +08:00
|
|
|
nstime_t nst;
|
|
|
|
|
|
|
|
nstime_init(&nst, 42000000043);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_u64_eq(nstime_ns(&nst), 42000000043, "ns incorrectly read");
|
|
|
|
expect_u64_eq(nstime_sec(&nst), 42, "sec incorrectly read");
|
|
|
|
expect_u64_eq(nstime_nsec(&nst), 43, "nsec incorrectly read");
|
2016-02-22 03:25:02 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_nstime_init2) {
|
2016-02-22 03:25:02 +08:00
|
|
|
nstime_t nst;
|
|
|
|
|
|
|
|
nstime_init2(&nst, 42, 43);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_u64_eq(nstime_sec(&nst), 42, "sec incorrectly read");
|
|
|
|
expect_u64_eq(nstime_nsec(&nst), 43, "nsec incorrectly read");
|
2016-02-22 03:25:02 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_nstime_copy) {
|
2016-02-22 03:25:02 +08:00
|
|
|
nstime_t nsta, nstb;
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 43);
|
2019-12-17 04:41:06 +08:00
|
|
|
nstime_init_zero(&nstb);
|
2016-02-22 03:25:02 +08:00
|
|
|
nstime_copy(&nstb, &nsta);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_u64_eq(nstime_sec(&nstb), 42, "sec incorrectly copied");
|
|
|
|
expect_u64_eq(nstime_nsec(&nstb), 43, "nsec incorrectly copied");
|
2016-02-22 03:25:02 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_nstime_compare) {
|
2016-02-22 03:25:02 +08:00
|
|
|
nstime_t nsta, nstb;
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 43);
|
|
|
|
nstime_copy(&nstb, &nsta);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 0, "Times should be equal");
|
|
|
|
expect_d_eq(nstime_compare(&nstb, &nsta), 0, "Times should be equal");
|
2016-02-22 03:25:02 +08:00
|
|
|
|
|
|
|
nstime_init2(&nstb, 42, 42);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 1,
|
2016-02-22 03:25:02 +08:00
|
|
|
"nsta should be greater than nstb");
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nstb, &nsta), -1,
|
2016-02-22 03:25:02 +08:00
|
|
|
"nstb should be less than nsta");
|
|
|
|
|
|
|
|
nstime_init2(&nstb, 42, 44);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), -1,
|
2016-02-22 03:25:02 +08:00
|
|
|
"nsta should be less than nstb");
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nstb, &nsta), 1,
|
2016-02-22 03:25:02 +08:00
|
|
|
"nstb should be greater than nsta");
|
|
|
|
|
|
|
|
nstime_init2(&nstb, 41, BILLION - 1);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 1,
|
2016-02-22 03:25:02 +08:00
|
|
|
"nsta should be greater than nstb");
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nstb, &nsta), -1,
|
2016-02-22 03:25:02 +08:00
|
|
|
"nstb should be less than nsta");
|
|
|
|
|
|
|
|
nstime_init2(&nstb, 43, 0);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), -1,
|
2016-02-22 03:25:02 +08:00
|
|
|
"nsta should be less than nstb");
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nstb, &nsta), 1,
|
2016-02-22 03:25:02 +08:00
|
|
|
"nstb should be greater than nsta");
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_nstime_add) {
|
2016-02-22 03:25:02 +08:00
|
|
|
nstime_t nsta, nstb;
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 43);
|
|
|
|
nstime_copy(&nstb, &nsta);
|
|
|
|
nstime_add(&nsta, &nstb);
|
|
|
|
nstime_init2(&nstb, 84, 86);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 0,
|
2016-02-22 03:25:02 +08:00
|
|
|
"Incorrect addition result");
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, BILLION - 1);
|
|
|
|
nstime_copy(&nstb, &nsta);
|
|
|
|
nstime_add(&nsta, &nstb);
|
|
|
|
nstime_init2(&nstb, 85, BILLION - 2);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 0,
|
2016-02-22 03:25:02 +08:00
|
|
|
"Incorrect addition result");
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2017-05-13 03:30:33 +08:00
|
|
|
TEST_BEGIN(test_nstime_iadd) {
|
|
|
|
nstime_t nsta, nstb;
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, BILLION - 1);
|
|
|
|
nstime_iadd(&nsta, 1);
|
|
|
|
nstime_init2(&nstb, 43, 0);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 0,
|
2017-05-13 03:30:33 +08:00
|
|
|
"Incorrect addition result");
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 1);
|
|
|
|
nstime_iadd(&nsta, BILLION + 1);
|
|
|
|
nstime_init2(&nstb, 43, 2);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 0,
|
2017-05-13 03:30:33 +08:00
|
|
|
"Incorrect addition result");
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_nstime_subtract) {
|
2016-02-22 03:25:02 +08:00
|
|
|
nstime_t nsta, nstb;
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 43);
|
|
|
|
nstime_copy(&nstb, &nsta);
|
|
|
|
nstime_subtract(&nsta, &nstb);
|
2019-12-17 04:41:06 +08:00
|
|
|
nstime_init_zero(&nstb);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 0,
|
2016-02-22 03:25:02 +08:00
|
|
|
"Incorrect subtraction result");
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 43);
|
|
|
|
nstime_init2(&nstb, 41, 44);
|
|
|
|
nstime_subtract(&nsta, &nstb);
|
|
|
|
nstime_init2(&nstb, 0, BILLION - 1);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 0,
|
2016-02-22 03:25:02 +08:00
|
|
|
"Incorrect subtraction result");
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2017-05-13 03:30:33 +08:00
|
|
|
TEST_BEGIN(test_nstime_isubtract) {
|
|
|
|
nstime_t nsta, nstb;
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 43);
|
|
|
|
nstime_isubtract(&nsta, 42*BILLION + 43);
|
2019-12-17 04:41:06 +08:00
|
|
|
nstime_init_zero(&nstb);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 0,
|
2017-05-13 03:30:33 +08:00
|
|
|
"Incorrect subtraction result");
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 43);
|
|
|
|
nstime_isubtract(&nsta, 41*BILLION + 44);
|
|
|
|
nstime_init2(&nstb, 0, BILLION - 1);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 0,
|
2017-05-13 03:30:33 +08:00
|
|
|
"Incorrect subtraction result");
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_nstime_imultiply) {
|
2016-02-22 03:25:02 +08:00
|
|
|
nstime_t nsta, nstb;
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 43);
|
|
|
|
nstime_imultiply(&nsta, 10);
|
|
|
|
nstime_init2(&nstb, 420, 430);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 0,
|
2016-02-22 03:25:02 +08:00
|
|
|
"Incorrect multiplication result");
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 666666666);
|
|
|
|
nstime_imultiply(&nsta, 3);
|
|
|
|
nstime_init2(&nstb, 127, 999999998);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 0,
|
2016-02-22 03:25:02 +08:00
|
|
|
"Incorrect multiplication result");
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_nstime_idivide) {
|
2016-02-22 03:25:02 +08:00
|
|
|
nstime_t nsta, nstb;
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 43);
|
|
|
|
nstime_copy(&nstb, &nsta);
|
|
|
|
nstime_imultiply(&nsta, 10);
|
|
|
|
nstime_idivide(&nsta, 10);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 0,
|
2016-02-22 03:25:02 +08:00
|
|
|
"Incorrect division result");
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 666666666);
|
|
|
|
nstime_copy(&nstb, &nsta);
|
|
|
|
nstime_imultiply(&nsta, 3);
|
|
|
|
nstime_idivide(&nsta, 3);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_d_eq(nstime_compare(&nsta, &nstb), 0,
|
2016-02-22 03:25:02 +08:00
|
|
|
"Incorrect division result");
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_nstime_divide) {
|
2016-02-22 03:25:02 +08:00
|
|
|
nstime_t nsta, nstb, nstc;
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 43);
|
|
|
|
nstime_copy(&nstb, &nsta);
|
|
|
|
nstime_imultiply(&nsta, 10);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_u64_eq(nstime_divide(&nsta, &nstb), 10,
|
2016-02-22 03:25:02 +08:00
|
|
|
"Incorrect division result");
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 43);
|
|
|
|
nstime_copy(&nstb, &nsta);
|
|
|
|
nstime_imultiply(&nsta, 10);
|
|
|
|
nstime_init(&nstc, 1);
|
|
|
|
nstime_add(&nsta, &nstc);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_u64_eq(nstime_divide(&nsta, &nstb), 10,
|
2016-02-22 03:25:02 +08:00
|
|
|
"Incorrect division result");
|
|
|
|
|
|
|
|
nstime_init2(&nsta, 42, 43);
|
|
|
|
nstime_copy(&nstb, &nsta);
|
|
|
|
nstime_imultiply(&nsta, 10);
|
|
|
|
nstime_init(&nstc, 1);
|
|
|
|
nstime_subtract(&nsta, &nstc);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_u64_eq(nstime_divide(&nsta, &nstb), 9,
|
2016-02-22 03:25:02 +08:00
|
|
|
"Incorrect division result");
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_nstime_monotonic) {
|
2016-10-11 13:15:10 +08:00
|
|
|
nstime_monotonic();
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
2016-02-22 03:25:02 +08:00
|
|
|
int
|
2017-01-16 08:56:30 +08:00
|
|
|
main(void) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return test(
|
2016-02-22 03:25:02 +08:00
|
|
|
test_nstime_init,
|
|
|
|
test_nstime_init2,
|
|
|
|
test_nstime_copy,
|
|
|
|
test_nstime_compare,
|
|
|
|
test_nstime_add,
|
2017-05-13 03:30:33 +08:00
|
|
|
test_nstime_iadd,
|
2016-02-22 03:25:02 +08:00
|
|
|
test_nstime_subtract,
|
2017-05-13 03:30:33 +08:00
|
|
|
test_nstime_isubtract,
|
2016-02-22 03:25:02 +08:00
|
|
|
test_nstime_imultiply,
|
|
|
|
test_nstime_idivide,
|
|
|
|
test_nstime_divide,
|
2020-06-02 21:42:44 +08:00
|
|
|
test_nstime_monotonic);
|
2016-02-22 03:25:02 +08:00
|
|
|
}
|