Skip to content

Commit b1e863e

Browse files
ioannis-karachalioskartben
authored andcommitted
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 <[email protected]>
1 parent 007350a commit b1e863e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,18 @@ static void *pwm_loopback_setup(void)
2222
return NULL;
2323
}
2424

25-
ZTEST_SUITE(pwm_loopback, NULL, pwm_loopback_setup, NULL, NULL, NULL);
25+
static void pwm_loopback_after(void *f)
26+
{
27+
struct test_pwm in;
28+
struct test_pwm out;
29+
int err;
30+
31+
ARG_UNUSED(f);
32+
33+
get_test_pwms(&out, &in);
34+
35+
err = pwm_disable_capture(in.dev, in.pwm);
36+
zassert_equal(err, 0, "failed to disable pwm capture (err %d)", err);
37+
}
38+
39+
ZTEST_SUITE(pwm_loopback, NULL, pwm_loopback_setup, NULL, pwm_loopback_after, NULL);

tests/drivers/pwm/pwm_loopback/src/test_pwm_loopback.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ static void test_capture(uint32_t period, uint32_t pulse, enum test_pwm_unit uni
8585
ztest_test_fail();
8686
}
8787

88+
pwm_disable_capture(in.dev, in.pwm);
89+
8890
if (err == -ENOTSUP) {
8991
TC_PRINT("capture type not supported\n");
9092
ztest_test_skip();

0 commit comments

Comments
 (0)