From 10b719b96288d9bac27263e1ef9edaa484878461 Mon Sep 17 00:00:00 2001 From: Ruihan Li Date: Tue, 18 Nov 2025 10:36:58 +0800 Subject: [PATCH] Enforce `Werror` for all tests (again) --- test/src/apps/devfs/full.c | 10 +++++++++- test/src/apps/epoll/epoll_pwait.c | 6 +++--- test/src/apps/epoll/epoll_wait.c | 4 ++-- test/src/apps/file_io/access_err.c | 2 -- test/src/apps/mmap/mmap_shared_filebacked.c | 2 +- test/src/apps/namespace/mnt_ns.c | 16 ++++++++-------- test/src/apps/namespace/unshare.c | 9 ++++++--- test/src/apps/network/tcp_client.c | 2 +- test/src/apps/network/tcp_server.c | 2 +- test/src/apps/network/unix_datagram_err.c | 1 - test/src/apps/network/unix_server.c | 2 +- test/src/apps/pseudofs/memfd_access_err.c | 4 ++-- test/src/apps/signal_c/sigaltstack.c | 11 ++++++----- test/src/apps/signal_c/signal_fd.c | 6 +++++- test/src/apps/test_common.mk | 2 +- 15 files changed, 46 insertions(+), 33 deletions(-) diff --git a/test/src/apps/devfs/full.c b/test/src/apps/devfs/full.c index d56274135..7ea168b09 100644 --- a/test/src/apps/devfs/full.c +++ b/test/src/apps/devfs/full.c @@ -37,8 +37,12 @@ FN_TEST(read) _ret == READ_SIZE && memcmp(buffer, all_zeros, READ_SIZE) == 0); TEST_RES(read(fd, buffer, 0), _ret == 0); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wnonnull" TEST_ERRNO(read(fd, NULL, 1), EFAULT); TEST_RES(read(fd, NULL, 0), _ret == 0); +#pragma GCC diagnostic pop } END_TEST() @@ -46,15 +50,19 @@ FN_TEST(write) { TEST_ERRNO(write(fd, buffer, 1), ENOSPC); TEST_ERRNO(write(fd, buffer, 0), ENOSPC); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wnonnull" TEST_ERRNO(write(fd, NULL, 1), ENOSPC); TEST_ERRNO(write(fd, NULL, 0), ENOSPC); +#pragma GCC diagnostic pop } END_TEST() FN_TEST(poll) { struct pollfd pfd = { .fd = fd, .events = POLLIN | POLLOUT }; - TEST_RES(poll(&pfd, 1, 0), pfd.revents == POLLIN | POLLOUT); + TEST_RES(poll(&pfd, 1, 0), pfd.revents == (POLLIN | POLLOUT)); } END_TEST() diff --git a/test/src/apps/epoll/epoll_pwait.c b/test/src/apps/epoll/epoll_pwait.c index f630c0c0a..397fc544b 100644 --- a/test/src/apps/epoll/epoll_pwait.c +++ b/test/src/apps/epoll/epoll_pwait.c @@ -11,7 +11,7 @@ // Signal handler for SIGUSR1 static void handle_sigusr1(int sig) { - write(STDOUT_FILENO, "SIGUSR1 handled\n", 16); + (void)!write(STDOUT_FILENO, "SIGUSR1 handled\n", 16); } int main(void) @@ -47,8 +47,8 @@ int main(void) sleep(3); // Sleep for several seconds to provide a time window to send SIGUSR1 const char *message = "Message from child process\n"; - write(pipefd[1], message, - strlen(message)); // Write a string to the pipe + (void)!write(pipefd[1], message, + strlen(message)); // Write a string to the pipe close(pipefd[1]); // Close write end of the pipe _exit(EXIT_SUCCESS); } else { diff --git a/test/src/apps/epoll/epoll_wait.c b/test/src/apps/epoll/epoll_wait.c index 3c5a70f18..1d125bdeb 100644 --- a/test/src/apps/epoll/epoll_wait.c +++ b/test/src/apps/epoll/epoll_wait.c @@ -42,8 +42,8 @@ int main(void) if (cpid == 0) { // Child process close(pipefd[0]); // Child closes read end of the pipe const char *message = "Hello, world!\n"; - write(pipefd[1], message, - strlen(message)); // Write a string to the pipe + (void)!write(pipefd[1], message, + strlen(message)); // Write a string to the pipe close(pipefd[1]); // Close write end of the pipe _exit(EXIT_SUCCESS); } else { // Parent process diff --git a/test/src/apps/file_io/access_err.c b/test/src/apps/file_io/access_err.c index edaa3c5f2..bfaf22872 100644 --- a/test/src/apps/file_io/access_err.c +++ b/test/src/apps/file_io/access_err.c @@ -118,7 +118,6 @@ FN_TEST(writeable) { int fd; char buf[1]; - void *addr; // Test 1: Normal file @@ -164,7 +163,6 @@ FN_TEST(path) { int fd; char buf[1]; - void *addr; // Test 1: Normal file diff --git a/test/src/apps/mmap/mmap_shared_filebacked.c b/test/src/apps/mmap/mmap_shared_filebacked.c index 32c2b3c09..d0f1e10a9 100644 --- a/test/src/apps/mmap/mmap_shared_filebacked.c +++ b/test/src/apps/mmap/mmap_shared_filebacked.c @@ -39,7 +39,7 @@ void verify_file_contents(const char *path, const char *expected_content) } char buffer[FILE_SIZE] = { 0 }; - fread(buffer, 1, FILE_SIZE, file); + (void)!fread(buffer, 1, FILE_SIZE, file); fclose(file); if (strstr(buffer, expected_content) != NULL) { diff --git a/test/src/apps/namespace/mnt_ns.c b/test/src/apps/namespace/mnt_ns.c index 329824244..a4f5830d4 100644 --- a/test/src/apps/namespace/mnt_ns.c +++ b/test/src/apps/namespace/mnt_ns.c @@ -29,7 +29,7 @@ static int unshare_child_fn(void) CHECK(umount(UNSHARE_MNT)); - CHECK_WITH(access(UNSHARE_FILE, F_OK), errno == ENOENT); + CHECK_WITH(access(UNSHARE_FILE, F_OK), _ret == -1 && errno == ENOENT); return 0; } @@ -37,8 +37,8 @@ static int unshare_child_fn(void) FN_TEST(unshare_newns) { // Setup - CHECK_WITH(mkdir("/mnt", 0755), errno == 0 | errno == EEXIST); - CHECK_WITH(mkdir(UNSHARE_MNT, 0755), errno == 0 | errno == EEXIST); + CHECK_WITH(mkdir("/mnt", 0755), _ret >= 0 || errno == EEXIST); + CHECK_WITH(mkdir(UNSHARE_MNT, 0755), _ret >= 0 || errno == EEXIST); TEST_ERRNO(access(UNSHARE_FILE, F_OK), ENOENT); @@ -88,9 +88,9 @@ static int clone_child_fn(void *arg) FN_TEST(clone_newns) { // Setup - CHECK_WITH(mkdir("/mnt", 0755), errno == 0 | errno == EEXIST); - CHECK_WITH(mkdir(CLONE_PARENT_MNT, 0755), errno == 0 | errno == EEXIST); - CHECK_WITH(mkdir(CLONE_CHILD_MNT, 0755), errno == 0 | errno == EEXIST); + CHECK_WITH(mkdir("/mnt", 0755), _ret >= 0 || errno == EEXIST); + CHECK_WITH(mkdir(CLONE_PARENT_MNT, 0755), _ret >= 0 || errno == EEXIST); + CHECK_WITH(mkdir(CLONE_CHILD_MNT, 0755), _ret >= 0 || errno == EEXIST); TEST_SUCC(mount("ramfs_parent", CLONE_PARENT_MNT, "ramfs", 0, "")); int fd = TEST_SUCC(open(PARENT_FILE, O_CREAT | O_WRONLY, 0644)); @@ -147,8 +147,8 @@ static int setns_target_fn(int pipe_write_fd) FN_TEST(setns_newns) { // Setup - CHECK_WITH(mkdir("/mnt", 0755), errno == 0 | errno == EEXIST); - CHECK_WITH(mkdir(SETNS_MNT, 0755), errno == 0 | errno == EEXIST); + CHECK_WITH(mkdir("/mnt", 0755), _ret >= 0 || errno == EEXIST); + CHECK_WITH(mkdir(SETNS_MNT, 0755), _ret >= 0 || errno == EEXIST); int pipefd[2]; TEST_SUCC(pipe(pipefd)); diff --git a/test/src/apps/namespace/unshare.c b/test/src/apps/namespace/unshare.c index 3ddc01364..f992c3fa8 100644 --- a/test/src/apps/namespace/unshare.c +++ b/test/src/apps/namespace/unshare.c @@ -1,12 +1,9 @@ // SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE -#include -#include #include #include #include -#include #include #include @@ -31,6 +28,8 @@ END_TEST() void *sleep_1s_thread(void *arg) { sleep(1); + + return NULL; } FN_TEST(single_thread_flags) @@ -58,6 +57,8 @@ void *unshare_files_thread(void *arg) CHECK(unshare(CLONE_FILES)); CHECK(close(test_fd)); + + return NULL; } FN_TEST(unshare_files) @@ -106,6 +107,8 @@ void *unshare_fs_thread(void *arg) CHECK(chdir(THREAD_CWD)); CHECK(getcwd((char *)arg, CWD_BUF_SIZE)); + + return NULL; } FN_TEST(unshare_fs) diff --git a/test/src/apps/network/tcp_client.c b/test/src/apps/network/tcp_client.c index c9a8b7edf..33f427db6 100644 --- a/test/src/apps/network/tcp_client.c +++ b/test/src/apps/network/tcp_client.c @@ -40,7 +40,7 @@ int main() // Send message to the server and receive the reply send(sock, hello, strlen(hello), 0); printf("Hello message sent\n"); - read(sock, buffer, 1024); + (void)!read(sock, buffer, 1024); printf("Server: %s\n", buffer); return 0; } diff --git a/test/src/apps/network/tcp_server.c b/test/src/apps/network/tcp_server.c index 4552ff843..bdbe03a6f 100644 --- a/test/src/apps/network/tcp_server.c +++ b/test/src/apps/network/tcp_server.c @@ -60,7 +60,7 @@ int main() } // Read the message from the client and reply - read(new_socket, buffer, 1024); + (void)!read(new_socket, buffer, 1024); printf("Client: %s\n", buffer); send(new_socket, hello, strlen(hello), 0); printf("Hello message sent\n"); diff --git a/test/src/apps/network/unix_datagram_err.c b/test/src/apps/network/unix_datagram_err.c index b4766da83..5ea425628 100644 --- a/test/src/apps/network/unix_datagram_err.c +++ b/test/src/apps/network/unix_datagram_err.c @@ -230,7 +230,6 @@ END_TEST() FN_TEST(blocking_recv) { - int i; int sk1, sk2; int pid; char buf[20]; diff --git a/test/src/apps/network/unix_server.c b/test/src/apps/network/unix_server.c index 609af3e14..7e552916b 100644 --- a/test/src/apps/network/unix_server.c +++ b/test/src/apps/network/unix_server.c @@ -63,7 +63,7 @@ int main() printf("Server is connected to client\n"); char *mesg = "Hello from unix socket server"; - write(accepted_fd, mesg, strlen(mesg)); + (void)!write(accepted_fd, mesg, strlen(mesg)); // Read data from the client memset(buf, 0, BUFFER_SIZE); diff --git a/test/src/apps/pseudofs/memfd_access_err.c b/test/src/apps/pseudofs/memfd_access_err.c index ff9e68eb5..7fd41ac3c 100644 --- a/test/src/apps/pseudofs/memfd_access_err.c +++ b/test/src/apps/pseudofs/memfd_access_err.c @@ -30,8 +30,8 @@ FN_TEST(path) { int fd = TEST_SUCC(open(memfd_path, O_PATH | O_RDWR)); char buf[10]; - int flags = - TEST_RES(fcntl(fd, F_GETFL), (_ret & O_ACCMODE) == O_RDONLY); + + TEST_RES(fcntl(fd, F_GETFL), (_ret & O_ACCMODE) == O_RDONLY); TEST_ERRNO(fcntl(fd, F_ADD_SEALS, F_SEAL_SEAL), EBADF); TEST_ERRNO(fcntl(fd, F_GET_SEALS), EBADF); diff --git a/test/src/apps/signal_c/sigaltstack.c b/test/src/apps/signal_c/sigaltstack.c index 70b0814b9..20ddac4b0 100644 --- a/test/src/apps/signal_c/sigaltstack.c +++ b/test/src/apps/signal_c/sigaltstack.c @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE -#include #include #include #include @@ -18,7 +17,7 @@ #define SS_AUTODISARM (1 << 31) #endif -static volatile void *g_alt_stack_base = NULL; +static void *volatile g_alt_stack_base = NULL; static volatile int recursion_level = 0; static volatile bool sigstack_enabled = false; static volatile int stack_flags = 0; @@ -69,7 +68,9 @@ void signal_handler(int sig, siginfo_t *info, void *ucontext) CHECK(on_sig_stack(uc)); if (recursion_level == 1) { - CHECK(sigaltstack(NULL, &old_stack)); + stack_t old_stack_tmp; + CHECK(sigaltstack(NULL, &old_stack_tmp)); + old_stack = old_stack_tmp; } if (recursion_level <= 3) { @@ -214,12 +215,12 @@ FN_TEST(stack_flags_in_uc_context) alt_stack.ss_flags = SS_ONSTACK | SS_AUTODISARM; TEST_SUCC(sigaltstack(&alt_stack, NULL)); TEST_RES(raise(SIGUSR2), - current_stack.ss_flags == SS_ONSTACK | SS_AUTODISARM); + current_stack.ss_flags == (SS_ONSTACK | SS_AUTODISARM)); alt_stack.ss_flags = SS_DISABLE | SS_AUTODISARM; TEST_SUCC(sigaltstack(&alt_stack, NULL)); TEST_RES(raise(SIGUSR2), - current_stack.ss_flags == SS_DISABLE | SS_AUTODISARM); + current_stack.ss_flags == (SS_DISABLE | SS_AUTODISARM)); alt_stack.ss_flags = 0; TEST_SUCC(sigaltstack(&alt_stack, NULL)); diff --git a/test/src/apps/signal_c/signal_fd.c b/test/src/apps/signal_c/signal_fd.c index 8906f406f..4ca805f6d 100644 --- a/test/src/apps/signal_c/signal_fd.c +++ b/test/src/apps/signal_c/signal_fd.c @@ -187,6 +187,8 @@ void *thread_func(void *arg) sleep(2); pid_t pid = CHECK(getpid()); CHECK(tgkill(pid, pid, SIGUSR1)); + + return NULL; } FN_TEST(tgkill_other_thread) @@ -216,6 +218,8 @@ void *thread_func2(void *arg) CHECK_WITH(sigprocmask(SIG_BLOCK, NULL, &sigset), sigisemptyset(&sigset)); CHECK_WITH(sigpending(&sigset), sigisemptyset(&sigset)); + + return NULL; } FN_TEST(blocking_syscall_dequeue_ignored_signals) @@ -259,4 +263,4 @@ FN_SETUP(cleanup) { CHECK(close(sfd)); } -END_SETUP() \ No newline at end of file +END_SETUP() diff --git a/test/src/apps/test_common.mk b/test/src/apps/test_common.mk index 5f645fe09..0118e0750 100644 --- a/test/src/apps/test_common.mk +++ b/test/src/apps/test_common.mk @@ -13,7 +13,7 @@ C_DEPS := $(addprefix $(DEP_OUTPUT_DIR)/,$(C_SRCS:%.c=%.d)) ASM_SRCS := $(wildcard *.S) ASM_OBJS := $(addprefix $(OBJ_OUTPUT_DIR)/,$(ASM_SRCS:%.S=%)) CC ?= gcc -C_FLAGS ?= -Wall -Werror +C_FLAGS += -Wall -Werror .PHONY: all all: $(C_OBJS) $(ASM_OBJS)