Skip to content

Commit

Permalink
refactor, ading Replayer::new
Browse files Browse the repository at this point in the history
Summary: The only constructor use was in tests. This publishes the constructor to standardize on it elsewhere, even though it is a transparent struct.

Reviewed By: VladimirMakaev

Differential Revision: D42169897

fbshipit-source-id: 373afd304c85fd85a3e87a16d8e10bb1e7258803
  • Loading branch information
rrnewton authored and facebook-github-bot committed Feb 7, 2023
1 parent 580d919 commit 75dbeae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
15 changes: 4 additions & 11 deletions detcore/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,17 +755,10 @@ impl Scheduler {
.iter()
.map(|(ix, path)| (*ix, Some(vec[*ix as usize].clone()), path.clone()))
.collect();
(
Some(Replayer {
cursor: vec.into_iter().collect(),
traced_event_count: 0,
desync_counts: BTreeMap::new(),
die_on_desync: cfg.die_on_desync,
replay_exhausted_panic: cfg.replay_exhausted_panic,
events_popped: 0,
}),
Some(toprint),
)
let mut replayer = Replayer::new(vec.into_iter());
replayer.replay_exhausted_panic = cfg.replay_exhausted_panic;
replayer.die_on_desync = cfg.die_on_desync;
(Some(replayer), Some(toprint))
}
None => (
None,
Expand Down
39 changes: 19 additions & 20 deletions detcore/src/scheduler/replayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ fn is_hard_desync(observed: &SchedEvent, expected: &SchedEvent) -> bool {
}

impl Replayer {
/// Allocate a new replayer.
pub fn new(i: impl IntoIterator<Item = SchedEvent>) -> Replayer {
let cursor = ReplayCursor::from_iter(i);
Replayer {
cursor,
desync_counts: BTreeMap::new(),
die_on_desync: false,
replay_exhausted_panic: false,
traced_event_count: 0,
events_popped: 0,
}
}

/// This function look-aheads into following instruction to determine if
/// an explicit timer preemption is required while replaying. This is required when
/// the original run schedule was modified before replaying which should be a valid
Expand Down Expand Up @@ -534,9 +547,6 @@ mod builder {

#[cfg(test)]
mod tests {

use std::iter::FromIterator;

use pretty_assertions::assert_eq;
use reverie::syscalls::Sysno;

Expand All @@ -548,17 +558,6 @@ mod tests {
DetTid::from_raw(raw)
}

fn create_replayer(i: impl IntoIterator<Item = SchedEvent>) -> Replayer {
Replayer {
cursor: ReplayCursor::from_iter(i),
desync_counts: BTreeMap::new(),
die_on_desync: false,
replay_exhausted_panic: false,
traced_event_count: 0,
events_popped: 0,
}
}

fn strip_times(vec: Vec<SchedEvent>) -> Vec<SchedEvent> {
vec.iter()
.map(|se| SchedEvent {
Expand All @@ -572,7 +571,7 @@ mod tests {
fn test_continue_() {
let mut b = builder::SchedTestBuilder::new();
let schedule = vec![b.branch(10, tid(3))];
let mut replayer = create_replayer(schedule.clone());
let mut replayer = Replayer::new(schedule.clone());
assert_eq!(
replayer.observe_event(&schedule[0]),
ReplayAction::Continue(None)
Expand All @@ -588,7 +587,7 @@ mod tests {
b.other(SOME_RIP, tid(3)),
b.branch(1, tid(5)),
];
let mut replayer = create_replayer(schedule.clone());
let mut replayer = Replayer::new(schedule.clone());
assert_eq!(
replayer.observe_event(&schedule[0]),
ReplayAction::Continue(Some(LogicalTime::from_rcbs(123)))
Expand All @@ -604,7 +603,7 @@ mod tests {
b.other(SOME_RIP, tid(3)),
b.syscall_post(Sysno::exit, SOME_RIP, tid(5)),
];
let mut replayer = create_replayer(schedule.clone());
let mut replayer = Replayer::new(schedule.clone());
assert_eq!(
replayer.observe_event(&schedule[0]),
ReplayAction::Continue(Some(LogicalTime::from_rcbs(123)))
Expand All @@ -618,7 +617,7 @@ mod tests {
b.other(SOME_RIP, tid(5)),
b.syscall_pre(Sysno::exit, SOME_RIP, tid(3)),
];
let mut replayer = create_replayer(schedule.clone());
let mut replayer = Replayer::new(schedule.clone());
assert_eq!(
replayer.observe_event(&schedule[0]),
ReplayAction::ContextSwitch(true, tid(3), None)
Expand All @@ -632,7 +631,7 @@ mod tests {
b.other(SOME_RIP, tid(5)),
b.syscall_post(Sysno::exit, SOME_RIP, tid(3)),
];
let mut replayer = create_replayer(schedule.clone());
let mut replayer = Replayer::new(schedule.clone());
assert_eq!(
replayer.observe_event(&schedule[0]),
ReplayAction::ContextSwitch(true, tid(3), None)
Expand All @@ -653,7 +652,7 @@ mod tests {
b.branch(123, tid(3)),
b.syscall_pre(Sysno::exit, SOME_RIP, tid(3)),
]);
let mut replayer = create_replayer(expected);
let mut replayer = Replayer::new(expected);
let action1 = replayer.observe_event(&observed[0]);
{
let counts = replayer.desync_counts.get(&tid(3)).unwrap();
Expand Down

0 comments on commit 75dbeae

Please sign in to comment.