tests: drivers: gpio: move the gpio 1pin test to new ztest API

Migrate the testsuite tests/drivers/gpio/gpio_api_1pin to the
new ztest API.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
This commit is contained in:
Enjia Mai 2022-08-26 15:38:37 +08:00 committed by Carles Cufí
commit 59884f3b88
6 changed files with 37 additions and 69 deletions

View file

@ -1,2 +1,3 @@
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_GPIO=y

View file

@ -1,41 +0,0 @@
/*
* Copyright (c) 2019 Piotr Mienkowski
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "test_gpio_api.h"
void test_main(void)
{
ztest_test_suite(gpio_api_1pin_test,
ztest_unit_test(test_gpio_pin_configure_push_pull),
ztest_unit_test(test_gpio_pin_configure_single_ended),
ztest_unit_test(test_gpio_pin_set_get_raw),
ztest_unit_test(test_gpio_pin_set_get),
ztest_unit_test(test_gpio_pin_set_get_active_high),
ztest_unit_test(test_gpio_pin_set_get_active_low),
ztest_unit_test(test_gpio_pin_toggle),
ztest_unit_test(test_gpio_port_set_masked_get_raw),
ztest_unit_test(test_gpio_port_set_masked_get),
ztest_unit_test(test_gpio_port_set_masked_get_active_high),
ztest_unit_test(test_gpio_port_set_masked_get_active_low),
ztest_unit_test(test_gpio_port_set_bits_clear_bits_raw),
ztest_unit_test(test_gpio_port_set_bits_clear_bits),
ztest_unit_test(test_gpio_port_set_clr_bits_raw),
ztest_unit_test(test_gpio_port_set_clr_bits),
ztest_unit_test(test_gpio_port_toggle),
ztest_unit_test(test_gpio_int_edge_rising),
ztest_unit_test(test_gpio_int_edge_falling),
ztest_unit_test(test_gpio_int_edge_both),
ztest_unit_test(test_gpio_int_edge_to_active),
ztest_unit_test(test_gpio_int_edge_to_inactive),
ztest_unit_test(test_gpio_int_level_high_interrupt_count_1),
ztest_unit_test(test_gpio_int_level_high_interrupt_count_5),
ztest_unit_test(test_gpio_int_level_low_interrupt_count_1),
ztest_unit_test(test_gpio_int_level_low_interrupt_count_5),
ztest_unit_test(test_gpio_int_level_active),
ztest_unit_test(test_gpio_int_level_inactive),
ztest_unit_test(test_gpio_pin_toggle_visual));
ztest_run_test_suite(gpio_api_1pin_test);
}

View file

@ -45,7 +45,7 @@ static void pin_set_raw_and_verify(const struct device *port,
* - Verify that it is not possible to change value of a pin via
* gpio_pin_set_raw function if pin is configured as an input.
*/
void test_gpio_pin_configure_push_pull(void)
ZTEST(gpio_api_1pin_conf, test_gpio_pin_configure_push_pull)
{
const struct device *port;
int ret;
@ -159,7 +159,7 @@ void test_gpio_pin_configure_push_pull(void)
* configured as input is low. Drivers that do not support Open
* Drain flag return ENOTSUP.
*/
void test_gpio_pin_configure_single_ended(void)
ZTEST(gpio_api_1pin_conf, test_gpio_pin_configure_single_ended)
{
const struct device *port;
int pin_in_val;
@ -303,3 +303,5 @@ void test_gpio_pin_configure_single_ended(void)
pin_get_raw_and_verify(port, TEST_PIN, 0, TEST_POINT(8));
}
}
ZTEST_SUITE(gpio_api_1pin_conf, NULL, NULL, NULL, NULL, NULL);

View file

