From 036a80a88d2bb5dcb9d6e1b74c131246a68f7141 Mon Sep 17 00:00:00 2001 From: lind Date: Thu, 24 Oct 2024 01:38:39 +0000 Subject: [PATCH] fix: test case ut_lind_fs_mmap_unsupported_file --- src/tests/fs_tests.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/tests/fs_tests.rs b/src/tests/fs_tests.rs index f2eb733..1ba0ed3 100644 --- a/src/tests/fs_tests.rs +++ b/src/tests/fs_tests.rs @@ -641,6 +641,8 @@ pub mod fs_tests { let _thelock = setup::lock_and_init(); let cage = interface::cagetable_getref(1); + // Removing the test directory if it exists + let _ = cage.rmdir_syscall("/testdir"); //Creating a directory. assert_eq!(cage.mkdir_syscall("/testdir", S_IRWXA), 0); @@ -654,13 +656,17 @@ pub mod fs_tests { //`mmap_syscall()` correctly results in `The `fildes` //argument refers to a file whose type is not //supported by mmap` error. - + let mmap_result = unsafe { + libc::mmap( + 0 as *mut c_void, 5, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0 + ) + }; + // Verify errno is set to ENODEV + let errno = get_errno(); /* Native linux will return ENODEV */ - assert_eq!( - cage.mmap_syscall(0 as *mut u8, 5, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0), - -(Errno::ENODEV as i32) - ); - + assert_eq!(errno, libc::ENODEV, "Expected errno to be ENODEV for unsupported file type"); + // Clean up and finalize + assert_eq!(cage.rmdir_syscall("/testdir"), 0); assert_eq!(cage.exit_syscall(libc::EXIT_SUCCESS), libc::EXIT_SUCCESS); lindrustfinalize(); }