tests: drivers: regulator: Test not implemented APIs with dummies

Instead of writing to existing fake APIs, use dummy devices with empty
APIs. This allows us to place APIs in ROM.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
This commit is contained in:
Pieter De Gendt 2024-11-30 15:59:03 +01:00 committed by Fabio Baltieri
commit d0d8158280

View file

@ -23,15 +23,22 @@ static const struct device *const reg4 = DEVICE_DT_GET(DT_NODELABEL(reg4));
/* REG5: regulator-boot-off and is_enabled */
static const struct device *const reg5 = DEVICE_DT_GET(DT_NODELABEL(reg5));
static DEVICE_API(regulator, dummy_regulator_api);
static DEVICE_API(regulator_parent, dummy_regulator_parent_api);
DEVICE_DEFINE(dummy_regulator, "dummy_regulator", NULL, NULL, NULL, NULL, POST_KERNEL,
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &dummy_regulator_api);
DEVICE_DEFINE(dummy_regulator_parent, "dummy_regulator_parent", NULL, NULL, NULL, NULL, POST_KERNEL,
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &dummy_regulator_parent_api);
/* Dummy regulator: empty API */
static const struct device *const dummy_reg = DEVICE_GET(dummy_regulator);
/* Dummy parent regulator: empty API */
static const struct device *const dummy_parent = DEVICE_GET(dummy_regulator_parent);
ZTEST(regulator_api, test_parent_dvs_state_set_not_implemented)
{
int ret;
struct regulator_parent_driver_api *api = (struct regulator_parent_driver_api *)parent->api;
regulator_dvs_state_set_t dvs_state_set = api->dvs_state_set;
api->dvs_state_set = NULL;
ret = regulator_parent_dvs_state_set(parent, 0);
api->dvs_state_set = dvs_state_set;
int ret = regulator_parent_dvs_state_set(dummy_parent, 0);
zassert_equal(ret, -ENOSYS);
}
@ -62,13 +69,7 @@ ZTEST(regulator_api, test_parent_dvs_state_set_fail)
ZTEST(regulator_api, test_parent_ship_mode_not_implemented)
{
int ret;
struct regulator_parent_driver_api *api = (struct regulator_parent_driver_api *)parent->api;
regulator_ship_mode_t ship_mode = api->ship_mode;
api->ship_mode = NULL;
ret = regulator_parent_ship_mode(parent);
api->ship_mode = ship_mode;
int ret = regulator_parent_ship_mode(dummy_parent);
zassert_equal(ret, -ENOSYS);
}
@ -188,13 +189,7 @@ ZTEST(regulator_api, test_enable_disable)
ZTEST(regulator_api, test_count_voltages_not_implemented)
{
unsigned int count;
struct regulator_driver_api *api = (struct regulator_driver_api *)reg0->api;
regulator_count_voltages_t count_voltages = api->count_voltages;
api->count_voltages = NULL;
count = regulator_count_voltages(reg0);
api->count_voltages = count_voltages;
unsigned int count = regulator_count_voltages(dummy_reg);
zassert_equal(count, 0U);
}
@ -212,13 +207,7 @@ ZTEST(regulator_api, test_count_voltages)
ZTEST(regulator_api, test_list_voltage_not_implemented)
{
int ret;
struct regulator_driver_api *api = (struct regulator_driver_api *)reg0->api;
regulator_list_voltage_t list_voltage = api->list_voltage;
api->list_voltage = NULL;
ret = regulator_list_voltage(reg0, 0, NULL);
api->list_voltage = list_voltage;
int ret = regulator_list_voltage(dummy_reg, 0, NULL);
zassert_equal(ret, -EINVAL);
}
@ -339,13 +328,7 @@ ZTEST(regulator_api, test_is_supported_voltage_dt_limit)
ZTEST(regulator_api, test_set_voltage_not_implemented)
{
int ret;
struct regulator_driver_api *api = (struct regulator_driver_api *)reg0->api;
regulator_set_voltage_t set_voltage = api->set_voltage;
api->set_voltage = NULL;
ret = regulator_set_voltage(reg0, 0, 0);
api->set_voltage = set_voltage;
int ret = regulator_set_voltage(dummy_reg, 0, 0);
zassert_equal(ret, -ENOSYS);
}
@ -388,13 +371,7 @@ ZTEST(regulator_api, test_set_voltage_dt_limit)
ZTEST(regulator_api, test_get_voltage_not_implemented)
{
int ret;
struct regulator_driver_api *api = (struct regulator_driver_api *)reg0->api;
regulator_get_voltage_t get_voltage = api->get_voltage;
api->get_voltage = NULL;
ret = regulator_get_voltage(reg0, NULL);
api->get_voltage = get_voltage;
int ret = regulator_get_voltage(dummy_reg, NULL);
zassert_equal(ret, -ENOSYS);
}
@ -445,13 +422,7 @@ ZTEST(regulator_api, test_get_voltage_error)
ZTEST(regulator_api, test_set_current_limit_not_implemented)
{
int ret;
struct regulator_driver_api *api = (struct regulator_driver_api *)reg0->api;
regulator_set_current_limit_t set_current_limit = api->set_current_limit;
api->set_current_limit = NULL;
ret = regulator_set_current_limit(reg0, 0, 0);
api->set_current_limit = set_current_limit;
int ret = regulator_set_current_limit(dummy_reg, 0, 0);
zassert_equal(ret, -ENOSYS);
}
@ -494,13 +465,7 @@ ZTEST(regulator_api, test_set_current_limit_dt_limit)
ZTEST(regulator_api, test_get_current_limit_not_implemented)
{
int ret;
struct regulator_driver_api *api = (struct regulator_driver_api *)reg0->api;
regulator_get_current_limit_t get_current_limit = api->get_current_limit;
api->get_current_limit = NULL;
ret = regulator_get_current_limit(reg0, NULL);
api->get_current_limit = get_current_limit;
int ret = regulator_get_current_limit(dummy_reg, NULL);
zassert_equal(ret, -ENOSYS);
}
@ -551,13 +516,7 @@ ZTEST(regulator_api, test_get_current_limit_error)
ZTEST(regulator_api, test_set_mode_not_implemented)
{
int ret;
struct regulator_driver_api *api = (struct regulator_driver_api *)reg0->api;
regulator_set_mode_t set_mode = api->set_mode;
api->set_mode = NULL;
ret = regulator_set_mode(reg0, 0);
api->set_mode = set_mode;
int ret = regulator_set_mode(dummy_reg, 0);
zassert_equal(ret, -ENOSYS);
}
@ -600,26 +559,14 @@ ZTEST(regulator_api, test_set_mode_dt_limit)
ZTEST(regulator_api, test_get_mode_not_implemented)
{
int ret;
struct regulator_driver_api *api = (struct regulator_driver_api *)reg0->api;
regulator_get_mode_t get_mode = api->get_mode;
api->get_mode = NULL;
ret = regulator_get_mode(reg0, NULL);
api->get_mode = get_mode;
int ret = regulator_get_mode(dummy_reg, NULL);
zassert_equal(ret, -ENOSYS);
}
ZTEST(regulator_api, test_set_active_discharge_not_implemented)
{
int ret;
struct regulator_driver_api *api = (struct regulator_driver_api *)reg0->api;
regulator_set_active_discharge_t set_active_discharge = api->set_active_discharge;
api->set_active_discharge = NULL;
ret = regulator_set_active_discharge(reg0, false);
api->set_active_discharge = set_active_discharge;
int ret = regulator_set_active_discharge(dummy_reg, false);
zassert_equal(ret, -ENOSYS);
}
@ -650,13 +597,7 @@ ZTEST(regulator_api, test_get_active_discharge_ok)
ZTEST(regulator_api, test_get_active_discharge_not_implemented)
{
int ret;
struct regulator_driver_api *api = (struct regulator_driver_api *)reg0->api;
regulator_get_active_discharge_t get_active_discharge = api->get_active_discharge;
api->get_active_discharge = NULL;
ret = regulator_get_active_discharge(reg0, NULL);
api->get_active_discharge = get_active_discharge;
int ret = regulator_get_active_discharge(dummy_reg, NULL);
zassert_equal(ret, -ENOSYS);
}
@ -707,13 +648,7 @@ ZTEST(regulator_api, test_get_mode_error)
ZTEST(regulator_api, test_get_error_flags_not_implemented)
{
int ret;
struct regulator_driver_api *api = (struct regulator_driver_api *)reg0->api;
regulator_get_error_flags_t get_error_flags = api->get_error_flags;
api->get_error_flags = NULL;
ret = regulator_get_error_flags(reg0, NULL);
api->get_error_flags = get_error_flags;
int ret = regulator_get_error_flags(dummy_reg, NULL);
zassert_equal(ret, -ENOSYS);
}