aboutsummaryrefslogtreecommitdiffstats
path: root/tests/socket
diff options
context:
space:
mode:
Diffstat (limited to 'tests/socket')
-rw-r--r--tests/socket/socket_test.c47
-rw-r--r--tests/socket/socket_test.err1
-rw-r--r--tests/socket/socket_test.ok4
3 files changed, 52 insertions, 0 deletions
diff --git a/tests/socket/socket_test.c b/tests/socket/socket_test.c
index 5b6abc42..57425ef5 100644
--- a/tests/socket/socket_test.c
+++ b/tests/socket/socket_test.c
@@ -73,6 +73,52 @@ static int test_sockinit(void)
return 0;
}
+static int test_sockinit2(void)
+{
+ int fd, rc;
+ char *name;
+
+ printf("Checking osmo_sock_init2() with bind to a random local UDP port\n");
+ fd = osmo_sock_init2(AF_INET, SOCK_DGRAM, IPPROTO_UDP,
+ "0.0.0.0", 0, NULL, 0, OSMO_SOCK_F_BIND);
+ OSMO_ASSERT(fd >= 0);
+ name = osmo_sock_get_name(NULL, fd);
+ /* expect it to be not connected. We cannot match on INADDR_ANY,
+ * as apparently that won't work on FreeBSD if there's only one
+ * address (e.g. 127.0.0.1) assigned to the entire system, like
+ * the Osmocom FreeBSD build slaves */
+ OSMO_ASSERT(!strncmp(name, "(NULL<->", 7));
+ talloc_free(name);
+ /* expect it to be blocking */
+ rc = fcntl(fd, F_GETFL);
+ OSMO_ASSERT(!(rc & O_NONBLOCK));
+ close(fd);
+
+ printf("Checking osmo_sock_init2() for OSMO_SOCK_F_NONBLOCK\n");
+ fd = osmo_sock_init2(AF_INET, SOCK_DGRAM, IPPROTO_UDP,
+ "0.0.0.0", 0, NULL, 0, OSMO_SOCK_F_BIND|OSMO_SOCK_F_NONBLOCK);
+ OSMO_ASSERT(fd >= 0);
+ /* expect it to be blocking */
+ rc = fcntl(fd, F_GETFL);
+ OSMO_ASSERT(rc & O_NONBLOCK);
+ close(fd);
+
+ printf("Checking osmo_sock_init2() for invalid flags\n");
+ fd = osmo_sock_init2(AF_INET, SOCK_DGRAM, IPPROTO_UDP, "0.0.0.0", 0, NULL, 0, 0);
+ OSMO_ASSERT(fd < 0);
+
+ printf("Checking osmo_sock_init2() for combined BIND + CONNECT\n");
+ fd = osmo_sock_init2(AF_INET, SOCK_DGRAM, IPPROTO_UDP, "127.0.0.1", 0, "127.0.0.1", 53,
+ OSMO_SOCK_F_BIND|OSMO_SOCK_F_CONNECT);
+ OSMO_ASSERT(fd >= 0);
+ name = osmo_sock_get_name(NULL, fd);
+ OSMO_ASSERT(!strncmp(name, "(127.0.0.1:53<->127.0.0.1", 25));
+ talloc_free(name);
+
+ return 0;
+}
+
+
const struct log_info_cat default_categories[] = {
};
@@ -88,6 +134,7 @@ int main(int argc, char *argv[])
log_set_print_filename(osmo_stderr_target, 0);
test_sockinit();
+ test_sockinit2();
return EXIT_SUCCESS;
}
diff --git a/tests/socket/socket_test.err b/tests/socket/socket_test.err
index 5367239c..ed6e1865 100644
--- a/tests/socket/socket_test.err
+++ b/tests/socket/socket_test.err
@@ -1 +1,2 @@
invalid: both bind and connect flags set: 0.0.0.0:0
+invalid: you have to specify either BIND or CONNECT flags
diff --git a/tests/socket/socket_test.ok b/tests/socket/socket_test.ok
index d6ec40ed..4b24fbce 100644
--- a/tests/socket/socket_test.ok
+++ b/tests/socket/socket_test.ok
@@ -1,3 +1,7 @@
Checking osmo_sock_init() with bind to a random local UDP port
Checking for OSMO_SOCK_F_NONBLOCK
Checking for invalid flags
+Checking osmo_sock_init2() with bind to a random local UDP port
+Checking osmo_sock_init2() for OSMO_SOCK_F_NONBLOCK
+Checking osmo_sock_init2() for invalid flags
+Checking osmo_sock_init2() for combined BIND + CONNECT