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 | |
| parent | 50a58f0fabd8a34c1b6108a107e08abe3c1ccd24 (diff) | |
Imported Upstream version 1.0.6 upstream/1.0.6
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/config/nm-test-device.c | 16 | ||||
| -rw-r--r-- | src/tests/test-general-with-expect.c | 39 | ||||
| -rw-r--r-- | src/tests/test-ip4-config.c | 4 | ||||
| -rw-r--r-- | src/tests/test-route-manager.c | 2 |
4 files changed, 48 insertions, 13 deletions
diff --git a/src/tests/config/nm-test-device.c b/src/tests/config/nm-test-device.c index b5f65ded..681f4966 100644 --- a/src/tests/config/nm-test-device.c +++ b/src/tests/config/nm-test-device.c @@ -26,10 +26,10 @@ #include "nm-device-private.h" #include "nm-utils.h" -static GObjectClass *g_object_class; - G_DEFINE_TYPE (NMTestDevice, nm_test_device, NM_TYPE_DEVICE) +#define PARENT_CLASS (G_OBJECT_CLASS (g_type_class_peek_parent (nm_test_device_parent_class))) + static void nm_test_device_init (NMTestDevice *self) { @@ -44,21 +44,21 @@ constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { - return g_object_class->constructor (type, - n_construct_params, - construct_params); + return PARENT_CLASS->constructor (type, + n_construct_params, + construct_params); } static void constructed (GObject *object) { - g_object_class->constructed (object); + PARENT_CLASS->constructed (object); } static void dispose (GObject *object) { - g_object_class->dispose (object); + PARENT_CLASS->dispose (object); } static NMDeviceCapabilities @@ -73,8 +73,6 @@ nm_test_device_class_init (NMTestDeviceClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); - g_object_class = g_type_class_peek (G_TYPE_OBJECT); - object_class->constructor = constructor; object_class->constructed = constructed; object_class->dispose = dispose; 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); diff --git a/src/tests/test-ip4-config.c b/src/tests/test-ip4-config.c index c8bdc75f..235cfd42 100644 --- a/src/tests/test-ip4-config.c +++ b/src/tests/test-ip4-config.c @@ -316,12 +316,12 @@ test_merge_subtract_mss_mtu (void) nm_ip4_config_set_mss (cfg3, expected_mss3); nm_ip4_config_set_mtu (cfg3, expected_mtu3, NM_IP_CONFIG_SOURCE_UNKNOWN); - nm_ip4_config_merge (cfg1, cfg2); + nm_ip4_config_merge (cfg1, cfg2, NM_IP_CONFIG_MERGE_DEFAULT); /* ensure MSS and MTU are in cfg1 */ g_assert_cmpuint (nm_ip4_config_get_mss (cfg1), ==, expected_mss2); g_assert_cmpuint (nm_ip4_config_get_mtu (cfg1), ==, expected_mtu2); - nm_ip4_config_merge (cfg1, cfg3); + nm_ip4_config_merge (cfg1, cfg3, NM_IP_CONFIG_MERGE_DEFAULT); /* ensure again the MSS and MTU in cfg1 got overriden */ g_assert_cmpuint (nm_ip4_config_get_mss (cfg1), ==, expected_mss3); g_assert_cmpuint (nm_ip4_config_get_mtu (cfg1), ==, expected_mtu3); diff --git a/src/tests/test-route-manager.c b/src/tests/test-route-manager.c index 0164930d..9046bf88 100644 --- a/src/tests/test-route-manager.c +++ b/src/tests/test-route-manager.c @@ -377,7 +377,7 @@ setup_dev0_ip6 (int ifindex) /* Add an address so that a route to the gateway below gets added. */ nm_platform_ip6_address_add (NM_PLATFORM_GET, ifindex, - *nmtst_inet6_from_string ("2001:db8:8086::2"), + *nmtst_inet6_from_string ("2001:db8:8086::666"), in6addr_any, 64, 3600, |