From f4e10ecacb46058be85789a87db1fe20311f9a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Tue, 20 Aug 2024 13:57:28 -0700 Subject: [PATCH 1/2] Use named temporary files in various tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's not at all clear why, but various tests fail when run in a vmtest VM that has the hosts /tmp/ mounted inside. The issue seems fixed once we switch to using named temporary files ¯\_(°ペ)_/¯ Switch over to using them, which makes a lot more sense in many cases anyway, because some tests are currently making up a path that does not represent reality. Signed-off-by: Daniel Müller --- src/mmap.rs | 17 ++++++++++------- src/symbolize/perf_map.rs | 10 +++++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/mmap.rs b/src/mmap.rs index 4cf1ffe48..dce6a9faf 100644 --- a/src/mmap.rs +++ b/src/mmap.rs @@ -128,7 +128,7 @@ mod tests { use std::ffi::CStr; use std::io::Write; - use tempfile::tempfile; + use tempfile::NamedTempFile; use test_log::test; use crate::util::ReadRaw; @@ -144,20 +144,22 @@ mod tests { /// Check that we can `mmap` an empty file. #[test] fn mmap_empty_file() { - let file = tempfile().unwrap(); - let mmap = Mmap::map(&file).unwrap(); + let file = NamedTempFile::new().unwrap(); + let file = file.as_file(); + let mmap = Mmap::map(file).unwrap(); assert_eq!(mmap.deref(), &[]); } /// Check that we can `mmap` a file. #[test] fn mmap() { - let mut file = tempfile().unwrap(); + let file = NamedTempFile::new().unwrap(); + let mut file = file.as_file(); let cstr = b"Daniel was here. Briefly.\0"; let () = file.write_all(cstr).unwrap(); let () = file.sync_all().unwrap(); - let mmap = Mmap::map(&file).unwrap(); + let mmap = Mmap::map(file).unwrap(); let mut data = mmap.deref(); let s = data.read_cstr().unwrap(); assert_eq!( @@ -169,12 +171,13 @@ mod tests { /// Check that we can properly restrict the view of a `Mmap`. #[test] fn view_constraining() { - let mut file = tempfile().unwrap(); + let file = NamedTempFile::new().unwrap(); + let mut file = file.as_file(); let s = b"abcdefghijklmnopqrstuvwxyz"; let () = file.write_all(s).unwrap(); let () = file.sync_all().unwrap(); - let mmap = Mmap::map(&file).unwrap(); + let mmap = Mmap::map(file).unwrap(); assert_eq!(mmap.deref(), b"abcdefghijklmnopqrstuvwxyz"); let mmap = mmap.constrain(1..15).unwrap(); diff --git a/src/symbolize/perf_map.rs b/src/symbolize/perf_map.rs index 99a2cfbc3..54f7ca928 100644 --- a/src/symbolize/perf_map.rs +++ b/src/symbolize/perf_map.rs @@ -206,7 +206,7 @@ mod tests { use scopeguard::defer; - use tempfile::tempfile; + use tempfile::NamedTempFile; use crate::symbolize::Input; use crate::symbolize::Process; @@ -257,9 +257,9 @@ mod tests { }; assert_ne!(format!("{func:?}"), ""); - let mut file = tempfile().unwrap(); + let mut file = NamedTempFile::new().unwrap(); let () = file.write_all(SAMPLE_PERF_MAP).unwrap(); - let perf_map = PerfMap::from_file(Path::new("SAMPLE_PERF_MAP"), &file).unwrap(); + let perf_map = PerfMap::from_file(file.path(), file.as_file()).unwrap(); assert_ne!(format!("{perf_map:?}"), ""); } @@ -295,9 +295,9 @@ mod tests { /// Check that we can load a perf map and use it to symbolize an address. #[test] fn perf_map_symbolization() { - let mut file = tempfile().unwrap(); + let mut file = NamedTempFile::new().unwrap(); let () = file.write_all(SAMPLE_PERF_MAP).unwrap(); - let perf_map = PerfMap::from_file(Path::new("SAMPLE_PERF_MAP"), &file).unwrap(); + let perf_map = PerfMap::from_file(file.path(), file.as_file()).unwrap(); for offset in 0..0xb { let sym = perf_map From 4d2fa41de2a70ba3eb9f5ca71c4403e7be0dc1d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Mon, 19 Aug 2024 13:34:26 -0700 Subject: [PATCH 2/2] Use vmtest-action version 0.8 in CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With vmtest-action version 0.8 released, it makes the most sense for us to consume this version as opposed to the current snapshot from the master branch. This way, we anticipate to consume stable releases and have Dependabot manage version bumps for us. Signed-off-by: Daniel Müller --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 01846c61a..5e39f0a1c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -208,7 +208,7 @@ jobs: EOF chmod a+x main.sh - name: Test and gather coverage - uses: danobi/vmtest-action@master + uses: danobi/vmtest-action@v0.8 with: kernel: bzImage command: sh -c 'cd ${{ github.workspace }} && ./main.sh'