Define `__asterinas__` macro in tests
This commit is contained in:
parent
da67967f6d
commit
f30bd698d1
|
|
@ -181,9 +181,15 @@ FN_TEST(path)
|
|||
|
||||
TEST_ERRNO(mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, 0), EBADF);
|
||||
// FIXME: Asterinas reports `EACCES` because it performs the permission check first.
|
||||
// TEST_ERRNO(mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
|
||||
// 0),
|
||||
// EBADF);
|
||||
#ifdef __asterinas__
|
||||
TEST_ERRNO(mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
|
||||
0),
|
||||
EACCES);
|
||||
#else
|
||||
TEST_ERRNO(mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
|
||||
0),
|
||||
EBADF);
|
||||
#endif
|
||||
|
||||
TEST_ERRNO(flock(fd, LOCK_SH), EBADF);
|
||||
TEST_ERRNO(flock(fd, LOCK_UN), EBADF);
|
||||
|
|
@ -214,9 +220,15 @@ FN_TEST(path)
|
|||
|
||||
TEST_ERRNO(mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, 0), EBADF);
|
||||
// FIXME: Asterinas reports `EACCES` because it performs the permission check first.
|
||||
// TEST_ERRNO(mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
|
||||
// 0),
|
||||
// EBADF);
|
||||
#ifdef __asterinas__
|
||||
TEST_ERRNO(mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
|
||||
0),
|
||||
EACCES);
|
||||
#else
|
||||
TEST_ERRNO(mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
|
||||
0),
|
||||
EBADF);
|
||||
#endif
|
||||
|
||||
TEST_ERRNO(flock(fd, LOCK_SH), EBADF);
|
||||
TEST_ERRNO(flock(fd, LOCK_UN), EBADF);
|
||||
|
|
|
|||
|
|
@ -42,8 +42,12 @@ FN_TEST(mremap)
|
|||
TEST_ERRNO(mremap(addr, 0, PAGE_SIZE, 0), EINVAL);
|
||||
|
||||
// There is no enough room to expand the mapping.
|
||||
// FIXME: Asterinas returns EACCESS here, which is not a correct error code.
|
||||
// TEST_ERRNO(mremap(addr, PAGE_SIZE, 2 * PAGE_SIZE, 0), ENOMEM);
|
||||
// FIXME: Asterinas returns EACCES here, which is not a correct error code.
|
||||
#ifdef __asterinas__
|
||||
TEST_ERRNO(mremap(addr, PAGE_SIZE, 2 * PAGE_SIZE, 0), EACCES);
|
||||
#else
|
||||
TEST_ERRNO(mremap(addr, PAGE_SIZE, 2 * PAGE_SIZE, 0), ENOMEM);
|
||||
#endif
|
||||
|
||||
char *hole = addr + 2 * PAGE_SIZE;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,7 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <sched.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include "../test.h"
|
||||
|
|
@ -15,10 +12,12 @@ FN_TEST(set_ns_empty_flags)
|
|||
{
|
||||
// FIXME: The following test will fail on Asterinas
|
||||
// because it currently does not support ns file.
|
||||
// const char *ns_path = "/proc/self/ns/user";
|
||||
// int fd_ns = TEST_SUCC(open(ns_path, O_RDONLY));
|
||||
// TEST_ERRNO(setns(fd_ns, 0), EINVAL);
|
||||
// TEST_SUCC(close(fd_ns));
|
||||
#ifndef __asterinas__
|
||||
const char *ns_path = "/proc/self/ns/user";
|
||||
int fd_ns = TEST_SUCC(open(ns_path, O_RDONLY));
|
||||
TEST_ERRNO(setns(fd_ns, 0), EINVAL);
|
||||
TEST_SUCC(close(fd_ns));
|
||||
#endif
|
||||
|
||||
pid_t pid = getpid();
|
||||
int pidfd = TEST_SUCC(syscall(SYS_pidfd_open, pid, 0));
|
||||
|
|
@ -33,10 +32,12 @@ FN_TEST(set_self_ns)
|
|||
// current user namespace. This is different from other namespaces.
|
||||
// FIXME: The following test will fail on Asterinas
|
||||
// because it currently does not support ns file.
|
||||
// const char *ns_path = "/proc/self/ns/user";
|
||||
// int fd_ns = TEST_SUCC(open(ns_path, O_RDONLY));
|
||||
// TEST_ERRNO(setns(fd_ns, CLONE_NEWUSER), EINVAL);
|
||||
// TEST_SUCC(close(fd_ns));
|
||||
#ifndef __asterinas__
|
||||
const char *ns_path = "/proc/self/ns/user";
|
||||
int fd_ns = TEST_SUCC(open(ns_path, O_RDONLY));
|
||||
TEST_ERRNO(setns(fd_ns, CLONE_NEWUSER), EINVAL);
|
||||
TEST_SUCC(close(fd_ns));
|
||||
#endif
|
||||
|
||||
pid_t pid = getpid();
|
||||
int pidfd = TEST_SUCC(syscall(SYS_pidfd_open, pid, 0));
|
||||
|
|
|
|||
|
|
@ -224,7 +224,11 @@ FN_TEST(get_link_error)
|
|||
// Invalid name attribute (too short) with index
|
||||
req.ifi.ifi_index = 1234;
|
||||
// FIXME: Asterinas will report `EINVAL` because it performs strict validation.
|
||||
// TEST_ERROR_SEGMENT(ENODEV);
|
||||
#ifdef __asterinas__
|
||||
TEST_ERROR_SEGMENT(EINVAL);
|
||||
#else
|
||||
TEST_ERROR_SEGMENT(ENODEV);
|
||||
#endif
|
||||
|
||||
// Invalid name attribute (too long) with index
|
||||
req.hdr.nlmsg_len = sizeof(struct nl_req) + 1;
|
||||
|
|
|
|||
|
|
@ -243,14 +243,15 @@ FN_TEST(bind_reuseaddr)
|
|||
|
||||
TEST_ERRNO(bind(sk2, psaddr, addrlen), EADDRINUSE);
|
||||
|
||||
TEST_SUCC(setsockopt(sk1, SOL_SOCKET, SO_REUSEADDR, &disable,
|
||||
sizeof(disable)));
|
||||
TEST_SUCC(setsockopt(sk2, SOL_SOCKET, SO_REUSEADDR, &enable,
|
||||
sizeof(enable)));
|
||||
// FIXME: The test will fail in Asterinas since it doesn't check
|
||||
// if the previous socket was bound with `SO_REUSEADDR`
|
||||
//
|
||||
// TEST_SUCC(setsockopt(sk1, SOL_SOCKET, SO_REUSEADDR, &disable,
|
||||
// sizeof(disable)));
|
||||
// TEST_SUCC(setsockopt(sk2, SOL_SOCKET, SO_REUSEADDR, &enable,
|
||||
// sizeof(enable)));
|
||||
// TEST_ERRNO(bind(sk2, psaddr, addrlen), EADDRINUSE);
|
||||
// if the previous socket was bound with `SO_REUSEADDR`.
|
||||
#ifndef __asterinas__
|
||||
TEST_ERRNO(bind(sk2, psaddr, addrlen), EADDRINUSE);
|
||||
#endif
|
||||
|
||||
TEST_SUCC(setsockopt(sk1, SOL_SOCKET, SO_REUSEADDR, &enable,
|
||||
sizeof(enable)));
|
||||
|
|
|
|||
|
|
@ -246,11 +246,13 @@ FN_TEST(poll_shutdown_readwrite)
|
|||
// FIXME: This socket error should be `EPIPE`, but in Asterinas it is
|
||||
// `ECONNRESET`. See the Linux implementation for details:
|
||||
// <https://github.com/torvalds/linux/blob/848e076317446f9c663771ddec142d7c2eb4cb43/net/ipv4/tcp_input.c#L4553-L4555>.
|
||||
//
|
||||
// TEST_RES(getsockopt(sk_connect, SOL_SOCKET, SO_ERROR, &err, &errlen),
|
||||
// errlen == sizeof(err) && err == EPIPE);
|
||||
#ifdef __asterinas__
|
||||
TEST_RES(getsockopt(sk_accept, SOL_SOCKET, SO_ERROR, &err, &errlen),
|
||||
errlen == sizeof(err) && err == ECONNRESET);
|
||||
#else
|
||||
TEST_RES(getsockopt(sk_connect, SOL_SOCKET, SO_ERROR, &err, &errlen),
|
||||
errlen == sizeof(err) && err == EPIPE);
|
||||
#endif
|
||||
}
|
||||
END_TEST()
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,9 @@ FN_TEST(bind_to_listening_port)
|
|||
|
||||
// Currently, Asterinas does not check whether the port is already in use
|
||||
// by a listening socket when binding, so this test will fail.
|
||||
// TEST_ERRNO(bind(sock2, (struct sockaddr *)&addr, addrlen), EADDRINUSE);
|
||||
#ifndef __asterinas__
|
||||
TEST_ERRNO(bind(sock2, (struct sockaddr *)&addr, addrlen), EADDRINUSE);
|
||||
#endif
|
||||
}
|
||||
END_TEST()
|
||||
|
||||
|
|
@ -105,7 +107,9 @@ FN_TEST(listen_on_the_same_port)
|
|||
|
||||
// Currently, Asterinas does not check whether the port is already in use
|
||||
// by a listening socket when binding, so this test will fail.
|
||||
// TEST_ERRNO(bind(sock3, (struct sockaddr *)&addr, addrlen), EADDRINUSE);
|
||||
#ifndef __asterinas__
|
||||
TEST_ERRNO(bind(sock3, (struct sockaddr *)&addr, addrlen), EADDRINUSE);
|
||||
#endif
|
||||
}
|
||||
END_TEST()
|
||||
|
||||
|
|
@ -188,16 +192,17 @@ FN_TEST(disable_reuse_after_bound)
|
|||
|
||||
TEST_SUCC(getsockname(sock1, (struct sockaddr *)&addr, &addrlen));
|
||||
|
||||
option = 1;
|
||||
TEST_SUCC(setsockopt(sock2, SOL_SOCKET, SO_REUSEADDR, &option,
|
||||
sizeof(option)));
|
||||
// The following test succeeds on Linux because Linux does not allow disabling
|
||||
// SO_REUSEADDR for TCP sockets once the socket is bound. In contrast, Asterinas
|
||||
// enforces a stricter rule: the port can be reused only if all sockets bound to it
|
||||
// have port reuse enabled.
|
||||
// See the discussion at <https://github.com/asterinas/asterinas/pull/2277#discussion_r2230139244>.
|
||||
//
|
||||
// option = 1;
|
||||
// TEST_SUCC(setsockopt(sock2, SOL_SOCKET, SO_REUSEADDR, &option,
|
||||
// sizeof(option)));
|
||||
// TEST_SUCC(bind(sock2, (struct sockaddr *)&addr, addrlen));
|
||||
#ifndef __asterinas__
|
||||
TEST_SUCC(bind(sock2, (struct sockaddr *)&addr, addrlen));
|
||||
#endif
|
||||
}
|
||||
END_TEST()
|
||||
|
||||
|
|
@ -207,4 +212,4 @@ FN_SETUP(cleanup)
|
|||
CHECK(close(sock2));
|
||||
CHECK(close(sock3));
|
||||
}
|
||||
END_SETUP()
|
||||
END_SETUP()
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
|
@ -48,7 +45,9 @@ FN_SETUP(create_and_bind)
|
|||
receiver = CHECK(socket(AF_INET, SOCK_DGRAM, 0));
|
||||
// FIXME: Asterinas cannot support binding to broadcast addresses now.
|
||||
// So all below code related to receiver is commented out.
|
||||
// CHECK(bind(receiver, (struct sockaddr *)&broadcast_addr, addr_len));
|
||||
#ifndef __asterinas__
|
||||
CHECK(bind(receiver, (struct sockaddr *)&broadcast_addr, addr_len));
|
||||
#endif
|
||||
}
|
||||
END_SETUP()
|
||||
|
||||
|
|
@ -83,8 +82,10 @@ FN_TEST(basic_broadcast)
|
|||
TEST_SUCC(sendto(sender, MESSAGE, MESSAGE_LEN, 0,
|
||||
(struct sockaddr *)&broadcast_addr, addr_len));
|
||||
|
||||
// TEST_SUCC(recvfrom(receiver, buf, sizeof(buf), 0,
|
||||
// (struct sockaddr *)&received_addr, &addr_len));
|
||||
#ifndef __asterinas__
|
||||
TEST_SUCC(recvfrom(receiver, buf, sizeof(buf), 0,
|
||||
(struct sockaddr *)&received_addr, &addr_len));
|
||||
#endif
|
||||
}
|
||||
END_TEST()
|
||||
|
||||
|
|
@ -120,8 +121,10 @@ FN_TEST(disable_receiver_broadcast)
|
|||
TEST_SUCC(sendto(sender, MESSAGE, MESSAGE_LEN, 0,
|
||||
(struct sockaddr *)&broadcast_addr, addr_len));
|
||||
|
||||
// TEST_SUCC(recvfrom(receiver, buf, sizeof(buf), 0,
|
||||
// (struct sockaddr *)&received_addr, &addr_len));
|
||||
#ifndef __asterinas__
|
||||
TEST_SUCC(recvfrom(receiver, buf, sizeof(buf), 0,
|
||||
(struct sockaddr *)&received_addr, &addr_len));
|
||||
#endif
|
||||
}
|
||||
END_TEST()
|
||||
|
||||
|
|
@ -132,16 +135,20 @@ FN_TEST(connect_then_disable_broadcast)
|
|||
TEST_SUCC(
|
||||
connect(sender, (struct sockaddr *)&broadcast_addr, addr_len));
|
||||
TEST_SUCC(send(sender, MESSAGE, MESSAGE_LEN, 0));
|
||||
// TEST_SUCC(recvfrom(receiver, buf, sizeof(buf), 0,
|
||||
// (struct sockaddr *)&received_addr, &addr_len));
|
||||
#ifndef __asterinas__
|
||||
TEST_SUCC(recvfrom(receiver, buf, sizeof(buf), 0,
|
||||
(struct sockaddr *)&received_addr, &addr_len));
|
||||
#endif
|
||||
|
||||
broadcast_opt = 0;
|
||||
TEST_SUCC(setsockopt(sender, SOL_SOCKET, SO_BROADCAST, &broadcast_opt,
|
||||
broadcast_opt_len));
|
||||
|
||||
TEST_SUCC(send(sender, MESSAGE, MESSAGE_LEN, 0));
|
||||
// TEST_SUCC(recvfrom(receiver, buf, sizeof(buf), 0,
|
||||
// (struct sockaddr *)&received_addr, &addr_len));
|
||||
#ifndef __asterinas__
|
||||
TEST_SUCC(recvfrom(receiver, buf, sizeof(buf), 0,
|
||||
(struct sockaddr *)&received_addr, &addr_len));
|
||||
#endif
|
||||
|
||||
TEST_ERRNO(sendto(sender, MESSAGE, MESSAGE_LEN, 0,
|
||||
(struct sockaddr *)&broadcast_addr, addr_len),
|
||||
|
|
@ -153,7 +160,9 @@ FN_TEST(connect_then_disable_broadcast)
|
|||
// FIXME: Asterinas cannot pass the following case.
|
||||
// The problem may be that we should invalidate the connected state
|
||||
// once the above connect fails.
|
||||
// TEST_ERRNO(send(sender, MESSAGE, MESSAGE_LEN, 0), EACCES);
|
||||
#ifndef __asterinas__
|
||||
TEST_ERRNO(send(sender, MESSAGE, MESSAGE_LEN, 0), EACCES);
|
||||
#endif
|
||||
}
|
||||
END_TEST()
|
||||
|
||||
|
|
@ -162,4 +171,4 @@ FN_SETUP(cleanup)
|
|||
CHECK(close(sender));
|
||||
CHECK(close(receiver));
|
||||
}
|
||||
END_SETUP()
|
||||
END_SETUP()
|
||||
|
|
|
|||
|
|
@ -140,8 +140,9 @@ FN_TEST(setsid_session_leader)
|
|||
{
|
||||
// FIXME: We fail this test to work around a gVisor bug.
|
||||
// See comments in `Process::to_new_session` for details.
|
||||
//
|
||||
// TEST_ERRNO(setsid(), EPERM);
|
||||
#ifndef __asterinas__
|
||||
TEST_ERRNO(setsid(), EPERM);
|
||||
#endif
|
||||
}
|
||||
END_TEST()
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "../test.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
|
@ -300,11 +299,15 @@ FN_TEST(nested_signals)
|
|||
// when the thread is stopped, while Linux does not.
|
||||
TEST_SUCC(kill(child_pid, SIGINT));
|
||||
sleep(1);
|
||||
// TEST_ERRNO(read(pipe_fds[0], buf, 1), EAGAIN);
|
||||
#ifndef __asterinas__
|
||||
TEST_ERRNO(read(pipe_fds[0], buf, 1), EAGAIN);
|
||||
#endif
|
||||
|
||||
TEST_SUCC(kill(child_pid, SIGTRAP));
|
||||
sleep(1);
|
||||
// TEST_ERRNO(read(pipe_fds[0], buf, 1), EAGAIN);
|
||||
#ifndef __asterinas__
|
||||
TEST_ERRNO(read(pipe_fds[0], buf, 1), EAGAIN);
|
||||
#endif
|
||||
|
||||
TEST_RES(wait4(child_pid, &status, WSTOPPED, NULL),
|
||||
_ret == child_pid && WIFSTOPPED(status) &&
|
||||
|
|
|
|||
|
|
@ -33,14 +33,7 @@ FN_TEST(kill_blocked_and_ignored)
|
|||
|
||||
signal(SIGCHLD, &signal_handler);
|
||||
|
||||
// FIXME: Currently, Asterinas never queues an ignored signal, so this test
|
||||
// will fail. See the comments at `PosixThread::enqueue_signal_locked` for
|
||||
// more details.
|
||||
//
|
||||
// received_signals = 0;
|
||||
// TEST_RES(sigprocmask(SIG_UNBLOCK, &sigs, NULL), received_signals == 1);
|
||||
//
|
||||
sigprocmask(SIG_UNBLOCK, &sigs, NULL);
|
||||
TEST_RES(sigprocmask(SIG_UNBLOCK, &sigs, NULL), received_signals == 1);
|
||||
}
|
||||
END_TEST()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue