diff --git a/tests/drivers/pwm/pwm_loopback/src/main.c b/tests/drivers/pwm/pwm_loopback/src/main.c index e3ccec475633e..230784030c780 100644 --- a/tests/drivers/pwm/pwm_loopback/src/main.c +++ b/tests/drivers/pwm/pwm_loopback/src/main.c @@ -22,4 +22,18 @@ static void *pwm_loopback_setup(void) return NULL; } -ZTEST_SUITE(pwm_loopback, NULL, pwm_loopback_setup, NULL, NULL, NULL); +static void pwm_loopback_after(void *f) +{ + struct test_pwm in; + struct test_pwm out; + int err; + + ARG_UNUSED(f); + + get_test_pwms(&out, &in); + + err = pwm_disable_capture(in.dev, in.pwm); + zassert_equal(err, 0, "failed to disable pwm capture (err %d)", err); +} + +ZTEST_SUITE(pwm_loopback, NULL, pwm_loopback_setup, NULL, pwm_loopback_after, NULL); diff --git a/tests/drivers/pwm/pwm_loopback/src/test_pwm_loopback.c b/tests/drivers/pwm/pwm_loopback/src/test_pwm_loopback.c index 42aed09141894..dbf4db8b036f5 100644 --- a/tests/drivers/pwm/pwm_loopback/src/test_pwm_loopback.c +++ b/tests/drivers/pwm/pwm_loopback/src/test_pwm_loopback.c @@ -85,6 +85,8 @@ static void test_capture(uint32_t period, uint32_t pulse, enum test_pwm_unit uni ztest_test_fail(); } + pwm_disable_capture(in.dev, in.pwm); + if (err == -ENOTSUP) { TC_PRINT("capture type not supported\n"); ztest_test_skip(); @@ -97,9 +99,12 @@ static void test_capture(uint32_t period, uint32_t pulse, enum test_pwm_unit uni "period capture off by more than 1%"); } - if (flags & PWM_CAPTURE_TYPE_PULSE) { + if (flags & PWM_POLARITY_INVERTED) { + zassert_within(pulse_capture, period - pulse, (period - pulse) / 100, + "pulse capture off by more than 1%"); + } else { zassert_within(pulse_capture, pulse, pulse / 100, - "pulse capture off by more than 1%"); + "pulse capture off by more than 1%"); } }