[libc] add remaining epoll functions, pipe (#84587)
The epoll_wait functions need the rest of the epoll functions (create, ctl) to be available to actually test them, as well as pipe to create a usable file descriptor. This patch adds epoll_create, epoll_create1, epoll_ctl, and pipe. These have tests, and the tests for epoll_wait, epoll_pwait, and epoll_pwait2 (currently disabled) are updated to use these newly available functions.
This commit is contained in:
@@ -215,6 +215,9 @@ set(TARGET_LIBC_ENTRYPOINTS
|
||||
libc.src.stdio.fileno
|
||||
|
||||
# sys/epoll.h entrypoints
|
||||
libc.src.sys.epoll.epoll_create
|
||||
libc.src.sys.epoll.epoll_create1
|
||||
libc.src.sys.epoll.epoll_ctl
|
||||
libc.src.sys.epoll.epoll_wait
|
||||
libc.src.sys.epoll.epoll_pwait
|
||||
# TODO: Need to check if pwait2 is available before providing.
|
||||
@@ -308,6 +311,7 @@ set(TARGET_LIBC_ENTRYPOINTS
|
||||
libc.src.unistd.link
|
||||
libc.src.unistd.linkat
|
||||
libc.src.unistd.lseek
|
||||
libc.src.unistd.pipe
|
||||
libc.src.unistd.pread
|
||||
libc.src.unistd.pwrite
|
||||
libc.src.unistd.read
|
||||
|
||||
@@ -41,4 +41,22 @@ add_proxy_header_library(
|
||||
libc.include.fenv
|
||||
)
|
||||
|
||||
add_proxy_header_library(
|
||||
signal_macros
|
||||
HDRS
|
||||
signal_macros.h
|
||||
FULL_BUILD_DEPENDS
|
||||
libc.include.llvm-libc-macros.signal_macros
|
||||
libc.include.signal
|
||||
)
|
||||
|
||||
add_proxy_header_library(
|
||||
sys_epoll_macros
|
||||
HDRS
|
||||
sys_epoll_macros.h
|
||||
FULL_BUILD_DEPENDS
|
||||
libc.include.sys_epoll
|
||||
libc.include.llvm-libc-macros.sys_epoll_macros
|
||||
)
|
||||
|
||||
add_subdirectory(types)
|
||||
|
||||
22
libc/hdr/signal_macros.h
Normal file
22
libc/hdr/signal_macros.h
Normal file
@@ -0,0 +1,22 @@
|
||||
//===-- Definition of macros from signal.h --------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_HDR_SIGNAL_MACROS_H
|
||||
#define LLVM_LIBC_HDR_SIGNAL_MACROS_H
|
||||
|
||||
#ifdef LIBC_FULL_BUILD
|
||||
|
||||
#include "include/llvm-libc-macros/signal-macros.h"
|
||||
|
||||
#else // Overlay mode
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#endif // LLVM_LIBC_FULL_BUILD
|
||||
|
||||
#endif // LLVM_LIBC_HDR_SIGNAL_MACROS_H
|
||||
22
libc/hdr/sys_epoll_macros.h
Normal file
22
libc/hdr/sys_epoll_macros.h
Normal file
@@ -0,0 +1,22 @@
|
||||
//===-- Definition of macros from sys/epoll.h -----------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_HDR_SYS_EPOLL_MACROS_H
|
||||
#define LLVM_LIBC_HDR_SYS_EPOLL_MACROS_H
|
||||
|
||||
#ifdef LIBC_FULL_BUILD
|
||||
|
||||
#include "include/llvm-libc-macros/sys-epoll-macros.h"
|
||||
|
||||
#else // Overlay mode
|
||||
|
||||
#include <sys/epoll.h>
|
||||
|
||||
#endif // LLVM_LIBC_FULL_BUILD
|
||||
|
||||
#endif // LLVM_LIBC_HDR_SYS/EPOLL_MACROS_H
|
||||
@@ -379,6 +379,7 @@ add_gen_header(
|
||||
.llvm-libc-types.struct_epoll_event
|
||||
.llvm-libc-types.struct_epoll_data
|
||||
.llvm-libc-types.sigset_t
|
||||
.llvm-libc-macros.sys_epoll_macros
|
||||
)
|
||||
|
||||
add_gen_header(
|
||||
|
||||
@@ -143,6 +143,12 @@ add_macro_header(
|
||||
sys-auxv-macros.h
|
||||
)
|
||||
|
||||
add_macro_header(
|
||||
sys_epoll_macros
|
||||
HDR
|
||||
sys-epoll-macros.h
|
||||
)
|
||||
|
||||
add_macro_header(
|
||||
sys_ioctl_macros
|
||||
HDR
|
||||
|
||||
@@ -10,6 +10,12 @@ add_header(
|
||||
sched-macros.h
|
||||
)
|
||||
|
||||
add_header(
|
||||
sys_epoll_macros
|
||||
HDR
|
||||
sys-epoll-macros.h
|
||||
)
|
||||
|
||||
add_header(
|
||||
sys_ioctl_macros
|
||||
HDR
|
||||
|
||||
40
libc/include/llvm-libc-macros/linux/sys-epoll-macros.h
Normal file
40
libc/include/llvm-libc-macros/linux/sys-epoll-macros.h
Normal file
@@ -0,0 +1,40 @@
|
||||
//===-- Macros defined in sys/epoll.h header file -------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_MACROS_LINUX_SYS_EPOLL_MACROS_H
|
||||
#define LLVM_LIBC_MACROS_LINUX_SYS_EPOLL_MACROS_H
|
||||
|
||||
#include "fcntl-macros.h"
|
||||
|
||||
// These are also defined in <linux/eventpoll.h> but that also contains a
|
||||
// different definition of the epoll_event struct that is different from the
|
||||
// userspace version.
|
||||
|
||||
#define EPOLL_CLOEXEC O_CLOEXEC
|
||||
|
||||
#define EPOLL_CTL_ADD 1
|
||||
#define EPOLL_CTL_DEL 2
|
||||
#define EPOLL_CTL_MOD 3
|
||||
|
||||
#define EPOLLIN 0x1
|
||||
#define EPOLLPRI 0x2
|
||||
#define EPOLLOUT 0x4
|
||||
#define EPOLLERR 0x8
|
||||
#define EPOLLHUP 0x10
|
||||
#define EPOLLRDNORM 0x40
|
||||
#define EPOLLRDBAND 0x80
|
||||
#define EPOLLWRNORM 0x100
|
||||
#define EPOLLWRBAND 0x200
|
||||
#define EPOLLMSG 0x400
|
||||
#define EPOLLRDHUP 0x2000
|
||||
#define EPOLLEXCLUSIVE 0x10000000
|
||||
#define EPOLLWAKEUP 0x20000000
|
||||
#define EPOLLONESHOT 0x40000000
|
||||
#define EPOLLET 0x80000000
|
||||
|
||||
#endif // LLVM_LIBC_MACROS_LINUX_SYS_EPOLL_MACROS_H
|
||||
16
libc/include/llvm-libc-macros/sys-epoll-macros.h
Normal file
16
libc/include/llvm-libc-macros/sys-epoll-macros.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//===-- Macros defined in sys/epoll.h header file -------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_MACROS_SYS_EPOLL_MACROS_H
|
||||
#define LLVM_LIBC_MACROS_SYS_EPOLL_MACROS_H
|
||||
|
||||
#ifdef __linux__
|
||||
#include "linux/sys-epoll-macros.h"
|
||||
#endif
|
||||
|
||||
#endif // LLVM_LIBC_MACROS_SYS_EPOLL_MACROS_H
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
// This definition can be adjusted/specialized for different targets and
|
||||
// platforms as necessary. This definition works for Linux on most targets.
|
||||
typedef struct {
|
||||
struct sigset_t {
|
||||
unsigned long __signals[__NSIGSET_WORDS];
|
||||
} sigset_t;
|
||||
};
|
||||
|
||||
#endif // LLVM_LIBC_TYPES_SIGSET_T_H
|
||||
|
||||
@@ -11,7 +11,11 @@
|
||||
|
||||
#include "llvm-libc-types/struct_epoll_data.h"
|
||||
|
||||
typedef struct epoll_event {
|
||||
typedef struct
|
||||
#ifdef __x86_64__
|
||||
[[gnu::packed]] // Necessary for compatibility.
|
||||
#endif
|
||||
epoll_event {
|
||||
__UINT32_TYPE__ events;
|
||||
epoll_data_t data;
|
||||
} epoll_event;
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
#include "__llvm-libc-common.h"
|
||||
|
||||
#include "llvm-libc-macros/sys-epoll-macros.h"
|
||||
|
||||
%%public_api()
|
||||
|
||||
#endif // LLVM_LIBC_SYS_EPOLL_H
|
||||
|
||||
@@ -572,6 +572,11 @@ def POSIX : StandardSpec<"POSIX"> {
|
||||
RetValSpec<OffTType>,
|
||||
[ArgSpec<IntType>, ArgSpec<OffTType>, ArgSpec<IntType>]
|
||||
>,
|
||||
FunctionSpec<
|
||||
"pipe",
|
||||
RetValSpec<IntType>,
|
||||
[ArgSpec<IntPtr>] //TODO: make this int[2]
|
||||
>,
|
||||
FunctionSpec<
|
||||
"pread",
|
||||
RetValSpec<SSizeTType>,
|
||||
|
||||
@@ -2,6 +2,27 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
|
||||
endif()
|
||||
|
||||
add_entrypoint_object(
|
||||
epoll_create
|
||||
ALIAS
|
||||
DEPENDS
|
||||
.${LIBC_TARGET_OS}.epoll_create
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
epoll_create1
|
||||
ALIAS
|
||||
DEPENDS
|
||||
.${LIBC_TARGET_OS}.epoll_create1
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
epoll_ctl
|
||||
ALIAS
|
||||
DEPENDS
|
||||
.${LIBC_TARGET_OS}.epoll_ctl
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
epoll_wait
|
||||
ALIAS
|
||||
|
||||
18
libc/src/sys/epoll/epoll_create.h
Normal file
18
libc/src/sys/epoll/epoll_create.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//===-- Implementation header for epoll_create function ---------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CREATE_H
|
||||
#define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CREATE_H
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
int epoll_create(int size);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CREATE_H
|
||||
18
libc/src/sys/epoll/epoll_create1.h
Normal file
18
libc/src/sys/epoll/epoll_create1.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//===-- Implementation header for epoll_create1 function --------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CREATE1_H
|
||||
#define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CREATE1_H
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
int epoll_create1(int flags);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CREATE1_H
|
||||
21
libc/src/sys/epoll/epoll_ctl.h
Normal file
21
libc/src/sys/epoll/epoll_ctl.h
Normal file
@@ -0,0 +1,21 @@
|
||||
//===-- Implementation header for epoll_ctl function ------------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CTL_H
|
||||
#define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CTL_H
|
||||
|
||||
#include "hdr/types/struct_epoll_event.h"
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
// TODO: event should be nullable
|
||||
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CTL_H
|
||||
@@ -15,8 +15,8 @@
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
// TODO: sigmask should be nullable
|
||||
int epoll_pwait(int epfd, epoll_event *events, int maxevents, int timeout,
|
||||
const sigset_t *sigmask);
|
||||
int epoll_pwait(int epfd, struct epoll_event *events, int maxevents,
|
||||
int timeout, const sigset_t *sigmask);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
|
||||
@@ -1,3 +1,41 @@
|
||||
add_entrypoint_object(
|
||||
epoll_create
|
||||
SRCS
|
||||
epoll_create.cpp
|
||||
HDRS
|
||||
../epoll_create.h
|
||||
DEPENDS
|
||||
libc.include.sys_syscall
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.errno.errno
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
epoll_create1
|
||||
SRCS
|
||||
epoll_create1.cpp
|
||||
HDRS
|
||||
../epoll_create1.h
|
||||
DEPENDS
|
||||
libc.include.sys_syscall
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.errno.errno
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
epoll_ctl
|
||||
SRCS
|
||||
epoll_ctl.cpp
|
||||
HDRS
|
||||
../epoll_ctl.h
|
||||
DEPENDS
|
||||
libc.hdr.types.struct_epoll_event
|
||||
libc.hdr.sys_epoll_macros
|
||||
libc.include.sys_syscall
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.errno.errno
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
epoll_wait
|
||||
SRCS
|
||||
@@ -23,7 +61,8 @@ add_entrypoint_object(
|
||||
libc.hdr.types.sigset_t
|
||||
libc.hdr.types.struct_epoll_event
|
||||
libc.hdr.types.struct_timespec
|
||||
libc.include.signal
|
||||
libc.hdr.sys_epoll_macros
|
||||
libc.hdr.signal_macros
|
||||
libc.include.sys_syscall
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.errno.errno
|
||||
@@ -39,9 +78,9 @@ add_entrypoint_object(
|
||||
libc.hdr.types.sigset_t
|
||||
libc.hdr.types.struct_epoll_event
|
||||
libc.hdr.types.struct_timespec
|
||||
libc.include.signal
|
||||
libc.hdr.sys_epoll_macros
|
||||
libc.hdr.signal_macros
|
||||
libc.include.sys_syscall
|
||||
libc.include.time
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.errno.errno
|
||||
)
|
||||
|
||||
38
libc/src/sys/epoll/linux/epoll_create.cpp
Normal file
38
libc/src/sys/epoll/linux/epoll_create.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
//===---------- Linux implementation of the epoll_create function ---------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/sys/epoll/epoll_create.h"
|
||||
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
#include "src/__support/common.h"
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include <sys/syscall.h> // For syscall numbers.
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, epoll_create, ([[maybe_unused]] int size)) {
|
||||
#ifdef SYS_epoll_create
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_create, size);
|
||||
#elif defined(SYS_epoll_create1)
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_create1, 0);
|
||||
#else
|
||||
#error \
|
||||
"epoll_create and epoll_create1 are unavailable. Unable to build epoll_create."
|
||||
#endif
|
||||
|
||||
// A negative return value indicates an error with the magnitude of the
|
||||
// value being the error code.
|
||||
if (ret < 0) {
|
||||
libc_errno = -ret;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
31
libc/src/sys/epoll/linux/epoll_create1.cpp
Normal file
31
libc/src/sys/epoll/linux/epoll_create1.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
//===---------- Linux implementation of the epoll_create1 function --------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/sys/epoll/epoll_create1.h"
|
||||
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
#include "src/__support/common.h"
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include <sys/syscall.h> // For syscall numbers.
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, epoll_create1, (int flags)) {
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_create1, flags);
|
||||
|
||||
// A negative return value indicates an error with the magnitude of the
|
||||
// value being the error code.
|
||||
if (ret < 0) {
|
||||
libc_errno = -ret;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
34
libc/src/sys/epoll/linux/epoll_ctl.cpp
Normal file
34
libc/src/sys/epoll/linux/epoll_ctl.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
//===---------- Linux implementation of the epoll_ctl function ----------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/sys/epoll/epoll_ctl.h"
|
||||
|
||||
#include "hdr/types/struct_epoll_event.h"
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
#include "src/__support/common.h"
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include <sys/syscall.h> // For syscall numbers.
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, epoll_ctl,
|
||||
(int epfd, int op, int fd, epoll_event *event)) {
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_ctl, epfd, op, fd,
|
||||
reinterpret_cast<long>(event));
|
||||
|
||||
// A negative return value indicates an error with the magnitude of the
|
||||
// value being the error code.
|
||||
if (ret < 0) {
|
||||
libc_errno = -ret;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "src/sys/epoll/epoll_pwait.h"
|
||||
|
||||
#include "hdr/signal_macros.h" // for NSIG
|
||||
#include "hdr/types/sigset_t.h"
|
||||
#include "hdr/types/struct_epoll_event.h"
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
@@ -23,7 +24,7 @@ LLVM_LIBC_FUNCTION(int, epoll_pwait,
|
||||
int timeout, const sigset_t *sigmask)) {
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(
|
||||
SYS_epoll_pwait, epfd, reinterpret_cast<long>(events), maxevents, timeout,
|
||||
reinterpret_cast<long>(sigmask), sizeof(sigset_t));
|
||||
reinterpret_cast<long>(sigmask), NSIG / 8);
|
||||
|
||||
// A negative return value indicates an error with the magnitude of the
|
||||
// value being the error code.
|
||||
@@ -32,7 +33,7 @@ LLVM_LIBC_FUNCTION(int, epoll_pwait,
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "src/sys/epoll/epoll_pwait2.h"
|
||||
|
||||
#include "hdr/signal_macros.h" // for NSIG
|
||||
#include "hdr/types/sigset_t.h"
|
||||
#include "hdr/types/struct_epoll_event.h"
|
||||
#include "hdr/types/struct_timespec.h"
|
||||
@@ -25,7 +26,7 @@ LLVM_LIBC_FUNCTION(int, epoll_pwait2,
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(
|
||||
SYS_epoll_pwait2, epfd, reinterpret_cast<long>(events), maxevents,
|
||||
reinterpret_cast<long>(timeout), reinterpret_cast<long>(sigmask),
|
||||
sizeof(sigset_t));
|
||||
NSIG / 8);
|
||||
|
||||
// A negative return value indicates an error with the magnitude of the
|
||||
// value being the error code.
|
||||
@@ -34,7 +35,7 @@ LLVM_LIBC_FUNCTION(int, epoll_pwait2,
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "src/sys/epoll/epoll_wait.h"
|
||||
|
||||
#include "hdr/signal_macros.h" // for NSIG
|
||||
#include "hdr/types/sigset_t.h"
|
||||
#include "hdr/types/struct_epoll_event.h"
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
@@ -27,7 +28,7 @@ LLVM_LIBC_FUNCTION(int, epoll_wait,
|
||||
#elif defined(SYS_epoll_pwait)
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(
|
||||
SYS_epoll_pwait, epfd, reinterpret_cast<long>(events), maxevents, timeout,
|
||||
reinterpret_cast<long>(nullptr), sizeof(sigset_t));
|
||||
reinterpret_cast<long>(nullptr), NSIG / 8);
|
||||
#else
|
||||
#error "epoll_wait and epoll_pwait are unavailable. Unable to build epoll_wait."
|
||||
#endif
|
||||
@@ -38,7 +39,7 @@ LLVM_LIBC_FUNCTION(int, epoll_wait,
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
@@ -160,6 +160,13 @@ add_entrypoint_object(
|
||||
.${LIBC_TARGET_OS}.lseek
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
pipe
|
||||
ALIAS
|
||||
DEPENDS
|
||||
.${LIBC_TARGET_OS}.pipe
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
pread
|
||||
ALIAS
|
||||
|
||||
@@ -273,6 +273,19 @@ add_entrypoint_object(
|
||||
libc.src.errno.errno
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
pipe
|
||||
SRCS
|
||||
pipe.cpp
|
||||
HDRS
|
||||
../pipe.h
|
||||
DEPENDS
|
||||
libc.include.unistd
|
||||
libc.include.sys_syscall
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.errno.errno
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
pread
|
||||
SRCS
|
||||
|
||||
33
libc/src/unistd/linux/pipe.cpp
Normal file
33
libc/src/unistd/linux/pipe.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
//===-- Linux implementation of pipe --------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/unistd/pipe.h"
|
||||
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
#include "src/__support/common.h"
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include <sys/syscall.h> // For syscall numbers.
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, pipe, (int pipefd[2])) {
|
||||
#ifdef SYS_pipe
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_pipe,
|
||||
reinterpret_cast<long>(pipefd));
|
||||
#elif defined(SYS_pipe2)
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(
|
||||
SYS_pipe2, reinterpret_cast<long>(pipefd), 0);
|
||||
#endif
|
||||
if (ret < 0) {
|
||||
libc_errno = -ret;
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
18
libc/src/unistd/pipe.h
Normal file
18
libc/src/unistd/pipe.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//===-- Implementation header for pipe --------------------------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_SRC_UNISTD_PIPE_H
|
||||
#define LLVM_LIBC_SRC_UNISTD_PIPE_H
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
int pipe(int pipefd[2]);
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC_UNISTD_PIPE_H
|
||||
@@ -1,4 +1,50 @@
|
||||
add_custom_target(libc_sys_epoll_unittests)
|
||||
|
||||
add_libc_unittest(
|
||||
epoll_create_test
|
||||
SUITE
|
||||
libc_sys_epoll_unittests
|
||||
SRCS
|
||||
epoll_create_test.cpp
|
||||
DEPENDS
|
||||
libc.include.sys_epoll
|
||||
libc.src.errno.errno
|
||||
libc.src.sys.epoll.epoll_create
|
||||
libc.src.unistd.close
|
||||
libc.test.UnitTest.ErrnoSetterMatcher
|
||||
)
|
||||
|
||||
add_libc_unittest(
|
||||
epoll_create1_test
|
||||
SUITE
|
||||
libc_sys_epoll_unittests
|
||||
SRCS
|
||||
epoll_create1_test.cpp
|
||||
DEPENDS
|
||||
libc.hdr.sys_epoll_macros
|
||||
libc.src.errno.errno
|
||||
libc.src.sys.epoll.epoll_create1
|
||||
libc.src.unistd.close
|
||||
libc.test.UnitTest.ErrnoSetterMatcher
|
||||
)
|
||||
|
||||
add_libc_unittest(
|
||||
epoll_ctl_test
|
||||
SUITE
|
||||
libc_sys_epoll_unittests
|
||||
SRCS
|
||||
epoll_ctl_test.cpp
|
||||
DEPENDS
|
||||
libc.hdr.sys_epoll_macros
|
||||
libc.hdr.types.struct_epoll_event
|
||||
libc.src.errno.errno
|
||||
libc.src.sys.epoll.epoll_create1
|
||||
libc.src.sys.epoll.epoll_ctl
|
||||
libc.src.unistd.pipe
|
||||
libc.src.unistd.close
|
||||
libc.test.UnitTest.ErrnoSetterMatcher
|
||||
)
|
||||
|
||||
add_libc_unittest(
|
||||
epoll_wait_test
|
||||
SUITE
|
||||
@@ -6,9 +52,14 @@ add_libc_unittest(
|
||||
SRCS
|
||||
epoll_wait_test.cpp
|
||||
DEPENDS
|
||||
libc.include.sys_epoll
|
||||
libc.hdr.sys_epoll_macros
|
||||
libc.hdr.types.struct_epoll_event
|
||||
libc.src.errno.errno
|
||||
libc.src.sys.epoll.epoll_create1
|
||||
libc.src.sys.epoll.epoll_ctl
|
||||
libc.src.sys.epoll.epoll_wait
|
||||
libc.src.unistd.pipe
|
||||
libc.src.unistd.close
|
||||
libc.test.UnitTest.ErrnoSetterMatcher
|
||||
)
|
||||
|
||||
@@ -19,9 +70,14 @@ add_libc_unittest(
|
||||
SRCS
|
||||
epoll_pwait_test.cpp
|
||||
DEPENDS
|
||||
libc.include.sys_epoll
|
||||
libc.hdr.sys_epoll_macros
|
||||
libc.hdr.types.struct_epoll_event
|
||||
libc.src.errno.errno
|
||||
libc.src.sys.epoll.epoll_create1
|
||||
libc.src.sys.epoll.epoll_ctl
|
||||
libc.src.sys.epoll.epoll_pwait
|
||||
libc.src.unistd.pipe
|
||||
libc.src.unistd.close
|
||||
libc.test.UnitTest.ErrnoSetterMatcher
|
||||
)
|
||||
|
||||
@@ -32,8 +88,14 @@ add_libc_unittest(
|
||||
SRCS
|
||||
epoll_pwait2_test.cpp
|
||||
DEPENDS
|
||||
libc.include.sys_epoll
|
||||
libc.hdr.sys_epoll_macros
|
||||
libc.hdr.types.struct_epoll_event
|
||||
libc.hdr.types.struct_timespec
|
||||
libc.src.errno.errno
|
||||
libc.src.sys.epoll.epoll_create1
|
||||
libc.src.sys.epoll.epoll_ctl
|
||||
libc.src.sys.epoll.epoll_pwait2
|
||||
libc.src.unistd.pipe
|
||||
libc.src.unistd.close
|
||||
libc.test.UnitTest.ErrnoSetterMatcher
|
||||
)
|
||||
|
||||
31
libc/test/src/sys/epoll/linux/epoll_create1_test.cpp
Normal file
31
libc/test/src/sys/epoll/linux/epoll_create1_test.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
//===-- Unittests for epoll_create1 ---------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "hdr/sys_epoll_macros.h"
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include "src/sys/epoll/epoll_create1.h"
|
||||
#include "src/unistd/close.h"
|
||||
#include "test/UnitTest/ErrnoSetterMatcher.h"
|
||||
#include "test/UnitTest/Test.h"
|
||||
|
||||
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
|
||||
|
||||
TEST(LlvmLibcEpollCreate1Test, Basic) {
|
||||
int fd = LIBC_NAMESPACE::epoll_create1(0);
|
||||
ASSERT_GT(fd, 0);
|
||||
ASSERT_ERRNO_SUCCESS();
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds());
|
||||
}
|
||||
|
||||
TEST(LlvmLibcEpollCreate1Test, CloseOnExecute) {
|
||||
int fd = LIBC_NAMESPACE::epoll_create1(EPOLL_CLOEXEC);
|
||||
ASSERT_GT(fd, 0);
|
||||
ASSERT_ERRNO_SUCCESS();
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds());
|
||||
}
|
||||
26
libc/test/src/sys/epoll/linux/epoll_create_test.cpp
Normal file
26
libc/test/src/sys/epoll/linux/epoll_create_test.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
//===-- Unittests for epoll_create ----------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include "src/sys/epoll/epoll_create.h"
|
||||
#include "src/unistd/close.h"
|
||||
#include "test/UnitTest/ErrnoSetterMatcher.h"
|
||||
#include "test/UnitTest/Test.h"
|
||||
|
||||
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
|
||||
|
||||
TEST(LlvmLibcEpollCreateTest, Basic) {
|
||||
int fd = LIBC_NAMESPACE::epoll_create(1);
|
||||
ASSERT_GT(fd, 0);
|
||||
ASSERT_ERRNO_SUCCESS();
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds());
|
||||
}
|
||||
|
||||
TEST(LlvmLibcEpollCreateTest, Fails) {
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_create(0), Fails(EINVAL));
|
||||
}
|
||||
47
libc/test/src/sys/epoll/linux/epoll_ctl_test.cpp
Normal file
47
libc/test/src/sys/epoll/linux/epoll_ctl_test.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
//===-- Unittests for epoll_ctl -------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "hdr/sys_epoll_macros.h"
|
||||
#include "hdr/types/struct_epoll_event.h"
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include "src/sys/epoll/epoll_create1.h"
|
||||
#include "src/sys/epoll/epoll_ctl.h"
|
||||
#include "src/unistd/close.h"
|
||||
#include "src/unistd/pipe.h"
|
||||
#include "test/UnitTest/ErrnoSetterMatcher.h"
|
||||
#include "test/UnitTest/Test.h"
|
||||
|
||||
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
|
||||
|
||||
TEST(LlvmLibcEpollCtlTest, Basic) {
|
||||
int epfd = LIBC_NAMESPACE::epoll_create1(0);
|
||||
ASSERT_GT(epfd, 0);
|
||||
ASSERT_ERRNO_SUCCESS();
|
||||
|
||||
int pipefd[2];
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::pipe(pipefd), Succeeds());
|
||||
|
||||
epoll_event event;
|
||||
event.events = EPOLLOUT;
|
||||
event.data.fd = pipefd[0];
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event),
|
||||
Succeeds());
|
||||
|
||||
// adding the same file fail.
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event),
|
||||
Fails(EEXIST));
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_DEL, pipefd[0], &event),
|
||||
Succeeds());
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds());
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds());
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(epfd), Succeeds());
|
||||
}
|
||||
@@ -5,16 +5,53 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "hdr/sys_epoll_macros.h"
|
||||
#include "hdr/types/struct_epoll_event.h"
|
||||
#include "hdr/types/struct_timespec.h"
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include "src/sys/epoll/epoll_create1.h"
|
||||
#include "src/sys/epoll/epoll_ctl.h"
|
||||
#include "src/sys/epoll/epoll_pwait2.h"
|
||||
#include "src/unistd/close.h"
|
||||
#include "src/unistd/pipe.h"
|
||||
#include "test/UnitTest/ErrnoSetterMatcher.h"
|
||||
#include "test/UnitTest/Test.h"
|
||||
|
||||
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
|
||||
|
||||
TEST(LlvmLibcEpollWaitTest, Basic) {
|
||||
EXPECT_THAT(LIBC_NAMESPACE::epoll_pwait2(-1, nullptr, 0, nullptr, nullptr),
|
||||
returns(EQ(-1ul)).with_errno(EQ(EINVAL)));
|
||||
}
|
||||
TEST(LlvmLibcEpollPwaitTest, Basic) {
|
||||
int epfd = LIBC_NAMESPACE::epoll_create1(0);
|
||||
ASSERT_GT(epfd, 0);
|
||||
ASSERT_ERRNO_SUCCESS();
|
||||
|
||||
// TODO: Complete these tests when epoll_create is implemented.
|
||||
int pipefd[2];
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::pipe(pipefd), Succeeds());
|
||||
|
||||
epoll_event event;
|
||||
event.events = EPOLLOUT;
|
||||
event.data.fd = pipefd[0];
|
||||
|
||||
timespec time_spec;
|
||||
time_spec.tv_sec = 0;
|
||||
time_spec.tv_nsec = 0;
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event),
|
||||
Succeeds());
|
||||
|
||||
// Timeout of 0 causes immediate return. We just need to check that the
|
||||
// interface works, we're not testing the kernel behavior here.
|
||||
ASSERT_THAT(
|
||||
LIBC_NAMESPACE::epoll_pwait2(epfd, &event, 1, &time_spec, nullptr),
|
||||
Succeeds());
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_pwait2(-1, &event, 1, &time_spec, nullptr),
|
||||
Fails(EBADF));
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_DEL, pipefd[0], &event),
|
||||
Succeeds());
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds());
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds());
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(epfd), Succeeds());
|
||||
}
|
||||
|
||||
@@ -5,16 +5,48 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "hdr/sys_epoll_macros.h"
|
||||
#include "hdr/types/struct_epoll_event.h"
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include "src/sys/epoll/epoll_create1.h"
|
||||
#include "src/sys/epoll/epoll_ctl.h"
|
||||
#include "src/sys/epoll/epoll_pwait.h"
|
||||
#include "src/unistd/close.h"
|
||||
#include "src/unistd/pipe.h"
|
||||
|
||||
#include "test/UnitTest/ErrnoSetterMatcher.h"
|
||||
#include "test/UnitTest/Test.h"
|
||||
|
||||
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
|
||||
|
||||
TEST(LlvmLibcEpollWaitTest, Basic) {
|
||||
EXPECT_THAT(LIBC_NAMESPACE::epoll_pwait(-1, nullptr, 0, 0, nullptr),
|
||||
returns(EQ(-1ul)).with_errno(EQ(EINVAL)));
|
||||
}
|
||||
TEST(LlvmLibcEpollPwaitTest, Basic) {
|
||||
int epfd = LIBC_NAMESPACE::epoll_create1(0);
|
||||
ASSERT_GT(epfd, 0);
|
||||
ASSERT_ERRNO_SUCCESS();
|
||||
|
||||
// TODO: Complete these tests when epoll_create is implemented.
|
||||
int pipefd[2];
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::pipe(pipefd), Succeeds());
|
||||
|
||||
epoll_event event;
|
||||
event.events = EPOLLOUT;
|
||||
event.data.fd = pipefd[0];
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event),
|
||||
Succeeds());
|
||||
|
||||
// Timeout of 0 causes immediate return. We just need to check that the
|
||||
// interface works, we're not testing the kernel behavior here.
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_pwait(epfd, &event, 1, 0, nullptr),
|
||||
Succeeds());
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_pwait(-1, &event, 1, 0, nullptr),
|
||||
Fails(EBADF));
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_DEL, pipefd[0], &event),
|
||||
Succeeds());
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds());
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds());
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(epfd), Succeeds());
|
||||
}
|
||||
|
||||
@@ -5,16 +5,45 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "hdr/sys_epoll_macros.h"
|
||||
#include "hdr/types/struct_epoll_event.h"
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include "src/sys/epoll/epoll_create1.h"
|
||||
#include "src/sys/epoll/epoll_ctl.h"
|
||||
#include "src/sys/epoll/epoll_wait.h"
|
||||
#include "src/unistd/close.h"
|
||||
#include "src/unistd/pipe.h"
|
||||
#include "test/UnitTest/ErrnoSetterMatcher.h"
|
||||
#include "test/UnitTest/Test.h"
|
||||
|
||||
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
|
||||
|
||||
TEST(LlvmLibcEpollWaitTest, Basic) {
|
||||
EXPECT_THAT(LIBC_NAMESPACE::epoll_wait(-1, nullptr, 0, 0),
|
||||
returns(EQ(-1ul)).with_errno(EQ(EINVAL)));
|
||||
}
|
||||
int epfd = LIBC_NAMESPACE::epoll_create1(0);
|
||||
ASSERT_GT(epfd, 0);
|
||||
ASSERT_ERRNO_SUCCESS();
|
||||
|
||||
// TODO: Complete these tests when epoll_create is implemented.
|
||||
int pipefd[2];
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::pipe(pipefd), Succeeds());
|
||||
|
||||
epoll_event event;
|
||||
event.events = EPOLLOUT;
|
||||
event.data.fd = pipefd[0];
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event),
|
||||
Succeeds());
|
||||
|
||||
// Timeout of 0 causes immediate return. We just need to check that the
|
||||
// interface works, we're not testing the kernel behavior here.
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_wait(epfd, &event, 1, 0), Succeeds());
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_wait(-1, &event, 1, 0), Fails(EBADF));
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_DEL, pipefd[0], &event),
|
||||
Succeeds());
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds());
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds());
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(epfd), Succeeds());
|
||||
}
|
||||
|
||||
@@ -212,6 +212,21 @@ add_libc_unittest(
|
||||
libc.test.UnitTest.ErrnoSetterMatcher
|
||||
)
|
||||
|
||||
add_libc_unittest(
|
||||
pipe_test
|
||||
SUITE
|
||||
libc_unistd_unittests
|
||||
SRCS
|
||||
pipe_test.cpp
|
||||
DEPENDS
|
||||
libc.include.errno
|
||||
libc.include.unistd
|
||||
libc.src.errno.errno
|
||||
libc.src.unistd.close
|
||||
libc.src.unistd.pipe
|
||||
libc.test.UnitTest.ErrnoSetterMatcher
|
||||
)
|
||||
|
||||
add_libc_unittest(
|
||||
rmdir_test
|
||||
SUITE
|
||||
|
||||
26
libc/test/src/unistd/pipe_test.cpp
Normal file
26
libc/test/src/unistd/pipe_test.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
//===-- Unittests for pipe ------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "src/unistd/close.h"
|
||||
#include "src/unistd/pipe.h"
|
||||
|
||||
#include "test/UnitTest/ErrnoSetterMatcher.h"
|
||||
#include "test/UnitTest/Test.h"
|
||||
|
||||
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
|
||||
|
||||
TEST(LlvmLibcPipeTest, SmokeTest) {
|
||||
|
||||
int pipefd[2];
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::pipe(pipefd), Succeeds());
|
||||
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds());
|
||||
ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds());
|
||||
}
|
||||
|
||||
// TODO: Functionality tests
|
||||
@@ -106,7 +106,7 @@ libc_support_library(
|
||||
hdrs = ["include/llvm-libc-macros/linux/fcntl-macros.h"],
|
||||
)
|
||||
|
||||
############################ Proxy Header Files ################################
|
||||
########################### Macro Proxy Header Files ###########################
|
||||
|
||||
libc_support_library(
|
||||
name = "hdr_math_macros",
|
||||
@@ -118,6 +118,33 @@ libc_support_library(
|
||||
hdrs = ["hdr/fenv_macros.h"],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "hdr_signal_macros",
|
||||
hdrs = ["hdr/signal_macros.h"],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "hdr_sys_epoll_macros",
|
||||
hdrs = ["hdr/sys_epoll_macros.h"],
|
||||
)
|
||||
|
||||
############################ Type Proxy Header Files ###########################
|
||||
|
||||
libc_support_library(
|
||||
name = "types_sigset_t",
|
||||
hdrs = ["hdr/types/sigset_t.h"],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "types_struct_epoll_event",
|
||||
hdrs = ["hdr/types/struct_epoll_event.h"],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "types_struct_timespec",
|
||||
hdrs = ["hdr/types/struct_timespec.h"],
|
||||
)
|
||||
|
||||
############################### Support libraries ##############################
|
||||
|
||||
libc_support_library(
|
||||
@@ -2941,6 +2968,17 @@ libc_function(
|
||||
],
|
||||
)
|
||||
|
||||
libc_function(
|
||||
name = "pipe",
|
||||
srcs = ["src/unistd/linux/pipe.cpp"],
|
||||
hdrs = ["src/unistd/pipe.h"],
|
||||
deps = [
|
||||
":__support_common",
|
||||
":__support_osutil_syscall",
|
||||
":errno",
|
||||
],
|
||||
)
|
||||
|
||||
libc_function(
|
||||
name = "lseek",
|
||||
srcs = ["src/unistd/linux/lseek.cpp"],
|
||||
@@ -3417,13 +3455,51 @@ libc_function(
|
||||
|
||||
############################## sys/epoll targets ###############################
|
||||
|
||||
libc_support_library(
|
||||
name = "types_sigset_t",
|
||||
hdrs = ["hdr/types/sigset_t.h"],
|
||||
libc_function(
|
||||
name = "epoll_create",
|
||||
srcs = ["src/sys/epoll/linux/epoll_create.cpp"],
|
||||
hdrs = ["src/sys/epoll/epoll_create.h"],
|
||||
target_compatible_with = select({
|
||||
"@platforms//os:linux": [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
weak = True,
|
||||
deps = [
|
||||
":__support_osutil_syscall",
|
||||
":errno",
|
||||
],
|
||||
)
|
||||
libc_support_library(
|
||||
name = "types_struct_epoll_event",
|
||||
hdrs = ["hdr/types/struct_epoll_event.h"],
|
||||
|
||||
libc_function(
|
||||
name = "epoll_create1",
|
||||
srcs = ["src/sys/epoll/linux/epoll_create1.cpp"],
|
||||
hdrs = ["src/sys/epoll/epoll_create1.h"],
|
||||
target_compatible_with = select({
|
||||
"@platforms//os:linux": [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
weak = True,
|
||||
deps = [
|
||||
":__support_osutil_syscall",
|
||||
":errno",
|
||||
],
|
||||
)
|
||||
|
||||
libc_function(
|
||||
name = "epoll_ctl",
|
||||
srcs = ["src/sys/epoll/linux/epoll_ctl.cpp"],
|
||||
hdrs = ["src/sys/epoll/epoll_ctl.h"],
|
||||
target_compatible_with = select({
|
||||
"@platforms//os:linux": [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
weak = True,
|
||||
deps = [
|
||||
":__support_osutil_syscall",
|
||||
":errno",
|
||||
":hdr_sys_epoll_macros",
|
||||
":types_struct_epoll_event",
|
||||
],
|
||||
)
|
||||
|
||||
libc_function(
|
||||
@@ -3438,6 +3514,8 @@ libc_function(
|
||||
deps = [
|
||||
":__support_osutil_syscall",
|
||||
":errno",
|
||||
":hdr_signal_macros",
|
||||
":hdr_sys_epoll_macros",
|
||||
":types_sigset_t",
|
||||
":types_struct_epoll_event",
|
||||
],
|
||||
@@ -3455,6 +3533,8 @@ libc_function(
|
||||
deps = [
|
||||
":__support_osutil_syscall",
|
||||
":errno",
|
||||
":hdr_signal_macros",
|
||||
":hdr_sys_epoll_macros",
|
||||
":types_sigset_t",
|
||||
":types_struct_epoll_event",
|
||||
],
|
||||
@@ -3466,9 +3546,18 @@ libc_function(
|
||||
# name = "epoll_pwait2",
|
||||
# srcs = ["src/sys/epoll/linux/epoll_pwait2.cpp"],
|
||||
# hdrs = ["src/sys/epoll/epoll_pwait2.h"],
|
||||
# target_compatible_with = select({
|
||||
# "@platforms//os:linux": [],
|
||||
# "//conditions:default": ["@platforms//:incompatible"],
|
||||
# }),
|
||||
# weak = True,
|
||||
# deps = [
|
||||
# ":__support_osutil_syscall",
|
||||
# ":errno",
|
||||
# ":hdr_signal_macros",
|
||||
# ":hdr_sys_epoll_macros",
|
||||
# ":types_sigset_t",
|
||||
# ":types_struct_epoll_event",
|
||||
# ":types_struct_timespec",
|
||||
# ],
|
||||
# )
|
||||
|
||||
@@ -10,11 +10,55 @@ package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
libc_test(
|
||||
name = "epoll_create_test",
|
||||
srcs = ["linux/epoll_create_test.cpp"],
|
||||
libc_function_deps = [
|
||||
"//libc:epoll_create",
|
||||
"//libc:close",
|
||||
],
|
||||
)
|
||||
|
||||
libc_test(
|
||||
name = "epoll_create1_test",
|
||||
srcs = ["linux/epoll_create1_test.cpp"],
|
||||
libc_function_deps = [
|
||||
"//libc:epoll_create1",
|
||||
"//libc:close",
|
||||
],
|
||||
deps = [
|
||||
"//libc:hdr_sys_epoll_macros",
|
||||
],
|
||||
)
|
||||
|
||||
libc_test(
|
||||
name = "epoll_ctl_test",
|
||||
srcs = ["linux/epoll_ctl_test.cpp"],
|
||||
libc_function_deps = [
|
||||
"//libc:epoll_create1",
|
||||
"//libc:epoll_ctl",
|
||||
"//libc:pipe",
|
||||
"//libc:close",
|
||||
],
|
||||
deps = [
|
||||
"//libc:hdr_sys_epoll_macros",
|
||||
"//libc:types_struct_epoll_event",
|
||||
],
|
||||
)
|
||||
|
||||
libc_test(
|
||||
name = "epoll_wait_test",
|
||||
srcs = ["linux/epoll_wait_test.cpp"],
|
||||
libc_function_deps = [
|
||||
"//libc:epoll_wait",
|
||||
"//libc:epoll_create1",
|
||||
"//libc:epoll_ctl",
|
||||
"//libc:pipe",
|
||||
"//libc:close",
|
||||
],
|
||||
deps = [
|
||||
"//libc:hdr_sys_epoll_macros",
|
||||
"//libc:types_struct_epoll_event",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -23,6 +67,14 @@ libc_test(
|
||||
srcs = ["linux/epoll_pwait_test.cpp"],
|
||||
libc_function_deps = [
|
||||
"//libc:epoll_pwait",
|
||||
"//libc:epoll_create1",
|
||||
"//libc:epoll_ctl",
|
||||
"//libc:pipe",
|
||||
"//libc:close",
|
||||
],
|
||||
deps = [
|
||||
"//libc:hdr_sys_epoll_macros",
|
||||
"//libc:types_struct_epoll_event",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -33,5 +85,14 @@ libc_test(
|
||||
# srcs = ["linux/epoll_pwait2_test.cpp"],
|
||||
# libc_function_deps = [
|
||||
# "//libc:epoll_pwait2",
|
||||
# "//libc:epoll_create1",
|
||||
# "//libc:epoll_ctl",
|
||||
# "//libc:pipe",
|
||||
# "//libc:close",
|
||||
# ],
|
||||
# deps = [
|
||||
# "//libc:hdr_sys_epoll_macros",
|
||||
# "//libc:types_struct_epoll_event",
|
||||
# "//libc:types_struct_timespec",
|
||||
# ],
|
||||
# )
|
||||
|
||||
Reference in New Issue
Block a user