tests: drivers: clock control api: Make test generic

Changes for making the clock control api tests generic for
any board.
All the device subsys definitions were moved to its own folder
according to the clock compatible.
Also if the clock's async feature is not supported by the target,
the test is skipped instead of failed.

Signed-off-by: Lucas Tamborrino <lucas.tamborrino@espressif.com>
This commit is contained in:
Lucas Tamborrino 2024-05-02 16:43:07 -03:00 committed by Carles Cufí
commit 9808aa9f9e
5 changed files with 100 additions and 52 deletions

View file

@ -0,0 +1,18 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/drivers/clock_control.h>
struct device_subsys_data {
clock_control_subsys_t subsys;
uint32_t startup_us;
};
struct device_data {
const struct device *dev;
const struct device_subsys_data *subsys_data;
uint32_t subsys_cnt;
};

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "device_subsys.h"
#include <zephyr/drivers/clock_control/esp32_clock_control.h>
/* Test common modules among espressif SOCs*/
static const struct device_subsys_data subsys_data[] = {
{.subsys = (void *) ESP32_LEDC_MODULE},
{.subsys = (void *) ESP32_UART1_MODULE},
{.subsys = (void *) ESP32_I2C0_MODULE},
{.subsys = (void *) ESP32_UHCI0_MODULE},
{.subsys = (void *) ESP32_RMT_MODULE},
{.subsys = (void *) ESP32_TWAI_MODULE},
{.subsys = (void *) ESP32_RNG_MODULE},
};
static const struct device_data devices[] = {
{
.dev = DEVICE_DT_GET_ONE(espressif_esp32_rtc),
.subsys_data = subsys_data,
.subsys_cnt = ARRAY_SIZE(subsys_data)
}
};

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2019, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "device_subsys.h"
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
static const struct device_subsys_data subsys_data[] = {
{
.subsys = CLOCK_CONTROL_NRF_SUBSYS_HF,
.startup_us =
IS_ENABLED(CONFIG_SOC_SERIES_NRF91X) ?
3000 : 500
},
#ifndef CONFIG_SOC_NRF52832
/* On nrf52832 LF clock cannot be stopped because it leads
* to RTC COUNTER register reset and that is unexpected by
* system clock which is disrupted and may hang in the test.
*/
{
.subsys = CLOCK_CONTROL_NRF_SUBSYS_LF,
.startup_us = (CLOCK_CONTROL_NRF_K32SRC ==
NRF_CLOCK_LFCLK_RC) ? 1000 : 500000
}
#endif /* !CONFIG_SOC_NRF52832 */
};
static const struct device_data devices[] = {
{
.dev = DEVICE_DT_GET_ONE(nordic_nrf_clock),
.subsys_data = subsys_data,
.subsys_cnt = ARRAY_SIZE(subsys_data)
}
};

View file

@ -9,53 +9,13 @@
LOG_MODULE_REGISTER(test);
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_clock)
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
#include "nrf_device_subsys.h"
#elif DT_HAS_COMPAT_STATUS_OKAY(espressif_esp32_rtc)
#include "esp32_device_subsys.h"
#else
#error "Unsupported board"
#endif
struct device_subsys_data {
clock_control_subsys_t subsys;
uint32_t startup_us;
};
struct device_data {
const struct device *dev;
const struct device_subsys_data *subsys_data;
uint32_t subsys_cnt;
};
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_clock)
static const struct device_subsys_data subsys_data[] = {
{
.subsys = CLOCK_CONTROL_NRF_SUBSYS_HF,
.startup_us =
IS_ENABLED(CONFIG_SOC_SERIES_NRF91X) ?
3000 : 500
},
#ifndef CONFIG_SOC_NRF52832
/* On nrf52832 LF clock cannot be stopped because it leads
* to RTC COUNTER register reset and that is unexpected by
* system clock which is disrupted and may hang in the test.
*/
{
.subsys = CLOCK_CONTROL_NRF_SUBSYS_LF,
.startup_us = (CLOCK_CONTROL_NRF_K32SRC ==
NRF_CLOCK_LFCLK_RC) ? 1000 : 500000
}
#endif /* !CONFIG_SOC_NRF52832 */
};
#endif /* DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_clock) */
static const struct device_data devices[] = {
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_clock)
{
.dev = DEVICE_DT_GET_ONE(nordic_nrf_clock),
.subsys_data = subsys_data,
.subsys_cnt = ARRAY_SIZE(subsys_data)
}
#endif
};
typedef void (*test_func_t)(const struct device *dev,
clock_control_subsys_t subsys,
uint32_t startup_us);
@ -194,7 +154,9 @@ static bool async_capable(const struct device *dev, clock_control_subsys_t subsy
int err;
err = clock_control_async_on(dev, subsys, async_capable_callback, NULL);
if (err < 0) {
if (err == -ENOSYS) {
ztest_test_skip();
} else if (err < 0) {
printk("failed %d", err);
return false;
}

View file

@ -1,8 +1,16 @@
common:
tags:
- drivers
- clock_control
tests:
drivers.clock.clock_control_api_default:
platform_allow:
- esp32_devkitc_wroom/esp32/procpu
- esp32_devkitc_wrover/esp32/procpu
- esp32c3_devkitm
- esp32s2_saola
- esp32s3_devkitm/esp32s3/procpu
drivers.clock.clock_control_nrf5:
tags:
- drivers
- clock_control
platform_allow:
- nrf51dk/nrf51822
- nrf52dk/nrf52832
@ -12,9 +20,6 @@ tests:
integration_platforms:
- nrf51dk/nrf51822
drivers.clock.clock_control_nrf5_lfclk_rc:
tags:
- drivers
- clock_control
platform_allow:
- nrf51dk/nrf51822
- nrf52dk/nrf52832