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