mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 17:33:23 +00:00
Add syscall eventfd and eventfd2
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
ccc4e6ec6b
commit
078f9a8891
@ -11,6 +11,7 @@ REGRESSION_BUILD_DIR ?= $(INITRAMFS)/regression
|
||||
# These test apps are sorted by name
|
||||
TEST_APPS := \
|
||||
execve \
|
||||
eventfd2 \
|
||||
fork \
|
||||
fork_c \
|
||||
getpid \
|
||||
|
5
regression/apps/eventfd2/Makefile
Normal file
5
regression/apps/eventfd2/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
include ../test_common.mk
|
||||
|
||||
EXTRA_C_FLAGS :=
|
55
regression/apps/eventfd2/eventfd2.c
Normal file
55
regression/apps/eventfd2/eventfd2.c
Normal file
@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
#include <err.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int efd;
|
||||
uint64_t u;
|
||||
ssize_t s;
|
||||
|
||||
uint64_t values[] = { 11, 222, 3333 };
|
||||
size_t length = sizeof(values) / sizeof(values[0]);
|
||||
|
||||
efd = eventfd(0, 0);
|
||||
if (efd == -1)
|
||||
err(EXIT_FAILURE, "eventfd");
|
||||
|
||||
switch (fork()) {
|
||||
case 0:
|
||||
for (size_t j = 0; j < length; j++) {
|
||||
printf("Child writing %ld to efd\n", values[j]);
|
||||
u = values[j]; /* strtoull() allows various bases */
|
||||
s = write(efd, &u, sizeof(uint64_t));
|
||||
if (s != sizeof(uint64_t))
|
||||
err(EXIT_FAILURE, "write");
|
||||
}
|
||||
|
||||
printf("Child completed write loop\n");
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
default:
|
||||
sleep(2);
|
||||
|
||||
printf("Parent about to read\n");
|
||||
s = read(efd, &u, sizeof(uint64_t));
|
||||
if (s != sizeof(uint64_t))
|
||||
err(EXIT_FAILURE, "read");
|
||||
printf("Parent read %" PRIu64 " (%#" PRIx64 ") from efd\n", u,
|
||||
u);
|
||||
if (u != 11 + 222 + 3333) {
|
||||
err(EXIT_FAILURE, "read eventfd");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
case -1:
|
||||
err(EXIT_FAILURE, "fork");
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ SCRIPT_DIR=/regression
|
||||
cd ${SCRIPT_DIR}/..
|
||||
|
||||
echo "Start process test......"
|
||||
tests="hello_world/hello_world fork/fork execve/execve fork_c/fork signal_c/signal_test pthread/pthread_test hello_pie/hello pty/open_pty getpid/getpid"
|
||||
tests="hello_world/hello_world fork/fork execve/execve fork_c/fork signal_c/signal_test pthread/pthread_test hello_pie/hello pty/open_pty getpid/getpid eventfd2/eventfd2"
|
||||
for testcase in ${tests}
|
||||
do
|
||||
echo "Running test ${testcase}......"
|
||||
|
@ -11,6 +11,7 @@ TESTS ?= \
|
||||
chown_test \
|
||||
chroot_test \
|
||||
epoll_test \
|
||||
eventfd_test \
|
||||
fsync_test \
|
||||
getdents_test \
|
||||
link_test \
|
||||
|
3
regression/syscall_test/blocklists/eventfd_test
Normal file
3
regression/syscall_test/blocklists/eventfd_test
Normal file
@ -0,0 +1,3 @@
|
||||
EventfdTest.IllegalPwrite
|
||||
EventfdTest.SpliceFromPipePartialSucceeds
|
||||
EventfdTest.NotifyNonZero_NoRandomSave
|
Reference in New Issue
Block a user