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

unit_test_readproc.rs 1.3KB

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