Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-bridge/blob/main/tests/native/v2/host/hcall.rs # omega-bridge Omega-first language interoperability: checked conversion backends and native language bindings Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-bridge / tests / native / v2 / host / hcall.rs` 39 lines ยท 1669 bytes Raw Blame History 1 // hcall.rs: the Rust oracle for hfile.om through the --host library (tests/native/v2/run.sh, section 11). 2 // hcall FILE MISSING LINK, as for hcall.c; expectations come from std, independently of the unit. 3 mod omega_native; 4 use omega_native::*; 5 use std::os::unix::fs::MetadataExt; 6 use std::sync::atomic::{AtomicBool, Ordering}; 7 8 static BAD: AtomicBool = AtomicBool::new(false); 9 fn check(what: &str, ok: bool) { 10 println!("{} {}", if ok { "PASS" } else { "FAIL" }, what); 11 if !ok { 12 BAD.store(true, Ordering::Relaxed); 13 } 14 } 15 16 fn peek(p: &str) -> Option { 17 let mut r: u64 = 0; 18 let s = unsafe { omega2_peek(&mut r, p.as_ptr(), p.len() as u64) }; 19 if s == OMEGA_OK { Some(r as i64) } else { None } 20 } 21 22 fn main() { 23 let a: Vec = std::env::args().collect(); 24 assert!(a.len() == 4, "usage: hcall FILE MISSING LINK"); 25 check("peek FILE reads its 5 bytes", peek(&a[1]) == Some(5)); 26 check("peek MISSING = -ENOENT (-2)", peek(&a[2]) == Some(-2)); 27 check("peek LINK = -ELOOP (-40, fopen with O_NOFOLLOW)", peek(&a[3]) == Some(-40)); 28 let m = std::fs::metadata(&a[1]).expect("metadata"); 29 let mut r: u64 = 0; 30 let s = unsafe { omega2_size(&mut r, a[1].as_ptr(), a[1].len() as u64) }; 31 check("size FILE == metadata len", s == OMEGA_OK && r == m.size()); 32 let p = std::fs::metadata("/proc/self").expect("/proc/self"); 33 let s = unsafe { omega2_ids(&mut r) }; 34 check("ids >= euid + egid (from /proc/self)", s == OMEGA_OK && r >= p.uid() as u64 + p.gid() as u64); 35 check("ident carries host=", OMEGA2_IDENT_hfile.contains(" host=")); 36 if BAD.load(Ordering::Relaxed) { 37 std::process::exit(1); 38 } 39 }