@ -57,7 +57,7 @@ static void pin_set_and_verify(const struct device *port, unsigned int pin,
* - Verify that gpio_pin_toggle function changes pin state from active to
* inactive and vice versa.
*/
void test_gpio_pin_toggle(void)
ZTEST(gpio_api_1pin_pin, test_gpio_pin_toggle)
{
const struct device *port;
int val_expected;
@ -99,7 +99,7 @@ void test_gpio_pin_toggle(void)
* - Verify visually that gpio_pin_toggle function changes pin state from active
* to inactive and vice versa.
*/
void test_gpio_pin_toggle_visual(void)
ZTEST(gpio_api_1pin_pin, test_gpio_pin_toggle_visual)
{
const struct device *port;
int val_expected;
@ -134,7 +134,7 @@ void test_gpio_pin_toggle_visual(void)
* - Verify that gpio_pin_get_raw reads the same value as set by
* gpio_pin_set_raw function.
*/
void test_gpio_pin_set_get_raw(void)
ZTEST(gpio_api_1pin_pin, test_gpio_pin_set_get_raw)
{
const struct device *port;
int val_expected;
@ -171,7 +171,7 @@ void test_gpio_pin_set_get_raw(void)
* - Verify that gpio_pin_get reads the same value as set by gpio_pin_set
* function.
*/
void test_gpio_pin_set_get(void)
ZTEST(gpio_api_1pin_pin, test_gpio_pin_set_get)
{
const struct device *port;
int val_expected;
@ -210,7 +210,7 @@ void test_gpio_pin_set_get(void)
* - Verify that there is no functional difference between gpio_pin_get_raw and
* gpio_pin_get functions if the pin is configured as Active High.
*/
void test_gpio_pin_set_get_active_high(void)
ZTEST(gpio_api_1pin_pin, test_gpio_pin_set_get_active_high)
{
const struct device *port;
int val_expected;
@ -260,7 +260,7 @@ void test_gpio_pin_set_get_active_high(void)
* - Verify that value read by gpio_pin_get function is inverted compared to
* gpio_pin_get_raw if the pin is configured as Active Low.
*/
void test_gpio_pin_set_get_active_low(void)
ZTEST(gpio_api_1pin_pin, test_gpio_pin_set_get_active_low)
{
const struct device *port;
int val_expected, val_raw_expected;
@ -304,3 +304,5 @@ void test_gpio_pin_set_get_active_low(void)
pin_get_raw_and_verify(port, TEST_PIN, val_raw_expected, i);
}
}
ZTEST_SUITE(gpio_api_1pin_pin, NULL, NULL, NULL, NULL, NULL);

View file

@ -206,25 +206,25 @@ void test_gpio_pin_interrupt_level(unsigned int cfg_flags,
}
/** @brief Verify GPIO_INT_EDGE_RISING flag. */
void test_gpio_int_edge_rising(void)
ZTEST(gpio_api_1pin_int, test_gpio_int_edge_rising)
{
test_gpio_pin_interrupt_edge(0, GPIO_INT_EDGE_RISING);
}
/** @brief Verify GPIO_INT_EDGE_FALLING flag. */
void test_gpio_int_edge_falling(void)
ZTEST(gpio_api_1pin_int, test_gpio_int_edge_falling)
{
test_gpio_pin_interrupt_edge(0, GPIO_INT_EDGE_FALLING);
}
/** @brief Verify GPIO_INT_EDGE_BOTH flag. */
void test_gpio_int_edge_both(void)
ZTEST(gpio_api_1pin_int, test_gpio_int_edge_both)
{
test_gpio_pin_interrupt_edge(0, GPIO_INT_EDGE_BOTH);
}
/** @brief Verify GPIO_INT_EDGE_TO_ACTIVE flag. */
void test_gpio_int_edge_to_active(void)
ZTEST(gpio_api_1pin_int, test_gpio_int_edge_to_active)
{
TC_PRINT("Step 1: Configure pin as active high\n");
test_gpio_pin_interrupt_edge(GPIO_ACTIVE_HIGH, GPIO_INT_EDGE_TO_ACTIVE);
@ -233,7 +233,7 @@ void test_gpio_int_edge_to_active(void)
}
/** @brief Verify GPIO_INT_EDGE_TO_INACTIVE flag. */
void test_gpio_int_edge_to_inactive(void)
ZTEST(gpio_api_1pin_int, test_gpio_int_edge_to_inactive)
{
TC_PRINT("Step 1: Configure pin as active high\n");
test_gpio_pin_interrupt_edge(GPIO_ACTIVE_HIGH, GPIO_INT_EDGE_TO_INACTIVE);
@ -242,31 +242,31 @@ void test_gpio_int_edge_to_inactive(void)
}
/** @brief Verify GPIO_INT_LEVEL_HIGH flag with 1 interrupt call */
void test_gpio_int_level_high_interrupt_count_1(void)
ZTEST(gpio_api_1pin_int, test_gpio_int_level_high_interrupt_count_1)
{
test_gpio_pin_interrupt_level(0, GPIO_INT_LEVEL_HIGH, 1);
}
/** @brief Verify GPIO_INT_LEVEL_HIGH flag with 5 interrupt call */
void test_gpio_int_level_high_interrupt_count_5(void)
ZTEST(gpio_api_1pin_int, test_gpio_int_level_high_interrupt_count_5)
{
test_gpio_pin_interrupt_level(0, GPIO_INT_LEVEL_HIGH, 5);
}
/** @brief Verify GPIO_INT_LEVEL_LOW flag with 1 interrupt call */
void test_gpio_int_level_low_interrupt_count_1(void)
ZTEST(gpio_api_1pin_int, test_gpio_int_level_low_interrupt_count_1)
{
test_gpio_pin_interrupt_level(0, GPIO_INT_LEVEL_LOW, 1);
}
/** @brief Verify GPIO_INT_LEVEL_LOW flag with 5 interrupt call */
void test_gpio_int_level_low_interrupt_count_5(void)
ZTEST(gpio_api_1pin_int, test_gpio_int_level_low_interrupt_count_5)
{
test_gpio_pin_interrupt_level(0, GPIO_INT_LEVEL_LOW, 5);
}
/** @brief Verify GPIO_INT_LEVEL_ACTIVE flag. */
void test_gpio_int_level_active(void)
ZTEST(gpio_api_1pin_int, test_gpio_int_level_active)
{
TC_PRINT("Step 1: Configure pin as active high\n");
test_gpio_pin_interrupt_level(GPIO_ACTIVE_HIGH, GPIO_INT_LEVEL_ACTIVE, 1);
@ -275,10 +275,12 @@ void test_gpio_int_level_active(void)
}
/** @brief Verify GPIO_INT_LEVEL_INACTIVE flag. */
void test_gpio_int_level_inactive(void)
ZTEST(gpio_api_1pin_int, test_gpio_int_level_inactive)
{
TC_PRINT("Step 1: Configure pin as active high\n");
test_gpio_pin_interrupt_level(GPIO_ACTIVE_HIGH, GPIO_INT_LEVEL_INACTIVE, 1);
TC_PRINT("Step 2: Configure pin as active low\n");
test_gpio_pin_interrupt_level(GPIO_ACTIVE_LOW, GPIO_INT_LEVEL_INACTIVE, 1);
}
ZTEST_SUITE(gpio_api_1pin_int, NULL, NULL, NULL, NULL, NULL);

View file

@ -108,7 +108,7 @@ static void port_set_clr_bits(const struct device *port,
* - Verify that gpio_port_toggle_bits function changes pin state from active to
* inactive and vice versa.
*/
void test_gpio_port_toggle(void)
ZTEST(gpio_api_1pin_port, test_gpio_port_toggle)
{
const struct device *port;
gpio_port_value_t val_expected;
@ -142,7 +142,7 @@ void test_gpio_port_toggle(void)
}
}
void test_gpio_port_set_masked_get_raw(void)
ZTEST(gpio_api_1pin_port, test_gpio_port_set_masked_get_raw)
{
const struct device *port;
int ret;
@ -182,7 +182,7 @@ void test_gpio_port_set_masked_get_raw(void)
}
}
void test_gpio_port_set_masked_get(void)
ZTEST(gpio_api_1pin_port, test_gpio_port_set_masked_get)
{
const struct device *port;
int ret;
@ -222,7 +222,7 @@ void test_gpio_port_set_masked_get(void)
}
}
void test_gpio_port_set_masked_get_active_high(void)
ZTEST(gpio_api_1pin_port, test_gpio_port_set_masked_get_active_high)
{
const struct device *port;
int ret;
@ -273,7 +273,7 @@ void test_gpio_port_set_masked_get_active_high(void)
}
}
void test_gpio_port_set_masked_get_active_low(void)
ZTEST(gpio_api_1pin_port, test_gpio_port_set_masked_get_active_low)
{
const struct device *port;
int ret;
@ -324,7 +324,7 @@ void test_gpio_port_set_masked_get_active_low(void)
}
}
void test_gpio_port_set_bits_clear_bits_raw(void)
ZTEST(gpio_api_1pin_port, test_gpio_port_set_bits_clear_bits_raw)
{
const struct device *port;
gpio_port_value_t val_expected = 0;
@ -363,7 +363,7 @@ void test_gpio_port_set_bits_clear_bits_raw(void)
}
}
void test_gpio_port_set_bits_clear_bits(void)
ZTEST(gpio_api_1pin_port, test_gpio_port_set_bits_clear_bits)
{
const struct device *port;
gpio_port_value_t val_expected = 0;
@ -402,7 +402,7 @@ void test_gpio_port_set_bits_clear_bits(void)
}
}
void test_gpio_port_set_clr_bits_raw(void)
ZTEST(gpio_api_1pin_port, test_gpio_port_set_clr_bits_raw)
{
const struct device *port;
gpio_port_value_t val_expected = 0;
@ -440,7 +440,7 @@ void test_gpio_port_set_clr_bits_raw(void)
}
}
void test_gpio_port_set_clr_bits(void)
ZTEST(gpio_api_1pin_port, test_gpio_port_set_clr_bits)
{
const struct device *port;
gpio_port_value_t val_expected = 0;
@ -476,3 +476,5 @@ void test_gpio_port_set_clr_bits(void)
port_get_and_verify(port, BIT(TEST_PIN), val_expected, i);
}
}
ZTEST_SUITE(gpio_api_1pin_port, NULL, NULL, NULL, NULL, NULL);