zephyr/tests/net/socket/socketpair/src/fcntl.c
Christopher Friedt f1d7c0b196 tests: net: socketpair: use a test fixture to deduplicate code
A fair bit of setup / teardown code was being duplicated in many
test cases in the socketpair testsuite.

Take advantage of the `setup()`, `before()`, and `after()`
functions in the new ZTest API.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00

30 lines
713 B
C

/*
* Copyright (c) 2020 Friedt Professional Engineering Services, Inc
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "_main.h"
ZTEST_USER_F(net_socketpair, test_fcntl)
{
int res;
int flags;
res = fcntl(fixture->sv[0], F_GETFL, 0);
zassert_not_equal(res, -1,
"fcntl(fixture->sv[0], F_GETFL) failed. errno: %d", errno);
flags = res;
zassert_equal(res & O_NONBLOCK, 0,
"socketpair should block by default");
res = fcntl(fixture->sv[0], F_SETFL, flags | O_NONBLOCK);
zassert_not_equal(res, -1,
"fcntl(fixture->sv[0], F_SETFL, flags | O_NONBLOCK) failed. errno: %d",
errno);
res = fcntl(fixture->sv[0], F_GETFL, 0);
zassert_equal(res ^ flags, O_NONBLOCK, "expected O_NONBLOCK set");
}