tests: posix: eventfd_basic: add new test
Introduce new test for eventfd, which will test it in only basic scope. The real reason why this is introduced is to have a test with minimal set of configuration dependencies, such as disabled pthreads (compared to full tests/posix/eventfd/ variant). This allows to test eventfd mechanism with both POSIX_API=n and POSIX_API=y. Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This commit is contained in:
parent
385abc7740
commit
3b0917bcbf
4 changed files with 103 additions and 0 deletions
8
tests/posix/eventfd_basic/CMakeLists.txt
Normal file
8
tests/posix/eventfd_basic/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.13.1)
|
||||||
|
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||||
|
project(eventfd_basic)
|
||||||
|
|
||||||
|
FILE(GLOB app_sources src/*.c)
|
||||||
|
target_sources(app PRIVATE ${app_sources})
|
12
tests/posix/eventfd_basic/prj.conf
Normal file
12
tests/posix/eventfd_basic/prj.conf
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# Networking config
|
||||||
|
CONFIG_NETWORKING=y
|
||||||
|
CONFIG_NET_TEST=y
|
||||||
|
CONFIG_NET_SOCKETS=y
|
||||||
|
|
||||||
|
# Network driver config
|
||||||
|
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||||
|
|
||||||
|
CONFIG_ZTEST=y
|
||||||
|
|
||||||
|
CONFIG_EVENTFD=y
|
||||||
|
CONFIG_EVENTFD_MAX=1
|
72
tests/posix/eventfd_basic/src/main.c
Normal file
72
tests/posix/eventfd_basic/src/main.c
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Tobias Svehagen
|
||||||
|
* Copyright (c) 2020 Grinn
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ztest.h>
|
||||||
|
|
||||||
|
#include <net/socket.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_POSIX_API
|
||||||
|
#include <sys/eventfd.h>
|
||||||
|
#else
|
||||||
|
#include <posix/sys/eventfd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void test_eventfd(void)
|
||||||
|
{
|
||||||
|
int fd = eventfd(0, 0);
|
||||||
|
|
||||||
|
zassert_true(fd >= 0, "fd == %d", fd);
|
||||||
|
|
||||||
|
zsock_close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_eventfd_write_then_read(void)
|
||||||
|
{
|
||||||
|
eventfd_t val;
|
||||||
|
int fd, ret;
|
||||||
|
|
||||||
|
fd = eventfd(0, 0);
|
||||||
|
zassert_true(fd >= 0, "fd == %d", fd);
|
||||||
|
|
||||||
|
ret = eventfd_write(fd, 3);
|
||||||
|
zassert_true(ret == 0, "write ret %d", ret);
|
||||||
|
|
||||||
|
ret = eventfd_write(fd, 2);
|
||||||
|
zassert_true(ret == 0, "write ret %d", ret);
|
||||||
|
|
||||||
|
ret = eventfd_read(fd, &val);
|
||||||
|
zassert_true(ret == 0, "read ret %d", ret);
|
||||||
|
zassert_true(val == 5, "val == %d", val);
|
||||||
|
|
||||||
|
zsock_close(fd);
|
||||||
|
|
||||||
|
/* Test EFD_SEMAPHORE */
|
||||||
|
|
||||||
|
fd = eventfd(0, EFD_SEMAPHORE);
|
||||||
|
zassert_true(fd >= 0, "fd == %d", fd);
|
||||||
|
|
||||||
|
ret = eventfd_write(fd, 3);
|
||||||
|
zassert_true(ret == 0, "write ret %d", ret);
|
||||||
|
|
||||||
|
ret = eventfd_write(fd, 2);
|
||||||
|
zassert_true(ret == 0, "write ret %d", ret);
|
||||||
|
|
||||||
|
ret = eventfd_read(fd, &val);
|
||||||
|
zassert_true(ret == 0, "read ret %d", ret);
|
||||||
|
zassert_true(val == 1, "val == %d", val);
|
||||||
|
|
||||||
|
zsock_close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_main(void)
|
||||||
|
{
|
||||||
|
ztest_test_suite(test_eventfd_basic,
|
||||||
|
ztest_unit_test(test_eventfd),
|
||||||
|
ztest_unit_test(test_eventfd_write_then_read)
|
||||||
|
);
|
||||||
|
ztest_run_test_suite(test_eventfd_basic);
|
||||||
|
}
|
11
tests/posix/eventfd_basic/testcase.yaml
Normal file
11
tests/posix/eventfd_basic/testcase.yaml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
common:
|
||||||
|
arch_exclude: posix
|
||||||
|
min_ram: 32
|
||||||
|
tags: posix pthread eventfd
|
||||||
|
tests:
|
||||||
|
posix.eventfd_basic:
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_POSIX_API=n
|
||||||
|
posix.eventfd_basic.posix_api:
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_POSIX_API=y
|
Loading…
Add table
Add a link
Reference in a new issue