//! Validate the ambient warm pool behind Image::acquire() on KVM: the first
//! acquire warms (boot+snapshot once), subsequent acquires are CoW restores.

#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
fn main() {
    use std::time::Instant;
    use supermachine::Image;

    let image = Image::from_oci("alpine").expect("from_oci");
    for i in 0..3 {
        let t = Instant::now();
        let vm = image.acquire().expect("acquire");
        let acq = t.elapsed();
        let o = vm
            .exec_builder()
            .argv(["/bin/echo", "ok"])
            .output()
            .expect("exec");
        eprintln!(
            "acquire #{i}: {acq:?}  exec_ok={} out={:?}",
            o.success(),
            String::from_utf8_lossy(&o.stdout).trim_end()
        );
        drop(vm);
    }
    eprintln!("=== done ===");
}

#[cfg(not(all(target_os = "linux", target_arch = "x86_64")))]
fn main() {
    eprintln!("kvm_acquire is Linux/x86_64 only");
}
