Skip to content

Create tests for ptrace #687

Open
Open
@xd009642

Description

@xd009642

Ptrace lacks proper tests, partially due to tests hanging due to calls to fork. Below I have some example test functionality I wrote to ensure that ptrace works, due to the fork this could cause a test to hang. (It also ignores the ptrace results which is less than optimal).

    #[test]
    fn ptrace_get_data_test() {
        match fork() {
            Ok(ForkResult::Parent{ child }) => {
                match waitpid(child, Some(__WALL))  {
                    Ok(WaitStatus::Stopped(child, _) )=> {
                        let r = ptrace_get_data::<user_regs_struct>(PTRACE_GETREGS, child);
                        println!("regs: {:#?}", r);
                        assert!(r.is_ok())
                        let _ = ptrace(PTRACE_CONT, child, ptr::null_mut(), ptr::null_mut());
                    },
                    _ => assert!(false),
	        }
            }
            Ok(ForkResult::Child) => {
	        let _ = ptrace(PTRACE_TRACEME, Pid::from_raw(0), ptr::null_mut(), ptr::null_mut());
                let _ = raise(Signal::SIGSTOP);
            }
            Err(err) => { 
                println!("Error {}", err);    
            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions