aboutsummaryrefslogtreecommitdiffstats
path: root/test/rio_poll_builder_test.c
blob: f4acb7b9c20ba31e8810e23999f31c7d522792bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * Copyright 2026 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the Apache License 2.0 (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

#include "../ssl/rio/poll_builder.h"
#include "testutil.h"

static int test_duplicate_fd(void)
{
#if RIO_POLL_METHOD == RIO_POLL_METHOD_POLL
    RIO_POLL_BUILDER rpb;
    struct pollfd *pfds;
    int ret = 0;

    if (!TEST_true(ossl_rio_poll_builder_init(&rpb)))
        return 0;

    if (!TEST_true(ossl_rio_poll_builder_add_fd(&rpb, 0, 1, 0))
        || !TEST_true(ossl_rio_poll_builder_add_fd(&rpb, 0, 0, 1)))
        goto out;

    pfds = rpb.pfd_heap != NULL ? rpb.pfd_heap : rpb.pfds;
    if (!TEST_size_t_eq(rpb.pfd_num, 1)
        || !TEST_int_eq(pfds[0].events, POLLIN | POLLOUT))
        goto out;

    ret = 1;
out:
    ossl_rio_poll_builder_cleanup(&rpb);
    return ret;
#else
    return TEST_skip("poll() backend is not in use");
#endif
}

int setup_tests(void)
{
    ADD_TEST(test_duplicate_fd);
    return 1;
}