This commit is contained in:
Alwin Berger 2022-12-12 15:16:45 +01:00
parent f7ee38ebb2
commit 6ad55e3b29

View File

@ -155,17 +155,19 @@ impl Default for QemuClockObserver {
//========== Feedback //========== Feedback
/// Nop feedback that annotates execution time in the new testcase, if any /// Nop feedback that annotates execution time in the new testcase, if any
/// for this Feedback, the testcase is never interesting (use with an OR) /// for this Feedback, the testcase is never interesting (use with an OR).
/// It decides, if the given [`QemuClockObserver`] value of a run is interesting.
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ClockFeedback { pub struct ClockTimeFeedback {
exec_time: Option<u64>, exec_time: Option<Duration>,
name: String, name: String,
} }
impl<S> Feedback<S> for ClockFeedback impl<S> Feedback<S> for ClockTimeFeedback
where where
S: UsesInput + HasClientPerfMonitor, S: UsesInput + HasClientPerfMonitor,
{ {
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>( fn is_interesting<EM, OT>(
&mut self, &mut self,
_state: &mut S, _state: &mut S,
@ -180,17 +182,18 @@ where
{ {
// TODO Replace with match_name_type when stable // TODO Replace with match_name_type when stable
let observer = observers.match_name::<QemuClockObserver>(self.name()).unwrap(); let observer = observers.match_name::<QemuClockObserver>(self.name()).unwrap();
self.exec_time = Some(observer.last_runtime()); self.exec_time = Some(Duration::from_nanos(observer.last_runtime() << 3)); // Assume a somewhat realistic multiplier of clock, it does not matter
Ok(false) Ok(false)
} }
/// Append to the testcase the generated metadata in case of a new corpus item /// Append to the testcase the generated metadata in case of a new corpus item
#[inline] #[inline]
fn append_metadata(&mut self, _state: &mut S, testcase: &mut Testcase<S::Input>) -> Result<(), Error> { fn append_metadata(
*testcase.exec_time_mut() = match self.exec_time { &mut self,
Some(s) => Some(Duration::from_nanos(s << 3)), //emulated time is << 3, real time more like * 360 _state: &mut S,
None => None, testcase: &mut Testcase<S::Input>,
}; ) -> Result<(), Error> {
*testcase.exec_time_mut() = self.exec_time;
self.exec_time = None; self.exec_time = None;
Ok(()) Ok(())
} }
@ -203,15 +206,15 @@ where
} }
} }
impl Named for ClockFeedback { impl Named for ClockTimeFeedback {
#[inline] #[inline]
fn name(&self) -> &str { fn name(&self) -> &str {
self.name.as_str() self.name.as_str()
} }
} }
impl ClockFeedback { impl ClockTimeFeedback {
/// Creates a new [`ClockFeedback`], deciding if the value of a [`TimeObserver`] with the given `name` of a run is interesting. /// Creates a new [`ClockFeedback`], deciding if the value of a [`QemuClockObserver`] with the given `name` of a run is interesting.
#[must_use] #[must_use]
pub fn new(name: &'static str) -> Self { pub fn new(name: &'static str) -> Self {
Self { Self {
@ -220,7 +223,7 @@ impl ClockFeedback {
} }
} }
/// Creates a new [`ClockFeedback`], deciding if the given [`TimeObserver`] value of a run is interesting. /// Creates a new [`ClockFeedback`], deciding if the given [`QemuClockObserver`] value of a run is interesting.
#[must_use] #[must_use]
pub fn new_with_observer(observer: &QemuClockObserver) -> Self { pub fn new_with_observer(observer: &QemuClockObserver) -> Self {
Self { Self {