test-ioloop.c revision d54edc1ad7b71020f6726363308985e0658657fb
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2015-2016 Dovecot authors, see the included COPYING file */
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainenstatic void timeout_callback(struct timeval *tv)
6e1e9e341ffe21a69a23229c2b896d03066a071eTimo Sirainenstatic void test_ioloop_fd_cb_left(struct test_ctx *ctx)
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainenstatic void test_ioloop_fd_cb_right(struct test_ctx *ctx)
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainenstatic void test_ioloop_fd_to(struct test_ctx *ctx)
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainenstatic void test_ioloop_fd(void)
785d9cca224d33ca3938e9166784f6483e8a27d7Timo Sirainen int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
0ea17cea21df405e6e74a167d08e1ff0ee95dd13Timo Sirainen struct timeout *to = timeout_add(2000, test_ioloop_fd_to, &test_ctx);
9740d55b228a670047c854484d5cc979a056a9afTimo Sirainenstatic void test_ioloop_timeout(void)
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen /* add a timeout by moving it from another ioloop */
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen to2 = timeout_add(1000, timeout_callback, &tv_callback);
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen /* add & remove immediately */
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen to = timeout_add(1000, timeout_callback, &tv_callback);
9261dbf0675204898c6557591c7aa376e23a52b2Timo Sirainen /* add the timeout we're actually testing below */
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen to = timeout_add(1000, timeout_callback, &tv_callback);
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen test_assert(timeval_diff_msecs(&tv_callback, &tv_start) >= 500);
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainenstatic void io_callback(void *context ATTR_UNUSED)
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainenstatic void test_ioloop_find_fd_conditions(void)
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen { IO_READ, { -1, -1 }, NULL } /* read+write as separate ios */
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen unsigned int i;
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen if (socketpair(AF_UNIX, SOCK_STREAM, 0, tests[i].fd) < 0)
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen tests[i].io = io_add(tests[i].fd[0], tests[i].condition, io_callback, (void *)NULL);
2526d52441ef368215ab6bf04fd0356d3b09d235Timo Sirainen io = io_add(tests[i-1].fd[0], IO_WRITE, io_callback, (void *)NULL);
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen test_assert_idx(io_loop_find_fd_conditions(ioloop, tests[i].fd[0]) == tests[i].condition, i);
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainenstatic void io_callback_pending_io(void *context ATTR_UNUSED)
cce169a321c9c629e4f2db1a69dae3b75bbcb27aTimo Sirainen struct istream *is = i_stream_create_from_data("data", 4);