Enforce `Werror` for all tests (again)

This commit is contained in:
Ruihan Li 2025-11-18 10:36:58 +08:00 committed by Tate, Hongliang Tian
parent bdbea8e8c6
commit 10b719b962
15 changed files with 46 additions and 33 deletions

View File

@ -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()

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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) {

View File

@ -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));

View File

@ -1,12 +1,9 @@
// SPDX-License-Identifier: MPL-2.0
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <sys/stat.h>
#include <errno.h>
#include <pthread.h>
#include <fcntl.h>
@ -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)

View File

@ -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;
}

View File

@ -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");

View File

@ -230,7 +230,6 @@ END_TEST()
FN_TEST(blocking_recv)
{
int i;
int sk1, sk2;
int pid;
char buf[20];

View File

@ -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);

View File

@ -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);

View File

@ -1,7 +1,6 @@
// SPDX-License-Identifier: MPL-2.0
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <ucontext.h>
@ -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));

View File

@ -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()
END_SETUP()

View File

@ -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)