Skip to content

Commit bc12672

Browse files
jilaypandyahenrikbrixandersen
authored andcommitted
tests: stepper: deprecate drv84xx_api test suite
refactor move_to_negative_direction, run_positive as well as run_negative direction from drv84xx_api to stepper test-suite refactor test_microstep_resolution to drv84xx_emul Signed-off-by: Jilay Pandya <[email protected]>
1 parent 215df9f commit bc12672

File tree

9 files changed

+97
-241
lines changed

9 files changed

+97
-241
lines changed

tests/drivers/stepper/drv84xx/api/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/drivers/stepper/drv84xx/api/Kconfig

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/drivers/stepper/drv84xx/api/boards/native_sim.overlay

Lines changed: 0 additions & 52 deletions
This file was deleted.

tests/drivers/stepper/drv84xx/api/prj.conf

Lines changed: 0 additions & 12 deletions
This file was deleted.

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

Lines changed: 0 additions & 145 deletions
This file was deleted.

tests/drivers/stepper/drv84xx/api/testcase.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/drivers/stepper/drv84xx/emul/boards/native_sim.overlay

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
sleep-gpios = <&gpio2 0 GPIO_ACTIVE_LOW>; /* D2 */
1717
en-gpios = <&gpio2 1 0>; /* 5 */
1818
m0-gpios = <&gpio3 0 0>;
19-
m1-gpios = <&gpio3 1 0>;
19+
m1-gpios = <&gpio4 1 0>;
2020
counter = <&counter0>;
2121

2222
#address-cells = <1>;
@@ -44,4 +44,11 @@
4444
status = "okay";
4545
gpio-controller;
4646
};
47+
48+
gpio4: gpio4 {
49+
compatible = "zephyr,gpio-emul";
50+
#gpio-cells = <0x2>;
51+
status = "okay";
52+
gpio-controller;
53+
};
4754
};

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct drv84xx_emul_fixture {
1919

2020
struct gpio_dt_spec en_pin = GPIO_DT_SPEC_GET_OR(DT_NODELABEL(drv84xx), en_gpios, {0});
2121
struct gpio_dt_spec slp_pin = GPIO_DT_SPEC_GET_OR(DT_NODELABEL(drv84xx), sleep_gpios, {0});
22+
struct gpio_dt_spec m0_pin = GPIO_DT_SPEC_GET_OR(DT_NODELABEL(drv84xx), m0_gpios, {0});
23+
struct gpio_dt_spec m1_pin = GPIO_DT_SPEC_GET_OR(DT_NODELABEL(drv84xx), m1_gpios, {0});
2224

2325
static void *drv84xx_emul_setup(void)
2426
{
@@ -77,4 +79,26 @@ ZTEST_F(drv84xx_emul, test_enable_off_gpio_pins)
7779
}
7880
}
7981

82+
ZTEST_F(drv84xx_emul, test_micro_step_res_set)
83+
{
84+
enum stepper_micro_step_resolution res;
85+
int value = 0;
86+
87+
zassert_ok(stepper_set_micro_step_res(fixture->dev, 4));
88+
89+
if (m0_pin.port == NULL || m1_pin.port == NULL) {
90+
ztest_test_skip();
91+
}
92+
93+
value = gpio_emul_output_get(m0_pin.port, m0_pin.pin);
94+
zassert_equal(value, 0, "M0 pin should be 0");
95+
96+
value = gpio_emul_output_get(m1_pin.port, m1_pin.pin);
97+
zassert_equal(value, 1, "M1 pin should be 1");
98+
99+
zassert_ok(stepper_get_micro_step_res(fixture->dev, &res));
100+
zassert_equal(res, 4, "Micro step resolution not set correctly, should be %d but is %d", 4,
101+
res);
102+
}
103+
80104
ZTEST_SUITE(drv84xx_emul, NULL, drv84xx_emul_setup, drv84xx_emul_before, drv84xx_emul_after, NULL);

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,33 @@ ZTEST_F(stepper, test_move_to_positive_step_count)
156156
fixture->dev->name);
157157
}
158158

159+
ZTEST_F(stepper, test_move_to_negative_step_count)
160+
{
161+
int32_t pos = -10;
162+
int32_t actual_steps;
163+
bool moving = false;
164+
int ret;
165+
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_to(fixture->dev, pos));
172+
zassert_ok(stepper_is_moving(fixture->dev, &moving));
173+
zassert_true(moving, "%s reported not moving after move_to", fixture->dev->name);
174+
175+
POLL_AND_CHECK_SIGNAL(
176+
stepper_signal, stepper_event, STEPPER_EVENT_STEPS_COMPLETED,
177+
K_MSEC(-pos * (100 + CONFIG_STEPPER_TEST_TIMING_TIMEOUT_TOLERANCE_PCT)));
178+
179+
zassert_ok(stepper_get_actual_position(fixture->dev, &actual_steps));
180+
zassert_equal(pos, actual_steps, "Position should be %d but is %d", pos, 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);
184+
}
185+
159186
ZTEST_F(stepper, test_move_by_positive_step_count)
160187
{
161188
int32_t steps = 20;
@@ -210,6 +237,44 @@ ZTEST_F(stepper, test_move_by_negative_step_count)
210237
fixture->dev->name);
211238
}
212239

240+
ZTEST_F(stepper, test_run_positive_direction)
241+
{
242+
uint64_t step_interval = 20000000;
243+
int32_t actual_steps = 0;
244+
int ret;
245+
246+
ret = stepper_set_microstep_interval(fixture->dev, step_interval);
247+
if (ret == -ENOSYS) {
248+
ztest_test_skip();
249+
}
250+
251+
zassert_ok(stepper_run(fixture->dev, STEPPER_DIRECTION_POSITIVE));
252+
k_usleep(110000);
253+
254+
zassert_ok(stepper_get_actual_position(fixture->dev, &actual_steps));
255+
zassert_true(IN_RANGE(actual_steps, 1, 6),
256+
"Current position should be between 1 and 6 but is %d", actual_steps);
257+
}
258+
259+
ZTEST_F(stepper, test_run_negative_direction)
260+
{
261+
uint64_t step_interval = 20000000;
262+
int32_t actual_steps = 0;
263+
int ret;
264+
265+
ret = stepper_set_microstep_interval(fixture->dev, step_interval);
266+
if (ret == -ENOSYS) {
267+
ztest_test_skip();
268+
}
269+
270+
zassert_ok(stepper_run(fixture->dev, STEPPER_DIRECTION_NEGATIVE));
271+
k_usleep(110000);
272+
273+
zassert_ok(stepper_get_actual_position(fixture->dev, &actual_steps));
274+
zassert_true(IN_RANGE(actual_steps, -6, -1),
275+
"Current position should be between -6 and -1 but is %d", actual_steps);
276+
}
277+
213278
ZTEST_F(stepper, test_stop)
214279
{
215280
/* Run the stepper in positive direction */

0 commit comments

Comments
 (0)