test_common divided into positive and negative tests 34/228534/1 submit/tizen/20200324.041440
authorAgnieszka Baumann <a.baumann@samsung.com>
Wed, 4 Mar 2020 16:13:37 +0000 (17:13 +0100)
committerAgnieszka Baumann <a.baumann@samsung.com>
Mon, 23 Mar 2020 13:32:07 +0000 (14:32 +0100)
Change-Id: I35fb99d45fdec21892019dc6268b7e1ed2a79c54

Makefile.am
src/tests/test_common.c
src/tests/test_common_neg.c [new file with mode: 0644]
src/tests/test_common_pos.c [new file with mode: 0644]
src/tests/test_common_wrap.c [new file with mode: 0644]

index 0fabd6e..bc6963f 100644 (file)
@@ -266,6 +266,8 @@ check_PROGRAMS = \
        src/tests/syslog_parser \
        src/tests/pipe_message \
        src/tests/test_common \
+       src/tests/test_common_neg \
+       src/tests/test_common_pos \
        src/tests/limiter \
        src/tests/dynamic_config \
        src/tests/sort_vector \
@@ -308,6 +310,14 @@ src_tests_test_common_SOURCES = src/tests/test_common.c src/shared/logcommon.c s
 src_tests_test_common_CFLAGS = $(check_CFLAGS)
 src_tests_test_common_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sendmsg,--wrap=recvmsg,--wrap=writev,--wrap=read,--wrap=poll,--wrap=fcntl,--wrap=fcntl64,--wrap=malloc,--wrap=calloc,--wrap=connect,--wrap=socket,--wrap=open,--wrap=open64,--wrap=ioctl
 
+src_tests_test_common_neg_SOURCES = src/tests/test_common_neg.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c src/shared/backend_androidlogger.c
+src_tests_test_common_neg_CFLAGS = $(check_CFLAGS)
+src_tests_test_common_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sendmsg,--wrap=recvmsg,--wrap=writev,--wrap=read,--wrap=poll,--wrap=fcntl,--wrap=fcntl64,--wrap=malloc,--wrap=calloc,--wrap=connect,--wrap=socket,--wrap=open,--wrap=open64,--wrap=ioctl
+
+src_tests_test_common_pos_SOURCES = src/tests/test_common_pos.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c src/shared/backend_androidlogger.c
+src_tests_test_common_pos_CFLAGS = $(check_CFLAGS)
+src_tests_test_common_pos_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sendmsg,--wrap=recvmsg,--wrap=writev,--wrap=read,--wrap=poll,--wrap=fcntl,--wrap=fcntl64,--wrap=malloc,--wrap=calloc,--wrap=connect,--wrap=socket,--wrap=open,--wrap=open64,--wrap=ioctl
+
 src_tests_limiter_SOURCES = src/tests/limiter.c src/libdlog/loglimiter.c src/shared/logconfig.c src/shared/logcommon.c src/shared/parsers.c
 src_tests_limiter_CFLAGS = $(check_CFLAGS)
 src_tests_limiter_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=snprintf,--wrap=malloc,--wrap=time
