Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Murmele committed Jun 5, 2024
1 parent 56a07fe commit c155268
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 26 deletions.
6 changes: 5 additions & 1 deletion examples/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ use std::io::prelude::*;

use embedded_sdmmc::{
Error as EsError, RawDirectory, RawVolume, ShortFileName, VolumeIdx, VolumeManager,
VolumeOpenMode,
};

use crate::linux::{Clock, LinuxBlockDevice};
Expand Down Expand Up @@ -531,7 +532,10 @@ fn main() -> Result<(), Error> {

let mut current_volume = None;
for volume_no in 0..4 {
match ctx.volume_mgr.open_raw_volume(VolumeIdx(volume_no)) {
match ctx
.volume_mgr
.open_raw_volume(VolumeIdx(volume_no), VolumeOpenMode::ReadWrite)
{
Ok(volume) => {
println!("Volume # {}: found", Context::volume_to_letter(volume_no));
match ctx.volume_mgr.open_root_dir(volume) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub mod filesystem;
pub mod sdcard;

use filesystem::SearchId;
use volume_mgr::VolumeOpenMode;
pub use volume_mgr::VolumeOpenMode;

#[doc(inline)]
pub use crate::blockdevice::{Block, BlockCount, BlockDevice, BlockIdx};
Expand Down
3 changes: 3 additions & 0 deletions src/volume_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ use crate::{
};
use heapless::Vec;

/// Opening volume mode
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum VolumeOpenMode {
/// Opening volume read only. This is faster than ReadWrite if only readings are done
ReadOnly,
/// Opening volume for reading and writing.
ReadWrite,
}

Expand Down
18 changes: 9 additions & 9 deletions tests/directories.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Directory related tests
use embedded_sdmmc::{Mode, ShortFileName};
use embedded_sdmmc::{Mode, ShortFileName, VolumeOpenMode};

mod utils;

Expand Down Expand Up @@ -41,7 +41,7 @@ fn fat16_root_directory_listing() {
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(disk, time_source);

let fat16_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(0))
.open_raw_volume(embedded_sdmmc::VolumeIdx(0), VolumeOpenMode::ReadWrite)
.expect("open volume 0");
let root_dir = volume_mgr
.open_root_dir(fat16_volume)
Expand Down Expand Up @@ -103,7 +103,7 @@ fn fat16_sub_directory_listing() {
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(disk, time_source);

let fat16_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(0))
.open_raw_volume(embedded_sdmmc::VolumeIdx(0), VolumeOpenMode::ReadWrite)
.expect("open volume 0");
let root_dir = volume_mgr
.open_root_dir(fat16_volume)
Expand Down Expand Up @@ -168,7 +168,7 @@ fn fat32_root_directory_listing() {
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(disk, time_source);

let fat32_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(1))
.open_raw_volume(embedded_sdmmc::VolumeIdx(1), VolumeOpenMode::ReadWrite)
.expect("open volume 1");
let root_dir = volume_mgr
.open_root_dir(fat32_volume)
Expand Down Expand Up @@ -230,7 +230,7 @@ fn open_dir_twice() {
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(disk, time_source);

let fat32_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(1))
.open_raw_volume(embedded_sdmmc::VolumeIdx(1), VolumeOpenMode::ReadWrite)
.expect("open volume 1");

let root_dir = volume_mgr
Expand Down Expand Up @@ -276,7 +276,7 @@ fn open_too_many_dirs() {
> = embedded_sdmmc::VolumeManager::new_with_limits(disk, time_source, 0x1000_0000);

let fat32_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(1))
.open_raw_volume(embedded_sdmmc::VolumeIdx(1), VolumeOpenMode::ReadWrite)
.expect("open volume 1");
let root_dir = volume_mgr
.open_root_dir(fat32_volume)
Expand All @@ -295,7 +295,7 @@ fn find_dir_entry() {
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(disk, time_source);

let fat32_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(1))
.open_raw_volume(embedded_sdmmc::VolumeIdx(1), VolumeOpenMode::ReadWrite)
.expect("open volume 1");

let root_dir = volume_mgr
Expand Down Expand Up @@ -325,7 +325,7 @@ fn delete_file() {
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(disk, time_source);

let fat32_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(1))
.open_raw_volume(embedded_sdmmc::VolumeIdx(1), VolumeOpenMode::ReadWrite)
.expect("open volume 1");

let root_dir = volume_mgr
Expand Down Expand Up @@ -370,7 +370,7 @@ fn make_directory() {
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(disk, time_source);

let fat32_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(1))
.open_raw_volume(embedded_sdmmc::VolumeIdx(1), VolumeOpenMode::ReadWrite)
.expect("open volume 1");

let root_dir = volume_mgr
Expand Down
4 changes: 2 additions & 2 deletions tests/open_files.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! File opening related tests
use embedded_sdmmc::{Error, Mode, VolumeIdx, VolumeManager};
use embedded_sdmmc::{Error, Mode, VolumeIdx, VolumeManager, VolumeOpenMode};

mod utils;

Expand All @@ -11,7 +11,7 @@ fn open_files() {
let mut volume_mgr: VolumeManager<utils::RamDisk<Vec<u8>>, utils::TestTimeSource, 4, 2, 1> =
VolumeManager::new_with_limits(disk, time_source, 0xAA00_0000);
let volume = volume_mgr
.open_raw_volume(VolumeIdx(0))
.open_raw_volume(VolumeIdx(0), VolumeOpenMode::ReadWrite)
.expect("open volume");
let root_dir = volume_mgr.open_root_dir(volume).expect("open root dir");

Expand Down
8 changes: 4 additions & 4 deletions tests/read_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn read_file_512_blocks() {
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(disk, time_source);

let fat16_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(0))
.open_raw_volume(embedded_sdmmc::VolumeIdx(0), VolumeOpenMode::ReadWrite)
.expect("open volume 0");
let root_dir = volume_mgr
.open_root_dir(fat16_volume)
Expand Down Expand Up @@ -56,7 +56,7 @@ fn read_file_all() {
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(disk, time_source);

let fat16_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(0))
.open_raw_volume(embedded_sdmmc::VolumeIdx(0), VolumeOpenMode::ReadWrite)
.expect("open volume 0");
let root_dir = volume_mgr
.open_root_dir(fat16_volume)
Expand Down Expand Up @@ -90,7 +90,7 @@ fn read_file_prime_blocks() {
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(disk, time_source);

let fat16_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(0))
.open_raw_volume(embedded_sdmmc::VolumeIdx(0), VolumeOpenMode::ReadWrite)
.expect("open volume 0");
let root_dir = volume_mgr
.open_root_dir(fat16_volume)
Expand Down Expand Up @@ -133,7 +133,7 @@ fn read_file_backwards() {
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(disk, time_source);

let fat16_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(0))
.open_raw_volume(embedded_sdmmc::VolumeIdx(0), VolumeOpenMode::ReadWrite)
.expect("open volume 0");
let root_dir = volume_mgr
.open_root_dir(fat16_volume)
Expand Down
54 changes: 45 additions & 9 deletions tests/volume.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Volume related tests
use embedded_sdmmc::VolumeOpenMode;

mod utils;

#[test]
Expand All @@ -16,36 +18,36 @@ fn open_all_volumes() {

// Open Volume 0
let fat16_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(0))
.open_raw_volume(embedded_sdmmc::VolumeIdx(0), VolumeOpenMode::ReadWrite)
.expect("open volume 0");

// Fail to Open Volume 0 again
assert!(matches!(
volume_mgr.open_raw_volume(embedded_sdmmc::VolumeIdx(0)),
volume_mgr.open_raw_volume(embedded_sdmmc::VolumeIdx(0), VolumeOpenMode::ReadWrite),
Err(embedded_sdmmc::Error::VolumeAlreadyOpen)
));

volume_mgr.close_volume(fat16_volume).expect("close fat16");

// Open Volume 1
let fat32_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(1))
.open_raw_volume(embedded_sdmmc::VolumeIdx(1), VolumeOpenMode::ReadWrite)
.expect("open volume 1");

// Fail to Volume 1 again
assert!(matches!(
volume_mgr.open_raw_volume(embedded_sdmmc::VolumeIdx(1)),
volume_mgr.open_raw_volume(embedded_sdmmc::VolumeIdx(1), VolumeOpenMode::ReadWrite),
Err(embedded_sdmmc::Error::VolumeAlreadyOpen)
));

// Open Volume 0 again
let fat16_volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(0))
.open_raw_volume(embedded_sdmmc::VolumeIdx(0), VolumeOpenMode::ReadWrite)
.expect("open volume 0");

// Open any volume - too many volumes (0 and 1 are open)
assert!(matches!(
volume_mgr.open_raw_volume(embedded_sdmmc::VolumeIdx(0)),
volume_mgr.open_raw_volume(embedded_sdmmc::VolumeIdx(0), VolumeOpenMode::ReadWrite),
Err(embedded_sdmmc::Error::TooManyOpenVolumes)
));

Expand All @@ -54,13 +56,13 @@ fn open_all_volumes() {

// This isn't a valid volume
assert!(matches!(
volume_mgr.open_raw_volume(embedded_sdmmc::VolumeIdx(2)),
volume_mgr.open_raw_volume(embedded_sdmmc::VolumeIdx(2), VolumeOpenMode::ReadWrite),
Err(embedded_sdmmc::Error::FormatError(_e))
));

// This isn't a valid volume
assert!(matches!(
volume_mgr.open_raw_volume(embedded_sdmmc::VolumeIdx(9)),
volume_mgr.open_raw_volume(embedded_sdmmc::VolumeIdx(9), VolumeOpenMode::ReadWrite),
Err(embedded_sdmmc::Error::NoSuchVolume)
));

Expand All @@ -79,7 +81,7 @@ fn close_volume_too_early() {
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(disk, time_source);

let volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(0))
.open_raw_volume(embedded_sdmmc::VolumeIdx(0), VolumeOpenMode::ReadWrite)
.expect("open volume 0");
let root_dir = volume_mgr.open_root_dir(volume).expect("open root dir");

Expand All @@ -102,6 +104,40 @@ fn close_volume_too_early() {
));
}

#[test]
fn volume_read_only_open_file_read_write() {
let time_source = utils::make_time_source();
let disk = utils::make_block_device(utils::DISK_SOURCE).unwrap();
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(disk, time_source);

let volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(0), VolumeOpenMode::ReadOnly)
.expect("open volume 0");
let root_dir = volume_mgr.open_root_dir(volume).expect("open root dir");

// Dir open
assert!(matches!(
volume_mgr.open_file_in_dir(root_dir, "64MB.DAT", embedded_sdmmc::Mode::ReadWriteAppend),
Err(embedded_sdmmc::Error::VolumeReadOnly)
));
}

#[test]
fn volume_read_only_open_file_read_only() {
let time_source = utils::make_time_source();
let disk = utils::make_block_device(utils::DISK_SOURCE).unwrap();
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(disk, time_source);

let volume = volume_mgr
.open_raw_volume(embedded_sdmmc::VolumeIdx(0), VolumeOpenMode::ReadOnly)
.expect("open volume 0");
let root_dir = volume_mgr.open_root_dir(volume).expect("open root dir");

volume_mgr
.open_file_in_dir(root_dir, "64MB.DAT", embedded_sdmmc::Mode::ReadOnly)
.unwrap();
}

// ****************************************************************************
//
// End Of File
Expand Down

0 comments on commit c155268

Please sign in to comment.