Skip to content
13 changes: 13 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ jobs:
timeout-minutes: 10
run: cargo test --locked --release --all --all-features --no-fail-fast -- --nocapture

# The tests attaching loop devices need root, so the run above leaves
# them out. Only the test binary runs as root, which keeps the cached
# build owned by the runner. The MTD ones stay out, as they load the
# mtdram and nandsim kernel modules.
- name: Tests needing root
timeout-minutes: 10
working-directory: updatehub
run: |
bin=$(cargo test --locked --release --all-features --lib --no-run --message-format=json \
| sed -n 's/.*"executable":"\([^"]*\)".*/\1/p')
sudo env "PATH=$PATH" "$bin" --ignored --test-threads=1 \
--skip utils::mtd --skip installer::flash --skip installer::ubifs

- name: Run listener test
run: |
export UH_LISTENER_TEST=updatehub-statechange.sock
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
socat

# used by excluded tests
e2fsprogs
mtdutils
];

Expand Down
26 changes: 4 additions & 22 deletions updatehub/src/object/installer/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,10 @@ impl Installer for objects::Copy {
#[cfg(test)]
mod tests {
use super::*;
use crate::{object::installer::tests::SERIALIZE, utils::definitions::IdExt};
use crate::utils::{definitions::IdExt, fs::tests::FakeLoopDevice};
use flate2::{Compression, write::GzEncoder};
use pretty_assertions::assert_eq;
use std::{
io::{Seek, SeekFrom, Write},
os::unix::fs::MetadataExt,
path::PathBuf,
};
use std::{io::Write, os::unix::fs::MetadataExt, path::PathBuf};
use tokio::io::AsyncBufReadExt;

const DEFAULT_BYTE: u8 = 0xF;
Expand All @@ -147,21 +143,9 @@ mod tests {
where
F: FnMut(&mut objects::Copy),
{
// Generate a sparse file for the faked device use
let mut image = tempfile::NamedTempFile::new()?;
image.seek(SeekFrom::Start(1024 * 1024 + FILE_SIZE as u64))?;
image.write_all(&[0])?;

// Setup faked device
let (loopdev, device) = {
// Loop device next_free is not thread safe
let mutex = SERIALIZE.clone();
let _mutex = mutex.lock().unwrap();
let loopdev = loopdev::LoopControl::open()?.next_free()?;
let device = loopdev.path().unwrap();
loopdev.attach_file(image.path())?;
(loopdev, device)
};
let loop_device = FakeLoopDevice::new(1024 * 1024 + FILE_SIZE as u64 + 1)?;
let device = loop_device.device.clone();

// Format the faked device
utils::fs::format(&device, definitions::Filesystem::Ext4, None)?;
Expand Down Expand Up @@ -258,8 +242,6 @@ mod tests {
}
}

loopdev.detach()?;

Ok(())
}

Expand Down
Loading
Loading