From 7a5f5f5b656e6b81ca84ef6524224854328c1a25 Mon Sep 17 00:00:00 2001 From: Gianmatteo Palmieri Date: Mon, 18 Mar 2024 16:16:22 +0100 Subject: [PATCH] new(tests): expect more params in open syscalls test Signed-off-by: Gianmatteo Palmieri --- .../open_by_handle_at_x.cpp | 46 +++++++++++++++---- .../syscall_exit_suite/openat2_x.cpp | 38 +++++++++++++-- 2 files changed, 73 insertions(+), 11 deletions(-) diff --git a/test/drivers/test_suites/syscall_exit_suite/open_by_handle_at_x.cpp b/test/drivers/test_suites/syscall_exit_suite/open_by_handle_at_x.cpp index 2befea40bf7..977292f3f38 100644 --- a/test/drivers/test_suites/syscall_exit_suite/open_by_handle_at_x.cpp +++ b/test/drivers/test_suites/syscall_exit_suite/open_by_handle_at_x.cpp @@ -8,7 +8,7 @@ #define MAX_FSPATH_LEN 4096 -void do___open_by_handle_atX_success(int *open_by_handle_fd, int *dirfd, char *fspath, int use_mountpoint) +void do___open_by_handle_atX_success(int *open_by_handle_fd, int *dirfd, char *fspath, uint32_t *dev, uint64_t *inode, int use_mountpoint) { /* * 0. Create (temporary) mount point (if use_mountpoint). @@ -100,7 +100,15 @@ void do___open_by_handle_atX_success(int *open_by_handle_fd, int *dirfd, char *f } /* - * 6. Cleaning phase. + * 6. Get dev and ino. + */ + struct stat file_stat; + assert_syscall_state(SYSCALL_SUCCESS, "fstat", syscall(__NR_fstat, *open_by_handle_fd, &file_stat), NOT_EQUAL, -1); + *dev = (uint32_t)file_stat.st_dev; + *inode = file_stat.st_ino; + + /* + * 7. Cleaning phase. */ close(*open_by_handle_fd); free(fhp); @@ -147,8 +155,10 @@ TEST(SyscallExit, open_by_handle_atX_success) int open_by_handle_fd; int dirfd; char fspath[MAX_FSPATH_LEN]; - do___open_by_handle_atX_success(&open_by_handle_fd, &dirfd, fspath, 0); - + uint32_t dev; + uint64_t inode; + do___open_by_handle_atX_success(&open_by_handle_fd, &dirfd, fspath, &dev, &inode, 0); + /*=============================== TRIGGER SYSCALL ===========================*/ evt_test->disable_capture(); @@ -177,9 +187,15 @@ TEST(SyscallExit, open_by_handle_atX_success) /* Parameter 4: path (type: PT_FSPATH) */ evt_test->assert_charbuf_param(4, fspath); + /* Parameter 5: dev (type: PT_UINT32) */ + evt_test->assert_numeric_param(5, dev); + + /* Parameter 6: ino (type: PT_UINT64) */ + evt_test->assert_numeric_param(6, inode); + /*=============================== ASSERT PARAMETERS ===========================*/ - evt_test->assert_num_params_pushed(4); + evt_test->assert_num_params_pushed(6); } @@ -194,7 +210,9 @@ TEST(SyscallExit, open_by_handle_atX_success_mp) int open_by_handle_fd; int dirfd; char fspath[MAX_FSPATH_LEN]; - do___open_by_handle_atX_success(&open_by_handle_fd, &dirfd, fspath, 1); + uint32_t dev; + uint64_t inode; + do___open_by_handle_atX_success(&open_by_handle_fd, &dirfd, fspath, &dev, &inode, 1); /*=============================== TRIGGER SYSCALL ===========================*/ @@ -225,9 +243,15 @@ TEST(SyscallExit, open_by_handle_atX_success_mp) /* Parameter 4: path (type: PT_FSPATH) */ evt_test->assert_charbuf_param(4, fspath); + /* Parameter 5: dev (type: PT_UINT32) */ + evt_test->assert_numeric_param(5, dev); + + /* Parameter 6: ino (type: PT_UINT64) */ + evt_test->assert_numeric_param(6, inode); + /*=============================== ASSERT PARAMETERS ===========================*/ - evt_test->assert_num_params_pushed(4); + evt_test->assert_num_params_pushed(6); } TEST(SyscallExit, open_by_handle_atX_failure) @@ -281,8 +305,14 @@ TEST(SyscallExit, open_by_handle_atX_failure) /* Parameter 4: path (type: PT_FSPATH) */ evt_test->assert_empty_param(4); + /* Parameter 5: dev (type: PT_UINT32) */ + evt_test->assert_empty_param(5); + + /* Parameter 6: ino (type: PT_UINT64) */ + evt_test->assert_empty_param(6); + /*=============================== ASSERT PARAMETERS ===========================*/ - evt_test->assert_num_params_pushed(4); + evt_test->assert_num_params_pushed(6); } #endif diff --git a/test/drivers/test_suites/syscall_exit_suite/openat2_x.cpp b/test/drivers/test_suites/syscall_exit_suite/openat2_x.cpp index 25900a58b70..99ebdd6e640 100644 --- a/test/drivers/test_suites/syscall_exit_suite/openat2_x.cpp +++ b/test/drivers/test_suites/syscall_exit_suite/openat2_x.cpp @@ -23,6 +23,12 @@ TEST(SyscallExit, openat2X_success) how.resolve = RESOLVE_BENEATH | RESOLVE_NO_MAGICLINKS; int32_t fd = syscall(__NR_openat2, dirfd, pathname, &how, sizeof(struct open_how)); assert_syscall_state(SYSCALL_SUCCESS, "openat2", fd, NOT_EQUAL, -1); + + /* Call `fstat` to retrieve the `dev` and `ino`. */ + struct stat file_stat; + assert_syscall_state(SYSCALL_SUCCESS, "fstat", syscall(__NR_fstat, fd, &file_stat), NOT_EQUAL, -1); + uint32_t dev = (uint32_t)file_stat.st_dev; + uint64_t inode = file_stat.st_ino; close(fd); /*=============================== TRIGGER SYSCALL ===========================*/ @@ -60,9 +66,15 @@ TEST(SyscallExit, openat2X_success) /* Parameter 6: resolve (type: PT_FLAGS32) */ evt_test->assert_numeric_param(6, (uint32_t)PPM_RESOLVE_BENEATH | PPM_RESOLVE_NO_MAGICLINKS); + /* Parameter 7: dev (type: PT_UINT32) */ + evt_test->assert_numeric_param(7, dev); + + /* Parameter 8: ino (type: PT_UINT64) */ + evt_test->assert_numeric_param(8, inode); + /*=============================== ASSERT PARAMETERS ===========================*/ - evt_test->assert_num_params_pushed(6); + evt_test->assert_num_params_pushed(8); } TEST(SyscallExit, openat2X_failure) @@ -122,9 +134,17 @@ TEST(SyscallExit, openat2X_failure) /* Parameter 6: resolve (type: PT_FLAGS32) */ evt_test->assert_numeric_param(6, (uint32_t)PPM_RESOLVE_BENEATH | PPM_RESOLVE_NO_MAGICLINKS); + /* Syscall fails so dev=0 && ino=0. */ + + /* Parameter 7: dev (type: PT_UINT32) */ + evt_test->assert_numeric_param(7, (uint32_t)0); + + /* Parameter 8: ino (type: PT_UINT64) */ + evt_test->assert_numeric_param(8, (uint64_t)0); + /*=============================== ASSERT PARAMETERS ===========================*/ - evt_test->assert_num_params_pushed(6); + evt_test->assert_num_params_pushed(8); } TEST(SyscallExit, openat2X_create_success) @@ -144,6 +164,12 @@ TEST(SyscallExit, openat2X_create_success) syscall(__NR_unlinkat, AT_FDCWD, pathname, 0); /* remove file before creating it */ int32_t fd = syscall(__NR_openat2, dirfd, pathname, &how, sizeof(struct open_how)); assert_syscall_state(SYSCALL_SUCCESS, "openat2", fd, NOT_EQUAL, -1); + + /* Call `fstat` to retrieve the `dev` and `ino`. */ + struct stat file_stat; + assert_syscall_state(SYSCALL_SUCCESS, "fstat", syscall(__NR_fstat, fd, &file_stat), NOT_EQUAL, -1); + uint32_t dev = (uint32_t)file_stat.st_dev; + uint64_t inode = file_stat.st_ino; close(fd); /*=============================== TRIGGER SYSCALL ===========================*/ @@ -181,8 +207,14 @@ TEST(SyscallExit, openat2X_create_success) /* Parameter 6: resolve (type: PT_FLAGS32) */ evt_test->assert_numeric_param(6, (uint32_t)PPM_RESOLVE_BENEATH | PPM_RESOLVE_NO_MAGICLINKS); + /* Parameter 7: dev (type: PT_UINT32) */ + evt_test->assert_numeric_param(7, dev); + + /* Parameter 8: ino (type: PT_UINT64) */ + evt_test->assert_numeric_param(8, inode); + /*=============================== ASSERT PARAMETERS ===========================*/ - evt_test->assert_num_params_pushed(6); + evt_test->assert_num_params_pushed(8); } #endif