Skip to content

Commit 0878bed

Browse files
nordic-pikrrlubos
authored andcommitted
[nrf fromlist] tests: drivers: pwm_gpio_loopback: Test improvement
Improve corss-channel test by setting different duty cycle on channels. This modification will enable detection of inter-channel effects like crosstalk. Upstream PR #: 93776 Signed-off-by: Piotr Krzyzanowski <[email protected]>
1 parent 5769fca commit 0878bed

File tree

1 file changed

+16
-7
lines changed
  • tests/drivers/pwm/pwm_gpio_loopback/src

1 file changed

+16
-7
lines changed

tests/drivers/pwm/pwm_gpio_loopback/src/main.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,25 @@ ZTEST(pwm_gpio_loopback, test_pwm)
234234

235235
ZTEST(pwm_gpio_loopback, test_pwm_cross)
236236
{
237+
uint8_t duty[TEST_PWM_COUNT];
238+
const int duty_step = 25;
239+
const int duty_variations = 5;
240+
241+
/* Initial sweep with increasing duty cycles */
237242
for (int i = 0; i < TEST_PWM_COUNT; i++) {
238-
/* Test case: [Duty: 40%] */
239-
test_run(&pwms_dt[i], &gpios_dt[i], 40, true);
243+
duty[i] = (i % duty_variations) * duty_step;
244+
test_run(&pwms_dt[i], &gpios_dt[i], duty[i], true);
240245
}
241246

242-
/* Set all channels and check if they retain the original
243-
* configuration without calling pwm_set again
244-
*/
245-
for (int i = 0; i < TEST_PWM_COUNT; i++) {
246-
test_run(&pwms_dt[i], &gpios_dt[i], 40, false);
247+
/* Repeat test with persistent config checks and rotated duty cycles */
248+
for (int j = 1; j < duty_variations; j++) {
249+
for (int i = 0; i < TEST_PWM_COUNT; i++) {
250+
test_run(&pwms_dt[i], &gpios_dt[i], duty[i], false);
251+
}
252+
for (int i = 0; i < TEST_PWM_COUNT; i++) {
253+
duty[i] = ((j + i) % duty_variations) * duty_step;
254+
test_run(&pwms_dt[i], &gpios_dt[i], duty[i], true);
255+
}
247256
}
248257
}
249258

0 commit comments

Comments
 (0)