Skip to content

Commit

Permalink
new(tests): expect more params in open syscalls test
Browse files Browse the repository at this point in the history
Signed-off-by: Gianmatteo Palmieri <[email protected]>
  • Loading branch information
mrgian committed Mar 18, 2024
1 parent 4ccecd0 commit 7a5f5f5
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

}

Expand All @@ -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 ===========================*/

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
38 changes: 35 additions & 3 deletions test/drivers/test_suites/syscall_exit_suite/openat2_x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===========================*/
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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 ===========================*/
Expand Down Expand Up @@ -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

0 comments on commit 7a5f5f5

Please sign in to comment.