MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / max_nesting_backing

Function max_nesting_backing

block/src/qcow/mod.rs:2720–2748  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2718
2719 #[test]
2720 fn max_nesting_backing() {
2721 let test_dir = TempDir::new_with_prefix("/tmp/ch").unwrap();
2722 let img_path = test_dir.as_path().join("test.img");
2723
2724 new_self_referential_qcow(img_path.as_path()).unwrap();
2725
2726 let err = QcowFile::from_with_nesting_depth(
2727 RawFile::new(
2728 File::open(img_path.as_path()).expect("Failed to open qcow image file"),
2729 false,
2730 ),
2731 MAX_NESTING_DEPTH,
2732 true,
2733 )
2734 .expect_err("Opening qcow file with itself as backing file should fail.");
2735
2736 // This type of error is complex. For comparing easily, we can check if it contains the
2737 // type name after formatting.
2738 assert!(format!("{err:?}").contains(&format!("{:?}", Error::MaxNestingDepthExceeded)));
2739 // This should recursively call the function ten times before throwing an error, and the
2740 // error `BackingFileOpen` should also be repeated ten times.
2741 assert_eq!(
2742 format!("{err:?}")
2743 .matches("BackingFileOpen")
2744 .collect::<Vec<_>>()
2745 .len() as u32,
2746 MAX_NESTING_DEPTH,
2747 );
2748 }
2749
2750 #[test]
2751 fn invalid_magic() {

Callers

nothing calls this directly

Calls 2

newFunction · 0.85

Tested by

no test coverage detected