@@ -118,37 +118,6 @@ impl ProcessCreateTime {
118118 }
119119 }
120120
121- #[ cfg( test) ]
122- pub ( super ) fn now ( ) -> std:: io:: Result < ProcessCreateTime > {
123- let mut spec = MaybeUninit :: < libc:: timespec > :: uninit ( ) ;
124- // SAFETY: valid pointer is passed to clock_gettime
125- crate :: cutils:: cerr ( unsafe {
126- libc:: clock_gettime (
127- if cfg ! ( target_os = "freebsd" ) {
128- libc:: CLOCK_REALTIME
129- } else {
130- libc:: CLOCK_BOOTTIME
131- } ,
132- spec. as_mut_ptr ( ) ,
133- )
134- } ) ?;
135- // SAFETY: The `libc::clock_gettime` will correctly initialize `spec`,
136- // otherwise it will return early with the `?` operator.
137- let spec = unsafe { spec. assume_init ( ) } ;
138-
139- // the below conversion is not as useless as clippy thinks, on 32bit systems
140- #[ allow( clippy:: useless_conversion) ]
141- Ok ( ProcessCreateTime :: new (
142- spec. tv_sec . into ( ) ,
143- spec. tv_nsec . into ( ) ,
144- ) )
145- }
146-
147- #[ cfg( test) ]
148- pub ( super ) fn secs ( & self ) -> i64 {
149- self . secs
150- }
151-
152121 pub ( super ) fn encode ( & self , target : & mut impl Write ) -> std:: io:: Result < ( ) > {
153122 let secs = self . secs . to_ne_bytes ( ) ;
154123 let nsecs = self . nsecs . to_ne_bytes ( ) ;
@@ -203,4 +172,18 @@ mod tests {
203172 SystemTime :: new( 6 , 500_000_000 )
204173 ) ;
205174 }
175+
176+ #[ test]
177+ fn get_process_start_time ( ) {
178+ use crate :: system:: { Process , WithProcess } ;
179+ let time = Process :: starting_time ( WithProcess :: Current ) . unwrap ( ) ;
180+
181+ let now = {
182+ let super :: SystemTime { secs, nsecs } = super :: SystemTime :: now ( ) . unwrap ( ) ;
183+ super :: ProcessCreateTime { secs, nsecs }
184+ } ;
185+
186+ assert ! ( time. secs > now. secs - 24 * 60 * 60 ) ;
187+ assert ! ( time < now) ;
188+ }
206189}
0 commit comments