use himpp::mpi::sys; #[test] fn get_version() { let val = sys::get_version().unwrap(); let val = sys::MppVersion::from(val); #[cfg(feature = "hi3559av100")] assert_eq!( val.to_string(), String::from("HI_VERSION=Hi3559AV100_MPP_V2.0.2.0 B060 Release") ); } #[test] fn get_chip_id() { let id = sys::get_chip_id().unwrap(); #[cfg(feature = "hi3559av100")] assert_eq!(id, 0x3559A100u32); } #[test] fn get_custom_code() { let code = sys::get_custom_code().unwrap(); assert_eq!(code, 0u32); } #[test] fn get_cur_pts() { let jitter_us = 12_000u64; let patterns = vec![1, 5, 10, 50, 100, 500]; for delay_ms in patterns { let before = sys::get_cur_pts().unwrap(); std::thread::sleep(std::time::Duration::from_millis(delay_ms)); let after = sys::get_cur_pts().unwrap(); assert!( (after - before) >= delay_ms * 1_000u64, "{} - {} >= {}", after, before, delay_ms * 1_000u64 ); assert!( (after - before) < delay_ms * 1_000u64 + jitter_us, "{} - {} >= {}", after, before, delay_ms * 1_000u64 + jitter_us ); } } #[test] fn mmz_alloc() { use himpp::mpi::sys; // let (p, v) = sys::mmz_alloc(4096, "", "").unwrap(); assert_ne!(p, 0); assert_ne!(v, 0); assert!( sys::mmz_free(p, v).is_ok(), "MmzFree({:X},{:X}) Failed!", p, v ); // let (p, v) = sys::mmz_alloc(4096 * 1000, "", "anonymous").unwrap(); assert_ne!(p, 0); assert_ne!(v, 0); assert!( sys::mmz_free(p, v).is_ok(), "MmzFree({:X},{:X}) Failed!", p, v ); // let (p, v) = sys::mmz_alloc(4096 * 10000, "", "").unwrap(); assert_ne!(p, 0); assert_ne!(v, 0); assert!( sys::mmz_free(p, v).is_ok(), "MmzFree({:X},{:X}) Failed!", p, v ); // let (p, v) = sys::mmz_alloc(4096 * 100000, "", "anonymous").unwrap(); assert_ne!(p, 0); assert_ne!(v, 0); assert!( sys::mmz_free(p, v).is_ok(), "MmzFree({:X},{:X}) Failed!", p, v ); // assert!(sys::mmz_alloc(0, "", "").is_err()); assert!(sys::mmz_alloc(4096, "", "unknown").is_err()); } #[test] fn mmz_alloc_cached() { use himpp::mpi::sys; // let (p, v) = sys::mmz_alloc_cached(4096, "", "").unwrap(); assert_ne!(p, 0); assert_ne!(v, 0); assert!( sys::mmz_free(p, v).is_ok(), "MmzFree({:X},{:X}) Failed!", p, v ); // let (p, v) = sys::mmz_alloc_cached(4096 * 1000, "", "anonymous").unwrap(); assert_ne!(p, 0); assert_ne!(v, 0); assert!( sys::mmz_free(p, v).is_ok(), "MmzFree({:X},{:X}) Failed!", p, v ); // let (p, v) = sys::mmz_alloc_cached(4096 * 10000, "", "").unwrap(); assert_ne!(p, 0); assert_ne!(v, 0); assert!( sys::mmz_free(p, v).is_ok(), "MmzFree({:X},{:X}) Failed!", p, v ); // let (p, v) = sys::mmz_alloc_cached(4096 * 100000, "", "anonymous").unwrap(); assert_ne!(p, 0); assert_ne!(v, 0); assert!( sys::mmz_free(p, v).is_ok(), "MmzFree({:X},{:X}) Failed!", p, v ); // assert!(sys::mmz_alloc_cached(0, "", "").is_err()); assert!(sys::mmz_alloc_cached(4096, "", "unknown").is_err()); } #[test] fn get_vir_mem_info() { use himpp::mpi::sys; // let (p, v) = sys::mmz_alloc(4096 * 1000, "", "anonymous").unwrap(); assert_ne!(p, 0); assert_ne!(v, 0); let (phy, cached) = sys::get_vir_mem_info(v).unwrap(); assert_eq!(phy, p); assert_eq!(cached, false); assert!( sys::mmz_free(p, v).is_ok(), "MmzFree({:X},{:X}) Failed!", p, v ); // let (p, v) = sys::mmz_alloc_cached(4096 * 1000, "", "anonymous").unwrap(); assert_ne!(p, 0); assert_ne!(v, 0); let (phy, cached) = sys::get_vir_mem_info(v).unwrap(); assert_eq!(phy, p); assert_eq!(cached, true); assert!( sys::mmz_free(p, v).is_ok(), "MmzFree({:X},{:X}) Failed!", p, v ); }