@@ -21,6 +21,84 @@ fn test_invalid_arg() {
2121 new_ucmd ! ( ) . arg ( "--definitely-invalid" ) . fails ( ) . code_is ( 1 ) ;
2222}
2323
24+ /// Helper function to check that ps output has the correct headers in the correct order
25+ #[ cfg( target_os = "linux" ) ]
26+ fn check_header ( flag : & str , expected_headers : & [ & str ] ) {
27+ let result = new_ucmd ! ( ) . arg ( flag) . succeeds ( ) ;
28+ let lines: Vec < & str > = result. stdout_str ( ) . lines ( ) . collect ( ) ;
29+ let headers: Vec < & str > = lines[ 0 ] . split_whitespace ( ) . collect ( ) ;
30+
31+ assert_eq ! ( headers, expected_headers) ;
32+ }
33+
34+ #[ test]
35+ #[ cfg( target_os = "linux" ) ]
36+ fn test_full_format_listing ( ) {
37+ // TODO: Upstream `ps -f` shows username but UID in the header
38+ check_header (
39+ "-f" ,
40+ & [ "USER" , "PID" , "PPID" , "C" , "STIME" , "TTY" , "TIME" , "CMD" ] ,
41+ ) ;
42+ }
43+
44+ #[ test]
45+ #[ cfg( target_os = "linux" ) ]
46+ fn test_extra_full_format ( ) {
47+ check_header (
48+ "-F" ,
49+ & [
50+ "UID" , "PID" , "PPID" , "C" , "SZ" , "RSS" , "PSR" , "STIME" , "TTY" , "TIME" , "CMD" ,
51+ ] ,
52+ ) ;
53+ }
54+
55+ #[ test]
56+ #[ cfg( target_os = "linux" ) ]
57+ fn test_job_format ( ) {
58+ check_header ( "-j" , & [ "PID" , "PGID" , "SID" , "TTY" , "TIME" , "CMD" ] ) ;
59+ }
60+
61+ #[ test]
62+ #[ cfg( target_os = "linux" ) ]
63+ fn test_psr_format ( ) {
64+ check_header ( "-P" , & [ "PID" , "PSR" , "TTY" , "TIME" , "CMD" ] ) ;
65+ }
66+
67+ #[ test]
68+ #[ cfg( target_os = "linux" ) ]
69+ fn test_signal_format ( ) {
70+ check_header (
71+ "-s" ,
72+ & [
73+ "UID" , "PID" , "PENDING" , "BLOCKED" , "IGNORED" , "CAUGHT" , "STAT" , "TTY" , "TIME" ,
74+ "COMMAND" ,
75+ ] ,
76+ ) ;
77+ }
78+
79+ #[ test]
80+ #[ cfg( target_os = "linux" ) ]
81+ fn test_user_format ( ) {
82+ check_header (
83+ "-u" ,
84+ & [
85+ "USER" , "PID" , "%CPU" , "%MEM" , "VSZ" , "RSS" , "TTY" , "STAT" , "START" , "TIME" , "COMMAND" ,
86+ ] ,
87+ ) ;
88+ }
89+
90+ #[ test]
91+ #[ cfg( target_os = "linux" ) ]
92+ fn test_virtual_memory_format ( ) {
93+ // TODO: Upstream `ps -v` shows MAJFL instead of MAJFLT
94+ check_header (
95+ "-v" ,
96+ & [
97+ "PID" , "TTY" , "STAT" , "TIME" , "MAJFLT" , "TRS" , "DRS" , "RSS" , "%MEM" , "COMMAND" ,
98+ ] ,
99+ ) ;
100+ }
101+
24102#[ test]
25103#[ cfg( target_os = "linux" ) ]
26104fn test_code_mapping ( ) {
0 commit comments