summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2020-06-11 16:59:51 -0400
committerDeterminant <[email protected]>2020-06-11 16:59:51 -0400
commitb02d58c4f3a2b7ad6e32fe3e7a493cec655631ba (patch)
treeaf658667c8f3c993f98653ee3ac96e794f5e1f53
parenta24f46984d51d8533c5ce85d18566394883fcf4b (diff)
add more tests
-rw-r--r--tests/common/mod.rs17
-rw-r--r--tests/rand_fail.rs67
2 files changed, 63 insertions, 21 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index def85fb..6e35ea1 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -101,6 +101,7 @@ impl WALStoreEmulState {
files: HashMap::new(),
}
}
+ pub fn clone(&self) -> Self { WALStoreEmulState{ files: self.files.clone() }}
}
/// Emulate the persistent storage state.
@@ -251,15 +252,14 @@ impl FailGen for CountFailGen {
}
/// An ordered list of intervals: `(begin, end, color)*`.
+#[derive(Clone)]
pub struct PaintStrokes(Vec<(u32, u32, u32)>);
impl PaintStrokes {
pub fn new() -> Self {
PaintStrokes(Vec::new())
}
- pub fn clone(&self) -> Self {
- PaintStrokes(self.0.clone())
- }
+
pub fn to_bytes(&self) -> WALBytes {
let mut res: Vec<u8> = Vec::new();
let is = std::mem::size_of::<u32>();
@@ -574,7 +574,7 @@ impl PaintingSim {
}
}
}
- canvas.print(40);
+ //canvas.print(40);
Ok(())
}
@@ -582,14 +582,13 @@ impl PaintingSim {
WALLoader::new(self.file_nbit, self.block_nbit, self.file_cache)
}
- pub fn get_nticks(&self) -> usize {
- let mut state = WALStoreEmulState::new();
+ pub fn get_nticks(&self, state: &mut WALStoreEmulState) -> usize {
let mut canvas = Canvas::new(self.csize);
let mut ops: Vec<PaintStrokes> = Vec::new();
let mut ringid_map = HashMap::new();
let fgen = Rc::new(CountFailGen::new());
self.run(
- &mut state,
+ state,
&mut canvas,
self.get_walloader(),
&mut ops,
@@ -612,6 +611,7 @@ impl PaintingSim {
return true;
}
let mut last_idx = 0;
+ let mut napplied = 0;
canvas.clear_queued();
wal.recover(WALStoreEmul::new(
state,
@@ -620,10 +620,11 @@ impl PaintingSim {
let s = PaintStrokes::from_bytes(&payload);
canvas.prepaint(&s, &ringid);
last_idx = *ringid_map.get(&ringid).unwrap() + 1;
+ napplied += 1;
},
))
.unwrap();
- println!("last = {}/{}", last_idx, ops.len());
+ println!("last = {}/{}, applied = {}", last_idx, ops.len(), napplied);
canvas.paint_all();
// recover complete
let canvas0 = if last_idx > 0 {
diff --git a/tests/rand_fail.rs b/tests/rand_fail.rs
index da583b2..055f933 100644
--- a/tests/rand_fail.rs
+++ b/tests/rand_fail.rs
@@ -3,12 +3,15 @@
use std::collections::HashMap;
use std::rc::Rc;
-fn single_point_failure(sim: &common::PaintingSim) {
- let nticks = sim.get_nticks();
- println!("nticks = {}", nticks);
+fn _multi_point_failure(sims: &[common::PaintingSim], state: &common::WALStoreEmulState, f: usize) {
+ let sim = &sims[0];
+ // save the current state and start from there
+ let mut state = state.clone();
+ let mut state0 = state.clone();
+ let nticks = sim.get_nticks(&mut state0);
+ println!("fail = {}, nticks = {}", f, nticks);
for i in 0..nticks {
- print!("fail pos = {}, ", i);
- let mut state = common::WALStoreEmulState::new();
+ println!("fail = {}, pos = {}", f, i);
let mut canvas = sim.new_canvas();
let mut ops: Vec<common::PaintStrokes> = Vec::new();
let mut ringid_map = HashMap::new();
@@ -24,17 +27,25 @@ fn single_point_failure(sim: &common::PaintingSim) {
)
.is_err()
{
- assert!(sim.check(
- &mut state,
- &mut canvas,
- sim.get_walloader(),
- &ops,
- &ringid_map,
- ))
+ if sims.len() > 1 {
+ _multi_point_failure(&sims[1..], &state, f + 1)
+ } else {
+ assert!(sim.check(
+ &mut state,
+ &mut canvas,
+ sim.get_walloader(),
+ &ops,
+ &ringid_map,
+ ))
+ }
}
}
}
+fn multi_point_failure(sims: &[common::PaintingSim]) {
+ _multi_point_failure(sims, &common::WALStoreEmulState::new(), 1);
+}
+
#[test]
fn single_point_failure1() {
let sim = common::PaintingSim {
@@ -50,5 +61,35 @@ fn single_point_failure1() {
stroke_max_n: 5,
seed: 0,
};
- single_point_failure(&sim);
+ multi_point_failure(&[sim]);
+}
+
+#[test]
+fn two_failures() {
+ let sims = [common::PaintingSim {
+ block_nbit: 5,
+ file_nbit: 6,
+ file_cache: 1000,
+ n: 10,
+ m: 5,
+ k: 100,
+ csize: 1000,
+ stroke_max_len: 10,
+ stroke_max_col: 256,
+ stroke_max_n: 3,
+ seed: 0,
+ }, common::PaintingSim {
+ block_nbit: 5,
+ file_nbit: 6,
+ file_cache: 1000,
+ n: 10,
+ m: 5,
+ k: 100,
+ csize: 1000,
+ stroke_max_len: 10,
+ stroke_max_col: 256,
+ stroke_max_n: 3,
+ seed: 0,
+ }];
+ multi_point_failure(&sims);
}