Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- "*"
cargo:
patterns: ["*"]
50 changes: 36 additions & 14 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Build stm32
working-directory: statime-stm32
run: cargo build

# Build std is handled by test job

test:
Expand Down Expand Up @@ -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
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ authors = [
"Folkert de Vries <[email protected]>",
"Dion Dokter <[email protected]>",
"Ruben Nijveld <[email protected]>",
"David Venhoek <[email protected]>",
"Bram Bruines <[email protected]>",
"Marlon Peeters <[email protected]>",
"Rick van der Wal <[email protected]>"
]
rust-version = "1.67" # MSRV
rust-version = "1.69" # MSRV

[workspace.dependencies]
arrayvec = { version = "0.7.4", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion statime-linux/src/tlvforwarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl TlvForwarder {
}

impl ForwardedTLVProvider for TlvForwarder {
fn next_if_smaller(&mut self, max_size: usize) -> Option<statime::port::ForwardedTLV> {
fn next_if_smaller(&mut self, max_size: usize) -> Option<statime::port::ForwardedTLV<'_>> {
use tokio::sync::broadcast::error::TryRecvError;

while self.peek.is_none() {
Expand Down
10 changes: 4 additions & 6 deletions statime/src/bmc/bmca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ pub(crate) enum RecommendedState {
}

#[cfg(test)]

mod tests {
use super::*;
use crate::{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions statime/src/port/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ 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<ForwardedTLV>;
fn next_if_smaller(&mut self, max_size: usize) -> Option<ForwardedTLV<'_>>;
}

/// Simple implementation when
#[derive(Debug, Copy, Clone)]
pub struct NoForwardedTLVs;

impl ForwardedTLVProvider for NoForwardedTLVs {
fn next_if_smaller(&mut self, _max_size: usize) -> Option<ForwardedTLV> {
fn next_if_smaller(&mut self, _max_size: usize) -> Option<ForwardedTLV<'_>> {
None
}
}
Expand Down
18 changes: 10 additions & 8 deletions statime/src/port/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
};

impl<A, C, F: Filter, R, S: PtpInstanceStateMutex> 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");

Expand Down Expand Up @@ -54,7 +54,11 @@ impl<A, C, F: Filter, R, S: PtpInstanceStateMutex> 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
Expand Down Expand Up @@ -91,7 +95,7 @@ impl<A, C, F: Filter, R, S: PtpInstanceStateMutex> 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");

Expand Down Expand Up @@ -189,7 +193,7 @@ impl<A, C, F: Filter, R, S: PtpInstanceStateMutex> 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(
Expand Down Expand Up @@ -221,7 +225,7 @@ impl<A, C, F: Filter, R, S: PtpInstanceStateMutex> 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(
Expand Down Expand Up @@ -258,7 +262,7 @@ impl<A, C, F: Filter, R, S: PtpInstanceStateMutex> 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,
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down
9 changes: 4 additions & 5 deletions statime/src/port/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
})
}
}
20 changes: 10 additions & 10 deletions statime/src/port/slave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<A, C: Clock, F: Filter, R, S> 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 {
Expand Down Expand Up @@ -68,7 +68,7 @@ impl<A, C: Clock, F: Filter, R, S> Port<'_, Running, A, R, C, F, S> {
&mut self,
timestamp_id: u16,
timestamp: Time,
) -> PortActionIterator {
) -> PortActionIterator<'_> {
match self.peer_delay_state {
PeerDelayState::Measuring {
id,
Expand Down Expand Up @@ -98,7 +98,7 @@ impl<A, C: Clock, F: Filter, R, S> 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);
Expand Down Expand Up @@ -164,7 +164,7 @@ impl<A, C: Clock, F: Filter, R, S> 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);
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<A, C: Clock, F: Filter, R, S> 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");
Expand Down Expand Up @@ -258,7 +258,7 @@ impl<A, C: Clock, F: Filter, R, S> 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![];
}
Expand Down Expand Up @@ -321,7 +321,7 @@ impl<A, C: Clock, F: Filter, R, S> 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![];
}
Expand Down Expand Up @@ -457,7 +457,7 @@ impl<A, C: Clock, F: Filter, R, S> Port<'_, Running, A, R, C, F, S> {
}

impl<A, C: Clock, F: Filter, R: Rng, S: PtpInstanceStateMutex> 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),
Expand All @@ -467,7 +467,7 @@ impl<A, C: Clock, F: Filter, R: Rng, S: PtpInstanceStateMutex> 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| {
Expand Down Expand Up @@ -516,7 +516,7 @@ impl<A, C: Clock, F: Filter, R: Rng, S: PtpInstanceStateMutex> 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");
Expand Down
Loading