+
+/* Use invalid domain when calling sw_socket. */
+static void socket_invalid_domain(void)
+{
+ int rc;
+
+ rc = sw_socket(PF_UNIX, SOCK_DGRAM, IPPROTO_SWIFT);
+
+ test(rc < 0 && errno == EINVAL);
+}
+
+/* Use invalid type when calling sw_socket. */
+static void socket_invalid_type(void)
+{
+ int rc;
+
+ rc = sw_socket(PF_INET, SOCK_STREAM, IPPROTO_SWIFT);
+
+ test(rc < 0 && errno == EINVAL);
+}
+
+/* Use invalid protocol when calling sw_socket. */
+static void socket_invalid_protocol(void)
+{
+ int rc;
+
+ rc = sw_socket(PF_INET, SOCK_DGRAM, -1);
+
+ test(rc < 0 && errno == EINVAL);
+}
+
+/*
+ * Use dup to fill the number of file descriptors for current process.
+ * Calling sw_socket must result in error.
+ *
+ * File descriptors are not closed. Test processes must be restarted.
+ */
+static void socket_insufficient_file_descriptors(void)
+{
+ int fd;
+ int rc;
+
+ while (1) {
+ /* Duplicate standard output. */
+ fd = dup(STDOUT_FILENO);
+ if (fd < 0)
+ break;
+ }
+
+ rc = sw_socket(PF_INET, SOCK_DGRAM, IPPROTO_SWIFT);
+
+ dprintf("errno = %d\n", errno);
+ test(rc < 0 && errno == EMFILE);
+}
+
+/* Valid call of sw_socket. */
+static void socket_ok(void)
+{
+ int rc;
+
+ rc = sw_socket(PF_INET, SOCK_DGRAM, IPPROTO_SWIFT);
+ dprintf("rc = %d, errno = %d\n", rc, errno);
+
+ test(rc > 0);
+}