MCPcopy Create free account
hub / github.com/aws/clock-bound / test_reader_new

Function test_reader_new

clock-bound/src/vmclock/shm_reader.rs:402–451  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

400 let vmclock_shm_tempfile = NamedTempFile::new().expect("create vmclock file failed");
401 let vmclock_shm_temppath = vmclock_shm_tempfile.into_temp_path();
402 let vmclock_shm_path = vmclock_shm_temppath.to_str().unwrap();
403 let mut vmclock_shm_file = OpenOptions::new()
404 .write(true)
405 .open(vmclock_shm_path)
406 .expect("open vmclock file failed");
407 let vmclock_content = VMClockContent {
408 magic: 0x4B4C4356,
409 size: 104_u32,
410 version: 1_u16,
411 counter_id: 1_u8,
412 time_type: 0_u8,
413 seq_count: 10_u32,
414 disruption_marker: 888888_u64,
415 flags: 0_u64,
416 _padding: [0x00, 0x00],
417 clock_status: VMClockClockStatus::Synchronized,
418 leap_second_smearing_hint: 0_u8,
419 tai_offset_sec: 0_i16,
420 leap_indicator: 0_u8,
421 counter_period_shift: 0_u8,
422 counter_value: 123456_u64,
423 counter_period_frac_sec: 0_u64,
424 counter_period_esterror_rate_frac_sec: 0_u64,
425 counter_period_maxerror_rate_frac_sec: 0_u64,
426 time_sec: 0_u64,
427 time_frac_sec: 0_u64,
428 time_esterror_nanosec: 0_u64,
429 time_maxerror_nanosec: 0_u64,
430 };
431 write_vmclock_content(&mut vmclock_shm_file, &vmclock_content);
432
433 let reader =
434 VMClockShmReader::new(&vmclock_shm_path).expect("Failed to create VMClockShmReader");
435
436 let version = unsafe { &*reader.version_ptr };
437 let seq_count = unsafe { &*reader.seq_count_ptr };
438 let vmclock_shm_body = unsafe { *reader.vmclock_shm_body_ptr };
439
440 assert_eq!(version.load(atomic::Ordering::Relaxed), 1_u16);
441 assert_eq!(seq_count.load(atomic::Ordering::Relaxed), 10_u32);
442 assert_eq!(vmclock_shm_body.counter_value, 123456_u64);
443 assert_eq!(
444 vmclock_shm_body.clock_status,
445 VMClockClockStatus::Synchronized
446 );
447 assert_eq!(vmclock_shm_body.disruption_marker, 888888_u64);
448 }
449
450 /// Assert that the reader will return an error when it tries to open a file that does not exist.
451 #[test]
452 fn test_reader_file_does_not_exist() {
453 let vmclock_shm_tempfile = NamedTempFile::new().expect("create vmclock file failed");
454 let vmclock_shm_temppath = vmclock_shm_tempfile.into_temp_path();

Callers

nothing calls this directly

Calls 3

write_vmclock_contentFunction · 0.70
newFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected