use turkos_exec_environment::environment::{Packet,Error,MAX_TEXT_BYTES}; const BASE:u64=0x80011000;const TOP:u64=0x80012000; const ARGS:[&[u8];3]=["başlat".as_bytes(),b"/bin/deneme","İstanbul".as_bytes()]; const ENV:[&[u8];2]=["DİL=tr_TR.UTF-8".as_bytes(),"İSİM=Önder".as_bytes()]; fn word(p:&Packet,at:usize)->u64{u64::from_le_bytes(p.bytes()[at..at+8].try_into().unwrap())} #[test]fn os_exec_environment_positive(){ let p=Packet::new(BASE,TOP,&ARGS,&ENV).unwrap();let s=p.start();assert_eq!(s.sp,TOP-512);assert_eq!((s.argc,s.envc),(3,2));assert_eq!((s.argv,s.envp),(s.sp+32,s.sp+72)); assert_eq!([word(&p,0),word(&p,8),word(&p,16),word(&p,24)],[3,s.argv,2,s.envp]);let mut cursor=128; for(at,list)in [(32,&ARGS[..]),(72,&ENV[..])]{for(i,text)in list.iter().enumerate(){assert_eq!(word(&p,at+i*8),s.sp+cursor as u64);assert_eq!(&p.bytes()[cursor..cursor+text.len()],*text);assert_eq!(p.bytes()[cursor+text.len()],0);cursor+=text.len()+1;}assert_eq!(word(&p,at+list.len()*8),0);} assert_eq!(p.text_bytes(),ARGS.iter().chain(ENV.iter()).map(|s|s.len()+1).sum());assert!(p.bytes()[cursor..].iter().all(|v|*v==0)); let full=[b'x';63];let exact=Packet::new(BASE,TOP,&[&full;4],&[]).unwrap();assert_eq!(exact.text_bytes(),MAX_TEXT_BYTES);assert_eq!(exact.bytes()[383],0);assert!(exact.bytes()[384..].iter().all(|v|*v==0)); let empty=Packet::new(BASE,TOP,&[],&[]).unwrap();assert_eq!(empty.text_bytes(),0);assert_eq!(word(&empty,32),0);assert_eq!(word(&empty,72),0); } #[test]fn os_exec_environment_negative(){ let mut published=Packet::new(BASE,TOP,&ARGS,&ENV).unwrap();let before=published.clone();let short=[b'x';63];let long=[b'y';64]; let attempt=Packet::new(BASE,TOP,&[&short,&short,&short,&long],&[]);assert_eq!(attempt,Err(Error::Total));if let Ok(new)=attempt{published=new;}assert_eq!(published,before); assert_eq!(Packet::new(BASE,TOP,&[b"a";5],&[]),Err(Error::Count));assert_eq!(Packet::new(BASE,TOP,&[],&[b"b";5]),Err(Error::Count)); assert_eq!(Packet::new(BASE,TOP,&[&[b'x';65]],&[]),Err(Error::String));assert_eq!(Packet::new(BASE,TOP,&[b"ok\0hidden"],&[]),Err(Error::Nul));assert_eq!(Packet::new(BASE,TOP,&[],&[b"X=ok\0bad"]),Err(Error::Nul)); for(base,top)in [(BASE+1,TOP),(BASE,TOP+1),(TOP,BASE),(BASE,BASE+16)]{assert_eq!(Packet::new(base,top,&ARGS,&ENV),Err(Error::Stack));} }