From bc2c128e4833e48ce59165e28494f11cd73b7256 Mon Sep 17 00:00:00 2001 From: ColeVick Date: Fri, 23 Aug 2024 10:35:51 -0700 Subject: [PATCH] add automatically generated bolero harnesses --- Cargo.toml | 7 + src/duration/mod.rs | 363 +++++++++++ src/efmt/formatter.rs | 52 ++ src/epoch/gregorian.rs | 53 ++ src/epoch/leap_seconds.rs | 25 + src/epoch/mod.rs | 1294 +++++++++++++++++++++++++++++++++++++ src/epoch/system_time.rs | 14 + src/errors.rs | 2 + src/month.rs | 24 + src/parser.rs | 50 ++ src/timescale/mod.rs | 78 +++ src/timeseries.rs | 62 ++ src/timeunits.rs | 87 +++ src/weekday.rs | 96 +++ 14 files changed, 2207 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 138b578..f4cc6f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ ut1 = ["std", "reqwest", "tabled", "openssl"] serde_json = "1.0.91" criterion = "0.5.1" iai = "0.1" +bolero = "0.11.1" [target.wasm32-unknown-unknown.dependencies] js-sys = { version = "0.3" } @@ -90,3 +91,9 @@ harness = false [[bench]] name = "iai_epoch" harness = false + +[profile.fuzz] +inherits="dev" +opt-level=3 +incremental=false +codegen-units=1 diff --git a/src/duration/mod.rs b/src/duration/mod.rs index 584ccbf..634a26a 100644 --- a/src/duration/mod.rs +++ b/src/duration/mod.rs @@ -67,6 +67,7 @@ pub mod ops; #[repr(C)] #[cfg_attr(feature = "python", pyclass)] #[cfg_attr(feature = "python", pyo3(module = "hifitime"))] +#[cfg_attr(test, derive(bolero::TypeGenerator))] pub struct Duration { pub(crate) centuries: i16, pub(crate) nanoseconds: u64, @@ -828,3 +829,365 @@ mod ut_duration { assert_eq!(nanoseconds, 0); } } +/// The following harnesses were automatically generated by an +/// experimental tool developed by the Kani team. +#[cfg(test)] +mod bolero_harnesses { + use super::*; + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_159_eq() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(callee, other): (Duration, Duration)| Some(callee.eq(&other))); + } + + /* + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_160_hash() { + bolero::check!().with_type().cloned().for_each(|(callee, hasher): (Duration , H/#0)| Some(callee.hash(&hasher))); + } + + + */ + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_161_default() { + bolero::check!() + .with_type() + .cloned() + .for_each(|()| Some(Duration::default())); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_162_from_parts() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(centuries, nanoseconds): (i16, u64)| { + Some(Duration::from_parts(centuries, nanoseconds)) + }); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_163_from_total_nanoseconds() { + bolero::check!() + .with_type() + .cloned() + .for_each(|nanos: i128| Some(Duration::from_total_nanoseconds(nanos))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_164_from_truncated_nanoseconds() { + bolero::check!() + .with_type() + .cloned() + .for_each(|nanos: i64| Some(Duration::from_truncated_nanoseconds(nanos))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_165_from_days() { + bolero::check!() + .with_type() + .cloned() + .for_each(|value: f64| Some(Duration::from_days(value))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_166_from_hours() { + bolero::check!() + .with_type() + .cloned() + .for_each(|value: f64| Some(Duration::from_hours(value))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_167_from_seconds() { + bolero::check!() + .with_type() + .cloned() + .for_each(|value: f64| Some(Duration::from_seconds(value))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_168_from_milliseconds() { + bolero::check!() + .with_type() + .cloned() + .for_each(|value: f64| Some(Duration::from_milliseconds(value))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_169_from_microseconds() { + bolero::check!() + .with_type() + .cloned() + .for_each(|value: f64| Some(Duration::from_microseconds(value))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_170_from_nanoseconds() { + bolero::check!() + .with_type() + .cloned() + .for_each(|value: f64| Some(Duration::from_nanoseconds(value))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_171_compose() { + bolero::check!().with_type().cloned().for_each( + |(sign, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds): ( + i8, + u64, + u64, + u64, + u64, + u64, + u64, + u64, + )| { + Some(Duration::compose( + sign, + days, + hours, + minutes, + seconds, + milliseconds, + microseconds, + nanoseconds, + )) + }, + ); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_172_compose_f64() { + bolero::check!().with_type().cloned().for_each( + |(sign, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds): ( + i8, + f64, + f64, + f64, + f64, + f64, + f64, + f64, + )| { + Some(Duration::compose_f64( + sign, + days, + hours, + minutes, + seconds, + milliseconds, + microseconds, + nanoseconds, + )) + }, + ); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_173_from_tz_offset() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(sign, hours, minutes): (i8, i64, i64)| { + Some(Duration::from_tz_offset(sign, hours, minutes)) + }); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_174_normalize() { + bolero::check!() + .with_type() + .cloned() + .for_each(|mut callee: Duration| Some(callee.normalize())); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_175_to_parts() { + bolero::check!() + .with_type() + .cloned() + .for_each(|callee: Duration| Some(callee.to_parts())); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_176_total_nanoseconds() { + bolero::check!() + .with_type() + .cloned() + .for_each(|callee: Duration| Some(callee.total_nanoseconds())); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_177_try_truncated_nanoseconds() { + bolero::check!() + .with_type() + .cloned() + .for_each(|callee: Duration| Some(callee.try_truncated_nanoseconds())); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_178_truncated_nanoseconds() { + bolero::check!() + .with_type() + .cloned() + .for_each(|callee: Duration| Some(callee.truncated_nanoseconds())); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_179_to_seconds() { + bolero::check!() + .with_type() + .cloned() + .for_each(|callee: Duration| Some(callee.to_seconds())); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_180_to_unit() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(callee, unit): (Duration, Unit)| Some(callee.to_unit(unit))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_181_abs() { + bolero::check!() + .with_type() + .cloned() + .for_each(|callee: Duration| Some(callee.abs())); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_182_signum() { + bolero::check!() + .with_type() + .cloned() + .for_each(|callee: Duration| Some(callee.signum())); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_183_decompose() { + bolero::check!() + .with_type() + .cloned() + .for_each(|callee: Duration| Some(callee.decompose())); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_184_subdivision() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(callee, unit): (Duration, Unit)| Some(callee.subdivision(unit))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_185_floor() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(callee, duration): (Duration, Duration)| Some(callee.floor(duration))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_186_ceil() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(callee, duration): (Duration, Duration)| Some(callee.ceil(duration))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_187_round() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(callee, duration): (Duration, Duration)| Some(callee.round(duration))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_188_approx() { + bolero::check!() + .with_type() + .cloned() + .for_each(|callee: Duration| Some(callee.approx())); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_189_min() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(callee, other): (Duration, Duration)| Some(callee.min(other))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_190_max() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(callee, other): (Duration, Duration)| Some(callee.max(other))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_191_is_negative() { + bolero::check!() + .with_type() + .cloned() + .for_each(|callee: Duration| Some(callee.is_negative())); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_192_eq() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(callee, unit): (Duration, Unit)| Some(callee.eq(&unit))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_193_partial_cmp() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(callee, unit): (Duration, Unit)| Some(callee.partial_cmp(&unit))); + } +} diff --git a/src/efmt/formatter.rs b/src/efmt/formatter.rs index 26df41a..e3efb90 100644 --- a/src/efmt/formatter.rs +++ b/src/efmt/formatter.rs @@ -19,6 +19,7 @@ use super::format::Format; use num_traits::Float; #[derive(Copy, Clone, Default, Debug, PartialEq)] +#[cfg_attr(test, derive(bolero::TypeGenerator))] pub(crate) struct Item { pub(crate) token: Token, pub(crate) sep_char: Option, @@ -302,3 +303,54 @@ impl fmt::Display for Formatter { Ok(()) } } +/// The following harnesses were automatically generated by an +/// experimental tool developed by the Kani team. +#[cfg(test)] +mod bolero_harnesses { + use super::*; + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_9_new() { + bolero::check!().with_type().cloned().for_each( + |(token, sep_char, second_sep_char): (Token, Option, Option)| { + Some(Item::new(token, sep_char, second_sep_char)) + }, + ); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_10_sep_char_is() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(callee, c_in): (Item, char)| Some(callee.sep_char_is(c_in))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_11_sep_char_is_not() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(callee, c_in): (Item, char)| Some(callee.sep_char_is_not(c_in))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_12_second_sep_char_is() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(callee, c_in): (Item, char)| Some(callee.second_sep_char_is(c_in))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_13_second_sep_char_is_not() { + bolero::check!() + .with_type() + .cloned() + .for_each(|(callee, c_in): (Item, char)| Some(callee.second_sep_char_is_not(c_in))); + } +} diff --git a/src/epoch/gregorian.rs b/src/epoch/gregorian.rs index 8fffb9d..4ed635d 100644 --- a/src/epoch/gregorian.rs +++ b/src/epoch/gregorian.rs @@ -795,3 +795,56 @@ mod ut_gregorian { } } } +/// The following harnesses were automatically generated by an +/// experimental tool developed by the Kani team. +#[cfg(test)] +mod bolero_harnesses { + use super::*; + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_0_is_gregorian_valid() { + bolero::check!().with_type().cloned().for_each( + |(year, month, day, hour, minute, second, nanos): (i32, u8, u8, u8, u8, u8, u32)| { + Some(is_gregorian_valid( + year, month, day, hour, minute, second, nanos, + )) + }, + ); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_1_january_years() { + bolero::check!() + .with_type() + .cloned() + .for_each(|year: i32| Some(january_years(year))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_2_july_years() { + bolero::check!() + .with_type() + .cloned() + .for_each(|year: i32| Some(july_years(year))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_3_usual_days_per_month() { + bolero::check!() + .with_type() + .cloned() + .for_each(|month: u8| Some(usual_days_per_month(month))); + } + + #[test] + #[cfg_attr(kani, kani::proof)] + fn bolero_test_4_is_leap_year() { + bolero::check!() + .with_type() + .cloned() + .for_each(|year: i32| Some(is_leap_year(year))); + } +} diff --git a/src/epoch/leap_seconds.rs b/src/epoch/leap_seconds.rs index 94ba9bf..7038a40 100644 --- a/src/epoch/leap_seconds.rs +++ b/src/epoch/leap_seconds.rs @@ -22,6 +22,7 @@ pub trait LeapSecondProvider: DoubleEndedIterator + Index