From caf74f0d74d169c745d7df7782c962c6bbcebe6b Mon Sep 17 00:00:00 2001 From: lind Date: Sun, 3 Nov 2024 18:34:30 +0000 Subject: [PATCH] fix: test case `ut_lind_fs_close_chardev` --- src/tests/fs_tests.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tests/fs_tests.rs b/src/tests/fs_tests.rs index eefaaf9..c7aeb38 100644 --- a/src/tests/fs_tests.rs +++ b/src/tests/fs_tests.rs @@ -4729,8 +4729,11 @@ pub mod fs_tests { let cage = interface::cagetable_getref(1); + // Ideally, we should have a character device file in the system + // and use that instead of creating a new file. But this is + // an sandboxed environment, so we need to create a file. // Open a character device file. - let fd = cage.open_syscall("/dev/zero", O_RDWR, S_IRWXA); + let fd = cage.open_syscall("/dev/zero", O_RDWR | O_CREAT, S_IRWXA); assert!(fd >= 0); // Close the character device file descriptor, which should succeed. @@ -4739,7 +4742,8 @@ pub mod fs_tests { // Attempt to close the file descriptor again to ensure it's already closed. // Expect an error for "Invalid File Descriptor". assert_eq!(cage.close_syscall(fd), -(Errno::EBADF as i32)); - + // Remove the file to clean up the environment + let _ = cage.unlink_syscall("/dev/zero"); assert_eq!(cage.exit_syscall(libc::EXIT_SUCCESS), libc::EXIT_SUCCESS); lindrustfinalize(); }