xref: /freebsd/crypto/openssl/test/rio_poll_builder_test.c (revision 78e936b2d0b5e6554425009199be31e76bc67c10)
1 /*
2  * Copyright 2026 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 
10 #include "../ssl/rio/poll_builder.h"
11 #include "testutil.h"
12 
test_duplicate_fd(void)13 static int test_duplicate_fd(void)
14 {
15 #if RIO_POLL_METHOD == RIO_POLL_METHOD_POLL
16     RIO_POLL_BUILDER rpb;
17     struct pollfd *pfds;
18     int ret = 0;
19 
20     if (!TEST_true(ossl_rio_poll_builder_init(&rpb)))
21         return 0;
22 
23     if (!TEST_true(ossl_rio_poll_builder_add_fd(&rpb, 0, 1, 0))
24         || !TEST_true(ossl_rio_poll_builder_add_fd(&rpb, 0, 0, 1)))
25         goto out;
26 
27     pfds = rpb.pfd_heap != NULL ? rpb.pfd_heap : rpb.pfds;
28     if (!TEST_size_t_eq(rpb.pfd_num, 1)
29         || !TEST_int_eq(pfds[0].events, POLLIN | POLLOUT))
30         goto out;
31 
32     ret = 1;
33 out:
34     ossl_rio_poll_builder_cleanup(&rpb);
35     return ret;
36 #else
37     return TEST_skip("poll() backend is not in use");
38 #endif
39 }
40 
setup_tests(void)41 int setup_tests(void)
42 {
43     ADD_TEST(test_duplicate_fd);
44     return 1;
45 }
46