@@ -9,16 +9,18 @@ use std::ffi::CString;
9
9
use std:: fs:: File ;
10
10
use std:: io:: Write ;
11
11
use std:: os:: unix:: prelude:: * ;
12
- use std:: env:: current_dir;
13
12
use tempfile:: tempfile;
14
13
use tempdir:: TempDir ;
15
14
use libc:: off_t;
15
+ use std:: process:: exit;
16
16
17
17
#[ test]
18
18
fn test_fork_and_waitpid ( ) {
19
+ #[ allow( unused_variables) ]
20
+ let m = :: FORK_MTX . lock ( ) . expect ( "Mutex got poisoned by another test" ) ;
19
21
let pid = fork ( ) ;
20
22
match pid {
21
- Ok ( Child ) => { } // ignore child here
23
+ Ok ( Child ) => exit ( 0 ) ,
22
24
Ok ( Parent { child } ) => {
23
25
// assert that child was created and pid > 0
24
26
let child_raw: :: libc:: pid_t = child. into ( ) ;
@@ -29,10 +31,10 @@ fn test_fork_and_waitpid() {
29
31
Ok ( WaitStatus :: Exited ( pid_t, _) ) => assert ! ( pid_t == child) ,
30
32
31
33
// panic, must never happen
32
- Ok ( _) => panic ! ( "Child still alive , should never happen" ) ,
34
+ s @ Ok ( _) => panic ! ( "Child exited {:?} , should never happen" , s ) ,
33
35
34
36
// panic, waitpid should never fail
35
- Err ( _ ) => panic ! ( "Error: waitpid Failed" )
37
+ Err ( s ) => panic ! ( "Error: waitpid returned Err({:?}" , s )
36
38
}
37
39
38
40
} ,
@@ -43,9 +45,12 @@ fn test_fork_and_waitpid() {
43
45
44
46
#[ test]
45
47
fn test_wait ( ) {
48
+ // Grab FORK_MTX so wait doesn't reap a different test's child process
49
+ #[ allow( unused_variables) ]
50
+ let m = :: FORK_MTX . lock ( ) . expect ( "Mutex got poisoned by another test" ) ;
46
51
let pid = fork ( ) ;
47
52
match pid {
48
- Ok ( Child ) => { } // ignore child here
53
+ Ok ( Child ) => exit ( 0 ) ,
49
54
Ok ( Parent { child } ) => {
50
55
let wait_status = wait ( ) ;
51
56
@@ -100,6 +105,8 @@ macro_rules! execve_test_factory(
100
105
( $test_name: ident, $syscall: ident, $unix_sh: expr, $android_sh: expr) => (
101
106
#[ test]
102
107
fn $test_name( ) {
108
+ #[ allow( unused_variables) ]
109
+ let m = :: FORK_MTX . lock( ) . expect( "Mutex got poisoned by another test" ) ;
103
110
// The `exec`d process will write to `writer`, and we'll read that
104
111
// data from `reader`.
105
112
let ( reader, writer) = pipe( ) . unwrap( ) ;
@@ -145,40 +152,43 @@ macro_rules! execve_test_factory(
145
152
146
153
#[ test]
147
154
fn test_fchdir ( ) {
155
+ // fchdir changes the process's cwd
156
+ #[ allow( unused_variables) ]
157
+ let m = :: CWD_MTX . lock ( ) . expect ( "Mutex got poisoned by another test" ) ;
158
+
148
159
let tmpdir = TempDir :: new ( "test_fchdir" ) . unwrap ( ) ;
149
160
let tmpdir_path = tmpdir. path ( ) . canonicalize ( ) . unwrap ( ) ;
150
161
let tmpdir_fd = File :: open ( & tmpdir_path) . unwrap ( ) . into_raw_fd ( ) ;
151
- let olddir_path = getcwd ( ) . unwrap ( ) ;
152
- let olddir_fd = File :: open ( & olddir_path) . unwrap ( ) . into_raw_fd ( ) ;
153
162
154
163
assert ! ( fchdir( tmpdir_fd) . is_ok( ) ) ;
155
164
assert_eq ! ( getcwd( ) . unwrap( ) , tmpdir_path) ;
156
165
157
- assert ! ( fchdir( olddir_fd) . is_ok( ) ) ;
158
- assert_eq ! ( getcwd( ) . unwrap( ) , olddir_path) ;
159
-
160
- assert ! ( close( olddir_fd) . is_ok( ) ) ;
161
166
assert ! ( close( tmpdir_fd) . is_ok( ) ) ;
162
167
}
163
168
164
169
#[ test]
165
170
fn test_getcwd ( ) {
166
- let tmp_dir = TempDir :: new ( "test_getcwd" ) . unwrap ( ) ;
167
- assert ! ( chdir( tmp_dir. path( ) ) . is_ok( ) ) ;
168
- assert_eq ! ( getcwd( ) . unwrap( ) , current_dir( ) . unwrap( ) ) ;
169
-
170
- // make path 500 chars longer so that buffer doubling in getcwd kicks in.
171
- // Note: One path cannot be longer than 255 bytes (NAME_MAX)
172
- // whole path cannot be longer than PATH_MAX (usually 4096 on linux, 1024 on macos)
173
- let mut inner_tmp_dir = tmp_dir. path ( ) . to_path_buf ( ) ;
171
+ // chdir changes the process's cwd
172
+ #[ allow( unused_variables) ]
173
+ let m = :: CWD_MTX . lock ( ) . expect ( "Mutex got poisoned by another test" ) ;
174
+
175
+ let tmpdir = TempDir :: new ( "test_getcwd" ) . unwrap ( ) ;
176
+ let tmpdir_path = tmpdir. path ( ) . canonicalize ( ) . unwrap ( ) ;
177
+ assert ! ( chdir( & tmpdir_path) . is_ok( ) ) ;
178
+ assert_eq ! ( getcwd( ) . unwrap( ) , tmpdir_path) ;
179
+
180
+ // make path 500 chars longer so that buffer doubling in getcwd
181
+ // kicks in. Note: One path cannot be longer than 255 bytes
182
+ // (NAME_MAX) whole path cannot be longer than PATH_MAX (usually
183
+ // 4096 on linux, 1024 on macos)
184
+ let mut inner_tmp_dir = tmpdir_path. to_path_buf ( ) ;
174
185
for _ in 0 ..5 {
175
186
let newdir = iter:: repeat ( "a" ) . take ( 100 ) . collect :: < String > ( ) ;
176
- //inner_tmp_dir = inner_tmp_dir.join(newdir).path();
177
187
inner_tmp_dir. push ( newdir) ;
178
188
assert ! ( mkdir( inner_tmp_dir. as_path( ) , stat:: S_IRWXU ) . is_ok( ) ) ;
179
189
}
180
190
assert ! ( chdir( inner_tmp_dir. as_path( ) ) . is_ok( ) ) ;
181
- assert_eq ! ( getcwd( ) . unwrap( ) , current_dir ( ) . unwrap ( ) ) ;
191
+ assert_eq ! ( getcwd( ) . unwrap( ) , inner_tmp_dir . as_path ( ) ) ;
182
192
}
183
193
184
194
#[ test]
0 commit comments