Skip to content

Commit be794a8

Browse files
yashaswi2000lind
andauthored
fixes for integration tests of sem_syscalls (#268)
Co-authored-by: lind <lind@nyu.edu>
1 parent c54156f commit be794a8

File tree

1 file changed

+48
-45
lines changed

1 file changed

+48
-45
lines changed

src/tests/fs_tests.rs

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,27 +1166,29 @@ pub mod fs_tests {
11661166
assert_eq!(cage1.sem_post_syscall(shmatret as u32), 0);
11671167
cage1.exit_syscall(EXIT_SUCCESS);
11681168
});
1169+
11691170
//Parent processes
1170-
let thread_parent = interface::helper_thread(move || {
1171-
// Parents waits for the semaphore
1172-
assert_eq!(cage.sem_wait_syscall(shmatret as u32), 0);
1173-
assert_eq!(cage.sem_getvalue_syscall(shmatret as u32), 0);
1174-
interface::sleep(interface::RustDuration::from_millis(100));
1175-
// Parents release the semaphore
1176-
assert_eq!(cage.sem_post_syscall(shmatret as u32), 0);
1177-
assert_eq!(cage.sem_getvalue_syscall(shmatret as u32), 1);
1178-
// Destroy the semaphore
1179-
assert_eq!(cage.sem_destroy_syscall(shmatret as u32), 0);
1180-
// mark the shared memory to be rmoved
1181-
let shmctlret2 = cage.shmctl_syscall(shmid, IPC_RMID, None);
1182-
assert_eq!(shmctlret2, 0);
1183-
//detach from shared memory
1184-
let shmdtret = cage.shmdt_syscall(0xfffff000 as *mut u8);
1185-
assert_eq!(shmdtret, shmid);
1186-
cage.exit_syscall(EXIT_SUCCESS);
1187-
});
1171+
// Parents waits for the semaphore
1172+
assert_eq!(cage.sem_wait_syscall(shmatret as u32), 0);
1173+
assert_eq!(cage.sem_getvalue_syscall(shmatret as u32), 0);
1174+
interface::sleep(interface::RustDuration::from_millis(100));
1175+
1176+
// Parents release the semaphore
1177+
assert_eq!(cage.sem_post_syscall(shmatret as u32), 0);
1178+
1179+
// wait for the child process to exit before destroying the semaphore.
11881180
thread_child.join().unwrap();
1189-
thread_parent.join().unwrap();
1181+
1182+
// Destroy the semaphore
1183+
assert_eq!(cage.sem_destroy_syscall(shmatret as u32), 0);
1184+
// mark the shared memory to be rmoved
1185+
let shmctlret2 = cage.shmctl_syscall(shmid, IPC_RMID, None);
1186+
assert_eq!(shmctlret2, 0);
1187+
//detach from shared memory
1188+
let shmdtret = cage.shmdt_syscall(0xfffff000 as *mut u8);
1189+
assert_eq!(shmdtret, shmid);
1190+
cage.exit_syscall(EXIT_SUCCESS);
1191+
11901192
lindrustfinalize();
11911193
}
11921194

@@ -1210,40 +1212,41 @@ pub mod fs_tests {
12101212
let thread_child = interface::helper_thread(move || {
12111213
let cage1 = interface::cagetable_getref(2);
12121214
// Child waits for the semaphore
1213-
assert_eq!(cage1.sem_trywait_syscall(shmatret as u32), 0);
1215+
assert_eq!(cage1.sem_wait_syscall(shmatret as u32), 0);
12141216
// Wait
12151217
interface::sleep(interface::RustDuration::from_millis(20));
12161218
// Release the semaphore
12171219
assert_eq!(cage1.sem_post_syscall(shmatret as u32), 0);
12181220
cage1.exit_syscall(EXIT_SUCCESS);
12191221
});
12201222
//Parent processes
1221-
let thread_parent = interface::helper_thread(move || {
1222-
// Parents waits for the semaphore
1223-
assert_eq!(
1224-
cage.sem_timedwait_syscall(
1225-
shmatret as u32,
1226-
interface::RustDuration::from_millis(100)
1227-
),
1228-
0
1229-
);
1230-
assert_eq!(cage.sem_getvalue_syscall(shmatret as u32), 0);
1231-
interface::sleep(interface::RustDuration::from_millis(10));
1232-
// Parents release the semaphore
1233-
assert_eq!(cage.sem_post_syscall(shmatret as u32), 0);
1234-
assert_eq!(cage.sem_getvalue_syscall(shmatret as u32), 1);
1235-
// Destroy the semaphore
1236-
assert_eq!(cage.sem_destroy_syscall(shmatret as u32), 0);
1237-
// mark the shared memory to be rmoved
1238-
let shmctlret2 = cage.shmctl_syscall(shmid, IPC_RMID, None);
1239-
assert_eq!(shmctlret2, 0);
1240-
//detach from shared memory
1241-
let shmdtret = cage.shmdt_syscall(0xfffff000 as *mut u8);
1242-
assert_eq!(shmdtret, shmid);
1243-
cage.exit_syscall(EXIT_SUCCESS);
1244-
});
1223+
// Parents waits for the semaphore
1224+
assert_eq!(
1225+
cage.sem_timedwait_syscall(
1226+
shmatret as u32,
1227+
interface::RustDuration::from_millis(100)
1228+
),
1229+
0
1230+
);
1231+
assert_eq!(cage.sem_getvalue_syscall(shmatret as u32), 0);
1232+
interface::sleep(interface::RustDuration::from_millis(10));
1233+
// Parents release the semaphore
1234+
assert_eq!(cage.sem_post_syscall(shmatret as u32), 0);
1235+
1236+
// wait for the child to exit before destroying the semaphore.
12451237
thread_child.join().unwrap();
1246-
thread_parent.join().unwrap();
1238+
1239+
// Destroy the semaphore
1240+
assert_eq!(cage.sem_destroy_syscall(shmatret as u32), 0);
1241+
// mark the shared memory to be rmoved
1242+
let shmctlret2 = cage.shmctl_syscall(shmid, IPC_RMID, None);
1243+
assert_eq!(shmctlret2, 0);
1244+
//detach from shared memory
1245+
let shmdtret = cage.shmdt_syscall(0xfffff000 as *mut u8);
1246+
assert_eq!(shmdtret, shmid);
1247+
1248+
cage.exit_syscall(EXIT_SUCCESS);
1249+
12471250
lindrustfinalize();
12481251
}
12491252

0 commit comments

Comments
 (0)