mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 08:06:32 +00:00
feat: 实现并测试 newfstatat 系统调用 (#1153)
* feat: 实现并测试 newfstatat 系统调用 新增了 newfstatat 系统调用的实现,并添加了相应的测试应用。 Signed-off-by: longjin <longjin@DragonOS.org> * feat(loongarch64/riscv64): 添加文件系统模块并实现GenericPosixStat结构 为loongarch64和riscv64架构添加filesystem模块,包含stat子模块,并实现GenericPosixStat结构用于处理文件状态信息。 Signed-off-by: longjin <longjin@DragonOS.org> --------- Signed-off-by: longjin <longjin@DragonOS.org>
This commit is contained in:
1
user/apps/test_newfstatat/.gitignore
vendored
Normal file
1
user/apps/test_newfstatat/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
test_newfstatat
|
20
user/apps/test_newfstatat/Makefile
Normal file
20
user/apps/test_newfstatat/Makefile
Normal file
@ -0,0 +1,20 @@
|
||||
ifeq ($(ARCH), x86_64)
|
||||
CROSS_COMPILE=x86_64-linux-musl-
|
||||
else ifeq ($(ARCH), riscv64)
|
||||
CROSS_COMPILE=riscv64-linux-musl-
|
||||
endif
|
||||
|
||||
CC=$(CROSS_COMPILE)gcc
|
||||
|
||||
.PHONY: all
|
||||
all: main.c
|
||||
$(CC) -static -o test_newfstatat main.c
|
||||
|
||||
.PHONY: install clean
|
||||
install: all
|
||||
mv test_newfstatat $(DADK_CURRENT_BUILD_DIR)/test_newfstatat
|
||||
|
||||
clean:
|
||||
rm test_newfstatat *.o
|
||||
|
||||
fmt:
|
65
user/apps/test_newfstatat/main.c
Normal file
65
user/apps/test_newfstatat/main.c
Normal file
@ -0,0 +1,65 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
|
||||
|
||||
#define TEST_DIR "test_dir"
|
||||
#define TEST_FILE "test_file"
|
||||
|
||||
void create_test_files() {
|
||||
mkdir(TEST_DIR, 0755);
|
||||
int fd = open(TEST_FILE, O_CREAT | O_RDWR, 0644);
|
||||
if (fd >= 0) close(fd);
|
||||
}
|
||||
|
||||
void cleanup_test_files() {
|
||||
unlink(TEST_FILE);
|
||||
rmdir(TEST_DIR);
|
||||
}
|
||||
|
||||
void run_test(const char *name, int (*test_func)(), int expected) {
|
||||
printf("Testing %s... ", name);
|
||||
int result = test_func();
|
||||
if (result == expected) {
|
||||
printf("[PASS]\n");
|
||||
} else {
|
||||
printf("[FAILED] (expected %d, got %d)\n", expected, result);
|
||||
}
|
||||
}
|
||||
|
||||
int test_normal_file() {
|
||||
struct stat st;
|
||||
return syscall(__NR_newfstatat, AT_FDCWD, TEST_FILE, &st, 0);
|
||||
}
|
||||
|
||||
int test_directory() {
|
||||
struct stat st;
|
||||
return syscall(__NR_newfstatat, AT_FDCWD, TEST_DIR, &st, 0);
|
||||
}
|
||||
|
||||
int test_invalid_fd() {
|
||||
struct stat st;
|
||||
return syscall(__NR_newfstatat, -1, TEST_FILE, &st, 0);
|
||||
}
|
||||
|
||||
int test_nonexistent_path() {
|
||||
struct stat st;
|
||||
return syscall(__NR_newfstatat, AT_FDCWD, "nonexistent_file", &st, 0);
|
||||
}
|
||||
|
||||
int main() {
|
||||
create_test_files();
|
||||
|
||||
run_test("normal file stat", test_normal_file, 0);
|
||||
run_test("directory stat", test_directory, 0);
|
||||
run_test("invalid file descriptor", test_invalid_fd, -1);
|
||||
run_test("nonexistent path", test_nonexistent_path, -1);
|
||||
|
||||
cleanup_test_files();
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user