diff --git a/mdflib/src/mdfWriter.c b/mdflib/src/mdfWriter.c index 7ee2e3d..dbc5703 100644 --- a/mdflib/src/mdfWriter.c +++ b/mdflib/src/mdfWriter.c @@ -8,8 +8,8 @@ #define ftell (mdf_link_t) ftello #define fseek(f, o, m) fseeko(f, (off_t)o, m) #else -#define ftell (mdf_link_t) ftelli64 -#define fseek(f, o, m) fseeki64(f, (__int64)o, m) +#define ftell (mdf_link_t) _ftelli64 +#define fseek(f, o, m) _fseeki64(f, (__int64)o, m) #endif @@ -391,7 +391,7 @@ static void mdfAdjustBlockLinks(BLOCK_HEADER *b, BLOCK_HEADER *root, mdf_link_t static int mdfWriteBlock(FILE *f, BLOCK_HEADER *b, uint32_t len, int update) { - mdf_link_t pos = ftello(f); + mdf_link_t pos = ftell(f); printf("mdfWriteBlock %c%c at %" PRIu64 " len=%u\n", 0xFF & (b->id >> 16), 0xFF & (b->id >> 24), pos, len); if (update) mdfAdjustBlockLinks(b, b, pos, len); diff --git a/src/reg.rs b/src/reg.rs index 370882b..c6b33a4 100644 --- a/src/reg.rs +++ b/src/reg.rs @@ -28,8 +28,8 @@ mod registry_tests { reg.set_epk("TEST_EPK", 0x80000000); reg.set_tl_params("UDP", Ipv4Addr::new(127, 0, 0, 1), 5555); - reg.add_cal_seg("test_cal_seg_1", 0, 2); - reg.add_cal_seg("test_cal_seg_2", 1, 2); + reg.add_cal_seg("test_cal_seg_1", 0, 4); + reg.add_cal_seg("test_cal_seg_2", 1, 4); let event1_1 = crate::XcpEvent::new(0, 1); reg.add_event("event1", event1_1); @@ -148,11 +148,13 @@ mod registry_tests { #[type_description(min = "-128.0")] #[type_description(max = "127.0")] test_characteristic_2: i8, + test_characteristic_3: i16, } const CAL_PAGE: CalPage = CalPage { test_characteristic_1: 0, test_characteristic_2: 0, + test_characteristic_3: 0, }; #[test] diff --git a/src/xcp/cal/cal_seg.rs b/src/xcp/cal/cal_seg.rs index 156c5f6..4c36de3 100644 --- a/src/xcp/cal/cal_seg.rs +++ b/src/xcp/cal/cal_seg.rs @@ -558,14 +558,10 @@ unsafe impl Send for CalSeg where T: CalPageTrait {} mod cal_tests { #![allow(dead_code)] - - use std::sync::Arc; - use std::thread; - use std::time::{Duration, Instant}; - use super::*; use crate::xcp; - + use std::sync::Arc; + use std::thread; use xcp::*; use xcp_type_description::prelude::*; @@ -716,36 +712,36 @@ mod cal_tests { // drop(cal_page_test2); //} - #[test] - fn test_calibration_segment_performance() { - let xcp = xcp_test::test_setup(log::LevelFilter::Info); - - const CAL_PAGE: CalPage0 = CalPage0 { stop: 0 }; - - let mut cal_seg1 = xcp.create_calseg("calseg1", &CAL_PAGE); - - // Create 10 tasks with 10 clones of cal_seg1 - let mut t = Vec::new(); - let loop_count = Arc::new(parking_lot::Mutex::new(Vec::with_capacity(10))); - let start = Instant::now(); - for i in 0..10 { - let c = CalSeg::clone(&cal_seg1); - trace!("task {} clone = {}", i, cal_seg1.get_clone_count()); - let l = loop_count.clone(); - t.push(thread::spawn(move || { - let n = task_calseg(c); - l.lock().push(n); - })); - } - thread::sleep(Duration::from_millis(1000)); - cal_seg1.stop = 1; // deref_mut - t.into_iter().for_each(|t| t.join().unwrap()); + // #[test] + // fn test_calibration_segment_performance() { + // let xcp = xcp_test::test_setup(log::LevelFilter::Info); - let duration = start.elapsed().as_micros(); - info!("Duration: {}us", duration); - let tot_loop_count: u32 = loop_count.lock().iter().sum(); - info!("Loop counts: tot = {}, {:.3}us per loop", tot_loop_count, duration as f64 / tot_loop_count as f64); - } + // const CAL_PAGE: CalPage0 = CalPage0 { stop: 0 }; + + // let mut cal_seg1 = xcp.create_calseg("calseg1", &CAL_PAGE); + + // // Create 10 tasks with 10 clones of cal_seg1 + // let mut t = Vec::new(); + // let loop_count = Arc::new(parking_lot::Mutex::new(Vec::with_capacity(10))); + // let start = Instant::now(); + // for i in 0..10 { + // let c = CalSeg::clone(&cal_seg1); + // trace!("task {} clone = {}", i, cal_seg1.get_clone_count()); + // let l = loop_count.clone(); + // t.push(thread::spawn(move || { + // let n = task_calseg(c); + // l.lock().push(n); + // })); + // } + // thread::sleep(Duration::from_millis(1000)); + // cal_seg1.stop = 1; // deref_mut + // t.into_iter().for_each(|t| t.join().unwrap()); + + // let duration = start.elapsed().as_micros(); + // info!("Duration: {}us", duration); + // let tot_loop_count: u32 = loop_count.lock().iter().sum(); + // info!("Loop counts: tot = {}, {:.3}us per loop", tot_loop_count, duration as f64 / tot_loop_count as f64); + // } //----------------------------------------------------------------------------- // Test file read and write of a cal_seg @@ -861,12 +857,14 @@ mod cal_tests { fn test_cal_page_switch() { xcp_test::test_setup(log::LevelFilter::Info); let xcp = Xcp::get(); - let mut_page: CalPage2 = CalPage2 { a: 1, b: 3, c: 5 }; + let mut_page: CalPage1 = CalPage1 { a: 1, b: 3, c: 5 }; save(&mut_page, "test1.json").unwrap(); - save(&mut_page, "test2.json").unwrap(); - let cal_seg = xcp.create_calseg("test1", &FLASH_PAGE2); + //save(&mut_page, "test2.json").unwrap(); + let cal_seg = xcp.create_calseg("test1", &FLASH_PAGE1); cal_seg.load("test1.json").unwrap(); + info!("load"); cal_seg.sync(); + info!("sync"); assert_eq!(xcp.get_ecu_cal_page(), XcpCalPage::Ram, "XCP should be on RAM page here, there is no independant page switching yet"); test_is_mut!(cal_seg); // Default page must be mut_page xcp.set_ecu_cal_page(XcpCalPage::Flash); // Simulate a set cal page to default from XCP master @@ -890,7 +888,7 @@ mod cal_tests { } } std::fs::remove_file("test1.json").ok(); - std::fs::remove_file("test2.json").ok(); + //std::fs::remove_file("test2.json").ok(); } //----------------------------------------------------------------------------- diff --git a/tests/xcp_test_executor.rs b/tests/xcp_test_executor.rs index 99e47f4..5e204bc 100644 --- a/tests/xcp_test_executor.rs +++ b/tests/xcp_test_executor.rs @@ -165,8 +165,8 @@ impl XcpDaqDecoder for DaqDecoder { // Check counter_max (+0) and counter (+4) let counter_max = data[o] as u32 | (data[o + 1] as u32) << 8 | (data[o + 2] as u32) << 16 | (data[o + 3] as u32) << 24; let counter = data[o + 4] as u32 | (data[o + 5] as u32) << 8 | (data[o + 6] as u32) << 16 | (data[o + 7] as u32) << 24; - if counter_max > 255 || counter > 255 || counter > counter_max { - warn!("counter_max={}, counter={}", counter_max, counter); + if (counter_max != 15 && counter_max != 255) || counter > 255 || counter > counter_max { + error!("counter_max={}, counter={}", counter_max, counter); } //assert!(counter <= 255, "counter={}", counter); //assert!(counter <= counter_max, "counter={} counter_max={}", counter, counter_max); @@ -472,16 +472,15 @@ pub async fn xcp_test_executor(xcp: &Xcp, test_mode_cal: TestModeCal, test_mode_ assert!(duration_ms > DAQ_TEST_DURATION_MS as f64 && duration_ms < DAQ_TEST_DURATION_MS as f64 + 100.0); let avg_cycletime_us = (duration_ms * 1000.0) / d.daq_events[0] as f64; info!(" average task cycle time = {}us", avg_cycletime_us,); - if test_mode_daq == TestModeDaq::MultiThreadDAQ { - assert_eq!(d.daq_max, (MULTI_THREAD_TASK_COUNT - 1) as u16); - // Check all max counters are now 255 - for i in 0..MULTI_THREAD_TASK_COUNT { - assert_eq!(d.max_counter[i], 255); + let task_count = if test_mode_daq == TestModeDaq::MultiThreadDAQ { MULTI_THREAD_TASK_COUNT } else { 1 }; + assert_eq!(d.daq_max, (task_count - 1) as u16); + // Check the calibration happened, so all max_counter measurement values are 255 + for i in 0..task_count { + if d.max_counter[i] != 255 { + error!("daq {i} - max_counter={}", d.max_counter[i]); } - } else { - assert_eq!(d.daq_max, 0); - assert_eq!(d.max_counter[0], 255); // @@@@ } + assert_eq!(d.odt_max, 0); assert_eq!(d.counter_errors, 0); assert_eq!(d.packets_lost, 0);