Merge pull request 'Fixes for Miri' (#95) from fixes-for-miri into main
All checks were successful
Rust/spacepackets/pipeline/head This commit looks good
All checks were successful
Rust/spacepackets/pipeline/head This commit looks good
Reviewed-on: #95
This commit is contained in:
commit
b8be9ae641
10
README.md
10
README.md
@ -61,3 +61,13 @@ cargo install grcov --locked
|
|||||||
|
|
||||||
After that, you can simply run `coverage.py` to test the project with coverage. You can optionally
|
After that, you can simply run `coverage.py` to test the project with coverage. You can optionally
|
||||||
supply the `--open` flag to open the coverage report in your webbrowser.
|
supply the `--open` flag to open the coverage report in your webbrowser.
|
||||||
|
|
||||||
|
# Miri
|
||||||
|
|
||||||
|
You can run the [`miri`](https://github.com/rust-lang/miri) tool on this library to check for
|
||||||
|
undefined behaviour (UB). This library does not use use any `unsafe` code blocks, but `miri` could
|
||||||
|
still catch UB from used libraries.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo +nightly miri nextest run --all-features
|
||||||
|
```
|
||||||
|
@ -71,7 +71,19 @@ mod tests {
|
|||||||
use std::format;
|
use std::format;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ascii_timestamp_a_unterminated() {
|
fn test_ascii_timestamp_a_unterminated_epoch() {
|
||||||
|
let date = chrono::DateTime::UNIX_EPOCH;
|
||||||
|
let stamp_formatter = generate_time_code_a(&date);
|
||||||
|
let stamp = format!("{}", stamp_formatter);
|
||||||
|
let t_sep = stamp.find('T');
|
||||||
|
assert!(t_sep.is_some());
|
||||||
|
assert_eq!(t_sep.unwrap(), 10);
|
||||||
|
assert_eq!(stamp.len(), FMT_STR_CODE_A_WITH_SIZE.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
|
fn test_ascii_timestamp_a_unterminated_now() {
|
||||||
let date = Utc::now();
|
let date = Utc::now();
|
||||||
let stamp_formatter = generate_time_code_a(&date);
|
let stamp_formatter = generate_time_code_a(&date);
|
||||||
let stamp = format!("{}", stamp_formatter);
|
let stamp = format!("{}", stamp_formatter);
|
||||||
@ -82,7 +94,24 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ascii_timestamp_a_terminated() {
|
fn test_ascii_timestamp_a_terminated_epoch() {
|
||||||
|
let date = chrono::DateTime::UNIX_EPOCH;
|
||||||
|
let stamp_formatter = generate_time_code_a_terminated(&date);
|
||||||
|
let stamp = format!("{}", stamp_formatter);
|
||||||
|
let t_sep = stamp.find('T');
|
||||||
|
assert!(t_sep.is_some());
|
||||||
|
assert_eq!(t_sep.unwrap(), 10);
|
||||||
|
let z_terminator = stamp.find('Z');
|
||||||
|
assert!(z_terminator.is_some());
|
||||||
|
assert_eq!(
|
||||||
|
z_terminator.unwrap(),
|
||||||
|
FMT_STR_CODE_A_TERMINATED_WITH_SIZE.1 - 1
|
||||||
|
);
|
||||||
|
assert_eq!(stamp.len(), FMT_STR_CODE_A_TERMINATED_WITH_SIZE.1);
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
|
fn test_ascii_timestamp_a_terminated_now() {
|
||||||
let date = Utc::now();
|
let date = Utc::now();
|
||||||
let stamp_formatter = generate_time_code_a_terminated(&date);
|
let stamp_formatter = generate_time_code_a_terminated(&date);
|
||||||
let stamp = format!("{}", stamp_formatter);
|
let stamp = format!("{}", stamp_formatter);
|
||||||
@ -99,7 +128,19 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ascii_timestamp_b_unterminated() {
|
fn test_ascii_timestamp_b_unterminated_epoch() {
|
||||||
|
let date = chrono::DateTime::UNIX_EPOCH;
|
||||||
|
let stamp_formatter = generate_time_code_b(&date);
|
||||||
|
let stamp = format!("{}", stamp_formatter);
|
||||||
|
let t_sep = stamp.find('T');
|
||||||
|
assert!(t_sep.is_some());
|
||||||
|
assert_eq!(t_sep.unwrap(), 8);
|
||||||
|
assert_eq!(stamp.len(), FMT_STR_CODE_B_WITH_SIZE.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
|
fn test_ascii_timestamp_b_unterminated_now() {
|
||||||
let date = Utc::now();
|
let date = Utc::now();
|
||||||
let stamp_formatter = generate_time_code_b(&date);
|
let stamp_formatter = generate_time_code_b(&date);
|
||||||
let stamp = format!("{}", stamp_formatter);
|
let stamp = format!("{}", stamp_formatter);
|
||||||
@ -110,7 +151,25 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ascii_timestamp_b_terminated() {
|
fn test_ascii_timestamp_b_terminated_epoch() {
|
||||||
|
let date = chrono::DateTime::UNIX_EPOCH;
|
||||||
|
let stamp_formatter = generate_time_code_b_terminated(&date);
|
||||||
|
let stamp = format!("{}", stamp_formatter);
|
||||||
|
let t_sep = stamp.find('T');
|
||||||
|
assert!(t_sep.is_some());
|
||||||
|
assert_eq!(t_sep.unwrap(), 8);
|
||||||
|
let z_terminator = stamp.find('Z');
|
||||||
|
assert!(z_terminator.is_some());
|
||||||
|
assert_eq!(
|
||||||
|
z_terminator.unwrap(),
|
||||||
|
FMT_STR_CODE_B_TERMINATED_WITH_SIZE.1 - 1
|
||||||
|
);
|
||||||
|
assert_eq!(stamp.len(), FMT_STR_CODE_B_TERMINATED_WITH_SIZE.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
|
fn test_ascii_timestamp_b_terminated_now() {
|
||||||
let date = Utc::now();
|
let date = Utc::now();
|
||||||
let stamp_formatter = generate_time_code_b_terminated(&date);
|
let stamp_formatter = generate_time_code_b_terminated(&date);
|
||||||
let stamp = format!("{}", stamp_formatter);
|
let stamp = format!("{}", stamp_formatter);
|
||||||
|
@ -1622,6 +1622,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
fn test_time_now() {
|
fn test_time_now() {
|
||||||
let timestamp_now = CdsTime::now_with_u16_days().unwrap();
|
let timestamp_now = CdsTime::now_with_u16_days().unwrap();
|
||||||
let compare_stamp = chrono::Utc::now();
|
let compare_stamp = chrono::Utc::now();
|
||||||
@ -1629,6 +1630,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
fn test_time_now_us_prec() {
|
fn test_time_now_us_prec() {
|
||||||
let timestamp_now = CdsTime::now_with_u16_days_us_precision().unwrap();
|
let timestamp_now = CdsTime::now_with_u16_days_us_precision().unwrap();
|
||||||
let compare_stamp = chrono::Utc::now();
|
let compare_stamp = chrono::Utc::now();
|
||||||
@ -1636,6 +1638,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
fn test_time_now_ps_prec() {
|
fn test_time_now_ps_prec() {
|
||||||
let timestamp_now = CdsTime::from_now_with_u16_days_ps_precision().unwrap();
|
let timestamp_now = CdsTime::from_now_with_u16_days_ps_precision().unwrap();
|
||||||
let compare_stamp = chrono::Utc::now();
|
let compare_stamp = chrono::Utc::now();
|
||||||
@ -1643,6 +1646,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
fn test_time_now_ps_prec_u16_days() {
|
fn test_time_now_ps_prec_u16_days() {
|
||||||
let timestamp_now = CdsTime::from_now_with_u16_days_ps_precision().unwrap();
|
let timestamp_now = CdsTime::from_now_with_u16_days_ps_precision().unwrap();
|
||||||
let compare_stamp = chrono::Utc::now();
|
let compare_stamp = chrono::Utc::now();
|
||||||
@ -1650,6 +1654,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
fn test_time_now_ps_prec_u24_days() {
|
fn test_time_now_ps_prec_u24_days() {
|
||||||
let timestamp_now = CdsTime::now_with_u24_days_ps_precision().unwrap();
|
let timestamp_now = CdsTime::now_with_u24_days_ps_precision().unwrap();
|
||||||
let compare_stamp = chrono::Utc::now();
|
let compare_stamp = chrono::Utc::now();
|
||||||
@ -2306,6 +2311,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
fn test_update_from_now() {
|
fn test_update_from_now() {
|
||||||
let mut stamp = CdsTime::new_with_u16_days(0, 0);
|
let mut stamp = CdsTime::new_with_u16_days(0, 0);
|
||||||
let _ = stamp.update_from_now();
|
let _ = stamp.update_from_now();
|
||||||
@ -2321,6 +2327,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
fn test_serialization() {
|
fn test_serialization() {
|
||||||
let stamp_now = CdsTime::now_with_u16_days().expect("Error retrieving time");
|
let stamp_now = CdsTime::now_with_u16_days().expect("Error retrieving time");
|
||||||
let val = to_allocvec(&stamp_now).expect("Serializing timestamp failed");
|
let val = to_allocvec(&stamp_now).expect("Serializing timestamp failed");
|
||||||
|
@ -947,6 +947,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
fn test_datetime_now() {
|
fn test_datetime_now() {
|
||||||
let now = chrono::Utc::now();
|
let now = chrono::Utc::now();
|
||||||
let cuc_now = CucTime::now(FractionalResolution::SixtyNs, LEAP_SECONDS);
|
let cuc_now = CucTime::now(FractionalResolution::SixtyNs, LEAP_SECONDS);
|
||||||
@ -1278,6 +1279,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
fn set_fract_resolution() {
|
fn set_fract_resolution() {
|
||||||
let mut stamp = CucTime::new(2000);
|
let mut stamp = CucTime::new(2000);
|
||||||
stamp.set_fractional_resolution(FractionalResolution::SixtyNs);
|
stamp.set_fractional_resolution(FractionalResolution::SixtyNs);
|
||||||
|
@ -551,6 +551,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
fn test_get_current_time() {
|
fn test_get_current_time() {
|
||||||
let sec_floats = seconds_since_epoch();
|
let sec_floats = seconds_since_epoch();
|
||||||
assert!(sec_floats > 0.0);
|
assert!(sec_floats > 0.0);
|
||||||
@ -565,6 +566,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
fn test_ccsds_epoch() {
|
fn test_ccsds_epoch() {
|
||||||
let now = SystemTime::now()
|
let now = SystemTime::now()
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
@ -685,6 +687,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore)]
|
||||||
fn test_from_now() {
|
fn test_from_now() {
|
||||||
let stamp_now = UnixTime::now().unwrap();
|
let stamp_now = UnixTime::now().unwrap();
|
||||||
let dt_now = stamp_now.chrono_date_time().unwrap();
|
let dt_now = stamp_now.chrono_date_time().unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user