diff --git a/.github/dependabot.yml b/.github/dependabot.yml index eeb6e1e56..d98eb3e95 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,19 +5,18 @@ updates: schedule: interval: weekly open-pull-requests-limit: 10 + groups: + github-actions: + patterns: ["*"] - package-ecosystem: cargo - directory: "/" + directories: ["/", "/fuzz/", "/statime-stm32/"] + allow: + - dependency-type: all schedule: interval: daily versioning-strategy: lockfile-only open-pull-requests-limit: 10 - -- package-ecosystem: cargo - directory: "/statime-stm32/" - schedule: - interval: "monthly" groups: - stm32-example: - patterns: - - "*" \ No newline at end of file + cargo: + patterns: ["*"] diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index afce3cb75..16be9c8fb 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -38,7 +38,7 @@ jobs: - name: Build stm32 working-directory: statime-stm32 run: cargo build - + # Build std is handled by test job test: @@ -108,24 +108,46 @@ jobs: fuzz: name: Smoke-test fuzzing targets runs-on: ubuntu-latest + strategy: + matrix: + include: + - fuzz_target: message_sound + corpus: "" + features: '' steps: - name: Checkout sources - uses: actions/checkout@v4 + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 with: persist-credentials: false - - name: Install stable toolchain - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af + - name: Install nightly toolchain + uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 with: toolchain: nightly - override: true - default: true - - name: Install cargo fuzz - uses: taiki-e/install-action@70233fe3d27d863712ee34eede2087e36bde6b5e + components: llvm-tools-preview + - name: Install cargo fuzz & rustfilt + uses: taiki-e/install-action@d6912b47771be2c443ec90dbb3d28e023987e782 with: - tool: cargo-fuzz - - name: Smoke-test fuzz targets + tool: cargo-fuzz,rustfilt + - name: Run `cargo fuzz` + env: + RUST_BACKTRACE: "1" + # prevents `cargo fuzz coverage` from rebuilding everything + RUSTFLAGS: "-C instrument-coverage" + run: | + cargo fuzz run --target $(rustc --print host-tuple) ${{matrix.features}} ${{matrix.fuzz_target}} ${{matrix.corpus}} -- -max_total_time=10 + - name: Fuzz codecov run: | - cargo fuzz build - for target in $(cargo fuzz list) ; do - cargo fuzz run $target -- -max_total_time=10 - done + cargo fuzz coverage --target $(rustc --print host-tuple) ${{matrix.features}} ${{matrix.fuzz_target}} ${{matrix.corpus}} + $(rustc --print sysroot)/lib/rustlib/$(rustc --print host-tuple)/bin/llvm-cov export -Xdemangler=rustfilt \ + target/x86_64-unknown-linux-musl/coverage/$(rustc --print host-tuple)/release/${{matrix.fuzz_target}} \ + -instr-profile=fuzz/coverage/${{matrix.fuzz_target}}/coverage.profdata \ + --format=lcov \ + -ignore-filename-regex="\.cargo|\.rustup" > lcov.info + - name: Upload coverage to Codecov + uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 + with: + files: ./lcov.info + fail_ci_if_error: false + flags: fuzz, fuzz-${{ matrix.fuzz_target }} + token: ${{ secrets.CODECOV_TOKEN }} + name: fuzz diff --git a/Cargo.toml b/Cargo.toml index a2befd179..a7a531613 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,12 +20,11 @@ authors = [ "Folkert de Vries ", "Dion Dokter ", "Ruben Nijveld ", - "David Venhoek ", "Bram Bruines ", "Marlon Peeters ", "Rick van der Wal " ] -rust-version = "1.67" # MSRV +rust-version = "1.69" # MSRV [workspace.dependencies] arrayvec = { version = "0.7.4", default-features = false } diff --git a/README.md b/README.md index 6c7f521c4..6aa7a27ac 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ The `statime` library has been built in a way to try and be platform-agnostic. T ## Rust version -Statime requires Rust version 1.67 at minimum. The easiest way to install Rust is through [rustup](https://rustup.rs) +Statime requires Rust version 1.69 at minimum. The easiest way to install Rust is through [rustup](https://rustup.rs) ## Running from source diff --git a/statime-linux/src/tlvforwarder.rs b/statime-linux/src/tlvforwarder.rs index 5b2252a98..e7365e938 100644 --- a/statime-linux/src/tlvforwarder.rs +++ b/statime-linux/src/tlvforwarder.rs @@ -51,7 +51,7 @@ impl TlvForwarder { } impl ForwardedTLVProvider for TlvForwarder { - fn next_if_smaller(&mut self, max_size: usize) -> Option { + fn next_if_smaller(&mut self, max_size: usize) -> Option> { use tokio::sync::broadcast::error::TryRecvError; while self.peek.is_none() { diff --git a/statime/src/bmc/bmca.rs b/statime/src/bmc/bmca.rs index a402bf349..716b26f06 100644 --- a/statime/src/bmc/bmca.rs +++ b/statime/src/bmc/bmca.rs @@ -295,7 +295,6 @@ pub(crate) enum RecommendedState { } #[cfg(test)] - mod tests { use super::*; use crate::{ @@ -540,8 +539,10 @@ mod tests { let slave_only = false; let sdo_id = Default::default(); let path_trace = false; - let mut clock_quality = ClockQuality::default(); - clock_quality.clock_class = 1; + let clock_quality = ClockQuality { + clock_class: 1, + ..Default::default() + }; assert!((1..=127).contains(&clock_quality.clock_class)); let own_data = InternalDefaultDS::new(InstanceConfig { @@ -673,9 +674,6 @@ mod tests { ) ); - // D0 is NOT better than E_best - let mut own_data = own_data; - let mut global_message = default_best_announce_message(); own_data.clock_identity = ClockIdentity([0; 8]); diff --git a/statime/src/port/actions.rs b/statime/src/port/actions.rs index a9fae9b89..9557d0478 100644 --- a/statime/src/port/actions.rs +++ b/statime/src/port/actions.rs @@ -33,7 +33,7 @@ impl ForwardedTLV<'_> { /// Source of TLVs that need to be forwarded, provided to announce sender. pub trait ForwardedTLVProvider { /// Should provide the next available TLV, unless it is larger than max_size - fn next_if_smaller(&mut self, max_size: usize) -> Option; + fn next_if_smaller(&mut self, max_size: usize) -> Option>; } /// Simple implementation when @@ -41,7 +41,7 @@ pub trait ForwardedTLVProvider { pub struct NoForwardedTLVs; impl ForwardedTLVProvider for NoForwardedTLVs { - fn next_if_smaller(&mut self, _max_size: usize) -> Option { + fn next_if_smaller(&mut self, _max_size: usize) -> Option> { None } } diff --git a/statime/src/port/master.rs b/statime/src/port/master.rs index 31db818f3..100f0fa6c 100644 --- a/statime/src/port/master.rs +++ b/statime/src/port/master.rs @@ -13,7 +13,7 @@ use crate::{ }; impl Port<'_, Running, A, R, C, F, S> { - pub(super) fn send_sync(&mut self) -> PortActionIterator { + pub(super) fn send_sync(&mut self) -> PortActionIterator<'_> { if matches!(self.port_state, PortState::Master) { log::trace!("sending sync message"); @@ -54,7 +54,11 @@ impl Port<'_, Running, A, R, C, F, } } - pub(super) fn handle_sync_timestamp(&mut self, id: u16, timestamp: Time) -> PortActionIterator { + pub(super) fn handle_sync_timestamp( + &mut self, + id: u16, + timestamp: Time, + ) -> PortActionIterator<'_> { if matches!(self.port_state, PortState::Master) { let packet_length = match self .instance_state @@ -91,7 +95,7 @@ impl Port<'_, Running, A, R, C, F, pub(super) fn send_announce( &mut self, tlv_provider: &mut impl ForwardedTLVProvider, - ) -> PortActionIterator { + ) -> PortActionIterator<'_> { if matches!(self.port_state, PortState::Master) { log::trace!("sending announce message"); @@ -189,7 +193,7 @@ impl Port<'_, Running, A, R, C, F, header: Header, message: DelayReqMessage, timestamp: Time, - ) -> PortActionIterator { + ) -> PortActionIterator<'_> { if matches!(self.port_state, PortState::Master) { log::debug!("Received DelayReq"); let delay_resp_message = Message::delay_resp( @@ -221,7 +225,7 @@ impl Port<'_, Running, A, R, C, F, &mut self, header: Header, timestamp: Time, - ) -> PortActionIterator { + ) -> PortActionIterator<'_> { log::debug!("Received PDelayReq"); let pdelay_resp_message = self.instance_state.with_ref(|state| { Message::pdelay_resp( @@ -258,7 +262,7 @@ impl Port<'_, Running, A, R, C, F, id: u16, requestor_identity: PortIdentity, timestamp: Time, - ) -> PortActionIterator { + ) -> PortActionIterator<'_> { let pdelay_resp_follow_up_messgae = self.instance_state.with_ref(|state| { Message::pdelay_resp_follow_up( &state.default_ds, @@ -718,7 +722,6 @@ mod tests { response_body.request_receive_timestamp, Time::from_micros(500).into() ); - drop(response); assert!(actions.next().is_none()); drop(actions); @@ -740,7 +743,6 @@ mod tests { response_body.response_origin_timestamp, Time::from_micros(550).into() ); - drop(response); assert!(actions.next().is_none()); drop(actions); } diff --git a/statime/src/port/mod.rs b/statime/src/port/mod.rs index fcecd69a3..df901cfbc 100644 --- a/statime/src/port/mod.rs +++ b/statime/src/port/mod.rs @@ -414,7 +414,7 @@ impl<'a, A: AcceptableMasterList, C: Clock, F: Filter, R: Rng, S: PtpInstanceSta } /// Handle the filter update timer going off - pub fn handle_filter_update_timer(&mut self) -> PortActionIterator { + pub fn handle_filter_update_timer(&mut self) -> PortActionIterator<'_> { let update = self.filter.update(&mut self.clock); if update.mean_delay.is_some() { self.mean_delay = update.mean_delay; @@ -779,7 +779,7 @@ mod tests { port_identity: PortIdentity, ) -> Port<'_, Running, AcceptAnyMaster, rand::rngs::mock::StepRng, TestClock, BasicFilter> { let port = Port::<_, _, _, _, BasicFilter>::new( - &state, + state, PortConfig { acceptable_master_list: AcceptAnyMaster, delay_mechanism: DelayMechanism::E2E { @@ -844,13 +844,12 @@ mod tests { let parent_ds = InternalParentDS::new(default_ds); - let state = RefCell::new(PtpInstanceState { + RefCell::new(PtpInstanceState { default_ds, current_ds: Default::default(), parent_ds, time_properties_ds: Default::default(), path_trace_ds: PathTraceDS::new(false), - }); - state + }) } } diff --git a/statime/src/port/slave.rs b/statime/src/port/slave.rs index 1b4a6e789..01db6cab1 100644 --- a/statime/src/port/slave.rs +++ b/statime/src/port/slave.rs @@ -36,7 +36,7 @@ impl Port<'_, Running, A, R, C, F, S> { &mut self, timestamp_id: u16, timestamp: Time, - ) -> PortActionIterator { + ) -> PortActionIterator<'_> { match self.port_state { PortState::Slave(ref mut state) => match state.delay_state { DelayState::Measuring { @@ -68,7 +68,7 @@ impl Port<'_, Running, A, R, C, F, S> { &mut self, timestamp_id: u16, timestamp: Time, - ) -> PortActionIterator { + ) -> PortActionIterator<'_> { match self.peer_delay_state { PeerDelayState::Measuring { id, @@ -98,7 +98,7 @@ impl Port<'_, Running, A, R, C, F, S> { header: Header, message: SyncMessage, recv_time: Time, - ) -> PortActionIterator { + ) -> PortActionIterator<'_> { match self.port_state { PortState::Slave(ref mut state) => { log::debug!("Received sync {:?}", header.sequence_id); @@ -164,7 +164,7 @@ impl Port<'_, Running, A, R, C, F, S> { &mut self, header: Header, message: FollowUpMessage, - ) -> PortActionIterator { + ) -> PortActionIterator<'_> { match self.port_state { PortState::Slave(ref mut state) => { log::debug!("Received FollowUp {:?}", header.sequence_id); @@ -211,7 +211,7 @@ impl Port<'_, Running, A, R, C, F, S> { &mut self, header: Header, message: DelayRespMessage, - ) -> PortActionIterator { + ) -> PortActionIterator<'_> { match self.port_state { PortState::Slave(ref mut state) => { log::debug!("Received DelayResp"); @@ -258,7 +258,7 @@ impl Port<'_, Running, A, R, C, F, S> { header: Header, message: PDelayRespMessage, recv_time: Time, - ) -> PortActionIterator { + ) -> PortActionIterator<'_> { if self.port_identity != message.requesting_port_identity { return actions![]; } @@ -321,7 +321,7 @@ impl Port<'_, Running, A, R, C, F, S> { &mut self, header: Header, message: PDelayRespFollowUpMessage, - ) -> PortActionIterator { + ) -> PortActionIterator<'_> { if self.port_identity != message.requesting_port_identity { return actions![]; } @@ -457,7 +457,7 @@ impl Port<'_, Running, A, R, C, F, S> { } impl Port<'_, Running, A, R, C, F, S> { - pub(super) fn send_delay_request(&mut self) -> PortActionIterator { + pub(super) fn send_delay_request(&mut self) -> PortActionIterator<'_> { match self.config.delay_mechanism { DelayMechanism::E2E { interval } => self.send_e2e_delay_request(interval), DelayMechanism::P2P { interval } => self.send_p2p_delay_request(interval), @@ -467,7 +467,7 @@ impl Port<'_, Running, fn send_p2p_delay_request( &mut self, log_min_pdelay_req_interval: Interval, - ) -> PortActionIterator { + ) -> PortActionIterator<'_> { let pdelay_id = self.pdelay_seq_ids.generate(); let pdelay_req = self.instance_state.with_ref(|state| { @@ -516,7 +516,7 @@ impl Port<'_, Running, fn send_e2e_delay_request( &mut self, log_min_delay_req_interval: Interval, - ) -> PortActionIterator { + ) -> PortActionIterator<'_> { match self.port_state { PortState::Slave(ref mut state) => { log::debug!("Starting new delay measurement");