No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unit_test_readproc.rs 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #[cfg(test)]
  2. mod tests {
  3. use procinfo::pid::{status, status_self};
  4. use {self_pids, get_pid_command, get_thread_count, get_ownprocess_mem, get_task_total};
  5. fn sol_self_pids() -> (i32, i32) {
  6. match status_self() {
  7. Ok(status) => (status.pid, status.ppid),
  8. Err(_) => panic!(),
  9. }
  10. }
  11. #[test]
  12. fn test0_ppid() {
  13. assert_eq!(sol_self_pids(), self_pids().unwrap());
  14. }
  15. #[test]
  16. fn test1_command() {
  17. assert_eq!(Err("PID not alive: no command name found"),
  18. get_pid_command(0));
  19. }
  20. #[test]
  21. fn test2_command() {
  22. assert_eq!(Ok("systemd".to_string()), get_pid_command(1));
  23. }
  24. #[test]
  25. fn test3_systemd_command() {
  26. let status = status(1).unwrap();
  27. assert_eq!("systemd".to_string(), status.command);
  28. }
  29. #[test]
  30. fn test4_systemd_threads() {
  31. let status = status(1).unwrap();
  32. assert_eq!(get_thread_count(1), Ok(status.threads));
  33. }
  34. // Only check if fn is defined
  35. #[test]
  36. #[should_panic]
  37. fn test8_mem() {
  38. assert_eq!(Ok((0, 0, 0)), get_ownprocess_mem());
  39. }
  40. #[test]
  41. #[should_panic]
  42. fn test9_get_task_total() {
  43. assert_eq!(Ok((0)), get_task_total());
  44. }
  45. }