Skip to content

Commit

Permalink
Fix mutex size after wait_queue modify
Browse files Browse the repository at this point in the history
--------
1. fix arceos_posix_api mutex size
2. add unit test for axsync/mutex size

Signed-off-by: guoweikang <[email protected]>
  • Loading branch information
guoweikang committed Oct 16, 2024
1 parent 33e80b8 commit f273247
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions api/arceos_posix_api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ fn main() {
// TODO: generate size and initial content automatically.
let (mutex_size, mutex_init) = if cfg!(feature = "multitask") {
if cfg!(feature = "smp") {
(6, "{0, 0, 8, 0, 0, 0}") // core::mem::transmute::<_, [usize; 6]>(axsync::Mutex::new(()))
(3, "{0, 0, 0}") // core::mem::transmute::<_, [usize; 6]>(axsync::Mutex::new(()))
} else {
(5, "{0, 8, 0, 0, 0}") // core::mem::transmute::<_, [usize; 5]>(axsync::Mutex::new(()))
(2, "{0, 0}") // core::mem::transmute::<_, [usize; 5]>(axsync::Mutex::new(()))
}
} else {
(1, "{0}")
Expand Down
19 changes: 19 additions & 0 deletions modules/axsync/src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,23 @@ mod tests {
assert_eq!(*M.lock(), NUM_ITERS * NUM_TASKS * 3);
println!("Mutex test OK");
}


fn assert_mem_content<T>(val: &T, content: &[usize]) {
let val_ptr = val as *const T as *const usize;
let size = core::mem::size_of::<T>() / core::mem::size_of::<usize>();
assert_eq!(size, content.len());
let usize_slice = unsafe { core::slice::from_raw_parts(val_ptr, size) };
for (i, chunk) in usize_slice.iter().enumerate() {
assert_eq!(*chunk, content[i]);
}
}

#[test]
fn mutex_test_for_posix() {
// Test mutex size is equal api/arceos_posix_api/build.rs
let mutex_tuple = axsync::Mutex::new(());
let content: [usize;2] = [0, 0];
assert_mem_content(&mutex_tuple, &content);
}
}

0 comments on commit f273247

Please sign in to comment.