暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

unit_test_readproc.rs 1.3KB

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