-#CPPFLAGS = -DDEBUG -DLOG_LEVEL=LOG_DEBUG -I. -I.. -I../include
-CPPFLAGS = -I. -I.. -I../include
+CPPFLAGS = -DDEBUG -DLOG_LEVEL=LOG_DEBUG -I. -I.. -I../include
+#CPPFLAGS = -I. -I.. -I../include
CFLAGS = -Wall -g
.PHONY: all clean
test_sw_sendmsg.o test_sw_recvmsg.o \
test_sw_setsockopt.o test_sw_getsockopt.o \
test_sw_close.o test_dummy.o
+ ../swift_raw.o ../swift_list.o
clean:
-rm -f *~ *.o
* Test sw_socket "syscall".
*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <errno.h>
+
+#include "swift_raw.h"
+#include "swift_types.h"
+
+#include "debug.h"
+#include "util.h"
+
#include "test_sw.h"
#include "test.h"
{
start_suite();
socket_dummy();
+ socket_invalid_domain();
+ socket_invalid_type();
+ socket_invalid_protocol();
+ socket_insufficient_file_descriptors();
+ socket_ok();
}
/* Dummy function for testing purposes only. */
{
test(1 == 1);
}
+
+/* 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);
+}