Skip to content

Commit 17bd782

Browse files
committed
Fix tests
1 parent a669b3c commit 17bd782

File tree

2 files changed

+19
-32
lines changed

2 files changed

+19
-32
lines changed

tests/nucleo-g474.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![no_std]
22
#![no_main]
3+
#![allow(clippy::uninlined_format_args)]
34

45
#[path = "../examples/utils/mod.rs"]
56
mod utils;
@@ -49,7 +50,6 @@ mod tests {
4950
let dp = stm32::Peripherals::take().unwrap();
5051
let mut rcc = dp.RCC.constrain();
5152
let mut delay = cp.SYST.delay(&rcc.clocks);
52-
defmt::dbg!(rcc.clocks.sys_clk);
5353

5454
let gpioa = dp.GPIOA.split(&mut rcc);
5555
let _pa1_important_dont_use_as_output = gpioa.pa1.into_floating_input();
@@ -132,19 +132,13 @@ mod tests {
132132
hi_duration = await_lo(&timer, pin_num, max).unwrap();
133133
assert!(
134134
hi_duration > min && hi_duration < max,
135-
"hi: {} < {} < {}",
136-
min,
137-
hi_duration,
138-
max
135+
"hi: {min} < {hi_duration} < {max}"
139136
);
140137

141138
lo_duration = await_hi(&timer, pin_num, max).unwrap();
142139
assert!(
143140
lo_duration > min && lo_duration < max,
144-
"lo: {} < {} < {}",
145-
min,
146-
lo_duration,
147-
max
141+
"lo: {min} < {lo_duration} < {max}"
148142
);
149143
}
150144

@@ -231,7 +225,7 @@ mod tests {
231225
adc::config::Resolution::Twelve,
232226
);
233227
debug!("temp: {}°C", temp);
234-
assert!((20.0..35.0).contains(&temp), "20.0 < {} < 35.0", temp);
228+
assert!((20.0..35.0).contains(&temp), "20.0 < {temp} < 35.0");
235229
}
236230

237231
#[test]
@@ -265,7 +259,7 @@ mod tests {
265259
adc.configure_channel(&Vref, adc::config::Sequence::One, sample_time);
266260
adc.configure_channel(&Temperature, adc::config::Sequence::Two, sample_time);
267261

268-
defmt::info!("Setup DMA");
262+
debug!("Setup DMA");
269263
let first_buffer = cortex_m::singleton!(: [u16; 2] = [0; 2]).unwrap();
270264
let mut transfer = channels.ch1.into_peripheral_to_memory_transfer(
271265
adc.enable_dma(adc::config::Dma::Single),
@@ -275,9 +269,9 @@ mod tests {
275269

276270
transfer.start(|adc| adc.start_conversion());
277271

278-
defmt::info!("Wait for Conversion");
272+
debug!("Wait for Conversion");
279273
while !transfer.get_transfer_complete_flag() {}
280-
defmt::info!("Conversion Done");
274+
debug!("Conversion Done");
281275

282276
transfer.pause(|adc| adc.cancel_conversion());
283277
let (_ch1, adc, first_buffer) = transfer.free();
@@ -302,6 +296,6 @@ mod tests {
302296
adc::config::Resolution::Twelve,
303297
);
304298
debug!("temp: {}°C", temp);
305-
assert!((20.0..35.0).contains(&temp), "20.0 < {} < 35.0", temp);
299+
assert!((20.0..35.0).contains(&temp), "20.0 < {temp} < 35.0");
306300
}
307301
}

tests/nucleo-g474_w_jumpers.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#![no_std]
22
#![no_main]
3+
#![allow(clippy::uninlined_format_args)]
34

45
// Requires a jumper from A1<->A2 (arduino naming) aka PA1<->PA4
56

67
#[path = "../examples/utils/mod.rs"]
78
mod utils;
89

10+
use utils::logger::println;
11+
912
mod common;
1013

1114
use stm32g4xx_hal::adc::{self, AdcClaim, AdcCommonExt};
@@ -83,9 +86,7 @@ mod tests {
8386
let reading = adc.convert(&opamp, sample_time);
8487
assert!(
8588
reading.abs_diff(setpoint) < 10,
86-
"reading: {}, setpoint {}",
87-
reading,
88-
setpoint
89+
"reading: {reading}, setpoint {setpoint}"
8990
);
9091
}
9192
}
@@ -114,9 +115,7 @@ mod tests {
114115
let reading = adc.convert(&pa2, sample_time);
115116
assert!(
116117
reading.abs_diff(setpoint) < 10,
117-
"reading: {}, setpoint {}",
118-
reading,
119-
setpoint
118+
"reading: {reading}, setpoint {setpoint}"
120119
);
121120
}
122121
}
@@ -141,9 +140,7 @@ mod tests {
141140
let reading = adc.convert(&opamp, sample_time);
142141
assert!(
143142
reading.abs_diff((setpoint * 2).min(4095)) < 20,
144-
"reading: {}, setpoint {}",
145-
reading,
146-
setpoint
143+
"reading: {reading}, setpoint {setpoint}"
147144
);
148145
}
149146
}
@@ -180,8 +177,7 @@ mod tests {
180177
let out = comp.output();
181178
assert!(
182179
comp.output() == (value_setpoint > ref_setpoint),
183-
"setpoint: {}, expected: '{}', got '{}'",
184-
value_setpoint,
180+
"setpoint: {value_setpoint}, expected: '{}', got '{}'",
185181
if value_setpoint > ref_setpoint {
186182
"HI"
187183
} else {
@@ -224,8 +220,7 @@ mod tests {
224220
let out = comp.output();
225221
assert!(
226222
comp.output() == (value_setpoint > ref_setpoint),
227-
"setpoint: {}, expected: '{}', got '{}'",
228-
value_setpoint,
223+
"setpoint: {value_setpoint}, expected: '{}', got '{}'",
229224
if value_setpoint > ref_setpoint {
230225
"HI"
231226
} else {
@@ -246,6 +241,7 @@ mod tests {
246241
///
247242
#[test]
248243
fn comp_dac_dac() {
244+
use super::*;
249245
let super::Peripherals {
250246
comp,
251247
mut value_dac,
@@ -264,7 +260,7 @@ mod tests {
264260
for s_ref in 4..=255 {
265261
let s_ref = s_ref << 4; // Convert from 8 to 12 bits
266262
if s_ref & 0xFF == 0 {
267-
defmt::println!("{}/{}...", s_ref, 4095);
263+
println!("{}/4095...", s_ref);
268264
}
269265
ref_dac.set_value(s_ref);
270266
for s_value in 0..=255 {
@@ -275,10 +271,7 @@ mod tests {
275271
if s_value.abs_diff(s_ref) > 20 {
276272
assert!(
277273
out == (s_value > s_ref),
278-
"s_value: {}, s_ref: {}, out: {}",
279-
s_value,
280-
s_ref,
281-
out
274+
"s_value: {s_value}, s_ref: {s_ref}, out: {out}"
282275
);
283276
}
284277
}

0 commit comments

Comments
 (0)