#include #include #include #include #include #include #include #include #include #include #define READERS 10 #define WRITERS 10 static void *read_test(void *data) { char buf[100]; int fd, good = 0, bad = 0; fd = open("/dev/null", O_WRONLY); //printf("read test on process : %d thread : %d\n", getpid(), syscall(SYS_gettid)); while (1) { if ((read(fd, buf, sizeof(buf)) != -1) || (errno != EBADF)) { int err = errno; fprintf(stderr, "%d: (%d/%d) got %d instead of %d\n", pthread_self(), bad, bad+good, err, EBADF); bad++; } else { good++; } } return 0; } static void *write_test(void *data) { char buf[100]; int fd, good = 0, bad = 0; fd = open("/dev/full", O_WRONLY); //printf("write test on process : %d thread : %d\n", getpid(), syscall(SYS_gettid)); while (1) { if ((write(fd, buf, sizeof(buf)) != -1) || (errno != ENOSPC)) { int err = errno; fprintf(stderr, "%d: (%d/%d) got %d instead of %d\n", pthread_self(), bad, bad+good, err, ENOSPC); bad++; } else { good++; } } return 0; } static void *overflow_queue(void * data) { mqd_t handle_; // Delete any stale queues (ignore any errors) mq_unlink("/testqueue"); struct mq_attr attr = {0}; attr.mq_maxmsg = 4; attr.mq_msgsize = 10; handle_ = mq_open("/testqueue", O_RDONLY | O_CREAT, S_IRWXU | S_IRWXG, &attr); assert(handle_ != -1); handle_ = mq_open("/testqueue", O_WRONLY | O_NONBLOCK); assert(handle_ != -1); while (1) { const char* data = "test"; int size = 4; auto volatile errno_prev = errno; auto ret = mq_send(handle_, data, size, 0); if (ret < 0) { printf("ret: %d, errno: %d, pre: %d\n", ret, errno, errno_prev); if (errno != EAGAIN) { printf("affending process : %d thread : %d\n", getpid(), syscall(SYS_gettid)); assert(errno == EAGAIN); } } } } int main(void) { pthread_t id; int i; for (i=0; i