static void test_ippool_basic0(void)
{
struct connman_ippool *pool;
+ int i;
+
+ __connman_ippool_init();
+
+ pool = __connman_ippool_create(23, 1, 500, NULL, NULL);
+ g_assert(pool == NULL);
+
+ for (i = 0; i < 100000; i++) {
+ pool = __connman_ippool_create(23, 1, 20, NULL, NULL);
+ g_assert(pool);
+
+ __connman_ippool_unref(pool);
+ }
+
+ __connman_ippool_cleanup();
+}
+
+static void test_ippool_basic1(void)
+{
+ struct connman_ippool *pool;
const char *gateway;
const char *broadcast;
const char *subnet_mask;
const char *end_ip;
int i;
- /* Test the IP range */
-
- pool = __connman_ippool_create(23, 1, 500, NULL, NULL);
- g_assert(pool == NULL);
+ __connman_ippool_init();
+ /* Test the IP range */
for (i = 1; i < 254; i++) {
pool = __connman_ippool_create(23, 1, i, NULL, NULL);
g_assert(pool);
__connman_ippool_unref(pool);
}
+
+ __connman_ippool_cleanup();
}
-static void test_ippool_basic1(void)
+static void test_ippool_exhaust0(void)
{
struct connman_ippool *pool;
const char *gateway;
GSList *list = NULL, *it;
int i = 0;
+ __connman_ippool_init();
+
/* Allocate all possible pools */
/*
}
g_slist_free(list);
+
+ __connman_ippool_cleanup();
}
-int main(int argc, char *argv[])
+static void collision_cb(struct connman_ippool *pool, void *user_data)
{
- int err;
+ int *flag = user_data;
- g_test_init(&argc, &argv, NULL);
+ LOG("collision detected");
+
+ g_assert(*flag == 0);
+ g_assert(pool);
+
+ *flag = 1;
+}
+
+static void test_ippool_collision0(void)
+{
+ struct connman_ippool *pool;
+ const char *gateway;
+ const char *broadcast;
+ const char *subnet_mask;
+ const char *start_ip;
+ const char *end_ip;
+ int flag;
__connman_ippool_init();
- g_test_add_func("/basic0", test_ippool_basic0);
- g_test_add_func("/basic1", test_ippool_basic1);
+ /* Test the IP range collision */
+
+ flag = 0;
+ pool = __connman_ippool_create(23, 1, 100, collision_cb, &flag);
+ g_assert(pool);
+
+ gateway = __connman_ippool_get_gateway(pool);
+ broadcast = __connman_ippool_get_broadcast(pool);
+ subnet_mask = __connman_ippool_get_subnet_mask(pool);
+ start_ip = __connman_ippool_get_start_ip(pool);
+ end_ip = __connman_ippool_get_end_ip(pool);
+
+ g_assert(gateway);
+ g_assert(broadcast);
+ g_assert(subnet_mask);
+ g_assert(start_ip);
+ g_assert(end_ip);
+
+ LOG("\n\tIP range %s --> %s\n"
+ "\tgateway %s broadcast %s mask %s", start_ip, end_ip,
+ gateway, broadcast, subnet_mask);
+
+ __connman_ippool_newaddr(23, start_ip, 24);
+
+ g_assert(flag == 0);
+
+ __connman_ippool_newaddr(42, start_ip, 16);
- err = g_test_run();
+ g_assert(flag == 1);
+
+ __connman_ippool_unref(pool);
+
+ flag = 0;
+
+ pool = __connman_ippool_create(23, 1, 100, collision_cb, &flag);
+ g_assert(pool);
+
+ gateway = __connman_ippool_get_gateway(pool);
+ broadcast = __connman_ippool_get_broadcast(pool);
+ subnet_mask = __connman_ippool_get_subnet_mask(pool);
+ start_ip = __connman_ippool_get_start_ip(pool);
+ end_ip = __connman_ippool_get_end_ip(pool);
+
+ g_assert(gateway);
+ g_assert(broadcast);
+ g_assert(subnet_mask);
+ g_assert(start_ip);
+ g_assert(end_ip);
+
+ LOG("\n\tIP range %s --> %s\n"
+ "\tgateway %s broadcast %s mask %s", start_ip, end_ip,
+ gateway, broadcast, subnet_mask);
+
+ __connman_ippool_newaddr(45, start_ip, 22);
+
+ g_assert(flag == 1);
+
+ __connman_ippool_unref(pool);
__connman_ippool_cleanup();
+}
+
+int main(int argc, char *argv[])
+{
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/basic0", test_ippool_basic0);
+ g_test_add_func("/basic1", test_ippool_basic1);
+ g_test_add_func("/exhaust0", test_ippool_exhaust0);
+ g_test_add_func("/collision0", test_ippool_collision0);
- return err;
+ return g_test_run();
}