From b1e863e3e7d2442ab68f182b478e833e781eff14 Mon Sep 17 00:00:00 2001 From: Ioannis Karachalios Date: Sun, 10 Nov 2024 20:36:08 +0200 Subject: [PATCH] tests: pwm_loopback: Capture disable omission issue As per the PWM API definition, -EBUSY should be returned when pwm_enable_capture is called and capturing is already enabled. This commit deals with adding a ztest_suite_before_t function that should disable capturing at the end of a single test. Some tests, though, such as test_pulse_capture, execute two sub-tests and so, capturing is disabled in between. In fact, the omission of pwm_disable_capture should not only result in aborting a single test, but it can also raise system exception due to invalid context. This is the case for z_impl_pwm_capture_cycles where z_pwm_capture_cycles_callback can be fired whilst the routine has already aborted and so struct z_pwm_capture_cb_data data, defined within function declaration, should not longer be valid. Signed-off-by: Ioannis Karachalios --- tests/drivers/pwm/pwm_loopback/src/main.c | 16 +++++++++++++++- .../pwm/pwm_loopback/src/test_pwm_loopback.c | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/drivers/pwm/pwm_loopback/src/main.c b/tests/drivers/pwm/pwm_loopback/src/main.c index e3ccec47563..230784030c7 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 42aed091418..5320d087de5 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();