From 0031c762cf03e080a2a0916948211496bb33297b Mon Sep 17 00:00:00 2001 From: Steffen Eiden Date: Tue, 3 Sep 2024 11:20:06 +0200 Subject: [PATCH] rust/pv_core: Fix rusttest `owned file descriptor already closed` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Newer rust std libary code checks if a fd is already closes and panics. Test code created a file with fd=17 and relied that test code never touched the file. This cannot be done anymore. Just use the working dir as backing file. Reviewed-by: Jan Höppner Signed-off-by: Steffen Eiden Signed-off-by: Jan Höppner --- rust/pv_core/src/uvdevice/test.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rust/pv_core/src/uvdevice/test.rs b/rust/pv_core/src/uvdevice/test.rs index c9adb848..e556d179 100644 --- a/rust/pv_core/src/uvdevice/test.rs +++ b/rust/pv_core/src/uvdevice/test.rs @@ -6,7 +6,6 @@ use std::{ ffi::{c_int, c_ulong}, - os::unix::prelude::FromRawFd, sync::{Mutex, MutexGuard}, }; @@ -65,13 +64,12 @@ impl IoctlCtx { pub mod mock_libc { use super::*; - pub unsafe fn ioctl(fd: c_int, cmd: c_ulong, data: *mut ffi::uvio_ioctl_cb) -> c_int { + pub unsafe fn ioctl(_fd: c_int, cmd: c_ulong, data: *mut ffi::uvio_ioctl_cb) -> c_int { let mut ctx = get_lock(&IOCTL_MTX); assert!(!ctx.called, "IOCTL called more than once"); ctx.called = true; assert_eq!(cmd, ctx.exp_cmd, "IOCTL cmd mismatch"); - assert_eq!(fd, 17, "IOCTL fd mismatch"); let data_ref: &mut ffi::uvio_ioctl_cb = &mut *data; @@ -131,10 +129,10 @@ impl UvCmd for TestCmd { } impl UvDevice { - /// use some random fd for `uvdevice` its OK, as the ioctl is mocked and never touches the + /// Use this file as backing file for `uvdevice`. This is OK, as the ioctl is mocked and never touches the /// passed file fn test_dev() -> Self { - UvDevice(unsafe { File::from_raw_fd(17) }) + Self(File::open(".").unwrap()) } }