index 6a78a0b..f8e1c4e 100644 (file)
@@ -1,334 +1,7 @@
-// C
-#include <assert.h>
-#include <stdlib.h>
-
-// POSIX
-#include <poll.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <sys/un.h>
-
-// DLog
-#include <backend_androidlogger.h>
-#include <logcommon.h>
-#include <logconfig.h>
-#include <logpipe.h>
-
-struct pipe_msg_header {
-       struct msghdr hdr;
-       struct iovec iov;
-       char ctl[CMSG_SPACE(sizeof(int))];
-};
-
-static struct pipe_msg_header msg_cache;
-static struct dlog_control_msg dcm_cache;
-static char large_buffer[1024];
-static size_t large_buffer_size;
-
-static bool fail_sendmsg;
-ssize_t __wrap_sendmsg(int sockfd, const struct msghdr *msg, int flags)
-{
-       assert(!msg->msg_name);
-       assert(!msg->msg_namelen);
-       assert(msg->msg_iovlen == 1);
-       assert(msg->msg_iov->iov_len == sizeof dcm_cache);
-       assert(msg->msg_controllen == sizeof msg_cache.ctl);
-
-       if (fail_sendmsg) {
-               errno = 52;
-               return -1;
-       }
-
-       memcpy(&dcm_cache, msg->msg_iov->iov_base, msg->msg_iov->iov_len);
-       memcpy(msg_cache.ctl, msg->msg_control, sizeof msg_cache.ctl);
-
-       return 0;
-}
-
-static ssize_t recvmsg_ret;
-static bool poison_recvmsg_result;
-static bool poison_recvmsg_pipefd;
-ssize_t __wrap_recvmsg(int sockfd, struct msghdr *msg, int flags)
-{
-       assert(msg->msg_iovlen == 1);
-       assert(msg->msg_iov->iov_len == sizeof dcm_cache);
-       assert(msg->msg_controllen == sizeof msg_cache.ctl);
-
-       if (recvmsg_ret <= 0) {
-               if (recvmsg_ret < 0)
-                       errno = 322;
-               return recvmsg_ret;
-       }
-
-       msg->msg_name = NULL;
-       msg->msg_namelen = 0;
-       memcpy(msg->msg_iov->iov_base, &dcm_cache, sizeof dcm_cache);
-       memcpy(msg->msg_control, msg_cache.ctl, sizeof msg_cache.ctl);
-
-       if (poison_recvmsg_result)
-               ((struct dlog_control_msg *)msg->msg_iov->iov_base)->result = 42;
-       if (poison_recvmsg_pipefd)
-               ((struct cmsghdr *)msg->msg_control)->cmsg_type = -1;
-
-       return recvmsg_ret;
-}
-
-static bool fail_poll;
-int __wrap_poll(struct pollfd *fds, nfds_t nfds, int timeout)
-{
-       if (fail_poll) {
-               errno = 997;
-               return -1;
-       }
-
-       return 0;
-}
-
-static int fail_read;
-static int partial_read;
-static int poison_datalen;
-static bool poison_read_result;
-ssize_t __wrap_read(int fd, void *buf, size_t count)
-{
-       if (fail_read & 1) {
-               errno = 666;
-               fail_read >>= 1;
-               partial_read >>= 1;
-               return -1;
-       }
-       fail_read >>= 1;
-
-       if (partial_read & 1) {
-               partial_read >>= 1;
-               return count - 1;
-       }
-       partial_read >>= 1;
-
-       if (count > large_buffer_size)
-               count = large_buffer_size;
-
-       memcpy(buf, large_buffer, count);
-       memmove(large_buffer, large_buffer + count, large_buffer_size - count);
-       large_buffer_size -= count;
-
-       if (poison_datalen) {
-               ((struct dlog_control_msg *)buf)->length -= poison_datalen;
-               poison_datalen = 0;
-       }
-
-       if (poison_read_result)
-               ((struct dlog_control_msg *)buf)->result = 42;
-
-       return count;
-}
-
-static bool fail_writev;
-ssize_t __wrap_writev(int fd, const struct iovec *iov, int iovcnt)
-{
-       if (fail_writev) {
-               errno = 54;
-               return -1;
-       }
-
-       large_buffer_size = 0U;
-       for (int i = 0; i < iovcnt; ++i) {
-               memcpy(large_buffer + large_buffer_size, iov[i].iov_base, iov[i].iov_len);
-               large_buffer_size += iov[i].iov_len;
-       }
-       return large_buffer_size;
-}
-
-static int fcntl_ret;
-int __wrap_fcntl(int fd, int cmd, ...)
-{
-       errno = EBADF;
-       return fcntl_ret;
-}
-int __wrap_fcntl64(int fd, int cmd, ...)
-{
-       return __wrap_fcntl(fd, cmd);
-}
-
-static bool fail_alloc;
-extern void *__real_malloc(size_t size);
-void *__wrap_malloc(size_t size)
-{
-       return fail_alloc ? NULL : __real_malloc(size);
-}
-
-extern void *__real_calloc(size_t nmemb, size_t size);
-void *__wrap_calloc(size_t nmemb, size_t size)
-{
-       return fail_alloc ? NULL : __real_calloc(nmemb, size);
-}
-
-static bool fail_connect;
-int __wrap_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
-{
-       if (fail_connect) {
-               errno = 1776;
-               return -1;
-       }
-
-       return 0;
-}
-
-static bool fail_socket;
-int __wrap_socket(int domain, int type, int protocol)
-{
-       if (fail_socket) {
-               errno = 1410;
-               return -1;
-       }
-
-       return 1683;
-}
-
-static bool check_open_flags;
-int __real_open(const char *pathname, int flags, int mode);
-int __wrap_open(const char *pathname, int flags, int mode)
-{
-       if (check_open_flags)
-               assert(flags == 0xFECAL);
-
-       if (!strcmp(pathname, "valid23"))
-               return 23;
-       if (!strcmp(pathname, "valid17"))
-               return 17;
-       if (!strcmp(pathname, "nonexistent")) {
-               errno = ENOENT;
-               return -1;
-       }
-       if (!strcmp(pathname, "inaccessible")) {
-               errno = EPERM;
-               return -1;
-       }
-
-       return __real_open(pathname, flags, mode);
-}
-int __wrap_open64(const char *pathname, int flags, int mode)
-{
-       return __wrap_open(pathname, flags, mode);
-}
-
-static int ioctl_errno;
-int __wrap_ioctl(int d, int request, char *argp)
-{
-       if (!ioctl_errno)
-               return 0;
-
-       errno = ioctl_errno;
-       return -1;
-}
+#include "test_common_wrap.c"
 
 int main(int argc, char **argv)
 {
-       {
-               const char *strings[] = {"we", "require", "more", "vespene gas"};
-               char *result = create_glued_string(strings, NELEMS(strings));
-               assert(result);
-               assert(!strncmp(result, "we require more vespene gas", sizeof "we require more vespene gas"));
-               free(result);
-       }
-
-       {
-               const char *strings[] = {"you", "must", "construct", "additional", "pylons", "!"};
-               char *result = create_glued_string(strings + 3, 2);
-               assert(result);
-               assert(!strncmp(result, "additional pylons", sizeof "additional pylons"));
-               free(result);
-       }
-
-       {
-               const log_id_t invalid_ids[] = {
-                       LOG_ID_INVALID - 7,
-                       LOG_ID_INVALID,
-                       LOG_ID_MAX,
-                       LOG_ID_MAX + 7,
-               };
-               const char *const invalid_names[] = {
-                       "foo",
-                       "mAiN",
-                       "radio los santos",
-                       "events",
-               };
-               const char *const valid_names[LOG_ID_MAX] = {
-                       "main",
-                       "system",
-                       "radio",
-                       "apps",
-                       "kmsg",
-                       "syslog",
-               };
-
-               for (size_t i = 0; i < NELEMS(invalid_ids); ++i)
-                       assert(!strcmp(log_name_by_id(invalid_ids[i]), ""));
-
-               for (size_t i = 0; i < NELEMS(invalid_names); ++i)
-                       assert(LOG_ID_INVALID == log_id_by_name(invalid_names[i]));
-
-               for (size_t i = 0; i < NELEMS(valid_names); ++i)
-                       assert(!strcmp(valid_names[i], log_name_by_id(log_id_by_name(valid_names[i]))));
-
-               for (int i = 0; i < LOG_ID_MAX; ++i)
-                       assert((log_id_t)i == log_id_by_name(log_name_by_id((log_id_t)i)));
-       }
-
-       {
-               struct {
-                       const char *str;
-                       dlogutil_sorting_order_e result;
-               } const test_cases[] = {
-                       { "sent_real", DLOGUTIL_SORT_SENT_REAL },
-                       { "sent_mono", DLOGUTIL_SORT_SENT_MONO },
-                       { "recv_real", DLOGUTIL_SORT_RECV_REAL },
-                       { "recv_mono", DLOGUTIL_SORT_RECV_MONO },
-                       {   "default", DLOGUTIL_SORT_DEFAULT   },
-                       { "x_invalid", DLOGUTIL_SORT_DEFAULT   },
-                       {          "", DLOGUTIL_SORT_DEFAULT   },
-               };
-               for (size_t i = 0; i < NELEMS(test_cases); ++i)
-                       assert(test_cases[i].result == get_order_from_string(test_cases[i].str));
-       }
-
-       {
-               struct {
-                       bool result;
-                       const char *ending;
-               } const test_cases[] = {
-                       {true, ""},
-                       {true, "man"},
-                       {false, "bat"},
-                       {true, "batman"},
-                       {false, "robin"},
-                       {false, "batman batman"},
-               };
-
-               for (size_t i = 0; i < NELEMS(test_cases); ++i)
-                       assert(test_cases[i].result == str_ends_with("batman", test_cases[i].ending));
-       }
-
-       assert(log_priority_from_char(0) == DLOG_UNKNOWN);
-       assert(log_priority_from_char(1) == DLOG_DEFAULT);
-       assert(log_priority_from_char(2) == DLOG_VERBOSE);
-       assert(log_priority_from_char(3) == DLOG_DEBUG);
-       assert(log_priority_from_char(4) == DLOG_INFO);
-       assert(log_priority_from_char(5) == DLOG_WARN);
-       assert(log_priority_from_char(6) == DLOG_ERROR);
-       assert(log_priority_from_char(7) == DLOG_FATAL);
-       assert(log_priority_from_char(8) == DLOG_SILENT);
-
-       assert(log_priority_from_char(-120) == DLOG_UNKNOWN);
-       assert(log_priority_from_char(-1)   == DLOG_UNKNOWN);
-       assert(log_priority_from_char(9)    == DLOG_UNKNOWN);
-       assert(log_priority_from_char(75)   == DLOG_UNKNOWN);
-
-       fail_alloc = true;
-       const char *const strings[] = {"storm", "earth", "fire"};
-       assert(!create_glued_string(strings, NELEMS(strings)));
-       fail_alloc = false;
 
        fail_sendmsg = true;
        assert(send_pipe(13, 37) == -52);
diff --git a/src/tests/test_common_neg.c b/src/tests/test_common_neg.c
new file mode 100644 (file)
index 0000000..e82f3a8
--- /dev/null
@@ -0,0 +1,43 @@
+ #include "test_common_wrap.c"
+
+int main(int argc, char **argv)
+{
+       {
+               const log_id_t invalid_ids[] = {
+                       LOG_ID_INVALID - 7,
+                       LOG_ID_INVALID,
+                       LOG_ID_MAX,
+                       LOG_ID_MAX + 7,
+               };
+               const char *const invalid_names[] = {
+                       "foo",
+                       "mAiN",
+                       "radio los santos",
+                       "events",
+               };
+               for (size_t i = 0; i < NELEMS(invalid_ids); ++i)
+                       assert(!strcmp(log_name_by_id(invalid_ids[i]), ""));
+               for (size_t i = 0; i < NELEMS(invalid_names); ++i)
+                       assert(LOG_ID_INVALID == log_id_by_name(invalid_names[i]));
+       }
+       {
+               const char *test_cases[] = {"x_invalid", ""};
+               for (size_t i = 0; i < NELEMS(test_cases); ++i)
+                       assert(DLOGUTIL_SORT_DEFAULT == get_order_from_string(test_cases[i]));
+       }
+       {
+               const char *test_cases[] = {"bat", "robin", "batman batman"};
+               for (size_t i = 0; i < NELEMS(test_cases); ++i)
+                       assert(false == str_ends_with("batman", test_cases[i]));
+       }
+
+       assert(log_priority_from_char(-120) == DLOG_UNKNOWN);
+       assert(log_priority_from_char(-1)   == DLOG_UNKNOWN);
+       assert(log_priority_from_char(9)    == DLOG_UNKNOWN);
+       assert(log_priority_from_char(75)   == DLOG_UNKNOWN);
+
+       fail_alloc = true;
+       const char *const strings[] = {"storm", "earth", "fire"};
+       assert(!create_glued_string(strings, NELEMS(strings)));
+       fail_alloc = false;
+}
diff --git a/src/tests/test_common_pos.c b/src/tests/test_common_pos.c
new file mode 100644 (file)
index 0000000..92430d4
--- /dev/null
@@ -0,0 +1,62 @@
+#include "test_common_wrap.c"
+
+int main(int argc, char **argv)
+{
+       {
+               const char *strings[] = {"we", "require", "more", "vespene gas"};
+               char *result = create_glued_string(strings, NELEMS(strings));
+               assert(result);
+               assert(!strncmp(result, "we require more vespene gas", sizeof "we require more vespene gas"));
+               free(result);
+       }
+       {
+               const char *strings[] = {"you", "must", "construct", "additional", "pylons", "!"};
+               char *result = create_glued_string(strings + 3, 2);
+               assert(result);
+               assert(!strncmp(result, "additional pylons", sizeof "additional pylons"));
+               free(result);
+       }
+       {
+               const char *const valid_names[LOG_ID_MAX] = {
+                       "main",
+                       "system",
+                       "radio",
+                       "apps",
+                       "kmsg",
+                       "syslog",
+               };
+               for (size_t i = 0; i < NELEMS(valid_names); ++i)
+                       assert(!strcmp(valid_names[i], log_name_by_id(log_id_by_name(valid_names[i]))));
+               for (int i = 0; i < LOG_ID_MAX; ++i)
+                       assert((log_id_t)i == log_id_by_name(log_name_by_id((log_id_t)i)));
+       }
+       {
+               struct {
+                       const char *str;
+                       dlogutil_sorting_order_e result;
+               } const test_cases[] = {
+                       { "sent_real", DLOGUTIL_SORT_SENT_REAL },
+                       { "sent_mono", DLOGUTIL_SORT_SENT_MONO },
+                       { "recv_real", DLOGUTIL_SORT_RECV_REAL },
+                       { "recv_mono", DLOGUTIL_SORT_RECV_MONO },
+                       {   "default", DLOGUTIL_SORT_DEFAULT   },
+               };
+               for (size_t i = 0; i < NELEMS(test_cases); ++i)
+                       assert(test_cases[i].result == get_order_from_string(test_cases[i].str));
+       }
+       {
+               const char *test_cases[] = {"", "man", "batman"};
+               for (size_t i = 0; i < NELEMS(test_cases); ++i)
+                       assert(true == str_ends_with("batman", test_cases[i]));
+       }
+
+       assert(log_priority_from_char(0) == DLOG_UNKNOWN);
+       assert(log_priority_from_char(1) == DLOG_DEFAULT);
+       assert(log_priority_from_char(2) == DLOG_VERBOSE);
+       assert(log_priority_from_char(3) == DLOG_DEBUG);
+       assert(log_priority_from_char(4) == DLOG_INFO);
+       assert(log_priority_from_char(5) == DLOG_WARN);
+       assert(log_priority_from_char(6) == DLOG_ERROR);
+       assert(log_priority_from_char(7) == DLOG_FATAL);
+       assert(log_priority_from_char(8) == DLOG_SILENT);
+}
diff --git a/src/tests/test_common_wrap.c b/src/tests/test_common_wrap.c
new file mode 100644 (file)
index 0000000..2218d00
--- /dev/null
@@ -0,0 +1,224 @@
+// C
+#include <assert.h>
+#include <stdlib.h>
+
+// POSIX
+#include <poll.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/un.h>
+
+// DLog
+#include <backend_androidlogger.h>
+#include <logcommon.h>
+#include <logconfig.h>
+#include <logpipe.h>
+
+struct pipe_msg_header {
+       struct msghdr hdr;
+       struct iovec iov;
+       char ctl[CMSG_SPACE(sizeof(int))];
+};
+
+static struct pipe_msg_header msg_cache;
+static struct dlog_control_msg dcm_cache;
+static char large_buffer[1024];
+static size_t large_buffer_size;
+
+static bool fail_sendmsg;
+ssize_t __wrap_sendmsg(int sockfd, const struct msghdr *msg, int flags)
+{
+       assert(!msg->msg_name);
+       assert(!msg->msg_namelen);
+       assert(msg->msg_iovlen == 1);
+       assert(msg->msg_iov->iov_len == sizeof dcm_cache);
+       assert(msg->msg_controllen == sizeof msg_cache.ctl);
+
+       if (fail_sendmsg) {
+               errno = 52;
+               return -1;
+       }
+
+       memcpy(&dcm_cache, msg->msg_iov->iov_base, msg->msg_iov->iov_len);
+       memcpy(msg_cache.ctl, msg->msg_control, sizeof msg_cache.ctl);
+
+       return 0;
+}
+
+static ssize_t recvmsg_ret;
+static bool poison_recvmsg_result;
+static bool poison_recvmsg_pipefd;
+ssize_t __wrap_recvmsg(int sockfd, struct msghdr *msg, int flags)
+{
+       assert(msg->msg_iovlen == 1);
+       assert(msg->msg_iov->iov_len == sizeof dcm_cache);
+       assert(msg->msg_controllen == sizeof msg_cache.ctl);
+
+       if (recvmsg_ret <= 0) {
+               if (recvmsg_ret < 0)
+                       errno = 322;
+               return recvmsg_ret;
+       }
+
+       msg->msg_name = NULL;
+       msg->msg_namelen = 0;
+       memcpy(msg->msg_iov->iov_base, &dcm_cache, sizeof dcm_cache);
+       memcpy(msg->msg_control, msg_cache.ctl, sizeof msg_cache.ctl);
+
+       if (poison_recvmsg_result)
+               ((struct dlog_control_msg *)msg->msg_iov->iov_base)->result = 42;
+       if (poison_recvmsg_pipefd)
+               ((struct cmsghdr *)msg->msg_control)->cmsg_type = -1;
+
+       return recvmsg_ret;
+}
+
+static bool fail_poll;
+int __wrap_poll(struct pollfd *fds, nfds_t nfds, int timeout)
+{
+       if (fail_poll) {
+               errno = 997;
+               return -1;
+       }
+
+       return 0;
+}
+
+static int fail_read;
+static int partial_read;
+static int poison_datalen;
+static bool poison_read_result;
+ssize_t __wrap_read(int fd, void *buf, size_t count)
+{
+       if (fail_read & 1) {
+               errno = 666;
+               fail_read >>= 1;
+               partial_read >>= 1;
+               return -1;
+       }
+       fail_read >>= 1;
+
+       if (partial_read & 1) {
+               partial_read >>= 1;
+               return count - 1;
+       }
+       partial_read >>= 1;
+
+       if (count > large_buffer_size)
+               count = large_buffer_size;
+
+       memcpy(buf, large_buffer, count);
+       memmove(large_buffer, large_buffer + count, large_buffer_size - count);
+       large_buffer_size -= count;
+
+       if (poison_datalen) {
+               ((struct dlog_control_msg *)buf)->length -= poison_datalen;
+               poison_datalen = 0;
+       }
+
+       if (poison_read_result)
+               ((struct dlog_control_msg *)buf)->result = 42;
+
+       return count;
+}
+
+static bool fail_writev;
+ssize_t __wrap_writev(int fd, const struct iovec *iov, int iovcnt)
+{
+       if (fail_writev) {
+               errno = 54;
+               return -1;
+       }
+
+       large_buffer_size = 0U;
+       for (int i = 0; i < iovcnt; ++i) {
+               memcpy(large_buffer + large_buffer_size, iov[i].iov_base, iov[i].iov_len);
+               large_buffer_size += iov[i].iov_len;
+       }
+       return large_buffer_size;
+}
+
+static int fcntl_ret;
+int __wrap_fcntl(int fd, int cmd, ...)
+{
+       errno = EBADF;
+       return fcntl_ret;
+}
+int __wrap_fcntl64(int fd, int cmd, ...)
+{
+       return __wrap_fcntl(fd, cmd);
+}
+
+static bool fail_alloc;
+extern void *__real_malloc(size_t size);
+void *__wrap_malloc(size_t size)
+{
+       return fail_alloc ? NULL : __real_malloc(size);
+}
+
+extern void *__real_calloc(size_t nmemb, size_t size);
+void *__wrap_calloc(size_t nmemb, size_t size)
+{
+       return fail_alloc ? NULL : __real_calloc(nmemb, size);
+}
+
+static bool fail_connect;
+int __wrap_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
+{
+       if (fail_connect) {
+               errno = 1776;
+               return -1;
+       }
+
+       return 0;
+}
+
+static bool fail_socket;
+int __wrap_socket(int domain, int type, int protocol)
+{
+       if (fail_socket) {
+               errno = 1410;
+               return -1;
+       }
+
+       return 1683;
+}
+
+static bool check_open_flags;
+int __real_open(const char *pathname, int flags, int mode);
+int __wrap_open(const char *pathname, int flags, int mode)
+{
+       if (check_open_flags)
+               assert(flags == 0xFECAL);
+
+       if (!strcmp(pathname, "valid23"))
+               return 23;
+       if (!strcmp(pathname, "valid17"))
+               return 17;
+       if (!strcmp(pathname, "nonexistent")) {
+               errno = ENOENT;
+               return -1;
+       }
+       if (!strcmp(pathname, "inaccessible")) {
+               errno = EPERM;
+               return -1;
+       }
+
+       return __real_open(pathname, flags, mode);
+}
+int __wrap_open64(const char *pathname, int flags, int mode)
+{
+       return __wrap_open(pathname, flags, mode);
+}
+
+static int ioctl_errno;
+int __wrap_ioctl(int d, int request, char *argp)
+{
+       if (!ioctl_errno)
+               return 0;
+
+       errno = ioctl_errno;
+       return -1;
+}