bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomistatic void test_multiplex_channel_write(struct test_channel *channel)
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomistatic void test_multiplex_stream_write(struct ostream *channel ATTR_UNUSED)
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi test_multiplex_channel_write(&test_channel[i_rand() % 2]);
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomistatic void test_istream_multiplex_stream_read(struct test_channel *channel)
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomistatic void test_istream_read_alt(struct test_channel *channel)
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomistatic void setup_channel(struct test_channel *channel,
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi /* setup first channel */
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi channel->io = io_add_istream(is, test_istream_multiplex_stream_read,
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi channel->in_alt = i_stream_create_fd(channel->fds[0], (size_t)-1);
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi channel->out_alt = o_stream_create_fd(channel->fds[1], IO_BLOCK_SIZE);
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi channel->io_alt = io_add_istream(channel->in_alt, test_istream_read_alt,
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi channel->received = buffer_create_dynamic(default_pool, 32768);
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi channel->received_alt = buffer_create_dynamic(default_pool, 32768);
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomistatic void teardown_channel(struct test_channel *channel)
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi test_assert(channel->received->used == channel->received_alt->used);
ad9afb64630511d5e25bc5bc11c5304986156928Timo Sirainen test_assert(o_stream_finish(channel->out) > 0);
ad9afb64630511d5e25bc5bc11c5304986156928Timo Sirainen test_assert(o_stream_finish(channel->out_alt) > 0);
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi struct ostream *os = o_stream_create_fd(fds[1], (size_t)-1);
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi struct istream *is = i_stream_create_fd(fds[0], (size_t)-1);
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi struct istream *ichan0 = i_stream_create_multiplex(is, (size_t)-1);
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi struct istream *ichan1 = i_stream_multiplex_add_channel(ichan0, 1);
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi struct ostream *ochan0 = o_stream_create_multiplex(os, 1024);
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi struct ostream *ochan1 = o_stream_multiplex_add_channel(ochan0, 1);
1de7b73a11afda43323410a4481d866930b1e632Aki Tuomi struct io *io = io_add(fds[1], IO_WRITE, test_multiplex_stream_write, os);