1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/periph/gpio_ll: test for features matching

Test that features implemented match the features claimed to be
supported.
This commit is contained in:
Marian Buschsieweke 2024-01-23 09:32:45 +01:00
parent a1bb536dbd
commit 447493e719
No known key found for this signature in database
GPG Key ID: 77AA882EC78084E6
2 changed files with 41 additions and 8 deletions

View File

@ -27,3 +27,8 @@ Implementations are allowed to not electrically disconnect GPIO pins in state
disconnected. For every MCU supported by GPIO LL so far at least some pins can
be electrically disconnected. You might need to change the GPIO pins tested
if the test for disconnected GPIOs being also electrically disconnected.
When features such as `periph_gpio_ll_pull_up` or `periph_gpio_ll_open_drain`
are provided, this test expect those to be available on the tested pins. If
those features are not available on all pins, suitable pins need to be
selected for the test to pass.

View File

@ -23,13 +23,14 @@
#include <string.h>
#include <stdlib.h>
#include "flash_utils.h"
#include "irq.h"
#include "modules.h"
#include "mutex.h"
#include "periph/gpio_ll.h"
#include "periph/gpio_ll_irq.h"
#include "timex.h"
#include "time_units.h"
#include "ztimer.h"
#include "flash_utils.h"
#ifndef LOW_ROM
#define LOW_ROM 0
@ -132,6 +133,8 @@ static void test_gpio_ll_init_input_configs(void)
is_supported = (0 == gpio_ll_init(port_in, PIN_IN_0, gpio_ll_in_pu));
printf_optional("Support for input with pull up: %s\n",
noyes[is_supported]);
/* check if this matches compile time checks */
expect(is_supported == IS_USED(MODULE_PERIPH_GPIO_LL_INPUT_PULL_UP));
if (is_supported) {
gpio_conf_t conf = gpio_ll_query_conf(port_in, PIN_IN_0);
print_conf(conf);
@ -141,6 +144,8 @@ static void test_gpio_ll_init_input_configs(void)
is_supported = (0 == gpio_ll_init(port_in, PIN_IN_0, gpio_ll_in_pd));
printf_optional("Support for input with pull down: %s\n",
noyes[is_supported]);
/* check if this matches compile time checks */
expect(is_supported == IS_USED(MODULE_PERIPH_GPIO_LL_INPUT_PULL_DOWN));
if (is_supported) {
gpio_conf_t conf = gpio_ll_query_conf(port_in, PIN_IN_0);
print_conf(conf);
@ -150,6 +155,8 @@ static void test_gpio_ll_init_input_configs(void)
is_supported = (0 == gpio_ll_init(port_in, PIN_IN_0, gpio_ll_in_pk));
printf_optional("Support for input with pull to bus level: %s\n",
noyes[is_supported]);
/* check if this matches compile time checks */
expect(is_supported == IS_USED(MODULE_PERIPH_GPIO_LL_INPUT_PULL_KEEP));
if (is_supported) {
gpio_conf_t conf = gpio_ll_query_conf(port_in, PIN_IN_0);
print_conf(conf);
@ -183,7 +190,9 @@ static void test_gpio_ll_init_output_configs(void)
"LOW: %s\n",
noyes[is_supported]);
if (is_supported) {
/* this is mandatory */
expect(is_supported);
{
gpio_conf_t conf = gpio_ll_query_conf(port_out, PIN_OUT_0);
print_conf(conf);
expect((conf.state == GPIO_OUTPUT_PUSH_PULL) && !conf.initial_value);
@ -213,7 +222,9 @@ static void test_gpio_ll_init_output_configs(void)
"HIGH: %s\n",
noyes[is_supported]);
if (is_supported) {
/* this is mandatory */
expect(is_supported);
{
gpio_conf_t conf = gpio_ll_query_conf(port_out, PIN_OUT_0);
print_conf(conf);
expect((conf.state == GPIO_OUTPUT_PUSH_PULL) && conf.initial_value);
@ -234,6 +245,8 @@ static void test_gpio_ll_init_output_configs(void)
printf_optional("Support for output (open drain with pull up) with initial "
"value of LOW: %s\n",
noyes[is_supported]);
/* check if this matches compile time checks */
expect(is_supported == IS_USED(MODULE_PERIPH_GPIO_LL_OPEN_DRAIN_PULL_UP));
if (is_supported) {
gpio_conf_t conf = gpio_ll_query_conf(port_out, PIN_OUT_0);
@ -257,6 +270,8 @@ static void test_gpio_ll_init_output_configs(void)
printf_optional("Support for output (open drain with pull up) with initial "
"value of HIGH: %s\n",
noyes[is_supported]);
/* check if this matches compile time checks */
expect(is_supported == IS_USED(MODULE_PERIPH_GPIO_LL_OPEN_DRAIN_PULL_UP));
if (is_supported) {
gpio_conf_t conf = gpio_ll_query_conf(port_out, PIN_OUT_0);
@ -280,6 +295,8 @@ static void test_gpio_ll_init_output_configs(void)
printf_optional("Support for output (open drain) with initial value of "
"LOW: %s\n",
noyes[is_supported]);
/* check if this matches compile time checks */
expect(is_supported == IS_USED(MODULE_PERIPH_GPIO_LL_OPEN_DRAIN));
if (is_supported) {
gpio_conf_t conf = gpio_ll_query_conf(port_out, PIN_OUT_0);
@ -303,6 +320,8 @@ static void test_gpio_ll_init_output_configs(void)
printf_optional("Support for output (open drain) with initial value of "
"HIGH: %s\n",
noyes[is_supported]);
/* check if this matches compile time checks */
expect(is_supported == IS_USED(MODULE_PERIPH_GPIO_LL_OPEN_DRAIN));
if (is_supported) {
gpio_conf_t conf = gpio_ll_query_conf(port_out, PIN_OUT_0);
@ -350,6 +369,8 @@ static void test_gpio_ll_init_output_configs(void)
printf_optional("Support for output (open source) with initial value of "
"LOW: %s\n",
noyes[is_supported]);
/* check if this matches compile time checks */
expect(is_supported == IS_USED(MODULE_PERIPH_GPIO_LL_OPEN_SOURCE));
if (is_supported) {
gpio_conf_t conf = gpio_ll_query_conf(port_out, PIN_OUT_0);
@ -399,6 +420,8 @@ static void test_gpio_ll_init_output_configs(void)
printf_optional("Support for output (open source) with initial value of "
"HIGH: %s\n",
noyes[is_supported]);
/* check if this matches compile time checks */
expect(is_supported == IS_USED(MODULE_PERIPH_GPIO_LL_OPEN_SOURCE));
if (is_supported) {
gpio_conf_t conf = gpio_ll_query_conf(port_out, PIN_OUT_0);
@ -419,9 +442,11 @@ static void test_gpio_ll_init_output_configs(void)
};
is_supported = (0 == gpio_ll_init(port_out, PIN_OUT_0, conf));
}
printf_optional("Support for output (open source with pull up) with initial "
printf_optional("Support for output (open source with pull down) with initial "
"value of HIGH: %s\n",
noyes[is_supported]);
/* check if this matches compile time checks */
expect(is_supported == IS_USED(MODULE_PERIPH_GPIO_LL_OPEN_SOURCE_PULL_DOWN));
if (is_supported) {
ztimer_sleep(ZTIMER_USEC, US_PER_MS);
@ -438,9 +463,11 @@ static void test_gpio_ll_init_output_configs(void)
};
is_supported = (0 == gpio_ll_init(port_out, PIN_OUT_0, conf));
}
printf_optional("Support for output (open source with pull up) with initial "
printf_optional("Support for output (open source with pull down) with initial "
"value of LOW: %s\n",
noyes[is_supported]);
/* check if this matches compile time checks */
expect(is_supported == IS_USED(MODULE_PERIPH_GPIO_LL_OPEN_SOURCE_PULL_DOWN));
if (is_supported) {
ztimer_sleep(ZTIMER_USEC, US_PER_MS);
@ -475,12 +502,13 @@ static void test_gpio_ll_init(void)
};
is_supported = (0 == gpio_ll_init(port_out, PIN_OUT_0, conf));
}
printf_optional("Support for disconnecting GPIO: %s\n", noyes[is_supported]);
printf_optional("\nSupport for disconnecting GPIO: %s\n", noyes[is_supported]);
/* This is mandatory */
expect(is_supported);
/* Ensure that gpio_ll_query_conf() correctly detects the state as
* disconnected. */
* disconnected. On MCUs that don't support this (e.g. ATmega),
* GPIO_DISCONNECT must be an alias of GPIO_INPUT. */
{
gpio_conf_t conf = gpio_ll_query_conf(port_out, PIN_OUT_0);
gpio_ll_print_conf(conf);