Skip to content

Commit

Permalink
Generalize some test code for multiple architectures (#49)
Browse files Browse the repository at this point in the history
* Run rustfmt with current stable

Signed-off-by: mulhern <[email protected]>

* Add try_into() call to convert size

On some architectures, off_t is i32.

Signed-off-by: mulhern <[email protected]>

* Change signature of create_backing_file

Adapt caller's signatures. No signatures other than those of the direct
callers need to be adapted.

Signed-off-by: mulhern <[email protected]>

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran authored Oct 10, 2022
1 parent 5ba7623 commit 2f5763f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
9 changes: 3 additions & 6 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ fn get_next_free_device() {

assert_eq!(
ld0.path(),
Some(PathBuf::from(&format!(
"/dev/loop{}",
num_devices_at_start
))),
Some(PathBuf::from(&format!("/dev/loop{}", num_devices_at_start))),
"should find the first loopback device"
);
}
Expand Down Expand Up @@ -63,7 +60,7 @@ fn attach_a_backing_file_with_sizelimit_overflow() {
attach_a_backing_file(0, 128 * 1024 * 1024 * 2, 128 * 1024 * 1024);
}

fn attach_a_backing_file(offset: u64, sizelimit: u64, file_size: i64) {
fn attach_a_backing_file(offset: u64, sizelimit: u64, file_size: i32) {
let _lock = setup();

let (devices, ld0_path, file_path) = {
Expand Down Expand Up @@ -148,7 +145,7 @@ fn detach_a_backing_file_with_sizelimit_overflow() {
detach_a_backing_file(0, 128 * 1024 * 1024 * 2, 128 * 1024 * 1024);
}

fn detach_a_backing_file(offset: u64, sizelimit: u64, file_size: i64) {
fn detach_a_backing_file(offset: u64, sizelimit: u64, file_size: i32) {
let num_devices_at_start = list_device(None).len();
let _lock = setup();

Expand Down
5 changes: 3 additions & 2 deletions tests/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use libc::fallocate;
use serde::{Deserialize, Deserializer};
use std::{
convert::TryInto,
io,
os::unix::io::AsRawFd,
process::Command,
Expand All @@ -15,9 +16,9 @@ lazy_static! {
static ref LOCK: Arc<Mutex<()>> = Arc::new(Mutex::new(()));
}

pub fn create_backing_file(size: i64) -> TempPath {
pub fn create_backing_file(size: i32) -> TempPath {
let file = NamedTempFile::new().expect("should be able to create a temp file");
if unsafe { fallocate(file.as_raw_fd(), 0, 0, size) } < 0 {
if unsafe { fallocate(file.as_raw_fd(), 0, 0, size.try_into().unwrap()) } < 0 {
panic!(
"should be able to allocate the tenp file: {}",
io::Error::last_os_error()
Expand Down

0 comments on commit 2f5763f

Please sign in to comment.