Debian Codegraph @

tests/btrfs-loopback.rs

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 use clone_file::*;
2 use std::fs;
3
4 const BASE_DIR: &'static str = env!("CARGO_MANIFEST_DIR");
5
6 fn ensure_test_sh() -> anyhow::Result<()> {
7 use anyhow::Context;
8 fs::metadata(format!("{BASE_DIR}/.btrfs-mnt")).context("please run tests with test.sh")?;
9 Ok(())
10 }
11
12 #[cfg(target_os = "linux")]
13 #[test]
14 fn clone_file_works() -> anyhow::Result<()> {
15 ensure_test_sh()?;
16
17 clone_file(
18 format!("{BASE_DIR}/.btrfs-mnt/src.bin"),
19 format!("{BASE_DIR}/.btrfs-mnt/dest.bin"),
20 )?;
21
22 Ok(())
23 }
24
25 #[cfg(target_os = "linux")]
26 #[test]
27 fn clone_file_range_works() -> anyhow::Result<()> {
28 ensure_test_sh()?;
29
30 clone_file_range(
31 format!("{BASE_DIR}/.btrfs-mnt/src.bin"),
32 // chopping 16K from start and 16K from end
33 16 << 10,
34 (50 << 20) - (16 << 10) * 2,
35 format!("{BASE_DIR}/.btrfs-mnt/dest-part.bin"),
36 0,
37 )?;
38
39 Ok(())
40 }
41
42 #[cfg(target_os = "linux")]
43 #[test]
44 fn clone_range_consistent_with_copy_range() -> anyhow::Result<()> {
45 ensure_test_sh()?;
46
47 clone_file_range(
48 format!("{BASE_DIR}/.btrfs-mnt/src.bin"),
49 0,
50 16 << 10,
51 format!("{BASE_DIR}/.btrfs-mnt/clone-range-small.bin"),
52 0,
53 )?;
54
55 copy_file_range(
56 format!("{BASE_DIR}/.btrfs-mnt/src.bin"),
57 0,
58 16 << 10,
59 format!("{BASE_DIR}/.btrfs-mnt/copy-range-small.bin"),
60 0,
61 )?;
62
63 Ok(())
64 }