Skip to content

Commit 215df9f

Browse files
jilaypandyahenrikbrixandersen
authored andcommitted
tests: stepper_api: check is_moving in stepper_api tests
add is_moving check to already existing stepper_api move_by and move_to tests. delete corresponding redundant test cases from drv84xx bugfixes in step_dir_stepper_common.c - start_stepping shall return 0 instead of return ret since timing_source_start can return 1 depending on which timing source in selected - stop timing source before triggering steps_completed event Signed-off-by: Jilay Pandya <[email protected]>
1 parent 5117b77 commit 215df9f

File tree

3 files changed

+45
-80
lines changed

3 files changed

+45
-80
lines changed

drivers/stepper/step_dir/step_dir_stepper_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static int start_stepping(const struct device *dev)
110110
}
111111

112112
stepper_handle_timing_signal(dev);
113-
return ret;
113+
return 0;
114114
}
115115

116116
static void update_remaining_steps(const struct device *dev)
@@ -151,8 +151,8 @@ static void position_mode_task(const struct device *dev)
151151
if (config->timing_source->needs_reschedule(dev) && atomic_get(&data->step_count) != 0) {
152152
(void)config->timing_source->start(dev);
153153
} else if (atomic_get(&data->step_count) == 0) {
154-
stepper_trigger_callback(data->dev, STEPPER_EVENT_STEPS_COMPLETED);
155154
config->timing_source->stop(data->dev);
155+
stepper_trigger_callback(data->dev, STEPPER_EVENT_STEPS_COMPLETED);
156156
}
157157
}
158158

tests/drivers/stepper/drv84xx/api/src/main.c

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -99,74 +99,6 @@ ZTEST_F(drv84xx_api, test_move_to_negative_direction_movement)
9999
zassert_equal(pos, -50, "Target position should be %d but is %d", -50, pos);
100100
}
101101

102-
ZTEST_F(drv84xx_api, test_move_to_is_moving_true_while_moving)
103-
{
104-
int32_t pos = 50;
105-
bool moving = false;
106-
107-
(void)stepper_enable(fixture->dev);
108-
(void)stepper_set_microstep_interval(fixture->dev, 20000000);
109-
(void)stepper_set_event_callback(fixture->dev, fixture->callback, NULL);
110-
(void)stepper_move_to(fixture->dev, pos);
111-
(void)stepper_is_moving(fixture->dev, &moving);
112-
zassert_true(moving, "Driver should be in state is_moving while moving");
113-
}
114-
115-
ZTEST_F(drv84xx_api, test_move_to_is_moving_false_when_completed)
116-
{
117-
int32_t pos = 50;
118-
bool moving = false;
119-
120-
(void)stepper_enable(fixture->dev);
121-
(void)stepper_set_microstep_interval(fixture->dev, 20000000);
122-
(void)stepper_set_event_callback(fixture->dev, fixture->callback, NULL);
123-
(void)stepper_move_to(fixture->dev, pos);
124-
(void)k_poll(&stepper_event, 1, K_SECONDS(5));
125-
unsigned int signaled;
126-
int result;
127-
128-
k_poll_signal_check(&stepper_signal, &signaled, &result);
129-
zassert_equal(signaled, 1, "No event detected");
130-
zassert_equal(result, STEPPER_EVENT_STEPS_COMPLETED,
131-
"Event was not STEPPER_EVENT_STEPS_COMPLETED event");
132-
(void)stepper_is_moving(fixture->dev, &moving);
133-
zassert_false(moving, "Driver should not be in state is_moving after finishing");
134-
}
135-
136-
ZTEST_F(drv84xx_api, test_move_by_is_moving_true_while_moving)
137-
{
138-
int32_t steps = 50;
139-
bool moving = false;
140-
141-
(void)stepper_enable(fixture->dev);
142-
(void)stepper_set_microstep_interval(fixture->dev, 20000000);
143-
(void)stepper_set_event_callback(fixture->dev, fixture->callback, NULL);
144-
(void)stepper_move_by(fixture->dev, steps);
145-
(void)stepper_is_moving(fixture->dev, &moving);
146-
zassert_true(moving, "Driver should be in state is_moving");
147-
}
148-
149-
ZTEST_F(drv84xx_api, test_move_by_is_moving_false_when_completed)
150-
{
151-
int32_t steps = 50;
152-
bool moving = true;
153-
154-
(void)stepper_enable(fixture->dev);
155-
(void)stepper_set_microstep_interval(fixture->dev, 20000000);
156-
(void)stepper_set_event_callback(fixture->dev, fixture->callback, NULL);
157-
(void)stepper_move_by(fixture->dev, steps);
158-
(void)k_poll(&stepper_event, 1, K_SECONDS(5));
159-
unsigned int signaled;
160-
int result;
161-
162-
k_poll_signal_check(&stepper_signal, &signaled, &result);
163-
zassert_equal(signaled, 1, "No event detected");
164-
zassert_equal(result, STEPPER_EVENT_STEPS_COMPLETED,
165-
"Event was not STEPPER_EVENT_STEPS_COMPLETED event");
166-
(void)stepper_is_moving(fixture->dev, &moving);
167-
zassert_false(moving, "Driver should not be in state is_moving after completion");
168-
}
169-
170102
ZTEST_F(drv84xx_api, test_run_positive_direction_correct_position)
171103
{
172104
uint64_t step_interval = 20000000;

tests/drivers/stepper/stepper_api/src/main.c

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ ZTEST_F(stepper, test_actual_position)
131131
ZTEST_F(stepper, test_move_to_positive_step_count)
132132
{
133133
int32_t pos = 10u;
134+
int32_t actual_steps;
135+
bool moving = false;
134136
int ret;
135137

136138
ret = stepper_set_microstep_interval(fixture->dev, 100 * USEC_PER_SEC);
@@ -139,42 +141,73 @@ ZTEST_F(stepper, test_move_to_positive_step_count)
139141
}
140142

141143
zassert_ok(stepper_move_to(fixture->dev, pos));
144+
zassert_ok(stepper_is_moving(fixture->dev, &moving));
145+
zassert_true(moving, "%s reported not moving after move_to", fixture->dev->name);
142146

143147
POLL_AND_CHECK_SIGNAL(
144148
stepper_signal, stepper_event, STEPPER_EVENT_STEPS_COMPLETED,
145149
K_MSEC(pos * (100 + CONFIG_STEPPER_TEST_TIMING_TIMEOUT_TOLERANCE_PCT)));
146150

147-
zassert_ok(stepper_get_actual_position(fixture->dev, &pos));
148-
zassert_equal(pos, 10u, "Target position should be %d but is %d", 10u, pos);
151+
zassert_ok(stepper_get_actual_position(fixture->dev, &actual_steps));
152+
zassert_equal(pos, actual_steps, "Position should be %d but is %d", pos, actual_steps);
149153
zassert_equal(user_data_received, fixture->dev, "User data not received");
154+
zassert_ok(stepper_is_moving(fixture->dev, &moving));
155+
zassert_false(moving, "%s reported moving even after completion of steps",
156+
fixture->dev->name);
150157
}
151158

