Skip to content

Commit

Permalink
Fix static muts in tickv
Browse files Browse the repository at this point in the history
  • Loading branch information
alevy committed Apr 22, 2024
1 parent 5a111e1 commit 5bdbeed
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions libraries/tickv/src/async_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ mod tests {
use crate::success_codes::SuccessCode;
use crate::tickv::{HASH_OFFSET, LEN_OFFSET, MAIN_KEY, VERSION, VERSION_OFFSET};
use core::hash::{Hash, Hasher};
use core::ptr::addr_of_mut;
use std::cell::Cell;
use std::cell::RefCell;
use std::collections::hash_map::DefaultHasher;
Expand Down Expand Up @@ -641,7 +642,8 @@ mod tests {

println!("HASHED KEY {:?}", get_hashed_key(b"ONE"));

let ret = unsafe { tickv.append_key(get_hashed_key(b"ONE"), &mut VALUE, 32) };
let ret =
unsafe { tickv.append_key(get_hashed_key(b"ONE"), &mut *addr_of_mut!(VALUE), 32) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand All @@ -652,7 +654,8 @@ mod tests {
_ => unreachable!(),
}

let ret = unsafe { tickv.append_key(get_hashed_key(b"TWO"), &mut VALUE, 32) };
let ret =
unsafe { tickv.append_key(get_hashed_key(b"TWO"), &mut *addr_of_mut!(VALUE), 32) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand Down Expand Up @@ -689,7 +692,8 @@ mod tests {
static mut BUF: [u8; 32] = [0; 32];

println!("Add key ONE");
let ret = unsafe { tickv.append_key(get_hashed_key(b"ONE"), &mut VALUE, 32) };
let ret =
unsafe { tickv.append_key(get_hashed_key(b"ONE"), &mut *addr_of_mut!(VALUE), 32) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand All @@ -702,7 +706,7 @@ mod tests {

println!("Get key ONE");

let ret = unsafe { tickv.get_key(get_hashed_key(b"ONE"), &mut BUF) };
let ret = unsafe { tickv.get_key(get_hashed_key(b"ONE"), &mut *addr_of_mut!(BUF)) };
match ret {
Ok(SuccessCode::Queued) => {
flash_ctrl_callback(&tickv);
Expand All @@ -713,7 +717,7 @@ mod tests {
}

println!("Get non-existent key TWO");
let ret = unsafe { tickv.get_key(get_hashed_key(b"TWO"), &mut BUF) };
let ret = unsafe { tickv.get_key(get_hashed_key(b"TWO"), &mut *addr_of_mut!(BUF)) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand All @@ -725,7 +729,8 @@ mod tests {
}

println!("Add key ONE again");
let ret = unsafe { tickv.append_key(get_hashed_key(b"ONE"), &mut VALUE, 32) };
let ret =
unsafe { tickv.append_key(get_hashed_key(b"ONE"), &mut *addr_of_mut!(VALUE), 32) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand All @@ -740,7 +745,8 @@ mod tests {
}

println!("Add key TWO");
let ret = unsafe { tickv.append_key(get_hashed_key(b"TWO"), &mut VALUE, 32) };
let ret =
unsafe { tickv.append_key(get_hashed_key(b"TWO"), &mut *addr_of_mut!(VALUE), 32) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand All @@ -752,7 +758,7 @@ mod tests {
}

println!("Get key ONE");
let ret = unsafe { tickv.get_key(get_hashed_key(b"ONE"), &mut BUF) };
let ret = unsafe { tickv.get_key(get_hashed_key(b"ONE"), &mut *addr_of_mut!(BUF)) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand All @@ -764,7 +770,7 @@ mod tests {
}

println!("Get key TWO");
let ret = unsafe { tickv.get_key(get_hashed_key(b"TWO"), &mut BUF) };
let ret = unsafe { tickv.get_key(get_hashed_key(b"TWO"), &mut *addr_of_mut!(BUF)) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand All @@ -776,7 +782,7 @@ mod tests {
}

println!("Get non-existent key THREE");
let ret = unsafe { tickv.get_key(get_hashed_key(b"THREE"), &mut BUF) };
let ret = unsafe { tickv.get_key(get_hashed_key(b"THREE"), &mut *addr_of_mut!(BUF)) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand All @@ -786,7 +792,7 @@ mod tests {
_ => unreachable!(),
}

let ret = unsafe { tickv.get_key(get_hashed_key(b"THREE"), &mut BUF) };
let ret = unsafe { tickv.get_key(get_hashed_key(b"THREE"), &mut *addr_of_mut!(BUF)) };
match ret {
Ok(SuccessCode::Queued) => {
flash_ctrl_callback(&tickv);
Expand Down Expand Up @@ -822,7 +828,7 @@ mod tests {
static mut BUF: [u8; 32] = [0; 32];

println!("Add key 0x1000");
let ret = unsafe { tickv.append_key(0x1000, &mut VALUE, 32) };
let ret = unsafe { tickv.append_key(0x1000, &mut *addr_of_mut!(VALUE), 32) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand All @@ -834,7 +840,7 @@ mod tests {
}

println!("Add key 0x2000");
let ret = unsafe { tickv.append_key(0x2000, &mut VALUE, 32) };
let ret = unsafe { tickv.append_key(0x2000, &mut *addr_of_mut!(VALUE), 32) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand All @@ -853,7 +859,7 @@ mod tests {
}

println!("Add key 0x3000");
let ret = unsafe { tickv.append_key(0x3000, &mut VALUE, 32) };
let ret = unsafe { tickv.append_key(0x3000, &mut *addr_of_mut!(VALUE), 32) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand All @@ -876,7 +882,7 @@ mod tests {
}

println!("Get key 0x1000");
let ret = unsafe { tickv.get_key(0x1000, &mut BUF) };
let ret = unsafe { tickv.get_key(0x1000, &mut *addr_of_mut!(BUF)) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand All @@ -898,7 +904,7 @@ mod tests {
}

println!("Get key 0x3000");
let ret = unsafe { tickv.get_key(0x3000, &mut BUF) };
let ret = unsafe { tickv.get_key(0x3000, &mut *addr_of_mut!(BUF)) };
match ret {
Ok(_) => flash_ctrl_callback(&tickv),
Err(_) => unreachable!(),
Expand Down Expand Up @@ -942,7 +948,8 @@ mod tests {
static mut BUF: [u8; 32] = [0; 32];

println!("Add key ONE");
let ret = unsafe { tickv.append_key(get_hashed_key(b"ONE"), &mut VALUE, 32) };
let ret =
unsafe { tickv.append_key(get_hashed_key(b"ONE"), &mut *addr_of_mut!(VALUE), 32) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand All @@ -954,7 +961,7 @@ mod tests {
}

println!("Get key ONE");
let ret = unsafe { tickv.get_key(get_hashed_key(b"ONE"), &mut BUF) };
let ret = unsafe { tickv.get_key(get_hashed_key(b"ONE"), &mut *addr_of_mut!(BUF)) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand All @@ -978,7 +985,7 @@ mod tests {

println!("Get non-existent key ONE");
unsafe {
match tickv.get_key(get_hashed_key(b"ONE"), &mut BUF) {
match tickv.get_key(get_hashed_key(b"ONE"), &mut *addr_of_mut!(BUF)) {
Ok(SuccessCode::Queued) => {
flash_ctrl_callback(&tickv);

Expand Down Expand Up @@ -1103,7 +1110,8 @@ mod tests {
}

println!("Add key ONE");
let ret = unsafe { tickv.append_key(get_hashed_key(b"ONE"), &mut VALUE, 32) };
let ret =
unsafe { tickv.append_key(get_hashed_key(b"ONE"), &mut *addr_of_mut!(VALUE), 32) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand Down Expand Up @@ -1156,7 +1164,7 @@ mod tests {
}

println!("Get non-existent key ONE");
match unsafe { tickv.get_key(get_hashed_key(b"ONE"), &mut BUF) } {
match unsafe { tickv.get_key(get_hashed_key(b"ONE"), &mut *addr_of_mut!(BUF)) } {
Ok(SuccessCode::Queued) => {
flash_ctrl_callback(&tickv);
assert_eq!(
Expand All @@ -1170,7 +1178,8 @@ mod tests {
}

println!("Add Key ONE");
let ret = unsafe { tickv.append_key(get_hashed_key(b"ONE"), &mut VALUE, 32) };
let ret =
unsafe { tickv.append_key(get_hashed_key(b"ONE"), &mut *addr_of_mut!(VALUE), 32) };
match ret {
Ok(SuccessCode::Queued) => {
// There is no actual delay in the test, just continue now
Expand Down

0 comments on commit 5bdbeed

Please sign in to comment.