diff options
-rw-r--r-- | Android.bp | 24 | ||||
-rw-r--r-- | cargo_embargo.json | 3 | ||||
-rw-r--r-- | src/errno.rs | 12 |
3 files changed, 33 insertions, 6 deletions
@@ -1,5 +1,7 @@ // This file is generated by cargo_embargo. -// Do not modify this file as changes will be overridden on upgrade. +// Do not modify this file after the first "rust_*" or "genrule" module +// because the changes will be overridden on upgrade. +// Content before the first "rust_*" or "genrule" module is preserved. rust_library_host { name: "libvmm_sys_util", @@ -13,3 +15,23 @@ rust_library_host { "liblibc", ], } + +rust_test_host { + name: "vmm-sys-util_test_src_lib", + crate_name: "vmm_sys_util", + cargo_env_compat: true, + cargo_pkg_version: "0.12.1", + srcs: ["src/lib.rs"], + test_suites: ["general-tests"], + auto_gen_config: true, + test_options: { + unit_test: true, + }, + edition: "2021", + rustlibs: [ + "libbincode", + "libbitflags-1.3.2", + "liblibc", + "libserde_json", + ], +} diff --git a/cargo_embargo.json b/cargo_embargo.json index bc1c4ce..4ba71a8 100644 --- a/cargo_embargo.json +++ b/cargo_embargo.json @@ -7,5 +7,6 @@ "device_supported": false } }, - "run_cargo": false + "run_cargo": false, + "tests": true } diff --git a/src/errno.rs b/src/errno.rs index 27b9bcf..3478b7c 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -132,7 +132,7 @@ pub fn errno_result<T>() -> Result<T> { #[cfg(test)] mod tests { use super::*; - use std::env::temp_dir; + use crate::tempfile::TempFile; use std::error::Error as _; use std::fs::OpenOptions; use std::io::{self, Read}; @@ -145,14 +145,16 @@ mod tests { let expected_errno = libc::EIO; // try to read from a file without read permissions - let mut path = temp_dir(); - path.push("test"); + let temp_file = TempFile::new().unwrap(); + let path = temp_file.as_path().to_owned(); + // Drop temp_file so we can cleanly reuse path below. + std::mem::drop(temp_file); let mut file = OpenOptions::new() .read(false) .write(true) .create(true) .truncate(true) - .open(path) + .open(&path) .unwrap(); let mut buf: Vec<u8> = Vec::new(); assert!(file.read_to_end(&mut buf).is_err()); @@ -174,6 +176,8 @@ mod tests { let last_err: io::Error = last_err.into(); // Test creating a `std::io::Error` from an `Error` assert_eq!(io::Error::last_os_error().kind(), last_err.kind()); + + assert!(std::fs::remove_file(&path).is_ok()); } #[test] |