xref: /aosp_15_r20/external/crosvm/e2e_tests/tests/pmem.rs (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1 // Copyright 2024 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 //! Testing virtio-pmem.
6 
7 #![cfg(any(target_os = "android", target_os = "linux"))]
8 
9 use fixture::utils::prepare_disk_img;
10 use fixture::vm::Config as VmConfig;
11 use fixture::vm::TestVm;
12 
13 /// Tests virtio-pmem device is mountable.
14 #[test]
test_mount_pmem()15 fn test_mount_pmem() {
16     mount_pmem(VmConfig::new());
17 }
18 
19 /// Tests virtio-pmem device is mountable with sandbox disabled.
20 #[test]
test_mount_pmem_disable_sandbox()21 fn test_mount_pmem_disable_sandbox() {
22     mount_pmem(VmConfig::new().disable_sandbox());
23 }
24 
mount_pmem(config: VmConfig)25 fn mount_pmem(config: VmConfig) {
26     let disk = prepare_disk_img();
27     let disk_path = disk.path().to_str().unwrap();
28     let config = config.extra_args(vec!["--pmem".to_string(), format!("{},ro", disk_path)]);
29 
30     let mut vm = TestVm::new(config).unwrap();
31     vm.exec_in_guest("mount -t ext4 /dev/pmem0 /mnt")
32         .expect("Failed to mount pmem device");
33 }
34 
35 /// Tests VMA virtio-pmem to be created successfully with the correct size.
36 #[test]
test_vma_pmem()37 fn test_vma_pmem() {
38     let vma_size = 1 << 30; // 1GiB
39     let config = VmConfig::new().extra_args(vec![
40         "--pmem".to_string(),
41         format!("vma_pmem,vma-size={},swap-interval-ms=0", vma_size),
42     ]);
43 
44     let mut vm = TestVm::new(config).unwrap();
45     assert_eq!(
46         vm.exec_in_guest("blockdev --getsize64 /dev/pmem0")
47             .unwrap()
48             .stdout
49             .trim()
50             .parse::<u64>()
51             .unwrap(),
52         vma_size
53     );
54 }
55