Browse Source

tests: drivers: spi: loopback: test device_deinit

Introduce test for device_deinit() which deinitializes the spi
bus, then configures miso as input, mosi as output using gpio,
utilizing the loopback to test directly controlling the pins.
Then reinit the spi device.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
pull/74835/merge
Bjarki Arge Andreasen 2 weeks ago committed by Benjamin Cabé
parent
commit
ecb5457898
  1. 33
      tests/drivers/spi/spi_loopback/src/spi.c

33
tests/drivers/spi/spi_loopback/src/spi.c

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
#include <zephyr/ztest.h>
#include <zephyr/drivers/spi.h>
#include <zephyr/pm/device_runtime.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/kernel.h>
#include <stdio.h>
#include <stdarg.h>
@ -56,7 +57,8 @@ static int spec_idx; @@ -56,7 +57,8 @@ static int spec_idx;
*/
struct spi_dt_spec spec_copies[5];
const struct gpio_dt_spec miso_pin = GPIO_DT_SPEC_GET_OR(DT_PATH(zephyr_user), miso_gpios, {});
const struct gpio_dt_spec mosi_pin = GPIO_DT_SPEC_GET_OR(DT_PATH(zephyr_user), mosi_gpios, {});
/*
********************
@ -831,6 +833,35 @@ ZTEST(spi_loopback, test_spi_concurrent_transfer_different_spec) @@ -831,6 +833,35 @@ ZTEST(spi_loopback, test_spi_concurrent_transfer_different_spec)
test_spi_concurrent_transfer_helper(specs);
}
ZTEST(spi_loopback, test_spi_deinit)
{
struct spi_dt_spec *spec = loopback_specs[0];
const struct device *dev = spec->bus;
int ret;
if (miso_pin.port == NULL || mosi_pin.port == NULL) {
TC_PRINT(" zephyr,user miso-gpios or mosi-gpios are not defined\n");
ztest_test_skip();
}
ret = device_deinit(dev);
if (ret == -ENOTSUP) {
TC_PRINT(" device deinit not supported\n");
ztest_test_skip();
}
zassert_ok(ret);
zassert_ok(gpio_pin_configure_dt(&miso_pin, GPIO_INPUT));
zassert_ok(gpio_pin_configure_dt(&mosi_pin, GPIO_OUTPUT_INACTIVE));
zassert_equal(gpio_pin_get_dt(&miso_pin), 0);
zassert_ok(gpio_pin_set_dt(&mosi_pin, 1));
zassert_equal(gpio_pin_get_dt(&miso_pin), 1);
zassert_ok(gpio_pin_set_dt(&mosi_pin, 0));
zassert_equal(gpio_pin_get_dt(&miso_pin), 0);
zassert_ok(gpio_pin_configure_dt(&mosi_pin, GPIO_INPUT));
zassert_ok(device_init(dev));
}
#if (CONFIG_SPI_ASYNC)
static struct k_poll_signal async_sig = K_POLL_SIGNAL_INITIALIZER(async_sig);
static struct k_poll_event async_evt =

Loading…
Cancel
Save