From 3d2e38529b22909321f2ff8bc10948471e9c83a6 Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 11:53:23 +0900 Subject: [PATCH 01/16] test(core,kernel): inline format args Some instances were not caught by `clippy::uninlined_format_args` because this lint only recognizes a small predefined set of formatting macros at the moment. --- src/r3_core/src/utils/binary_heap/tests.rs | 24 +++++++++++----------- src/r3_core/src/utils/binary_search.rs | 22 ++++++-------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/r3_core/src/utils/binary_heap/tests.rs b/src/r3_core/src/utils/binary_heap/tests.rs index 32000e8ea0..a2c94ad18f 100644 --- a/src/r3_core/src/utils/binary_heap/tests.rs +++ b/src/r3_core/src/utils/binary_heap/tests.rs @@ -46,28 +46,28 @@ fn test_inner + std::f let mut subject = T::default(); let mut reference = Vec::new(); - log::debug!("max_len = {}, bytecode len = {}", max_len, bytecode.len()); + log::debug!("max_len = {max_len}, bytecode len = {}", bytecode.len()); for cmd in interpret(&bytecode, max_len) { - log::trace!(" {:?}", cmd); + log::trace!(" {cmd:?}"); match cmd { Cmd::Insert(value) => { let i = subject.heap_push(value, Ctx); - log::trace!(" → {}", i); + log::trace!(" → {i}"); let i = reference.binary_search(&value).unwrap_or_else(|x| x); reference.insert(i, value); } Cmd::Remove(i) => { let out_subject = subject.heap_remove(i, Ctx).unwrap(); - log::trace!(" → {}", out_subject); + log::trace!(" → {out_subject}"); let i_ref = reference.binary_search(&out_subject).unwrap(); reference.remove(i_ref); } } - log::trace!("[sorted: {:?}]", reference); - log::trace!("[subject: {:?}]", subject); + log::trace!("[sorted: {reference:?}]"); + log::trace!("[subject: {subject:?}]"); if subject.len() > 0 { assert_eq!(subject[0], reference[0]); } @@ -120,7 +120,7 @@ impl BinaryHeapCtx for TrackingCtx<'_> { fn on_move(&mut self, e: &mut El, new_index: usize) { self.el_position[e.id] = Some(new_index); - log::trace!(" on_move{:?}", (e, new_index)); + log::trace!(" on_move({e:?}, {new_index})"); } } @@ -135,13 +135,13 @@ fn position_tracking(bytecode: Vec) { log::debug!("bytecode len = {}", bytecode.len()); for cmd in interpret(&bytecode, usize::MAX) { - log::trace!(" {:?}", cmd); + log::trace!(" {cmd:?}"); match cmd { Cmd::Insert(value) => { let id = el_position.len(); el_position.push(None); let i = subject.heap_push(El { value, id }, TrackingCtx { el_position }); - log::trace!(" → {}", i); + log::trace!(" → {i}"); // `on_move` should have reported the position for the // newly-inserted element @@ -149,15 +149,15 @@ fn position_tracking(bytecode: Vec) { } Cmd::Remove(i) => { let out_subject = subject.heap_remove(i, TrackingCtx { el_position }).unwrap(); - log::trace!(" → {:?}", out_subject); + log::trace!(" → {out_subject:?}"); // For a removed element, we must modify `el_position` manually el_position[out_subject.id] = None; } } - log::trace!("[subject: {:?}]", subject); - log::trace!("[el_position: {:?}]", el_position); + log::trace!("[subject: {subject:?}]"); + log::trace!("[el_position: {el_position:?}]"); // Check if `el_position` correctly represents // the current state of `subject` diff --git a/src/r3_core/src/utils/binary_search.rs b/src/r3_core/src/utils/binary_search.rs index b705d3cc5c..4d28a40cd3 100644 --- a/src/r3_core/src/utils/binary_search.rs +++ b/src/r3_core/src/utils/binary_search.rs @@ -45,7 +45,7 @@ mod tests { fn lower_bound(mut values: Vec, arbitrary_value: u32) { values.sort(); - log::debug!("values = {:?}", values); + log::debug!("values = {values:?}"); for (i, &e) in values.iter().enumerate() { let mut expected = i; @@ -54,12 +54,7 @@ mod tests { } let got = lower_bound!(values.len(), |i| values[i] < e); - log::debug!( - " lower_bound(values[{}]) = {} (expected {})", - i, - got, - expected - ); + log::debug!(" lower_bound(values[{i}]) = {got} (expected {expected})"); assert_eq!(got, expected); } @@ -70,29 +65,24 @@ mod tests { } let mid = win[0] + (win[1] - win[0]) / 2; let got = lower_bound!(values.len(), |i| values[i] < mid); - log::debug!( - " lower_bound(mean(values[{}] + values[{} + 1])) = {}", - i, - i, - got - ); + log::debug!(" lower_bound(mean(values[{i}] + values[{i} + 1])) = {got}"); assert_eq!(got, i + 1); } if values.is_empty() { let got = lower_bound!(values.len(), |i| values[i] < arbitrary_value); - log::debug!(" lower_bound({}) = {}", arbitrary_value, got); + log::debug!(" lower_bound({arbitrary_value}) = {got}"); assert_eq!(got, 0); } else { if *values.first().unwrap() > 0 { #[allow(unused_comparisons)] let got = lower_bound!(values.len(), |i| values[i] < 0); - log::debug!(" lower_bound(0) = {}", got); + log::debug!(" lower_bound(0) = {got}"); assert_eq!(got, 0); } if *values.last().unwrap() < u32::MAX { let got = lower_bound!(values.len(), |i| values[i] < u32::MAX); - log::debug!(" lower_bound({}) = {}", u32::MAX, got); + log::debug!(" lower_bound({}) = {got}", u32::MAX); assert_eq!(got, values.len()); } } From 7144488f6747fecda726f2e7dc5aaa6e48e83c49 Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 17:35:04 +0900 Subject: [PATCH 02/16] test(kernel): inline format args Ditto. --- src/r3_kernel/src/utils/ctz.rs | 6 ++---- src/r3_kernel/src/utils/int.rs | 6 +++--- src/r3_kernel/src/utils/prio_bitmap.rs | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/r3_kernel/src/utils/ctz.rs b/src/r3_kernel/src/utils/ctz.rs index ddabc385ef..400b3bf474 100644 --- a/src/r3_kernel/src/utils/ctz.rs +++ b/src/r3_kernel/src/utils/ctz.rs @@ -298,8 +298,7 @@ mod tests { assert_eq!( expected, got, - "func({}) = {}, expected = {}", - in_value, got, expected, + "func({in_value}) = {got}, expected = {expected}", ); } @@ -323,8 +322,7 @@ mod tests { assert_eq!( expected, got, - "func({}) = {}, expected = {}", - in_value, got, expected, + "func({in_value}) = {got}, expected = {expected}", ); } } diff --git a/src/r3_kernel/src/utils/int.rs b/src/r3_kernel/src/utils/int.rs index 01978dd31d..97c4c54069 100644 --- a/src/r3_kernel/src/utils/int.rs +++ b/src/r3_kernel/src/utils/int.rs @@ -280,9 +280,9 @@ mod tests { let got_set_bits: Vec = i.one_digits().collect(); - log::trace!("i = 0x{:x}", i); - log::trace!(" got = {:?}", got_set_bits); - log::trace!(" expected = {:?}", set_bits); + log::trace!("i = 0x{i:x}"); + log::trace!(" got = {got_set_bits:?}"); + log::trace!(" expected = {set_bits:?}"); got_set_bits == set_bits } diff --git a/src/r3_kernel/src/utils/prio_bitmap.rs b/src/r3_kernel/src/utils/prio_bitmap.rs index f05438a5ca..fee98dded3 100644 --- a/src/r3_kernel/src/utils/prio_bitmap.rs +++ b/src/r3_kernel/src/utils/prio_bitmap.rs @@ -280,10 +280,10 @@ mod tests { let mut subject = T::INIT; let mut reference = BTreePrioBitmap::new(); - log::info!("size = {}", size); + log::info!("size = {size}"); for cmd in interpret(&bytecode, size) { - log::trace!(" {:?}", cmd); + log::trace!(" {cmd:?}"); match cmd { Cmd::Insert(bit) => { subject.set(bit); From 851de5b8f863381da39c84011874d40fb0e57d59 Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 17:38:46 +0900 Subject: [PATCH 03/16] refactor(test_suite): inline format args Ditto. The instances in `kernel_tets::interrupt_misc` were missed by Clippy due to conditional compilation. --- .../compute_atomics_round_robin.rs | 10 ++----- .../src/kernel_tests/compute_round_robin.rs | 10 +++---- .../interrupt_handler_priority.rs | 2 +- .../src/kernel_tests/interrupt_misc.rs | 10 +++---- .../src/kernel_tests/mutex_misc.rs | 28 ++++++------------- .../src/kernel_tests/startup_hook_priority.rs | 2 +- .../src/kernel_tests/task_queue_fifo.rs | 2 +- .../src/kernel_tests/time_misc.rs | 14 +++++----- .../src/kernel_tests/time_stress.rs | 4 +-- .../src/kernel_tests/timer_misc.rs | 4 +-- src/r3_test_suite/src/utils.rs | 2 +- src/r3_test_suite/src/utils/benchmark.rs | 3 +- src/r3_test_suite/src/utils/compute.rs | 2 +- src/r3_test_suite/src/utils/conditional.rs | 2 +- 14 files changed, 39 insertions(+), 56 deletions(-) diff --git a/src/r3_test_suite/src/kernel_tests/compute_atomics_round_robin.rs b/src/r3_test_suite/src/kernel_tests/compute_atomics_round_robin.rs index 57013fc33a..f66ee1f40c 100644 --- a/src/r3_test_suite/src/kernel_tests/compute_atomics_round_robin.rs +++ b/src/r3_test_suite/src/kernel_tests/compute_atomics_round_robin.rs @@ -246,12 +246,8 @@ fn judge_task_body>>() { let Wrapping(local_counter_sum) = local_counters.iter().cloned().map(Wrapping).sum(); - log::debug!("counter = {}", counter); - log::debug!( - "local_counters = {:?} (sum = {})", - local_counters, - local_counter_sum - ); + log::debug!("counter = {counter}"); + log::debug!("local_counters = {local_counters:?} (sum = {local_counter_sum})"); assert_eq!(counter, local_counter_sum); @@ -271,7 +267,7 @@ fn timer_body>>(sched_state: &mut // Switch the running task let new_task = (sched_state.cur_task + 1) % NUM_TASKS; - log::trace!("scheduing tasks[{}]", new_task); + log::trace!("scheduing tasks[{new_task}]"); tasks[sched_state.cur_task].set_priority(2).unwrap(); tasks[new_task].set_priority(1).unwrap(); sched_state.cur_task = new_task; diff --git a/src/r3_test_suite/src/kernel_tests/compute_round_robin.rs b/src/r3_test_suite/src/kernel_tests/compute_round_robin.rs index bdfcf433d3..91be071b29 100644 --- a/src/r3_test_suite/src/kernel_tests/compute_round_robin.rs +++ b/src/r3_test_suite/src/kernel_tests/compute_round_robin.rs @@ -163,21 +163,21 @@ fn worker_body>>( while !state.stop.load(Ordering::Relaxed) { i += 1; - log::trace!("[{}] Iteration {}: starting", worker_id, i); + log::trace!("[{worker_id}] Iteration {i}: starting"); task_state.output = Init::INIT; // Run the computation task_state.kernel_state.run(&mut task_state.output); // Validate the output - log::trace!("[{}] Iteration {}: validating", worker_id, i); + log::trace!("[{worker_id}] Iteration {i}: validating"); let valid = task_state.output == *ref_output; if !valid { stop::(); panic!("Output validation failed"); } - log::trace!("[{}] Iteration {}: complete", worker_id, i); + log::trace!("[{worker_id}] Iteration {i}: complete"); // Note: Some targets don't support CAS atomics. Non-atomic load/store // suffices because `run_count` is only written by this task. @@ -192,7 +192,7 @@ fn timer_body>>(sched_state: &mut // Switch the running task let new_task = (sched_state.cur_task + 1) % NUM_TASKS; - log::trace!("scheduing tasks[{}]", new_task); + log::trace!("scheduing tasks[{new_task}]"); tasks[sched_state.cur_task].set_priority(3).unwrap(); tasks[new_task].set_priority(2).unwrap(); sched_state.cur_task = new_task; @@ -209,7 +209,7 @@ fn timer_body>>(sched_state: &mut } if sched_state.time % 20 == 0 { - log::debug!("run_count = {:?}", run_count); + log::debug!("run_count = {run_count:?}"); } let min_run_count: usize = *run_count.iter().min().unwrap(); diff --git a/src/r3_test_suite/src/kernel_tests/interrupt_handler_priority.rs b/src/r3_test_suite/src/kernel_tests/interrupt_handler_priority.rs index 2e7867b2cd..15f52d8529 100644 --- a/src/r3_test_suite/src/kernel_tests/interrupt_handler_priority.rs +++ b/src/r3_test_suite/src/kernel_tests/interrupt_handler_priority.rs @@ -117,7 +117,7 @@ fn task_body>>() { } fn isr>>(i: usize) { - log::trace!("isr({})", i); + log::trace!("isr({i})"); D::app().seq.expect_and_replace(i, i + 1); if i == 10 { diff --git a/src/r3_test_suite/src/kernel_tests/interrupt_misc.rs b/src/r3_test_suite/src/kernel_tests/interrupt_misc.rs index e784cf51b4..9d2f5020f9 100644 --- a/src/r3_test_suite/src/kernel_tests/interrupt_misc.rs +++ b/src/r3_test_suite/src/kernel_tests/interrupt_misc.rs @@ -79,7 +79,7 @@ fn startup_hook>>() { int.disable().unwrap(); match int.is_pending() { Ok(false) | Err(kernel::QueryInterruptLineError::NotSupported) => {} - value => panic!("{:?}", value), + value => panic!("{value:?}"), } // Before doing the next test, make sure `clear` is supported @@ -89,7 +89,7 @@ fn startup_hook>>() { int.pend().unwrap(); match int.is_pending() { Ok(true) | Err(kernel::QueryInterruptLineError::NotSupported) => {} - value => panic!("{:?}", value), + value => panic!("{value:?}"), } int.clear().unwrap(); } @@ -149,7 +149,7 @@ fn task_body>>() { int.pend().unwrap(); match int.is_pending() { Ok(true) | Err(kernel::QueryInterruptLineError::NotSupported) => {} - value => panic!("{:?}", value), + value => panic!("{value:?}"), } int.clear().unwrap(); unsafe { System::release_cpu_lock() }.unwrap(); @@ -160,7 +160,7 @@ fn task_body>>() { int.pend().unwrap(); match int.is_pending() { Ok(true) | Err(kernel::QueryInterruptLineError::NotSupported) => {} - value => panic!("{:?}", value), + value => panic!("{value:?}"), } int.clear().unwrap(); int.enable().unwrap(); @@ -168,7 +168,7 @@ fn task_body>>() { match int.is_pending() { Ok(false) | Err(kernel::QueryInterruptLineError::NotSupported) => {} - value => panic!("{:?}", value), + value => panic!("{value:?}"), } if let &[pri, ..] = D::INTERRUPT_PRIORITIES { diff --git a/src/r3_test_suite/src/kernel_tests/mutex_misc.rs b/src/r3_test_suite/src/kernel_tests/mutex_misc.rs index 2143c08065..d5b4fa5925 100644 --- a/src/r3_test_suite/src/kernel_tests/mutex_misc.rs +++ b/src/r3_test_suite/src/kernel_tests/mutex_misc.rs @@ -210,12 +210,12 @@ fn task1_body, System = System>>( let mut free = (1u32 << N) - 1; // 0b1111 let mut locked: ArrayVec = ArrayVec::new(); for i in (0..100).rev() { - log::trace!(" locked = {:?}", locked); + log::trace!(" locked = {locked:?}"); // All held mutexes but the last one should be prevented from being // unlocked for &[i, _] in locked.array_windows::<2>() { - log::trace!(" making sure m[{}] is unlockable at this point", i); + log::trace!(" making sure m[{i}] is unlockable at this point"); assert_eq!( app.m[i].unlock(), Err(r3::kernel::UnlockMutexError::BadObjectState) @@ -237,12 +237,12 @@ fn task1_body, System = System>>( } else { rng.next() as usize % app.m.len() }; - log::trace!(" new_level = {}", new_level); + log::trace!(" new_level = {new_level}"); while new_level < locked.len() { // Unlock the last held mutex let i = locked.pop().unwrap(); - log::trace!(" unlocking m[{:?}]", i); + log::trace!(" unlocking m[{i}]"); app.m[i].unlock().unwrap(); free |= 1 << i; } @@ -258,7 +258,7 @@ fn task1_body, System = System>>( // Choose the method to use let method = (rng.next() & 0xff) % 3; - log::trace!(" locking m[{:?}] using method {:?})", i, method); + log::trace!(" locking m[{i}] using method {method:?})"); let m = app.m[i]; match method { 0 => m.lock().unwrap(), @@ -286,11 +286,7 @@ fn task1_body, System = System>>( let cur_task: LocalTask = LocalTask::current().unwrap(); for pri in 0..=3 { let exceeds_ceiling = pri < 1; - log::trace!( - "set_priority({}) exceeds_ceiling = {:?}", - pri, - exceeds_ceiling - ); + log::trace!("set_priority({pri}) exceeds_ceiling = {exceeds_ceiling}"); cur_task.set_priority(pri).unwrap(); assert_eq!(cur_task.priority().unwrap(), pri); @@ -322,11 +318,7 @@ fn task1_body, System = System>>( // restricted according to the locking protocol's precondition. for pri2 in 0..=3 { let exceeds_ceiling = pri2 < 1; - log::trace!( - " set_priority({}) exceeds_ceiling = {:?}", - pri2, - exceeds_ceiling - ); + log::trace!(" set_priority({pri2}) exceeds_ceiling = {exceeds_ceiling}"); if exceeds_ceiling { assert_eq!( cur_task.set_priority(pri2), @@ -360,11 +352,7 @@ fn task1_body, System = System>>( // restricted according to the locking protocol's precondition. for pri in (0..=3).rev() { let exceeds_ceiling = pri < 1; - log::trace!( - "task3.set_priority({}) exceeds_ceiling = {:?}", - pri, - exceeds_ceiling - ); + log::trace!("task3.set_priority({pri}) exceeds_ceiling = {exceeds_ceiling}"); if exceeds_ceiling { assert_eq!( app.task3.set_priority(pri), diff --git a/src/r3_test_suite/src/kernel_tests/startup_hook_priority.rs b/src/r3_test_suite/src/kernel_tests/startup_hook_priority.rs index 449afbc655..fa89e3a0a4 100644 --- a/src/r3_test_suite/src/kernel_tests/startup_hook_priority.rs +++ b/src/r3_test_suite/src/kernel_tests/startup_hook_priority.rs @@ -103,7 +103,7 @@ impl App { } fn hook>>(i: usize) { - log::trace!("hook({})", i); + log::trace!("hook({i})"); D::app().seq.expect_and_replace(i, i + 1); if i == 18 { diff --git a/src/r3_test_suite/src/kernel_tests/task_queue_fifo.rs b/src/r3_test_suite/src/kernel_tests/task_queue_fifo.rs index 3f7948b02f..d71dc41ea5 100644 --- a/src/r3_test_suite/src/kernel_tests/task_queue_fifo.rs +++ b/src/r3_test_suite/src/kernel_tests/task_queue_fifo.rs @@ -64,7 +64,7 @@ fn task1_body>>() { fn task2_body>>(i: usize) { D::app().seq.expect_and_replace(i, i + 1); - log::trace!("*Rabbit noise {}*", i); + log::trace!("*Rabbit noise {i}*"); if i == 4 { D::success(); } diff --git a/src/r3_test_suite/src/kernel_tests/time_misc.rs b/src/r3_test_suite/src/kernel_tests/time_misc.rs index bc9f7d9e32..6ec2323cb8 100644 --- a/src/r3_test_suite/src/kernel_tests/time_misc.rs +++ b/src/r3_test_suite/src/kernel_tests/time_misc.rs @@ -59,7 +59,7 @@ fn startup_hook>>() { fn task_body>>() { let now = if let Some(cap) = System::TIME_CAPABILITY { let now = System::time(cap).unwrap(); - log::trace!("time = {:?}", now); + log::trace!("time = {now:?}"); Some((cap, now)) } else { None @@ -72,13 +72,13 @@ fn task_body>>() { // Now change the time let now2 = Time::from_millis(114514); - log::trace!("changing system time to {:?}", now2); + log::trace!("changing system time to {now2:?}"); System::set_time(now2).unwrap(); // Because we just changed the time to `now2`, the current time should be // still very close to `now2` let now2_got = System::time(cap).unwrap(); - log::trace!("time = {:?}", now2_got); + log::trace!("time = {now2_got:?}"); assert_eq!(now2_got.duration_since(now2).unwrap().as_secs(), 0); } @@ -105,16 +105,16 @@ fn task_body>>() { let now4_got = if let Some(cap) = System::TIME_CAPABILITY { // System time should wrap around let now3 = Time::from_micros(0xfffffffffffe0000); - log::trace!("changing system time to {:?}", now3); + log::trace!("changing system time to {now3:?}"); System::set_time(now3).unwrap(); let d = Duration::from_micros(0x40000); - log::trace!("sleeping for {:?}", d); + log::trace!("sleeping for {d:?}"); System::sleep(d).unwrap(); let now4 = now3 + d; let now4_got = System::time(cap).unwrap(); - log::trace!("time = {:?} (expected >= {:?})", now4_got, now4); + log::trace!("time = {now4_got:?} (expected >= {now4:?})"); assert!(now4_got.as_micros() >= now4.as_micros()); Some((cap, now4_got)) @@ -128,7 +128,7 @@ fn task_body>>() { if let Some((cap, now4_got)) = now4_got { let now5 = now4_got; let now5_got = System::time(cap).unwrap(); - log::trace!("time = {:?} (expected {:?})", now5_got, now5); + log::trace!("time = {now5_got:?} (expected {now5:?})"); assert!(now5_got.as_micros() >= now5.as_micros()); assert!(now5_got.as_micros() <= now5.as_micros() + 100_000); } diff --git a/src/r3_test_suite/src/kernel_tests/time_stress.rs b/src/r3_test_suite/src/kernel_tests/time_stress.rs index a5cd848d3d..cca08fd6bb 100644 --- a/src/r3_test_suite/src/kernel_tests/time_stress.rs +++ b/src/r3_test_suite/src/kernel_tests/time_stress.rs @@ -51,7 +51,7 @@ fn task_body>>(i: usize) { for i in 0.. { let now = System::time().unwrap(); - log::trace!("[{}] time = {:?}", i, now); + log::trace!("[{i}] time = {now:?}"); if now.as_secs() >= 2 { break; @@ -69,7 +69,7 @@ fn task_body>>(i: usize) { let now2 = Time::from_micros(now.as_micros().wrapping_add(delay.as_micros() as _)); let now2_got = System::time().unwrap(); - log::trace!("[{}] time = {:?} (expected = {:?})", i, now2_got, now2); + log::trace!("[{i}] time = {now2_got:?} (expected = {now2:?})"); // `now2 <= now2_got < now2 + timing_error` let delta = now2_got.duration_since(now2); diff --git a/src/r3_test_suite/src/kernel_tests/timer_misc.rs b/src/r3_test_suite/src/kernel_tests/timer_misc.rs index aa08651240..dfaed778f7 100644 --- a/src/r3_test_suite/src/kernel_tests/timer_misc.rs +++ b/src/r3_test_suite/src/kernel_tests/timer_misc.rs @@ -113,7 +113,7 @@ fn task_body>>() { if let Some(cap) = System::TIME_CAPABILITY { let now = Time::from_millis(100); let now_got = System::time(cap).unwrap(); - log::trace!("time = {:?} (expected {:?})", now_got, now); + log::trace!("time = {now_got:?} (expected {now:?})"); assert!(now_got.as_micros() >= now.as_micros()); assert!(now_got.as_micros() <= now.as_micros() + 100_000); } @@ -125,7 +125,7 @@ fn task_body>>() { if let Some(cap) = System::TIME_CAPABILITY { let now = Time::from_millis(200); let now_got = System::time(cap).unwrap(); - log::trace!("time = {:?} (expected {:?})", now_got, now); + log::trace!("time = {now_got:?} (expected {now:?})"); assert!(now_got.as_micros() >= now.as_micros()); assert!(now_got.as_micros() <= now.as_micros() + 100_000); } diff --git a/src/r3_test_suite/src/utils.rs b/src/r3_test_suite/src/utils.rs index d7147dcea0..ed6913cbe4 100644 --- a/src/r3_test_suite/src/utils.rs +++ b/src/r3_test_suite/src/utils.rs @@ -36,7 +36,7 @@ impl SeqTracker { pub(crate) fn expect_and_replace(&self, old: usize, new: usize) { // Note: Some targets don't support CAS atomics let got = self.counter.load(Ordering::Relaxed); - log::debug!("{} (expected: {}) → {}", got, old, new); + log::debug!("{got} (expected: {old}) → {new}"); assert_eq!(got, old, "expected {old}, got {got}"); self.counter.store(new, Ordering::Relaxed); } diff --git a/src/r3_test_suite/src/utils/benchmark.rs b/src/r3_test_suite/src/utils/benchmark.rs index c9da656956..9f967ea07d 100644 --- a/src/r3_test_suite/src/utils/benchmark.rs +++ b/src/r3_test_suite/src/utils/benchmark.rs @@ -185,9 +185,8 @@ fn main_task>() { let mean = FixedPoint2(sum * 100 / samples.len() as u32); log::warn!( - "{}... mean = {}, med = {} [{}]", + "{}... mean = {mean}, med = {} [{}]", interval.name, - mean, percentiles[2], Options::PERFORMANCE_TIME_UNIT, ); diff --git a/src/r3_test_suite/src/utils/compute.rs b/src/r3_test_suite/src/utils/compute.rs index be48ff4352..a3d849ac94 100644 --- a/src/r3_test_suite/src/utils/compute.rs +++ b/src/r3_test_suite/src/utils/compute.rs @@ -296,7 +296,7 @@ mod tests { let mut state = KernelState::INIT; state.run(&mut out); - log::trace!("out = {:#?}", out); + log::trace!("out = {out:#?}"); for sample in out.samples.iter() { for &value in sample.iter() { diff --git a/src/r3_test_suite/src/utils/conditional.rs b/src/r3_test_suite/src/utils/conditional.rs index d341c695fd..464424533e 100644 --- a/src/r3_test_suite/src/utils/conditional.rs +++ b/src/r3_test_suite/src/utils/conditional.rs @@ -83,7 +83,7 @@ pub trait KernelTimeExt: traits::KernelBase { fn assert_time_ms_range(range: Range) { let Some(cap) = Self::TIME_CAPABILITY else { return }; let t = Self::time_ms(cap); - log::trace!("time = {:?}ms (expected = {:?}ms)", t, range); + log::trace!("time = {t:?}ms (expected = {range:?}ms)"); assert!( range.contains(&t), "time = {t:?}ms (expected = {range:?}ms)" From e2986e280101f71aa01753d84a00416df1a5174b Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 16:54:08 +0900 Subject: [PATCH 04/16] refactor(test_runner): inline format args Ditto. --- src/r3_test_runner/src/driverinterface.rs | 16 +++--- src/r3_test_runner/src/main.rs | 18 +++--- src/r3_test_runner/src/targets/demux.rs | 2 +- src/r3_test_runner/src/targets/jlink.rs | 4 +- src/r3_test_runner/src/targets/kflash.rs | 14 ++--- src/r3_test_runner/src/targets/probe_rs.rs | 14 ++--- src/r3_test_runner/src/targets/rp_pico.rs | 64 ++++++++-------------- src/r3_test_runner/src/targets/serial.rs | 6 +- src/r3_test_runner/src/targets/slip.rs | 2 +- src/r3_test_runner/src/utils.rs | 12 ++-- 10 files changed, 62 insertions(+), 90 deletions(-) diff --git a/src/r3_test_runner/src/driverinterface.rs b/src/r3_test_runner/src/driverinterface.rs index 25cad26a12..2ded31315b 100644 --- a/src/r3_test_runner/src/driverinterface.rs +++ b/src/r3_test_runner/src/driverinterface.rs @@ -112,8 +112,8 @@ impl TestDriver { // Locate the test driver's crate let crate_path = driver_base_path.join(crate_name); - log::debug!("driver.crate_name = {:?}", crate_name); - log::debug!("driver.crate_path = {:?}", crate_path); + log::debug!("driver.crate_name = {crate_name:?}"); + log::debug!("driver.crate_path = {crate_path:?}"); async move { if !crate_path.is_dir() { @@ -158,7 +158,7 @@ impl TestDriver { return Err(TestDriverNewError::DriverMetadata(e)); } }; - log::trace!("driver.meta = {:?}", meta); + log::trace!("driver.meta = {meta:?}"); // Find the target directory let target_dir = { @@ -191,7 +191,7 @@ impl TestDriver { // Put generated linker scripts in a directory let linker_scripts = target.linker_scripts(); - log::debug!("linker_scripts = {:?}", linker_scripts); + log::debug!("linker_scripts = {linker_scripts:?}"); let link_dir = tempdir::TempDir::new("r3_test_runner").map_err(TestDriverNewError::TempDirError)?; @@ -263,7 +263,7 @@ impl TestDriver { Ok(output_bytes) => { // Check the output let output_str = String::from_utf8_lossy(&output_bytes); - log::debug!("Output (lossy UTF-8) = {:?}", output_str); + log::debug!("Output (lossy UTF-8) = {output_str:?}"); if output_str.contains("!- TEST WAS SUCCESSFUL -!") { Ok(()) @@ -313,7 +313,7 @@ impl TestDriver { if exe_path.exists() { if let Err(e) = std::fs::remove_file(exe_path) { // Failure is non-fatal - log::warn!("Failed to remove '{}': {}", exe_path.display(), e); + log::warn!("Failed to remove '{}': {e}", exe_path.display()); } } @@ -428,7 +428,7 @@ async fn debug_probe_program_and_get_output_until>( let num_bytes = tokio::select! { read_result = read_fut => { - log::trace!("... `read` resolved to {:?}", read_result); + log::trace!("... `read` resolved to {read_result:?}"); read_result.unwrap_or(0) }, _ = timeout_fut => { @@ -489,7 +489,7 @@ async fn read_to_end_timeout( let num_bytes = tokio::select! { read_result = read_fut => { - log::trace!("... `read` resolved to {:?}", read_result); + log::trace!("... `read` resolved to {read_result:?}"); read_result.unwrap_or(0) }, _ = &mut timeout_fut => { diff --git a/src/r3_test_runner/src/main.rs b/src/r3_test_runner/src/main.rs index 394eba0db7..d8ed90c2c7 100644 --- a/src/r3_test_runner/src/main.rs +++ b/src/r3_test_runner/src/main.rs @@ -26,7 +26,7 @@ async fn main() { .init(); if let Err(e) = main_inner().await { - log::error!("Command failed.\n{:?}", e); + log::error!("Command failed.\n{e:?}"); std::process::exit(1); } } @@ -135,19 +135,19 @@ async fn main_inner() -> anyhow::Result<()> { // was built. let driver_base_path = { let manifest_dir = env!("CARGO_MANIFEST_DIR"); - log::debug!("CARGO_MANIFEST_DIR = {}", manifest_dir); + log::debug!("CARGO_MANIFEST_DIR = {manifest_dir}"); Path::new(manifest_dir) .parent() .expect("Couldn't get the parent of `CARGO_MANIFEST_DIR`") }; let target_arch = opt.target_arch.unwrap_or_else(|| opt.target.target_arch()); - log::debug!("target_arch = {}", target_arch); + log::debug!("target_arch = {target_arch}"); let target_arch_opt = target_arch.build_opt().with_context(|| { format!("The target architecture '{target_arch}' is invalid or unsupported.") })?; - log::debug!("target_arch_opt = {:?}", target_arch_opt); + log::debug!("target_arch_opt = {target_arch_opt:?}"); // Initialize the test driver interface let test_driver = driverinterface::TestDriver::new( @@ -213,7 +213,7 @@ async fn main_inner() -> anyhow::Result<()> { } let full_test_name = test_run.case.to_string(); - log::info!(" - {}", test_run); + log::info!(" - {test_run}"); // Build the test driver test_driver @@ -267,11 +267,11 @@ async fn main_inner() -> anyhow::Result<()> { match test_result { Ok(()) => { - log::info!("Test run '{}' was successful", test_run); + log::info!("Test run '{test_run}' was successful"); } Err(msg) => { // Test did run, but the result was failure. - log::error!("Test run '{}' failed: {}", test_run, msg); + log::error!("Test run '{test_run}' failed: {msg}"); failed_tests.push(test_run.to_string()); continue; } @@ -289,13 +289,13 @@ async fn main_inner() -> anyhow::Result<()> { log::error!("Failed tests:"); for test_run_name in failed_tests { - log::error!(" - {}", test_run_name); + log::error!(" - {test_run_name}"); } if !tests_skipped_to_fail_fast.is_empty() { log::warn!("Skipped tests:"); for test_run_name in tests_skipped_to_fail_fast { - log::warn!(" - {}", test_run_name); + log::warn!(" - {test_run_name}"); } } diff --git a/src/r3_test_runner/src/targets/demux.rs b/src/r3_test_runner/src/targets/demux.rs index 2ba366fb41..385e84085d 100644 --- a/src/r3_test_runner/src/targets/demux.rs +++ b/src/r3_test_runner/src/targets/demux.rs @@ -118,7 +118,7 @@ impl AsyncBufRead for Demux<'_> { Pin::new(&mut this.inner).consume(num_bytes); } Err(e) => { - log::trace!("Ignoring error while outputting to stdout: {:?}", e); + log::trace!("Ignoring error while outputting to stdout: {e:?}"); // Ignore any I/O errors caused by stdout Pin::new(&mut this.inner).consume(payload_len); } diff --git a/src/r3_test_runner/src/targets/jlink.rs b/src/r3_test_runner/src/targets/jlink.rs index 6f5a0b1194..6c898b367e 100644 --- a/src/r3_test_runner/src/targets/jlink.rs +++ b/src/r3_test_runner/src/targets/jlink.rs @@ -115,7 +115,7 @@ impl DebugProbe for Fe310JLinkDebugProbe { let mut cmd = String::new(); writeln!(cmd, "r").unwrap(); for (path, (_, offset)) in section_files.iter().zip(regions.iter()) { - writeln!(cmd, "loadbin \"{}\" 0x{:08x}", path.display(), offset).unwrap(); + writeln!(cmd, "loadbin \"{}\" 0x{offset:08x}", path.display()).unwrap(); } writeln!(cmd, "setpc 0x{entry:x}").unwrap(); writeln!(cmd, "g").unwrap(); @@ -123,7 +123,7 @@ impl DebugProbe for Fe310JLinkDebugProbe { // Flash the program and reset the chip // (`probe-rs` doesn't support FE310-based boards at this time) - log::debug!("Launching JLinkExe and executing '{:?}'", cmd); + log::debug!("Launching JLinkExe and executing '{cmd:?}'"); subprocess::CmdBuilder::new("JLinkExe") .args([ "-device", diff --git a/src/r3_test_runner/src/targets/kflash.rs b/src/r3_test_runner/src/targets/kflash.rs index f33c4992a4..219f019696 100644 --- a/src/r3_test_runner/src/targets/kflash.rs +++ b/src/r3_test_runner/src/targets/kflash.rs @@ -222,7 +222,7 @@ impl DebugProbe for KflashDebugProbe { } // Boot the program - log::debug!("Booting from 0x{:08x}", entry); + log::debug!("Booting from 0x{entry:08x}"); boot(&mut self.serial, entry as u32).await?; // Now, pass the channel to the caller @@ -310,7 +310,7 @@ async fn maix_enter_isp_mode( let serial_inner = serial.get_mut(); log::debug!("Trying to put the chip into ISP mode"); for cmd in cmds { - log::trace!("Performing the command {:?}", cmd); + log::trace!("Performing the command {cmd:?}"); match cmd { BootCmd::Dtr(b) => { serial_inner @@ -348,8 +348,7 @@ async fn maix_enter_isp_mode( match tokio::time::timeout(COMM_TIMEOUT, slip::read_frame(serial)).await { Ok(Ok(frame)) => { log::trace!( - "Received a packet: {:?} The chip probably successfully entered ISP mode", - frame + "Received a packet: {frame:?} The chip probably successfully entered ISP mode", ); } Ok(Err(e)) => return Err(e.into()), @@ -372,10 +371,9 @@ async fn flash_dataframe( let chunk_addr = address + (i * CHUNK_LEN) as u32; log::debug!( - "Programming the range {:?}/{:?} at 0x{:x} ({}%)", + "Programming the range {:?}/{:?} at 0x{chunk_addr:x} ({}%)", (i * CHUNK_LEN)..(i * CHUNK_LEN + chunk.len()), data.len(), - chunk_addr, i * CHUNK_LEN * 100 / data.len(), ); @@ -416,7 +414,7 @@ async fn flash_dataframe( } } - log::trace!("Got {:?}. Retrying...", reason); + log::trace!("Got {reason:?}. Retrying..."); } if let Some(error) = error { @@ -502,7 +500,7 @@ async fn read_to_end_and_discard( let mut buf = [0u8; 256]; loop { let num_bytes = reader.read(&mut buf).await?; - log::trace!("Discarding {} byte(s)", num_bytes); + log::trace!("Discarding {num_bytes} byte(s)"); } } diff --git a/src/r3_test_runner/src/targets/probe_rs.rs b/src/r3_test_runner/src/targets/probe_rs.rs index 6a7a4a5ec7..22d62501ca 100644 --- a/src/r3_test_runner/src/targets/probe_rs.rs +++ b/src/r3_test_runner/src/targets/probe_rs.rs @@ -169,17 +169,14 @@ pub async fn attach_rtt( .await .unwrap(); if let Some(x) = addr { - log::debug!("Found the RTT header at 0x{:x}", x); + log::debug!("Found the RTT header at 0x{x:x}"); probe_rs_rtt::ScanRegion::Exact(x as u32) } else { probe_rs_rtt::ScanRegion::Ram } } Err(e) => { - log::warn!( - "Couldn't read the executable to find the RTT header: {:?}", - e - ); + log::warn!("Couldn't read the executable to find the RTT header: {e:?}"); probe_rs_rtt::ScanRegion::Ram } }; @@ -233,10 +230,7 @@ fn find_rtt_symbol(elf_bytes: &[u8]) -> Option { let elf = match goblin::elf::Elf::parse(elf_bytes) { Ok(elf) => elf, Err(e) => { - log::warn!( - "Couldn't parse the executable to find the RTT header: {:?}", - e - ); + log::warn!("Couldn't parse the executable to find the RTT header: {e:?}"); return None; } }; @@ -267,7 +261,7 @@ impl<'a, 'probe> CoreHaltGuard<'a, 'probe> { impl Drop for CoreHaltGuard<'_, '_> { fn drop(&mut self) { if let Err(e) = self.core.run() { - log::warn!("Failed to restart the core (ignored): {:?}", e); + log::warn!("Failed to restart the core (ignored): {e:?}"); } } } diff --git a/src/r3_test_runner/src/targets/rp_pico.rs b/src/r3_test_runner/src/targets/rp_pico.rs index 758227cdc2..966cdce93e 100644 --- a/src/r3_test_runner/src/targets/rp_pico.rs +++ b/src/r3_test_runner/src/targets/rp_pico.rs @@ -75,8 +75,7 @@ impl Target for RaspberryPiPico { (Ok(serial), Err(e)) => { log::debug!( "Connected to a test driver serial interface. Connecting to \ - a PICOBOOT USB interface failed with the following error: {}", - e + a PICOBOOT USB interface failed with the following error: {e}", ); Some(BufStream::new(serial)) } @@ -84,8 +83,7 @@ impl Target for RaspberryPiPico { log::debug!( "Connected to a PICOBOOT USB interface. Connecting to \ a test driver serial interface failed with the following \ - error: {}", - e + error: {e}", ); None } @@ -94,10 +92,8 @@ impl Target for RaspberryPiPico { nor a PICOBOOT USB interface. Please put your Pico into \ BOOTSEL mode before executing this command.\n\ \n\ - Serial interface error: {}\n\n\ - PICOBOOT interface error: {}", - e1, - e2, + Serial interface error: {e1}\n\n\ + PICOBOOT interface error: {e2}", ), (Ok(_), Ok(_)) => anyhow::bail!( "Connected to both of a test driver serial \ @@ -189,7 +185,7 @@ fn open_serial() -> Result { let port = ports .iter() .find(|port_info| { - log::trace!(" ...{:?}", port_info); + log::trace!(" ...{port_info:?}"); use serialport::{SerialPortInfo, SerialPortType, UsbPortInfo}; matches!( @@ -208,7 +204,7 @@ fn open_serial() -> Result { port_info.port_name.starts_with("/dev/tty.usbmodem") }) .ok_or_else(|| anyhow!("Could not locate the test driver serial port."))?; - log::debug!("Test driver serial port = {:?}", port); + log::debug!("Test driver serial port = {port:?}"); // Open the serial port tokio_serial::new(&port.port_name, 115200) @@ -237,8 +233,7 @@ async fn program_and_run_by_picoboot(exe: &std::path::Path) -> Result<()> { log::debug!("Transfering the image"); for (region_data, region_addr) in loadable_code.regions.iter() { log::debug!( - " ... 0x{:08x}..=0x{:08x}", - region_addr, + " ... 0x{region_addr:08x}..=0x{:08x}", region_addr + region_data.len() as u64 - 1 ); @@ -248,7 +243,7 @@ async fn program_and_run_by_picoboot(exe: &std::path::Path) -> Result<()> { device_handle = device_handle_tmp; let num_bytes_written = result.with_context(|| "Failed to issue a 'write' command.")?; if num_bytes_written != 32 { - anyhow::bail!("Short write ({} < 32)", num_bytes_written); + anyhow::bail!("Short write ({num_bytes_written} < 32)"); } let (result, device_handle_tmp) = @@ -257,11 +252,7 @@ async fn program_and_run_by_picoboot(exe: &std::path::Path) -> Result<()> { let num_bytes_written = result.with_context(|| "Failed to transmit the 'write' command's payload.")?; if num_bytes_written != region_data.len() { - anyhow::bail!( - "Short write ({} < {})", - num_bytes_written, - region_data.len() - ); + anyhow::bail!("Short write ({num_bytes_written} < {})", region_data.len()); } let (result, device_handle_tmp) = read_bulk_empty(device_handle, in_endpoint_i).await; @@ -278,7 +269,7 @@ async fn program_and_run_by_picoboot(exe: &std::path::Path) -> Result<()> { let (result, _) = write_bulk_all(device_handle, out_endpoint_i, bytemuck::bytes_of(&hdr)).await; let num_bytes_written = result.with_context(|| "Failed to issue a 'reboot' command.")?; if num_bytes_written != 32 { - anyhow::bail!("Short write ({} < 32)", num_bytes_written); + anyhow::bail!("Short write ({num_bytes_written} < 32)"); } Ok(()) @@ -298,7 +289,7 @@ async fn write_bulk_all( let mut buf = &buf[..]; let mut num_bytes_written = 0; - log::trace!("write_bulk_all({})", endpoint); + log::trace!("write_bulk_all({endpoint})"); while !buf.is_empty() { match device_handle.write_bulk(endpoint, buf, DEFAULE_TIMEOUT) { @@ -322,7 +313,7 @@ async fn read_bulk_empty( endpoint: u8, ) -> (rusb::Result<()>, rusb::DeviceHandle) { spawn_blocking(move || { - log::trace!("read_bulk_empty({})", endpoint); + log::trace!("read_bulk_empty({endpoint})"); let result = match device_handle.read_bulk(endpoint, &mut [], DEFAULE_TIMEOUT) { Ok(0) => Ok(()), @@ -350,14 +341,12 @@ fn open_picoboot() -> Result { let device = devices .iter() .find(|device| { - log::trace!(" ...{:?}", device); + log::trace!(" ...{device:?}"); let descriptor = match device.device_descriptor() { Ok(x) => x, Err(e) => { log::warn!( - "Could not get the device descriptor of '{:?}'; ignoring. Cause: {}", - device, - e + "Could not get the device descriptor of '{device:?}'; ignoring. Cause: {e}", ); return false; } @@ -367,7 +356,7 @@ fn open_picoboot() -> Result { }) .ok_or_else(|| anyhow!("Could not locate the RP2040 bootrom device."))?; - log::debug!("Found the RP2040 bootrom device: {:?}", device); + log::debug!("Found the RP2040 bootrom device: {device:?}"); // Locate the USB PICOBOOT interface log::debug!("Looking for the USB PICOBOOT interface"); @@ -383,7 +372,7 @@ fn open_picoboot() -> Result { .descriptors() .next() .filter(|interface_descriptor| { - log::trace!(" ...{:?}", interface_descriptor); + log::trace!(" ...{interface_descriptor:?}"); ( interface_descriptor.class_code(), interface_descriptor.sub_class_code(), @@ -394,44 +383,39 @@ fn open_picoboot() -> Result { .next() // Fail if no eligible interface was found .ok_or_else(|| { - anyhow!( - "Could not locate the RP2040 PICOBOOT interface from the device '{:?}'.", - device - ) + anyhow!("Could not locate the RP2040 PICOBOOT interface from the device '{device:?}'.",) })?; let interface_i = interface.interface_number(); - log::debug!("PICOBOOT interface number = {}", interface_i); + log::debug!("PICOBOOT interface number = {interface_i}"); // Locate the endpoints log::debug!("Looking for the USB PICOBOOT endpoints"); let out_endpoint_i = interface .endpoint_descriptors() .find(|endpoint_descriptor| { - log::trace!(" ...{:?}", endpoint_descriptor); + log::trace!(" ...{endpoint_descriptor:?}"); endpoint_descriptor.direction() == rusb::Direction::Out }) .ok_or_else(|| { anyhow!( - "Could not locate the RP2040 PICOBOOT BULK OUT endpoint from the device '{:?}'.", - device + "Could not locate the RP2040 PICOBOOT BULK OUT endpoint from the device '{device:?}'.", ) })? .address(); - log::debug!("PICOBOOT BULK OUT endpoint = {}", out_endpoint_i); + log::debug!("PICOBOOT BULK OUT endpoint = {out_endpoint_i}"); let in_endpoint_i = interface .endpoint_descriptors() .find(|endpoint_descriptor| { - log::trace!(" ...{:?}", endpoint_descriptor); + log::trace!(" ...{endpoint_descriptor:?}"); endpoint_descriptor.direction() == rusb::Direction::In }) .ok_or_else(|| { anyhow!( - "Could not locate the RP2040 PICOBOOT BULK IN endpoint from the device '{:?}'.", - device + "Could not locate the RP2040 PICOBOOT BULK IN endpoint from the device '{device:?}'.", ) })? .address(); - log::debug!("PICOBOOT BULK IN endpoint = {}", in_endpoint_i); + log::debug!("PICOBOOT BULK IN endpoint = {in_endpoint_i}"); // Open the device let mut device_handle = device diff --git a/src/r3_test_runner/src/targets/serial.rs b/src/r3_test_runner/src/targets/serial.rs index 20e4425691..02d9fa05bf 100644 --- a/src/r3_test_runner/src/targets/serial.rs +++ b/src/r3_test_runner/src/targets/serial.rs @@ -12,11 +12,11 @@ pub fn choose_serial() -> Result { } }; if let Some(p) = var { - log::info!("Using the serial port {:?} (manually selected)", p); + log::info!("Using the serial port {p:?} (manually selected)"); Ok(p) } else { let ports = tokio_serial::available_ports()?; - log::trace!("Available ports: {:?}", ports); + log::trace!("Available ports: {ports:?}"); if ports.is_empty() { return Err(ChooseSerialError::NoPortsAvailable); } else if ports.len() > 1 { @@ -26,7 +26,7 @@ pub fn choose_serial() -> Result { } let p = ports.into_iter().next().unwrap().port_name; - log::info!("Using the serial port {:?} (automatically selected)", p); + log::info!("Using the serial port {p:?} (automatically selected)"); Ok(p) } } diff --git a/src/r3_test_runner/src/targets/slip.rs b/src/r3_test_runner/src/targets/slip.rs index e42c9c9806..d7b2ec2ed1 100644 --- a/src/r3_test_runner/src/targets/slip.rs +++ b/src/r3_test_runner/src/targets/slip.rs @@ -54,7 +54,7 @@ impl FrameExtractorState { Ok(Some(FrameExtractorAction::StartFrame)) } _ => { - log::trace!("Ignoring 0x{:?} outside a frame", b); + log::trace!("Ignoring 0x{b:?} outside a frame"); Ok(None) } }, diff --git a/src/r3_test_runner/src/utils.rs b/src/r3_test_runner/src/utils.rs index 4da49981f7..6c8e63c80f 100644 --- a/src/r3_test_runner/src/utils.rs +++ b/src/r3_test_runner/src/utils.rs @@ -71,13 +71,13 @@ where match f().await { Ok(x) => return Ok(x), Err(e) => { - log::warn!("Attempt failed: {:?}", e); + log::warn!("Attempt failed: {e:?}"); count -= 1; if count == 0 { log::warn!("Retry limit reached"); return Err(e); } else { - log::warn!("Retrying... (remaining count = {:?})", count); + log::warn!("Retrying... (remaining count = {count:?})"); } } } @@ -95,18 +95,14 @@ where match f().await { Ok(x) => return Ok(x), Err(e) => { - log::warn!("Attempt failed: {:?}", e); + log::warn!("Attempt failed: {e:?}"); count -= 1; if count == 0 { log::warn!("Retry limit reached"); return Err(e); } else { let delay = (16 >> count).max(1); - log::warn!( - "Retrying in {} seconds... (remaining count = {:?})", - delay, - count - ); + log::warn!("Retrying in {delay} seconds... (remaining count = {count:?})"); sleep(Duration::from_secs(delay)).await; } From 29382e2bf165536b9241dd40650920bcafa689ed Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 11:58:23 +0900 Subject: [PATCH 05/16] refactor(portkit): inline format args Ditto. --- src/r3_portkit/src/num/wrapping.rs | 10 ++++----- src/r3_portkit/src/tickless.rs | 33 ++++++++++++------------------ 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/r3_portkit/src/num/wrapping.rs b/src/r3_portkit/src/num/wrapping.rs index b734394176..042136b83b 100644 --- a/src/r3_portkit/src/num/wrapping.rs +++ b/src/r3_portkit/src/num/wrapping.rs @@ -276,12 +276,11 @@ mod tests { fn do_test_add_assign64(values: &mut dyn Iterator) { let mut counter_got: Wrapping<{MAX as u64}> = Init::INIT; let mut counter_expected: NaiveWrapping<{MAX as u64}> = Init::INIT; - log::trace!("do_test_add_assign64 (MAX = {})", MAX); + log::trace!("do_test_add_assign64 (MAX = {MAX})"); for value in values { log::trace!( - " - ({} + {}) % (MAX + 1) = {} % (MAX + 1) = {}", + " - ({} + {value}) % (MAX + 1) = {} % (MAX + 1) = {}", counter_expected.inner, - value, (counter_expected.inner + value as u128), (counter_expected.inner + value as u128) % (MAX + 1), ); @@ -330,12 +329,11 @@ mod tests { fn do_test_add_assign128_multi32(values: &mut dyn Iterator) { let mut counter_got: Wrapping<{MAX as u64}> = Init::INIT; let mut counter_expected: NaiveWrapping<{MAX as u64}> = Init::INIT; - log::trace!("do_test_add_assign128_multi32 (MAX = {})", MAX); + log::trace!("do_test_add_assign128_multi32 (MAX = {MAX})"); for value in values { log::trace!( - " - ({} + {}) % (MAX + 1) = {} % (MAX + 1) = {}", + " - ({} + {value}) % (MAX + 1) = {} % (MAX + 1) = {}", counter_expected.inner, - value, (counter_expected.inner + value), (counter_expected.inner + value) % (MAX + 1), ); diff --git a/src/r3_portkit/src/tickless.rs b/src/r3_portkit/src/tickless.rs index 6fd5dbb4a3..89cadc0eed 100644 --- a/src/r3_portkit/src/tickless.rs +++ b/src/r3_portkit/src/tickless.rs @@ -961,10 +961,10 @@ mod tests { let _ = env_logger::builder().is_test(true).try_init(); - log::info!("CFG = {:?}", CFG); - log::info!("MAX_TIMEOUT = {:?}", MAX_TIMEOUT); - log::info!("HW_PERIOD = {:?}", HW_PERIOD); - log::info!("PERIOD = {:?}", PERIOD); + log::info!("CFG = {CFG:?}"); + log::info!("MAX_TIMEOUT = {MAX_TIMEOUT:?}"); + log::info!("HW_PERIOD = {HW_PERIOD:?}"); + log::info!("PERIOD = {PERIOD:?}"); if $resettable { hw_tick_count = 0x1234567; @@ -978,17 +978,17 @@ mod tests { } let tick_count = state.tick_count(&CFG, hw_tick_count); - log::trace!(" HW = {}, OS = {}", hw_tick_count, tick_count); + log::trace!(" HW = {hw_tick_count}, OS = {tick_count}"); assert_eq!(tick_count, 0); for op in ops { - log::debug!(" {:?}", op); + log::debug!(" {op:?}"); let mut state2 = state; let start_tick_count = state.mark_reference(&CFG, hw_tick_count); - log::trace!(" HW = {}, OS = {}", hw_tick_count, start_tick_count); - log::trace!(" state = {:?}", state); + log::trace!(" HW = {hw_tick_count}, OS = {start_tick_count}"); + log::trace!(" state = {state:?}"); assert_eq!(state.tick_count(&CFG, hw_tick_count), start_tick_count); @@ -997,7 +997,7 @@ mod tests { hw_tick_count } else { let end_tick_count = add_mod(start_tick_count, op.timeout, PERIOD); - log::trace!(" Want to wait until OS = {}", end_tick_count); + log::trace!(" Want to wait until OS = {end_tick_count}"); state.tick_count_to_hw_tick_count(&CFG, end_tick_count) }; let len_hw_tick_count = sub_mod(end_hw_tick_count, hw_tick_count, HW_PERIOD); @@ -1015,16 +1015,14 @@ mod tests { } log::trace!( - " Should wait for {} HW ticks (end HW = {})", - len_hw_tick_count, - end_hw_tick_count + " Should wait for {len_hw_tick_count} HW ticks (end HW = {end_hw_tick_count})" ); // Extend the timeout by an interrupt latency let late_len_hw_tick_count = len_hw_tick_count + op.latency; assert!(late_len_hw_tick_count <= CFG.hw_max_tick_count()); - log::trace!(" Will wait for {} HW ticks", late_len_hw_tick_count); + log::trace!(" Will wait for {late_len_hw_tick_count} HW ticks"); // OS tick count should increase monotonically (this // property is assumed, not checked here) while we are @@ -1036,19 +1034,14 @@ mod tests { vec![len_hw_tick_count.saturating_sub(1), len_hw_tick_count], ); for hw_elapsed in sample_points { - log::trace!(" - HW = {} + {}", hw_tick_count, hw_elapsed); + log::trace!(" - HW = {hw_tick_count} + {hw_elapsed}"); let hw_tick_count = add_mod(hw_tick_count, hw_elapsed, HW_PERIOD); let tick_count = state.tick_count(&CFG, hw_tick_count); elapsed += sub_mod(tick_count, last_tick_count, PERIOD); last_tick_count = tick_count; - log::trace!( - " OS = {} ({} + {})", - tick_count, - start_tick_count, - elapsed - ); + log::trace!(" OS = {tick_count} ({start_tick_count} + {elapsed})"); // The OS tick count shouldn't increase more than // `CFG.max_tick_count()` between timer interrupts or From 721f2d5d7dcd934177432aa6b8fddc5dccf7f8af Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 11:58:56 +0900 Subject: [PATCH 06/16] test(port_std): inline format args Ditto. --- src/r3_port_std/benches/test_suite.rs | 2 +- src/r3_port_std/src/ums/tests.rs | 4 +--- src/r3_port_std/tests/kernel_tests/external_interrupt.rs | 2 +- .../tests/kernel_tests/interrupt_table_sparsity.rs | 2 +- src/r3_port_std/tests/kernel_tests/stack_align.rs | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/r3_port_std/benches/test_suite.rs b/src/r3_port_std/benches/test_suite.rs index c0050c3aaa..19931a3a3e 100644 --- a/src/r3_port_std/benches/test_suite.rs +++ b/src/r3_port_std/benches/test_suite.rs @@ -107,7 +107,7 @@ fn main() { .init(); for (name, entry) in KERNEL_BENCHMARKS { - log::info!("--- kernel benchmark '{}' ---", name); + log::info!("--- kernel benchmark '{name}' ---"); entry(); } } diff --git a/src/r3_port_std/src/ums/tests.rs b/src/r3_port_std/src/ums/tests.rs index 3aeabdea84..d6e27f236d 100644 --- a/src/r3_port_std/src/ums/tests.rs +++ b/src/r3_port_std/src/ums/tests.rs @@ -216,9 +216,7 @@ fn yield_ring(count: usize) { let sum: usize = new_counters.iter().sum(); log::info!( - "new_counters = {:?}, sum = {:?} ({:?} ns/iter)", - new_counters, - sum, + "new_counters = {new_counters:?}, sum = {sum:?} ({:?} ns/iter)", duration / sum as u64 ); diff --git a/src/r3_port_std/tests/kernel_tests/external_interrupt.rs b/src/r3_port_std/tests/kernel_tests/external_interrupt.rs index 42f392f188..b21579ed92 100644 --- a/src/r3_port_std/tests/kernel_tests/external_interrupt.rs +++ b/src/r3_port_std/tests/kernel_tests/external_interrupt.rs @@ -69,7 +69,7 @@ fn task_body1>>>() { log::debug!("spawning an external thread"); spawn(move || { sleep(Duration::from_millis(100)); - log::debug!("pending {:?}", int); + log::debug!("pending {int:?}"); r3_port_std::pend_interrupt_line::(int.num()).unwrap(); }); diff --git a/src/r3_port_std/tests/kernel_tests/interrupt_table_sparsity.rs b/src/r3_port_std/tests/kernel_tests/interrupt_table_sparsity.rs index e231a68da7..b1f28ccb51 100644 --- a/src/r3_port_std/tests/kernel_tests/interrupt_table_sparsity.rs +++ b/src/r3_port_std/tests/kernel_tests/interrupt_table_sparsity.rs @@ -56,7 +56,7 @@ impl App> { fn hook_body>>>() { let handlers = ::INTERRUPT_HANDLERS; - log::debug!("INTERRUPT_HANDLERS = {:#?}", handlers); + log::debug!("INTERRUPT_HANDLERS = {handlers:#?}"); assert_eq!(handlers.storage.len(), 8); assert_eq!(handlers.get(0), None); assert_eq!(handlers.get(1), None); diff --git a/src/r3_port_std/tests/kernel_tests/stack_align.rs b/src/r3_port_std/tests/kernel_tests/stack_align.rs index 8028650b22..be62a2bbd8 100644 --- a/src/r3_port_std/tests/kernel_tests/stack_align.rs +++ b/src/r3_port_std/tests/kernel_tests/stack_align.rs @@ -38,7 +38,7 @@ fn task_body>>>() { let stack = task_cb.attr.stack.as_ptr(); let start = stack.as_mut_ptr(); let end = start.wrapping_add(stack.len()); - log::trace!("stack = {:?}..{:?}", start, end); + log::trace!("stack = {start:?}..{end:?}"); assert_eq!(start as usize % expected_alignment, 0); assert_eq!(end as usize % expected_alignment, 0); From 64f3e49e9a080bdd76df5051d2b5715d3d576f7a Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 11:59:03 +0900 Subject: [PATCH 07/16] refactor(port_std): inline format args Ditto. --- src/r3_port_std/src/lib.rs | 28 ++++++++++++++-------------- src/r3_port_std/src/sched.rs | 28 +++++++--------------------- src/r3_port_std/src/ums.rs | 4 ++-- 3 files changed, 23 insertions(+), 37 deletions(-) diff --git a/src/r3_port_std/src/lib.rs b/src/r3_port_std/src/lib.rs index d100f48375..c4f8e67006 100644 --- a/src/r3_port_std/src/lib.rs +++ b/src/r3_port_std/src/lib.rs @@ -169,7 +169,7 @@ impl TaskState { } unsafe fn exit_and_dispatch(&self, state: &'static State) -> ! { - log::trace!("exit_and_dispatch({:p}) enter", self); + log::trace!("exit_and_dispatch({self:p}) enter"); self.assert_current_thread(); let mut lock = state.thread_group.get().unwrap().lock(); @@ -196,7 +196,7 @@ impl TaskState { // Invoke the dispatcher unsafe { state.yield_cpu::() }; - log::trace!("exit_and_dispatch({:p}) calling exit_thread", self); + log::trace!("exit_and_dispatch({self:p}) calling exit_thread"); unsafe { ums::exit_thread() }; } } @@ -260,7 +260,7 @@ impl State { ::boot(); } }); - log::trace!("startup thread = {:?}", thread_id); + log::trace!("startup thread = {thread_id:?}"); lock.scheduler().task_thread = Some(thread_id); lock.scheduler().recycle_thread(thread_id); lock.preempt(); @@ -346,7 +346,7 @@ impl State { // there's no data race let running_task = unsafe { *Traits::state().running_task_ptr() }; lock.scheduler().task_thread = if let Some(task) = running_task { - log::trace!("dispatching task {:p}", task); + log::trace!("dispatching task {task:p}"); let mut tsm = task.port_task_state.tsm.lock(); @@ -357,7 +357,7 @@ impl State { THREAD_ROLE.with(|role| role.set(ThreadRole::Task)); assert!(!self.is_cpu_lock_active::()); - log::debug!("task {:p} is now running", task); + log::debug!("task {task:p} is now running"); // Safety: The port can call this unsafe { @@ -373,7 +373,7 @@ impl State { } }); - log::trace!("spawned thread {:?} for the task {:p}", thread, task); + log::trace!("spawned thread {thread:?} for the task {task:p}"); *tsm = Tsm::Running(thread); Some(thread) @@ -435,7 +435,7 @@ impl State { &self, task: &'static TaskCb, ) { - log::trace!("initialize_task_state {:p}", task); + log::trace!("initialize_task_state {task:p}"); expect_worker_thread::(); assert!(self.is_cpu_lock_active::()); @@ -495,7 +495,7 @@ impl State { num: InterruptNum, priority: InterruptPriority, ) -> Result<(), SetInterruptLinePriorityError> { - log::trace!("set_interrupt_line_priority{:?}", (num, priority)); + log::trace!("set_interrupt_line_priority({num}, {priority})"); assert!(matches!( expect_worker_thread::(), ThreadRole::Boot | ThreadRole::Task @@ -518,7 +518,7 @@ impl State { &'static self, num: InterruptNum, ) -> Result<(), EnableInterruptLineError> { - log::trace!("enable_interrupt_line{:?}", (num,)); + log::trace!("enable_interrupt_line({num})"); expect_worker_thread::(); let mut lock = self.thread_group.get().unwrap().lock(); @@ -538,7 +538,7 @@ impl State { &self, num: InterruptNum, ) -> Result<(), EnableInterruptLineError> { - log::trace!("disable_interrupt_line{:?}", (num,)); + log::trace!("disable_interrupt_line({num})"); expect_worker_thread::(); (self.thread_group.get().unwrap().lock()) @@ -551,7 +551,7 @@ impl State { &'static self, num: InterruptNum, ) -> Result<(), PendInterruptLineError> { - log::trace!("pend_interrupt_line{:?}", (num,)); + log::trace!("pend_interrupt_line({num})"); expect_worker_thread::(); let mut lock = self.thread_group.get().unwrap().lock(); @@ -571,7 +571,7 @@ impl State { &self, num: InterruptNum, ) -> Result<(), ClearInterruptLineError> { - log::trace!("clear_interrupt_line{:?}", (num,)); + log::trace!("clear_interrupt_line({num})"); expect_worker_thread::(); (self.thread_group.get().unwrap().lock()) @@ -647,7 +647,7 @@ impl State { pub fn pend_tick_after(&self, tick_count_delta: UTicks) { expect_worker_thread::(); - log::trace!("pend_tick_after({:?})", tick_count_delta); + log::trace!("pend_tick_after({tick_count_delta:?})"); // Calculate when `timer_tick` should be called let now = Instant::now() + Duration::from_micros(tick_count_delta.into()); @@ -713,7 +713,7 @@ pub fn shutdown() { pub fn pend_interrupt_line( num: InterruptNum, ) -> Result<(), PendInterruptLineError> { - log::trace!("external-pend_interrupt_line{:?}", (num,)); + log::trace!("external-pend_interrupt_line({num})"); assert_eq!( THREAD_ROLE.with(|r| r.get()), diff --git a/src/r3_port_std/src/sched.rs b/src/r3_port_std/src/sched.rs index 6e5ecfc546..f21974aa59 100644 --- a/src/r3_port_std/src/sched.rs +++ b/src/r3_port_std/src/sched.rs @@ -124,11 +124,11 @@ impl ums::Scheduler for SchedState { fn thread_exited(&mut self, thread_id: ums::ThreadId) { let Some(i) = self.zombies.iter().position(|id| *id == thread_id) else { - log::warn!("thread_exited: unexpected thread {:?}", thread_id); + log::warn!("thread_exited: unexpected thread {thread_id:?}"); return; }; - log::trace!("removing the zombie thread {:?}", thread_id); + log::trace!("removing the zombie thread {thread_id:?}"); self.zombies.swap_remove(i); } } @@ -162,10 +162,7 @@ pub fn check_preemption_by_interrupt( // Masking by CPU Lock if sched_state.cpu_lock && is_interrupt_priority_managed(pri) { - log::trace!( - "not handling an interrupt with priority {} because of CPU Lock", - pri - ); + log::trace!("not handling an interrupt with priority {pri} because of CPU Lock"); break; } @@ -173,10 +170,8 @@ pub fn check_preemption_by_interrupt( if let Some(&(existing_pri, _)) = sched_state.active_int_handlers.last() { if existing_pri < pri { log::trace!( - "not handling an interrupt with priority {} because of \ - an active interrupt handler with priority {}", - pri, - existing_pri, + "not handling an interrupt with priority {pri} because of \ + an active interrupt handler with priority {existing_pri}", ); break; } @@ -204,11 +199,7 @@ pub fn check_preemption_by_interrupt( // Make this interrupt handler inactive let (_, popped_thread_id) = lock.scheduler().active_int_handlers.pop().unwrap(); assert_eq!(thread_id, popped_thread_id); - log::trace!( - "an interrupt handler for an interrupt {} (priority = {}) exited", - num, - pri - ); + log::trace!("an interrupt handler for an interrupt {num} (priority = {pri}) exited"); // Make sure this thread will run to completion lock.scheduler().zombies.push(thread_id); @@ -216,12 +207,7 @@ pub fn check_preemption_by_interrupt( let _ = check_preemption_by_interrupt(thread_group, &mut lock); }); - log::trace!( - "handling an interrupt {} (priority = {}) with thread {:?}", - num, - pri, - thread_id - ); + log::trace!("handling an interrupt {num} (priority = {pri}) with thread {thread_id:?}"); lock.scheduler().active_int_handlers.push((pri, thread_id)); diff --git a/src/r3_port_std/src/ums.rs b/src/r3_port_std/src/ums.rs index f4ece2e6d5..8fe00570c0 100644 --- a/src/r3_port_std/src/ums.rs +++ b/src/r3_port_std/src/ums.rs @@ -173,7 +173,7 @@ impl<'a, Sched: Scheduler> ThreadGroupLockGuard<'a, Sched> { // Save the `JoinHandle` representing the spawned thread self.guard.threads[ptr].join_handle = Some(join_handle); - log::trace!("created {:?}", thread_id); + log::trace!("created {thread_id:?}"); thread_id } @@ -307,7 +307,7 @@ fn finalize_thread( thread_id: ThreadId, result: Result<()>, ) { - log::trace!("{:?} exited with result {:?}", thread_id, result); + log::trace!("{thread_id:?} exited with result {result:?}"); // Delete the current thread let mut state_guard = thread_group.lock().unwrap(); From 9843900440e4b5dbca93f64ea30aa5eb2ba1c019 Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 17:36:30 +0900 Subject: [PATCH 08/16] refactor(examples): inline format args Ditto. The instances in `basic_wio_terminal` were missed by Clippy due to conditional compilation. --- examples/basic/src/main.rs | 2 +- examples/basic_wio_terminal/src/main.rs | 4 ++-- examples/common/build.rs | 12 +++--------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/examples/basic/src/main.rs b/examples/basic/src/main.rs index a27a5ac865..dfc25571fd 100644 --- a/examples/basic/src/main.rs +++ b/examples/basic/src/main.rs @@ -39,7 +39,7 @@ const fn configure_app(b: &mut r3_kernel::Cfg<'_, SystemTraits>) -> Objects { } fn task1_body() { - log::trace!("COTTAGE = {:#?}", COTTAGE); + log::trace!("COTTAGE = {COTTAGE:#?}"); log::trace!("KENREL = {:#?}", System::debug()); COTTAGE.task2.activate().unwrap(); diff --git a/examples/basic_wio_terminal/src/main.rs b/examples/basic_wio_terminal/src/main.rs index 97592b1c04..eed1cda658 100644 --- a/examples/basic_wio_terminal/src/main.rs +++ b/examples/basic_wio_terminal/src/main.rs @@ -848,10 +848,10 @@ fn panic(info: &PanicInfo) -> ! { #[cortex_m_rt::exception] fn DefaultHandler(x: i16) -> ! { - panic!("unhandled exception {}", x); + panic!("unhandled exception {x}"); } #[cortex_m_rt::exception] fn HardFault(fr: &cortex_m_rt::ExceptionFrame) -> ! { - panic!("hard fault: {:?}", fr); + panic!("hard fault: {fr:?}"); } diff --git a/examples/common/build.rs b/examples/common/build.rs index 7066fd384e..1e4c14bd19 100644 --- a/examples/common/build.rs +++ b/examples/common/build.rs @@ -40,7 +40,7 @@ fn main() { w!("pub static ANIMATION_FRAMES_565: &[fn() -> \ ImageRaw<'static, Rgb565, LittleEndian>] = &[\n"); for i in 0..frames.len() { - w!(" animation_{}_565,\n", i); + w!(" animation_{i}_565,\n"); } w!("];\n"); @@ -69,14 +69,8 @@ fn write_image(out: &mut impl Write, dir: &Path, name: &str, image: &RgbaImage) .collect::>(), ) .unwrap(); - w!( - "pub fn {}() -> ImageRaw<'static, Rgb565, LittleEndian> {{\n", - name565 - ); - w!( - " static IMAGE: &[u8] = include_bytes!(\"{}\");\n", - name565 - ); + w!("pub fn {name565}() -> ImageRaw<'static, Rgb565, LittleEndian> {{\n"); + w!(" static IMAGE: &[u8] = include_bytes!(\"{name565}\");\n"); w!(" ImageRaw::new(IMAGE, {})\n", image.width()); w!("}}\n"); } From de96a5d462b7a802dfedd87e299177ba8900dedc Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 16:53:37 +0900 Subject: [PATCH 09/16] doc(core): inline format args This instance was missed by Clippy due to being in a doc comment. --- src/r3_core/src/kernel/mutex.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r3_core/src/kernel/mutex.rs b/src/r3_core/src/kernel/mutex.rs index f87b962ade..2b1a5f96a1 100644 --- a/src/r3_core/src/kernel/mutex.rs +++ b/src/r3_core/src/kernel/mutex.rs @@ -67,7 +67,7 @@ define_object! { /// Err(LockMutexError::Abandoned) => { /// app.mutex.mark_consistent().unwrap(); /// } -/// Err(e) => panic!("failed to lock the mutex: {:?}", e), +/// Err(e) => panic!("failed to lock the mutex: {e:?}"), /// } /// app.mutex.unlock().unwrap(); /// } From 01b5e7c80536f017b614d85412d6d7ed56d0533e Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 17:20:22 +0900 Subject: [PATCH 10/16] refactor(port_riscv): inline format args Ditto. They were missed by Clippy due to conditional compilation. --- src/r3_port_riscv/src/threading/imp/instemu.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r3_port_riscv/src/threading/imp/instemu.rs b/src/r3_port_riscv/src/threading/imp/instemu.rs index c28a555553..dc4ebab13b 100644 --- a/src/r3_port_riscv/src/threading/imp/instemu.rs +++ b/src/r3_port_riscv/src/threading/imp/instemu.rs @@ -168,7 +168,7 @@ unsafe fn panic_on_unhandled_exception(fl_state: *mut usize, mcause: usize) -> ! // Read the original PC from the first-level state let pc = unsafe { *fl_state.offset(16) }; - panic!("unhandled exception {} at 0x{:08x}", mcause, pc); + panic!("unhandled exception {mcause} at 0x{pc:08x}"); } #[cfg(not(feature = "emulate-lr-sc"))] From 9d065b6d1fcf9ebb1ea4de29cb934252314d7594 Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 17:37:56 +0900 Subject: [PATCH 11/16] test(port_riscv): inline format args Ditto. They were missed by Clippy due to conditional compilation. --- .../src/driver_kernel_tests/execute_lr_sc.rs | 3 +-- src/r3_port_riscv_test_driver/src/panic_rtt.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/r3_port_riscv_test_driver/src/driver_kernel_tests/execute_lr_sc.rs b/src/r3_port_riscv_test_driver/src/driver_kernel_tests/execute_lr_sc.rs index 74cb07a848..102cfe2559 100644 --- a/src/r3_port_riscv_test_driver/src/driver_kernel_tests/execute_lr_sc.rs +++ b/src/r3_port_riscv_test_driver/src/driver_kernel_tests/execute_lr_sc.rs @@ -261,8 +261,7 @@ unsafe fn do_test() { let expected = unsafe { &*ST2.as_ptr() }; assert_eq!( *got, *expected, - "reached an incorrect final state after executing '{}'", - code + "reached an incorrect final state after executing '{code}'", ); } diff --git a/src/r3_port_riscv_test_driver/src/panic_rtt.rs b/src/r3_port_riscv_test_driver/src/panic_rtt.rs index 390b9d1c85..27ff4d2c94 100644 --- a/src/r3_port_riscv_test_driver/src/panic_rtt.rs +++ b/src/r3_port_riscv_test_driver/src/panic_rtt.rs @@ -11,7 +11,7 @@ fn panic(info: &PanicInfo) -> ! { if let Some(mut channel) = unsafe { UpChannel::conjure(0) } { channel.set_mode(ChannelMode::BlockIfFull); - writeln!(channel, "{}", info).ok(); + writeln!(channel, "{info}").ok(); } loop {} From c89cf2e36f25e30898aa58eb3ccd3a8a5461ecb7 Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 18:26:45 +0900 Subject: [PATCH 12/16] refactor(support_rp2040): inline format args Ditto. --- src/r3_support_rp2040/src/usbstdio.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r3_support_rp2040/src/usbstdio.rs b/src/r3_support_rp2040/src/usbstdio.rs index 52b0ec5d77..983950913d 100644 --- a/src/r3_support_rp2040/src/usbstdio.rs +++ b/src/r3_support_rp2040/src/usbstdio.rs @@ -166,7 +166,7 @@ fn map_usb_error_to_nb_error(e: usb_device::UsbError) -> nb::Error unreachable!("{:?}", e), + | usb_device::UsbError::EndpointMemoryOverflow => unreachable!("{e:?}"), // I think the following ones are protocol errors? I'm not sure // if they can be returned by `write` and `flush`. // @@ -174,7 +174,7 @@ fn map_usb_error_to_nb_error(e: usb_device::UsbError) -> nb::Error { - panic!("{:?} is probably unexpected, but I'm not sure", e) + panic!("{e:?} is probably unexpected, but I'm not sure") } } } From 4e807b9d93a684ab883ee8b9b17e619b9bc3ddca Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 17:51:19 +0900 Subject: [PATCH 13/16] test(kernel): use "alternate" hexadecimal formatting The "alternate" flag (`#`) prepends the output with a hexadecimal literal prefix `0x`. --- src/r3_kernel/src/utils/int.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r3_kernel/src/utils/int.rs b/src/r3_kernel/src/utils/int.rs index 97c4c54069..77b749c63a 100644 --- a/src/r3_kernel/src/utils/int.rs +++ b/src/r3_kernel/src/utils/int.rs @@ -280,7 +280,7 @@ mod tests { let got_set_bits: Vec = i.one_digits().collect(); - log::trace!("i = 0x{i:x}"); + log::trace!("i = {i:#x}"); log::trace!(" got = {got_set_bits:?}"); log::trace!(" expected = {set_bits:?}"); From f4e9ce1305ed642bb9c648167b24533730726ab2 Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 17:51:36 +0900 Subject: [PATCH 14/16] refactor(port_riscv): use "alternate" hexadecimal formatting Ditto. --- src/r3_port_riscv/src/threading/imp/instemu.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r3_port_riscv/src/threading/imp/instemu.rs b/src/r3_port_riscv/src/threading/imp/instemu.rs index dc4ebab13b..a3ce44704c 100644 --- a/src/r3_port_riscv/src/threading/imp/instemu.rs +++ b/src/r3_port_riscv/src/threading/imp/instemu.rs @@ -168,7 +168,7 @@ unsafe fn panic_on_unhandled_exception(fl_state: *mut usize, mcause: usize) -> ! // Read the original PC from the first-level state let pc = unsafe { *fl_state.offset(16) }; - panic!("unhandled exception {mcause} at 0x{pc:08x}"); + panic!("unhandled exception {mcause} at {pc:#08x}"); } #[cfg(not(feature = "emulate-lr-sc"))] From 00cc2e8ab0eeb75ba82d126da7c5383ee04c3ec6 Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 17:51:44 +0900 Subject: [PATCH 15/16] refactor(port_std): use "alternate" hexadecimal formatting Ditto. --- src/r3_port_std/src/threading_windows.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r3_port_std/src/threading_windows.rs b/src/r3_port_std/src/threading_windows.rs index 10d35b9700..3da7f0c72a 100644 --- a/src/r3_port_std/src/threading_windows.rs +++ b/src/r3_port_std/src/threading_windows.rs @@ -207,7 +207,7 @@ impl IsNull for *mut T { /// Panic with an error code returned by `GetLastError`. #[cold] fn panic_last_error() -> ! { - panic!("Win32 error 0x{:08x}", unsafe { + panic!("Win32 error {:#08x}", unsafe { errhandlingapi::GetLastError() }); } From 2344f900176cd79f079ad43244e931246fed018f Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 14 Jan 2023 17:52:20 +0900 Subject: [PATCH 16/16] refactor(test_runner): use "alternate" hexadecimal formatting Ditto. --- src/r3_test_runner/src/targets/jlink.rs | 4 ++-- src/r3_test_runner/src/targets/kflash.rs | 6 +++--- src/r3_test_runner/src/targets/probe_rs.rs | 2 +- src/r3_test_runner/src/targets/rp_pico.rs | 4 ++-- src/r3_test_runner/src/targets/slip.rs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/r3_test_runner/src/targets/jlink.rs b/src/r3_test_runner/src/targets/jlink.rs index 6c898b367e..6321f62fc2 100644 --- a/src/r3_test_runner/src/targets/jlink.rs +++ b/src/r3_test_runner/src/targets/jlink.rs @@ -115,9 +115,9 @@ impl DebugProbe for Fe310JLinkDebugProbe { let mut cmd = String::new(); writeln!(cmd, "r").unwrap(); for (path, (_, offset)) in section_files.iter().zip(regions.iter()) { - writeln!(cmd, "loadbin \"{}\" 0x{offset:08x}", path.display()).unwrap(); + writeln!(cmd, "loadbin \"{}\" {offset:#08x}", path.display()).unwrap(); } - writeln!(cmd, "setpc 0x{entry:x}").unwrap(); + writeln!(cmd, "setpc {entry:#x}").unwrap(); writeln!(cmd, "g").unwrap(); writeln!(cmd, "q").unwrap(); diff --git a/src/r3_test_runner/src/targets/kflash.rs b/src/r3_test_runner/src/targets/kflash.rs index 219f019696..7c9c6bd211 100644 --- a/src/r3_test_runner/src/targets/kflash.rs +++ b/src/r3_test_runner/src/targets/kflash.rs @@ -213,7 +213,7 @@ impl DebugProbe for KflashDebugProbe { log::debug!("Programming the region {} of {}", i + 1, regions.len()); if region.1 < 0x80000000 { log::debug!( - "Starting address (0x{:x}) is out of range, ignoreing", + "Starting address ({:#x}) is out of range, ignoreing", region.1 ); continue; @@ -222,7 +222,7 @@ impl DebugProbe for KflashDebugProbe { } // Boot the program - log::debug!("Booting from 0x{entry:08x}"); + log::debug!("Booting from {entry:#08x}"); boot(&mut self.serial, entry as u32).await?; // Now, pass the channel to the caller @@ -371,7 +371,7 @@ async fn flash_dataframe( let chunk_addr = address + (i * CHUNK_LEN) as u32; log::debug!( - "Programming the range {:?}/{:?} at 0x{chunk_addr:x} ({}%)", + "Programming the range {:?}/{:?} at {chunk_addr:#x} ({}%)", (i * CHUNK_LEN)..(i * CHUNK_LEN + chunk.len()), data.len(), i * CHUNK_LEN * 100 / data.len(), diff --git a/src/r3_test_runner/src/targets/probe_rs.rs b/src/r3_test_runner/src/targets/probe_rs.rs index 22d62501ca..67cc863a75 100644 --- a/src/r3_test_runner/src/targets/probe_rs.rs +++ b/src/r3_test_runner/src/targets/probe_rs.rs @@ -169,7 +169,7 @@ pub async fn attach_rtt( .await .unwrap(); if let Some(x) = addr { - log::debug!("Found the RTT header at 0x{x:x}"); + log::debug!("Found the RTT header at {x:#x}"); probe_rs_rtt::ScanRegion::Exact(x as u32) } else { probe_rs_rtt::ScanRegion::Ram diff --git a/src/r3_test_runner/src/targets/rp_pico.rs b/src/r3_test_runner/src/targets/rp_pico.rs index 966cdce93e..2427c5f0ed 100644 --- a/src/r3_test_runner/src/targets/rp_pico.rs +++ b/src/r3_test_runner/src/targets/rp_pico.rs @@ -233,7 +233,7 @@ async fn program_and_run_by_picoboot(exe: &std::path::Path) -> Result<()> { log::debug!("Transfering the image"); for (region_data, region_addr) in loadable_code.regions.iter() { log::debug!( - " ... 0x{region_addr:08x}..=0x{:08x}", + " ... {region_addr:#08x}..={:#08x}", region_addr + region_data.len() as u64 - 1 ); @@ -261,7 +261,7 @@ async fn program_and_run_by_picoboot(exe: &std::path::Path) -> Result<()> { } log::debug!( - "Rebooting RP2040 to start execution at 0x{:08x}", + "Rebooting RP2040 to start execution at {:#08x}", loadable_code.entry ); diff --git a/src/r3_test_runner/src/targets/slip.rs b/src/r3_test_runner/src/targets/slip.rs index d7b2ec2ed1..77497a6f81 100644 --- a/src/r3_test_runner/src/targets/slip.rs +++ b/src/r3_test_runner/src/targets/slip.rs @@ -32,7 +32,7 @@ enum FrameExtractorAction { #[derive(thiserror::Error, Debug, Clone, Copy)] pub enum FrameExtractorProtocolError { - #[error("Expected SLIP escape, got 0x{0:x}")] + #[error("Expected SLIP escape, got {0:#02x}")] InvalidEscape(u8), } @@ -54,7 +54,7 @@ impl FrameExtractorState { Ok(Some(FrameExtractorAction::StartFrame)) } _ => { - log::trace!("Ignoring 0x{b:?} outside a frame"); + log::trace!("Ignoring {b:#02x} outside a frame"); Ok(None) } },