[tests] Add cache fixtures
- Generate temp xml and metadata files - Correct existing tests to use cache fixtures - Fix cache xml generation
This commit is contained in:
parent
0acc57d17f
commit
9253117132
@ -2,6 +2,7 @@ use anyhow::Result;
|
|||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
|
use common::cache::*;
|
||||||
use common::common_args::*;
|
use common::common_args::*;
|
||||||
use common::fixture::*;
|
use common::fixture::*;
|
||||||
use common::input_arg::*;
|
use common::input_arg::*;
|
||||||
@ -51,7 +52,7 @@ impl<'a> Program<'a> for CacheCheck {
|
|||||||
|
|
||||||
impl<'a> InputProgram<'a> for CacheCheck {
|
impl<'a> InputProgram<'a> for CacheCheck {
|
||||||
fn mk_valid_input(td: &mut TestDir) -> Result<std::path::PathBuf> {
|
fn mk_valid_input(td: &mut TestDir) -> Result<std::path::PathBuf> {
|
||||||
common::thin::mk_valid_md(td) // FIXME: create cache metadata
|
mk_valid_md(td)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn file_not_found() -> &'a str {
|
fn file_not_found() -> &'a str {
|
||||||
|
@ -2,9 +2,9 @@ use anyhow::Result;
|
|||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
|
use common::cache::*;
|
||||||
use common::common_args::*;
|
use common::common_args::*;
|
||||||
use common::input_arg::*;
|
use common::input_arg::*;
|
||||||
|
|
||||||
use common::program::*;
|
use common::program::*;
|
||||||
use common::target::*;
|
use common::target::*;
|
||||||
use common::test_dir::*;
|
use common::test_dir::*;
|
||||||
@ -46,7 +46,7 @@ impl<'a> Program<'a> for CacheDump {
|
|||||||
|
|
||||||
impl<'a> InputProgram<'a> for CacheDump {
|
impl<'a> InputProgram<'a> for CacheDump {
|
||||||
fn mk_valid_input(td: &mut TestDir) -> Result<std::path::PathBuf> {
|
fn mk_valid_input(td: &mut TestDir) -> Result<std::path::PathBuf> {
|
||||||
common::thin::mk_valid_md(td) // FIXME: generate cache metadata
|
mk_valid_md(td)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn file_not_found() -> &'a str {
|
fn file_not_found() -> &'a str {
|
||||||
|
35
tests/common/cache.rs
Normal file
35
tests/common/cache.rs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
use anyhow::Result;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use thinp::file_utils;
|
||||||
|
//use thinp::io_engine::*;
|
||||||
|
|
||||||
|
use crate::args;
|
||||||
|
use crate::common::cache_xml_generator::{write_xml, CacheGen};
|
||||||
|
use crate::common::process::*;
|
||||||
|
use crate::common::target::*;
|
||||||
|
use crate::common::test_dir::TestDir;
|
||||||
|
|
||||||
|
//-----------------------------------------------
|
||||||
|
|
||||||
|
pub fn mk_valid_xml(td: &mut TestDir) -> Result<PathBuf> {
|
||||||
|
let xml = td.mk_path("meta.xml");
|
||||||
|
let mut gen = CacheGen::new(512, 128, 1024, 80, 50); // bs, cblocks, oblocks, res, dirty
|
||||||
|
write_xml(&xml, &mut gen)?;
|
||||||
|
Ok(xml)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mk_valid_md(td: &mut TestDir) -> Result<PathBuf> {
|
||||||
|
let xml = td.mk_path("meta.xml");
|
||||||
|
let md = td.mk_path("meta.bin");
|
||||||
|
|
||||||
|
let mut gen = CacheGen::new(512, 4096, 32768, 80, 50);
|
||||||
|
write_xml(&xml, &mut gen)?;
|
||||||
|
|
||||||
|
let _file = file_utils::create_sized_file(&md, 4096 * 4096);
|
||||||
|
run_ok(CACHE_RESTORE, args!["-i", &xml, "-o", &md])?;
|
||||||
|
|
||||||
|
Ok(md)
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------
|
@ -60,26 +60,26 @@ impl XmlGen for CacheGen {
|
|||||||
hint_width: 4,
|
hint_width: 4,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut cblocks = Vec::new();
|
let nr_resident = (self.nr_cache_blocks * self.percent_resident as u32) / 100u32;
|
||||||
for n in 0..self.nr_cache_blocks {
|
let mut cblocks = (0..self.nr_cache_blocks).collect::<Vec<u32>>();
|
||||||
cblocks.push(n);
|
|
||||||
}
|
|
||||||
cblocks.shuffle(&mut rand::thread_rng());
|
cblocks.shuffle(&mut rand::thread_rng());
|
||||||
|
cblocks.truncate(nr_resident as usize);
|
||||||
|
cblocks.sort();
|
||||||
|
|
||||||
v.mappings_b()?;
|
v.mappings_b()?;
|
||||||
{
|
{
|
||||||
let nr_resident = (self.nr_cache_blocks * 100u32) / (self.percent_resident as u32);
|
|
||||||
let mut used = HashSet::new();
|
let mut used = HashSet::new();
|
||||||
for n in 0..nr_resident {
|
let mut rng = rand::thread_rng();
|
||||||
|
for cblock in cblocks {
|
||||||
let mut oblock = 0u64;
|
let mut oblock = 0u64;
|
||||||
while used.contains(&oblock) {
|
while used.contains(&oblock) {
|
||||||
oblock = rand::thread_rng().gen();
|
oblock = rng.gen_range(0..self.nr_origin_blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
used.insert(oblock);
|
used.insert(oblock);
|
||||||
// FIXME: dirty should vary
|
// FIXME: dirty should vary
|
||||||
v.mapping(&ir::Map {
|
v.mapping(&ir::Map {
|
||||||
cblock: cblocks[n as usize],
|
cblock,
|
||||||
oblock,
|
oblock,
|
||||||
dirty: false,
|
dirty: false,
|
||||||
})?;
|
})?;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// https://github.com/rust-lang/rust/issues/46379
|
// https://github.com/rust-lang/rust/issues/46379
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
pub mod cache;
|
||||||
pub mod cache_xml_generator;
|
pub mod cache_xml_generator;
|
||||||
pub mod common_args;
|
pub mod common_args;
|
||||||
pub mod fixture;
|
pub mod fixture;
|
||||||
|
Loading…
Reference in New Issue
Block a user