152159
ZTEST_F(stepper, test_move_by_positive_step_count)
153160
{
154161
int32_t steps = 20;
162+
int32_t actual_steps;
163+
bool moving = false;
164+
int ret;
155165

156-
(void)stepper_set_microstep_interval(fixture->dev, 100 * USEC_PER_SEC);
157-
(void)stepper_move_by(fixture->dev, steps);
166+
ret = stepper_set_microstep_interval(fixture->dev, 100 * USEC_PER_SEC);
167+
if (ret == -ENOSYS) {
168+
ztest_test_skip();
169+
}
170+
171+
zassert_ok(stepper_move_by(fixture->dev, steps));
172+
zassert_ok(stepper_is_moving(fixture->dev, &moving));
173+
zassert_true(moving, "%s reported not moving after move_by", fixture->dev->name);
158174

159175
POLL_AND_CHECK_SIGNAL(
160176
stepper_signal, stepper_event, STEPPER_EVENT_STEPS_COMPLETED,
161177
K_MSEC(steps * (100 + CONFIG_STEPPER_TEST_TIMING_TIMEOUT_TOLERANCE_PCT)));
162-
(void)stepper_get_actual_position(fixture->dev, &steps);
163-
zassert_equal(steps, 20u, "Target position should be %d but is %d", 20u, steps);
178+
179+
zassert_ok(stepper_get_actual_position(fixture->dev, &actual_steps));
180+
zassert_equal(steps, actual_steps, "Position should be %d but is %d", steps, actual_steps);
181+
zassert_ok(stepper_is_moving(fixture->dev, &moving));
182+
zassert_false(moving, "%s reported moving even after completion of steps",
183+
fixture->dev->name);
164184
}
165185

166186
ZTEST_F(stepper, test_move_by_negative_step_count)
167187
{
168188
int32_t steps = -20;
189+
int32_t actual_steps;
190+
bool moving = false;
191+
int ret;
192+
193+
ret = stepper_set_microstep_interval(fixture->dev, 100 * USEC_PER_SEC);
194+
if (ret == -ENOSYS) {
195+
ztest_test_skip();
196+
}
169197

170-
(void)stepper_set_microstep_interval(fixture->dev, 100 * USEC_PER_SEC);
171-
(void)stepper_move_by(fixture->dev, steps);
198+
zassert_ok(stepper_move_by(fixture->dev, steps));
199+
zassert_ok(stepper_is_moving(fixture->dev, &moving));
200+
zassert_true(moving, "%s reported not moving after move_by", fixture->dev->name);
172201

173202
POLL_AND_CHECK_SIGNAL(
174203
stepper_signal, stepper_event, STEPPER_EVENT_STEPS_COMPLETED,
175204
K_MSEC(-steps * (100 + CONFIG_STEPPER_TEST_TIMING_TIMEOUT_TOLERANCE_PCT)));
176-
(void)stepper_get_actual_position(fixture->dev, &steps);
177-
zassert_equal(steps, -20u, "Target position should be %d but is %d", -20u, steps);
205+
206+
zassert_ok(stepper_get_actual_position(fixture->dev, &actual_steps));
207+
zassert_equal(steps, actual_steps, "Position should be %d but is %d", steps, actual_steps);
208+
zassert_ok(stepper_is_moving(fixture->dev, &moving));
209+
zassert_false(moving, "%s reported moving even after completion of steps",
210+
fixture->dev->name);
178211
}
179212

180213
ZTEST_F(stepper, test_stop)

0 commit comments

Comments
 (0)