add with_timeout constructor for Observer
This commit is contained in:
parent
ae9486814e
commit
ff759e2ca7
@ -71,11 +71,7 @@ where
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn run_target(&mut self, input: &I) -> Result<ExitKind, Error> {
|
fn run_target(&mut self, input: &I) -> Result<ExitKind, Error> {
|
||||||
let bytes = input.target_bytes();
|
let bytes = input.target_bytes();
|
||||||
|
|
||||||
|
|
||||||
let ret = (self.harness_fn)(self, bytes.as_slice());
|
let ret = (self.harness_fn)(self, bytes.as_slice());
|
||||||
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
unsafe {
|
unsafe {
|
||||||
write_volatile(
|
write_volatile(
|
||||||
|
@ -128,6 +128,15 @@ impl TimeObserver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_timeout(name: &'static str, tmout: u64) -> Self {
|
||||||
|
Self {
|
||||||
|
name: name.to_string(),
|
||||||
|
start_time: Duration::from_secs(0),
|
||||||
|
last_runtime: None,
|
||||||
|
exec_tmout: Some(Duration::from_secs(tmout)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn last_runtime(&self) -> &Option<Duration> {
|
pub fn last_runtime(&self) -> &Option<Duration> {
|
||||||
&self.last_runtime
|
&self.last_runtime
|
||||||
}
|
}
|
||||||
@ -135,22 +144,21 @@ impl TimeObserver {
|
|||||||
|
|
||||||
impl Observer for TimeObserver {
|
impl Observer for TimeObserver {
|
||||||
fn pre_exec(&mut self) -> Result<(), Error> {
|
fn pre_exec(&mut self) -> Result<(), Error> {
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
match self.exec_tmout {
|
match self.exec_tmout {
|
||||||
Some(exec_tmout) => unsafe {
|
Some(exec_tmout) => unsafe {
|
||||||
let milli_sec = exec_tmout.as_millis() as i64;
|
let milli_sec = exec_tmout.as_millis() as i64;
|
||||||
let it_value = Timeval{
|
let it_value = Timeval {
|
||||||
tv_sec: milli_sec / 1000,
|
tv_sec: milli_sec / 1000,
|
||||||
tv_usec: milli_sec % 1000,
|
tv_usec: milli_sec % 1000,
|
||||||
};
|
};
|
||||||
let it_interval = Timeval{
|
let it_interval = Timeval {
|
||||||
tv_sec: 0,
|
tv_sec: 0,
|
||||||
tv_usec: 0,
|
tv_usec: 0,
|
||||||
};
|
};
|
||||||
setitimer(
|
setitimer(
|
||||||
ITIMER_REAL,
|
ITIMER_REAL,
|
||||||
&mut Itimerval{
|
&mut Itimerval {
|
||||||
it_interval,
|
it_interval,
|
||||||
it_value,
|
it_value,
|
||||||
},
|
},
|
||||||
@ -171,17 +179,17 @@ impl Observer for TimeObserver {
|
|||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
match self.exec_tmout {
|
match self.exec_tmout {
|
||||||
Some(_) => unsafe {
|
Some(_) => unsafe {
|
||||||
let it_value = Timeval{
|
let it_value = Timeval {
|
||||||
tv_sec: 0,
|
tv_sec: 0,
|
||||||
tv_usec: 0,
|
tv_usec: 0,
|
||||||
};
|
};
|
||||||
let it_interval = Timeval{
|
let it_interval = Timeval {
|
||||||
tv_sec: 0,
|
tv_sec: 0,
|
||||||
tv_usec: 0,
|
tv_usec: 0,
|
||||||
};
|
};
|
||||||
setitimer(
|
setitimer(
|
||||||
ITIMER_REAL,
|
ITIMER_REAL,
|
||||||
&mut Itimerval{
|
&mut Itimerval {
|
||||||
it_interval,
|
it_interval,
|
||||||
it_value,
|
it_value,
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user