diff options
| author | Michael Biebl <biebl@debian.org> | 2015-08-28 01:13:48 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2015-08-28 01:13:48 +0200 |
| commit | 81836c2d44802b4cca833d7775dd627e0797a7e2 (patch) | |
| tree | 91154e6cefc0465306603f51ec0010d9963bbea4 /src/tests/test-general-with-expect.c | |
| parent | 50a58f0fabd8a34c1b6108a107e08abe3c1ccd24 (diff) | |
Imported Upstream version 1.0.6 upstream/1.0.6
Diffstat (limited to 'src/tests/test-general-with-expect.c')
| -rw-r--r-- | src/tests/test-general-with-expect.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/tests/test-general-with-expect.c b/src/tests/test-general-with-expect.c index bb52bde2..fe76e3fa 100644 --- a/src/tests/test-general-with-expect.c +++ b/src/tests/test-general-with-expect.c @@ -35,6 +35,42 @@ /*******************************************/ +static void +test_nm_utils_monotonic_timestamp_as_boottime (void) +{ + gint64 timestamp_ns_per_tick, now, now_boottime, now_boottime_2, now_boottime_3; + struct timespec tp; + clockid_t clockid; + guint i; + + if (clock_gettime (CLOCK_BOOTTIME, &tp) != 0 && errno == EINVAL) + clockid = CLOCK_MONOTONIC; + else + clockid = CLOCK_BOOTTIME; + + for (i = 0; i < 10; i++) { + + if (clock_gettime (clockid, &tp) != 0) + g_assert_not_reached (); + now_boottime = ( ((gint64) tp.tv_sec) * NM_UTILS_NS_PER_SECOND ) + ((gint64) tp.tv_nsec); + + now = nm_utils_get_monotonic_timestamp_ns (); + + now_boottime_2 = nm_utils_monotonic_timestamp_as_boottime (now, 1); + g_assert_cmpint (now_boottime_2, >=, 0); + g_assert_cmpint (now_boottime_2, >=, now_boottime); + g_assert_cmpint (now_boottime_2 - now_boottime, <=, NM_UTILS_NS_PER_SECOND / 1000); + + for (timestamp_ns_per_tick = 1; timestamp_ns_per_tick <= NM_UTILS_NS_PER_SECOND; timestamp_ns_per_tick *= 10) { + now_boottime_3 = nm_utils_monotonic_timestamp_as_boottime (now / timestamp_ns_per_tick, timestamp_ns_per_tick); + + g_assert_cmpint (now_boottime_2 / timestamp_ns_per_tick, ==, now_boottime_3); + } + } +} + +/*******************************************/ + struct test_nm_utils_kill_child_async_data { GMainLoop *loop; @@ -385,7 +421,7 @@ _remove_at_indexes_init_random_idx (GArray *idx, guint array_len, guint idx_len) } static void -test_nm_utils_array_remove_at_indexes () +test_nm_utils_array_remove_at_indexes (void) { gs_unref_array GArray *idx = NULL, *array = NULL; gs_unref_hashtable GHashTable *unique = NULL; @@ -822,6 +858,7 @@ main (int argc, char **argv) { nmtst_init_assert_logging (&argc, &argv, "DEBUG", "DEFAULT"); + g_test_add_func ("/general/nm_utils_monotonic_timestamp_as_boottime", test_nm_utils_monotonic_timestamp_as_boottime); g_test_add_func ("/general/nm_utils_kill_child", test_nm_utils_kill_child); g_test_add_func ("/general/nm_ethernet_address_is_valid", test_nm_ethernet_address_is_valid); g_test_add_func ("/general/nm_multi_index", test_nm_multi_index); |