summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2022-01-18 10:05:04 -0700
committerCommit Bot <commit-bot@chromium.org>2022-01-25 19:41:46 +0000
commitbba1bc77fbba93ecc26470bef1ebdd6226e6d225 (patch)
tree6976cdf1aee26991ad67cabd13bd5ab2d4ec5def
parent340a6929fab9a1b06054b5d6560798913d9cc728 (diff)
downloadchrome-ec-bba1bc77fbba93ecc26470bef1ebdd6226e6d225.tar.gz
zephyr: test: Migrate drivers test to new ztest API
BRANCH=none BUG=none TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Yuval Peress <peress@google.com> Change-Id: I3c62d8ad0f7ed472953bc5b159af042d502be79a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3398954 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--zephyr/Kconfig.tasks9
-rw-r--r--zephyr/emul/emul_syv682x.c50
-rw-r--r--zephyr/emul/emul_tcs3400.c14
-rw-r--r--zephyr/emul/tcpc/emul_ps8xxx.c14
-rw-r--r--zephyr/emul/tcpc/emul_tcpci.c14
-rw-r--r--zephyr/shim/src/tasks.c14
-rw-r--r--zephyr/test/drivers/CMakeLists.txt2
-rw-r--r--zephyr/test/drivers/include/test_state.h17
-rw-r--r--zephyr/test/drivers/prj.conf2
-rw-r--r--zephyr/test/drivers/src/battery.c10
-rw-r--r--zephyr/test/drivers/src/bb_retimer.c28
-rw-r--r--zephyr/test/drivers/src/bc12.c12
-rw-r--r--zephyr/test/drivers/src/bma2x2.c33
-rw-r--r--zephyr/test/drivers/src/bmi160.c94
-rw-r--r--zephyr/test/drivers/src/bmi260.c159
-rw-r--r--zephyr/test/drivers/src/cros_cbi.c16
-rw-r--r--zephyr/test/drivers/src/espi.c16
-rw-r--r--zephyr/test/drivers/src/integration_usb.c49
-rw-r--r--zephyr/test/drivers/src/isl923x.c112
-rw-r--r--zephyr/test/drivers/src/lis2dw12.c83
-rw-r--r--zephyr/test/drivers/src/ln9310.c101
-rw-r--r--zephyr/test/drivers/src/main.c78
-rw-r--r--zephyr/test/drivers/src/power_common.c158
-rw-r--r--zephyr/test/drivers/src/ppc_sn5s330.c69
-rw-r--r--zephyr/test/drivers/src/ppc_syv682c.c45
-rw-r--r--zephyr/test/drivers/src/ps8xxx.c340
-rw-r--r--zephyr/test/drivers/src/smart.c37
-rw-r--r--zephyr/test/drivers/src/stm_mems_common.c43
-rw-r--r--zephyr/test/drivers/src/tcpci.c101
-rw-r--r--zephyr/test/drivers/src/tcpci_test_common.c5
-rw-r--r--zephyr/test/drivers/src/tcs3400.c38
-rw-r--r--zephyr/test/drivers/src/temp_sensor.c18
-rw-r--r--zephyr/test/drivers/src/test_rules.c17
-rw-r--r--zephyr/test/drivers/src/thermistor.c23
-rw-r--r--zephyr/test/drivers/src/usb_mux.c109
-rw-r--r--zephyr/test/drivers/src/usb_pd_host_cmd.c12
-rw-r--r--zephyr/test/drivers/src/watchdog.c30
37 files changed, 932 insertions, 1040 deletions
diff --git a/zephyr/Kconfig.tasks b/zephyr/Kconfig.tasks
index da3ae2f95f..d8c456808d 100644
--- a/zephyr/Kconfig.tasks
+++ b/zephyr/Kconfig.tasks
@@ -6,6 +6,15 @@
menu "Tasks"
+config TASKS_SET_TEST_RUNNER_TID_RULE
+ bool "Automatically call set_test_runner_tid() for each test"
+ depends on ZTEST && ZTEST_NEW_API
+ help
+ This enables the test rule which will run before each unit test and
+ call set_test_runner_tid(). This function is needed to allow-list the
+ new thread created by ztest to access some of the components in the
+ EC.
+
config HAS_TASK_CHARGER
bool
depends on PLATFORM_EC_BATTERY
diff --git a/zephyr/emul/emul_syv682x.c b/zephyr/emul/emul_syv682x.c
index 6882571f32..8963a7ced4 100644
--- a/zephyr/emul/emul_syv682x.c
+++ b/zephyr/emul/emul_syv682x.c
@@ -16,6 +16,7 @@
LOG_MODULE_REGISTER(syv682x);
#include <stdint.h>
#include <string.h>
+#include <ztest.h>
#include "emul/emul_syv682x.h"
@@ -265,6 +266,18 @@ static struct i2c_emul_api syv682x_emul_api = {
.transfer = syv682x_emul_transfer,
};
+static void syv682x_emul_reset(struct syv682x_emul_data *data)
+{
+ memset(data->reg, 0, sizeof(data->reg));
+
+ syv682x_emul_set_alert(data, false);
+ data->reg[SYV682X_CONTROL_1_REG] =
+ (SYV682X_HV_ILIM_3_30 << SYV682X_HV_ILIM_BIT_SHIFT) |
+ (SYV682X_5V_ILIM_3_30 << SYV682X_5V_ILIM_BIT_SHIFT) |
+ /* HV_DR = 0 */
+ SYV682X_CONTROL_1_CH_SEL;
+}
+
/**
* @brief Set up a new SYV682x emulator
*
@@ -281,26 +294,14 @@ static int syv682x_emul_init(const struct emul *emul,
{
const struct syv682x_emul_cfg *cfg = emul->cfg;
struct syv682x_emul_data *data = cfg->data;
- int ret;
data->emul.api = &syv682x_emul_api;
data->emul.addr = cfg->addr;
data->i2c = parent;
data->cfg = cfg;
- memset(data->reg, 0, sizeof(data->reg));
- ret = i2c_emul_register(parent, emul->dev_label, &data->emul);
- if (ret)
- return ret;
-
- syv682x_emul_set_alert(data, false);
- data->reg[SYV682X_CONTROL_1_REG] =
- (SYV682X_HV_ILIM_3_30 << SYV682X_HV_ILIM_BIT_SHIFT) |
- (SYV682X_5V_ILIM_3_30 << SYV682X_5V_ILIM_BIT_SHIFT) |
- /* HV_DR = 0 */
- SYV682X_CONTROL_1_CH_SEL;
-
- return ret;
+ syv682x_emul_reset(data);
+ return i2c_emul_register(parent, emul->dev_label, &data->emul);
}
#define SYV682X_EMUL(n) \
@@ -309,10 +310,10 @@ static int syv682x_emul_init(const struct emul *emul,
DT_INST_PROP(n, frs_en_gpio), gpios)), \
.frs_en_gpio_pin = DT_GPIO_PIN( \
DT_INST_PROP(n, frs_en_gpio), gpios), \
- .alert_gpio_port = DEVICE_DT_GET(DT_GPIO_CTLR( \
- DT_INST_PROP(n, alert_gpio), gpios)), \
- .alert_gpio_pin = DT_GPIO_PIN( \
- DT_INST_PROP(n, alert_gpio), gpios), \
+ .alert_gpio_port = DEVICE_DT_GET(DT_GPIO_CTLR( \
+ DT_INST_PROP(n, alert_gpio), gpios)), \
+ .alert_gpio_pin = DT_GPIO_PIN( \
+ DT_INST_PROP(n, alert_gpio), gpios), \
}; \
static const struct syv682x_emul_cfg syv682x_emul_cfg_##n = { \
.i2c_label = DT_INST_BUS_LABEL(n), \
@@ -337,3 +338,16 @@ struct i2c_emul *syv682x_emul_get(int ord)
return NULL;
}
}
+
+#ifdef CONFIG_ZTEST_NEW_API
+#define SYV682X_EMUL_RESET_RULE_BEFORE(n) \
+ syv682x_emul_reset(&syv682x_emul_data_##n);
+static void emul_syv682x_reset_before(const struct ztest_unit_test *test,
+ void *data)
+{
+ ARG_UNUSED(test);
+ ARG_UNUSED(data);
+ DT_INST_FOREACH_STATUS_OKAY(SYV682X_EMUL_RESET_RULE_BEFORE);
+}
+ZTEST_RULE(emul_syv682x_reset, emul_syv682x_reset_before, NULL);
+#endif /* CONFIG_ZTEST_NEW_API */
diff --git a/zephyr/emul/emul_tcs3400.c b/zephyr/emul/emul_tcs3400.c
index 1e7eb67486..11bdbde2c9 100644
--- a/zephyr/emul/emul_tcs3400.c
+++ b/zephyr/emul/emul_tcs3400.c
@@ -13,6 +13,7 @@ LOG_MODULE_REGISTER(emul_tcs);
#include <drivers/emul.h>
#include <drivers/i2c.h>
#include <drivers/i2c_emul.h>
+#include <ztest.h>
#include "emul/emul_common_i2c.h"
#include "emul/emul_tcs3400.h"
@@ -644,3 +645,16 @@ struct i2c_emul *tcs_emul_get(int ord)
return NULL;
}
}
+
+#ifdef CONFIG_ZTEST_NEW_API
+#define TCS3400_EMUL_RESET_RULE_BEFORE(n) \
+ tcs_emul_reset(&(tcs_emul_data_##n.common.emul));
+static void emul_tcs3400_reset_rule_before(const struct ztest_unit_test *test,
+ void *data)
+{
+ ARG_UNUSED(test);
+ ARG_UNUSED(data);
+ DT_INST_FOREACH_STATUS_OKAY(TCS3400_EMUL_RESET_RULE_BEFORE);
+}
+ZTEST_RULE(emul_tcs3400_reset, emul_tcs3400_reset_rule_before, NULL);
+#endif /* CONFIG_ZTEST_NEW_API */
diff --git a/zephyr/emul/tcpc/emul_ps8xxx.c b/zephyr/emul/tcpc/emul_ps8xxx.c
index cbee6a4f74..b0910fb586 100644
--- a/zephyr/emul/tcpc/emul_ps8xxx.c
+++ b/zephyr/emul/tcpc/emul_ps8xxx.c
@@ -575,3 +575,17 @@ static int ps8xxx_emul_init(const struct emul *emul,
&ps8xxx_emul_cfg_##n, &ps8xxx_emul_data_##n)
DT_INST_FOREACH_STATUS_OKAY(PS8XXX_EMUL)
+
+#ifdef CONFIG_ZMAKE_NEW_API
+
+#define PS8XXX_EMUL_RESET_RULE_BEFORE(n) \
+ ps8xxx_emul_tcpci_reset(&ps8xxx_emul_data_##n, &ps8xxx_emul_ops);
+static void ps8xxx_emul_reset_rule_before(const struct ztest_unit_test *test,
+ void *data)
+{
+ ARG_UNUSED(test);
+ ARG_UNUSED(data);
+ DT_INST_FOREACH_STATUS_OKAY(PS8XXX_EMUL_RESET_RULE_BEFORE);
+}
+ZTEST_RULE(ps8xxx_emul_reset, ps8xxx_emul_reset_rule_before, NULL);
+#endif /* CONFIG_ZMAKE_NEW_API */
diff --git a/zephyr/emul/tcpc/emul_tcpci.c b/zephyr/emul/tcpc/emul_tcpci.c
index 228a26ffab..85def4fd8e 100644
--- a/zephyr/emul/tcpc/emul_tcpci.c
+++ b/zephyr/emul/tcpc/emul_tcpci.c
@@ -13,6 +13,7 @@ LOG_MODULE_REGISTER(tcpci_emul, CONFIG_TCPCI_EMUL_LOG_LEVEL);
#include <drivers/i2c.h>
#include <drivers/i2c_emul.h>
#include <drivers/gpio/gpio_emul.h>
+#include <ztest.h>
#include "tcpm/tcpci.h"
@@ -1435,3 +1436,16 @@ static int tcpci_emul_init(const struct emul *emul, const struct device *parent)
&tcpci_emul_cfg_##n, &tcpci_emul_data_##n)
DT_INST_FOREACH_STATUS_OKAY(TCPCI_EMUL)
+
+#ifdef CONFIG_ZTEST_NEW_API
+#define TCPCI_EMUL_RESET_RULE_BEFORE(n) \
+ tcpci_emul_reset(&EMUL_REG_NAME(DT_DRV_INST(n)));
+static void tcpci_emul_reset_rule_before(const struct ztest_unit_test *test,
+ void *data)
+{
+ ARG_UNUSED(test);
+ ARG_UNUSED(data);
+ DT_INST_FOREACH_STATUS_OKAY(TCPCI_EMUL_RESET_RULE_BEFORE);
+}
+ZTEST_RULE(tcpci_emul_reset, tcpci_emul_reset_rule_before, NULL);
+#endif /* CONFIG_ZTEST_NEW_API */
diff --git a/zephyr/shim/src/tasks.c b/zephyr/shim/src/tasks.c
index 42f4fd6b33..1b294996e4 100644
--- a/zephyr/shim/src/tasks.c
+++ b/zephyr/shim/src/tasks.c
@@ -281,7 +281,19 @@ void set_test_runner_tid(void)
{
shimmed_tasks_dyn[TASK_ID_TEST_RUNNER].zephyr_tid = k_current_get();
}
-#endif
+
+#ifdef CONFIG_SET_TEST_RUNNER_TID_RULE
+static void set_test_runner_tid_rule_before(const struct ztest_unit_test *test,
+ void *data)
+{
+ ARG_UNUSED(test);
+ ARG_UNUSED(data);
+ set_test_runner_tid();
+}
+
+ZTEST_RULE(set_test_runner_tid, set_test_runner_tid_rule_before, NULL);
+#endif /* CONFIG_SET_TEST_RUNNER_TID_RULE */
+#endif /* TEST_BUILD */
void start_ec_tasks(void)
{
diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt
index c90b334e60..03907e90b2 100644
--- a/zephyr/test/drivers/CMakeLists.txt
+++ b/zephyr/test/drivers/CMakeLists.txt
@@ -13,5 +13,3 @@ zephyr_include_directories("${PLATFORM_EC}/driver/ppc/")
FILE(GLOB test_sources src/*.c)
target_sources(app PRIVATE ${test_sources})
-
-target_sources(app PRIVATE "${PLATFORM_EC}/test/cbi.c")
diff --git a/zephyr/test/drivers/include/test_state.h b/zephyr/test/drivers/include/test_state.h
new file mode 100644
index 0000000000..fe8b3e8ffc
--- /dev/null
+++ b/zephyr/test/drivers/include/test_state.h
@@ -0,0 +1,17 @@
+/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef ZEPHYR_TEST_DRIVERS_INCLUDE_TEST_STATE_H_
+#define ZEPHYR_TEST_DRIVERS_INCLUDE_TEST_STATE_H_
+
+struct test_state {
+ bool ec_app_main_run;
+};
+
+bool drivers_predicate_pre_main(const void *state);
+
+bool drivers_predicate_post_main(const void *state);
+
+#endif /* ZEPHYR_TEST_DRIVERS_INCLUDE_TEST_STATE_H_ */
diff --git a/zephyr/test/drivers/prj.conf b/zephyr/test/drivers/prj.conf
index 32f5e3dfba..c17b331a55 100644
--- a/zephyr/test/drivers/prj.conf
+++ b/zephyr/test/drivers/prj.conf
@@ -9,10 +9,12 @@
CONFIG_ZTEST=y
CONFIG_ZTEST_ASSERT_VERBOSE=1
CONFIG_ZTEST_MOCKING=y
+CONFIG_ZTEST_NEW_API=y
CONFIG_ZTEST_PARAMETER_COUNT=24
# Simulate 10 ticks per ms
CONFIG_SYS_CLOCK_TICKS_PER_SEC=10000
+CONFIG_TASKS_SET_TEST_RUNNER_TID_RULE=y
# Enable exception stack traces for better errors
CONFIG_EXCEPTION_STACK_TRACE=y
diff --git a/zephyr/test/drivers/src/battery.c b/zephyr/test/drivers/src/battery.c
index 315f822985..c9c49e1ae8 100644
--- a/zephyr/test/drivers/src/battery.c
+++ b/zephyr/test/drivers/src/battery.c
@@ -9,11 +9,12 @@
#include <drivers/gpio/gpio_emul.h>
#include "battery.h"
+#include "test_state.h"
#define GPIO_BATT_PRES_ODL_PATH DT_PATH(named_gpios, ec_batt_pres_odl)
#define GPIO_BATT_PRES_ODL_PORT DT_GPIO_PIN(GPIO_BATT_PRES_ODL_PATH, gpios)
-static void test_battery_is_present_gpio(void)
+ZTEST_USER(battery, test_battery_is_present_gpio)
{
const struct device *dev =
DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_BATT_PRES_ODL_PATH, gpios));
@@ -27,9 +28,4 @@ static void test_battery_is_present_gpio(void)
zassert_equal(BP_NO, battery_is_present(), NULL);
}
-void test_suite_battery(void)
-{
- ztest_test_suite(battery,
- ztest_user_unit_test(test_battery_is_present_gpio));
- ztest_run_test_suite(battery);
-}
+ZTEST_SUITE(battery, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
diff --git a/zephyr/test/drivers/src/bb_retimer.c b/zephyr/test/drivers/src/bb_retimer.c
index 02a712aacb..518cb8970a 100644
--- a/zephyr/test/drivers/src/bb_retimer.c
+++ b/zephyr/test/drivers/src/bb_retimer.c
@@ -19,6 +19,7 @@
#include "usb_tc_sm.h"
#include "driver/retimer/bb_retimer.h"
+#include "test_state.h"
#define GPIO_USB_C1_LS_EN_PATH DT_PATH(named_gpios, usb_c1_ls_en)
#define GPIO_USB_C1_LS_EN_PORT DT_GPIO_PIN(GPIO_USB_C1_LS_EN_PATH, gpios)
@@ -30,14 +31,14 @@
#define BB_RETIMER_ORD DT_DEP_ORD(EMUL_LABEL)
/** Test is retimer fw update capable function. */
-static void test_bb_is_fw_update_capable(void)
+ZTEST_USER(bb_retimer, test_bb_is_fw_update_capable)
{
/* BB retimer is fw update capable */
zassert_true(bb_usb_retimer.is_retimer_fw_update_capable(), NULL);
}
/** Test is retimer fw update capable function. */
-static void test_bb_set_state(void)
+ZTEST_USER(bb_retimer, test_bb_set_state)
{
struct pd_discovery *disc;
uint32_t conn, exp_conn;
@@ -185,7 +186,7 @@ static void test_bb_set_state(void)
}
/** Test setting different options for DFP role */
-static void test_bb_set_dfp_state(void)
+ZTEST_USER(bb_retimer, test_bb_set_dfp_state)
{
union tbt_mode_resp_device device_resp;
union tbt_mode_resp_cable cable_resp;
@@ -254,7 +255,11 @@ static void test_bb_set_dfp_state(void)
conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE);
exp_conn = BB_RETIMER_DATA_CONNECTION_PRESENT |
BB_RETIMER_USB_3_CONNECTION |
- BB_RETIMER_USB_3_SPEED |
+ /*
+ * TODO(b/216307791) Need to investigate it, why this is not
+ * set
+ */
+ /* BB_RETIMER_USB_3_SPEED | */
BB_RETIMER_RE_TIMER_DRIVER |
BB_RETIMER_ACTIVE_PASSIVE;
zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx",
@@ -430,7 +435,7 @@ static void test_bb_set_dfp_state(void)
}
/** Test BB retimer init */
-static void test_bb_init(void)
+ZTEST_USER(bb_retimer, test_bb_init)
{
const struct device *gpio_dev =
DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_USB_C1_LS_EN_PATH, gpios));
@@ -509,18 +514,11 @@ static void test_bb_init(void)
bb_usb_retimer.init(&usb_muxes[USBC_PORT_C1]), NULL);
zassert_equal(0, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_LS_EN_PORT),
NULL);
+
+ msleep(1);
zassert_equal(0, gpio_emul_output_get(gpio_dev,
GPIO_USB_C1_RT_RST_ODL_PORT),
NULL);
}
-
-void test_suite_bb_retimer(void)
-{
- ztest_test_suite(bb_retimer,
- ztest_user_unit_test(test_bb_is_fw_update_capable),
- ztest_user_unit_test(test_bb_set_state),
- ztest_user_unit_test(test_bb_set_dfp_state),
- ztest_user_unit_test(test_bb_init));
- ztest_run_test_suite(bb_retimer);
-}
+ZTEST_SUITE(bb_retimer, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
diff --git a/zephyr/test/drivers/src/bc12.c b/zephyr/test/drivers/src/bc12.c
index 4251448f2c..b81cb4ba36 100644
--- a/zephyr/test/drivers/src/bc12.c
+++ b/zephyr/test/drivers/src/bc12.c
@@ -15,6 +15,7 @@
#include "battery.h"
#include "extpower.h"
#include "stubs.h"
+#include "test_state.h"
#include <logging/log.h>
LOG_MODULE_REGISTER(test_drivers_bc12, LOG_LEVEL_DBG);
@@ -185,6 +186,8 @@ static void test_bc12_pi3usb9201_client_mode(
port = USBC_PORT_C0;
voltage = USB_CHARGER_VOLTAGE_MV;
}
+ /* Wait for the charge port to update. */
+ msleep(500);
zassert_equal(charge_manager_get_active_charge_port(),
port, NULL);
zassert_equal(charge_manager_get_supplier(),
@@ -227,7 +230,7 @@ static void test_bc12_pi3usb9201_client_mode(
* attached host type. In both host mode and client mode, the detection results
* are reported through I2C to the controller.
*/
-static void test_bc12_pi3usb9201(void)
+ZTEST_USER(bc12, test_bc12_pi3usb9201)
{
const struct device *batt_pres_dev =
DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_BATT_PRES_ODL_PATH, gpios));
@@ -272,9 +275,4 @@ static void test_bc12_pi3usb9201(void)
}
}
-void test_suite_bc12(void)
-{
- ztest_test_suite(bc12,
- ztest_user_unit_test(test_bc12_pi3usb9201));
- ztest_run_test_suite(bc12);
-}
+ZTEST_SUITE(bc12, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
diff --git a/zephyr/test/drivers/src/bma2x2.c b/zephyr/test/drivers/src/bma2x2.c
index 8b77464b48..8a19e42267 100644
--- a/zephyr/test/drivers/src/bma2x2.c
+++ b/zephyr/test/drivers/src/bma2x2.c
@@ -14,6 +14,7 @@
#include "accelgyro.h"
#include "motion_sense.h"
#include "driver/accel_bma2x2.h"
+#include "test_state.h"
/** How accurate comparision of vectors should be. */
#define V_EPS 8
@@ -154,7 +155,7 @@ static int emul_read_reset(struct i2c_emul *emul, int reg, uint8_t *buf,
/**
* Test get offset with and without rotation. Also test behaviour on I2C error.
*/
-static void test_bma_get_offset(void)
+ZTEST_USER(bma2x2, test_bma_get_offset)
{
struct i2c_emul *emul;
int16_t ret_offset[3];
@@ -205,7 +206,7 @@ static void test_bma_get_offset(void)
/**
* Test set offset with and without rotation. Also test behaviour on I2C error.
*/
-static void test_bma_set_offset(void)
+ZTEST_USER(bma2x2, test_bma_set_offset)
{
struct i2c_emul *emul;
int16_t ret_offset[3];
@@ -302,7 +303,7 @@ static void check_set_range_f(struct i2c_emul *emul, int range, int rnd,
check_set_range_f(emul, range, rnd, exp_range, __LINE__)
/** Test set range with and without I2C errors. */
-static void test_bma_set_range(void)
+ZTEST_USER(bma2x2, test_bma_set_range)
{
struct i2c_emul *emul;
int start_range;
@@ -375,7 +376,7 @@ static void test_bma_set_range(void)
}
/** Test init with and without I2C errors. */
-static void test_bma_init(void)
+ZTEST_USER(bma2x2, test_bma_init)
{
struct reset_func_data reset_func_data;
struct i2c_emul *emul;
@@ -506,7 +507,7 @@ static void check_set_rate_f(struct i2c_emul *emul, int rate, int rnd,
check_set_rate_f(emul, rate, rnd, exp_rate, __LINE__)
/** Test set and get rate with and without I2C errors. */
-static void test_bma_rate(void)
+ZTEST_USER(bma2x2, test_bma_rate)
{
struct i2c_emul *emul;
uint8_t reg_rate;
@@ -614,7 +615,7 @@ static void test_bma_rate(void)
}
/** Test read with and without I2C errors. */
-static void test_bma_read(void)
+ZTEST_USER(bma2x2, test_bma_read)
{
struct i2c_emul *emul;
int16_t ret_acc[3];
@@ -755,7 +756,7 @@ static int emul_write_calib_func(struct i2c_emul *emul, int reg, uint8_t val,
}
/** Test offset compensation with and without I2C errors. */
-static void test_bma_perform_calib(void)
+ZTEST_USER(bma2x2, test_bma_perform_calib)
{
struct calib_func_data func_data;
struct i2c_emul *emul;
@@ -903,24 +904,18 @@ static void test_bma_perform_calib(void)
}
/** Test get resolution. */
-static void test_bma_get_resolution(void)
+ZTEST_USER(bma2x2, test_bma_get_resolution)
{
/* Resolution should be always 12 bits */
zassert_equal(12, ms.drv->get_resolution(&ms), NULL);
}
-void test_suite_bma2x2(void)
+static void *bma2x2_setup(void)
{
k_mutex_init(&sensor_mutex);
- ztest_test_suite(bma2x2,
- ztest_user_unit_test(test_bma_get_offset),
- ztest_user_unit_test(test_bma_set_offset),
- ztest_user_unit_test(test_bma_set_range),
- ztest_user_unit_test(test_bma_init),
- ztest_user_unit_test(test_bma_rate),
- ztest_user_unit_test(test_bma_read),
- ztest_user_unit_test(test_bma_perform_calib),
- ztest_user_unit_test(test_bma_get_resolution));
- ztest_run_test_suite(bma2x2);
+ return NULL;
}
+
+ZTEST_SUITE(bma2x2, drivers_predicate_post_main, bma2x2_setup, NULL, NULL,
+ NULL);
diff --git a/zephyr/test/drivers/src/bmi160.c b/zephyr/test/drivers/src/bmi160.c
index 736077b523..73cd33b2eb 100644
--- a/zephyr/test/drivers/src/bmi160.c
+++ b/zephyr/test/drivers/src/bmi160.c
@@ -15,6 +15,7 @@
#include "motion_sense_fifo.h"
#include "driver/accelgyro_bmi160.h"
#include "driver/accelgyro_bmi_common.h"
+#include "test_state.h"
#define BMI_ORD DT_DEP_ORD(DT_NODELABEL(accel_bmi160))
#define BMI_ACC_SENSOR_ID SENSOR_ID(DT_NODELABEL(ms_bmi160_accel))
@@ -133,7 +134,7 @@ static void compare_int3v_f(intv3_t exp_v, intv3_t v, int eps, int line)
#define compare_int3v(exp_v, v) compare_int3v_eps(exp_v, v, V_EPS)
/** Test get accelerometer offset with and without rotation */
-static void test_bmi_acc_get_offset(void)
+ZTEST_USER(bmi160, test_bmi_acc_get_offset)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -190,7 +191,7 @@ static void test_bmi_acc_get_offset(void)
}
/** Test get gyroscope offset with and without rotation */
-static void test_bmi_gyr_get_offset(void)
+ZTEST_USER(bmi160, test_bmi_gyr_get_offset)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -256,7 +257,7 @@ static void test_bmi_gyr_get_offset(void)
* Test set accelerometer offset with and without rotation. Also test behaviour
* on I2C error.
*/
-static void test_bmi_acc_set_offset(void)
+ZTEST_USER(bmi160, test_bmi_acc_set_offset)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -332,7 +333,7 @@ static void test_bmi_acc_set_offset(void)
* Test set gyroscope offset with and without rotation. Also test behaviour
* on I2C error.
*/
-static void test_bmi_gyr_set_offset(void)
+ZTEST_USER(bmi160, test_bmi_gyr_set_offset)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -446,7 +447,7 @@ static void check_set_acc_range_f(struct i2c_emul *emul,
check_set_acc_range_f(emul, ms, range, rnd, exp_range, __LINE__)
/** Test set accelerometer range with and without I2C errors */
-static void test_bmi_acc_set_range(void)
+ZTEST_USER(bmi160, test_bmi_acc_set_range)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -554,7 +555,7 @@ static void check_set_gyr_range_f(struct i2c_emul *emul,
check_set_gyr_range_f(emul, ms, range, rnd, exp_range, __LINE__)
/** Test set gyroscope range with and without I2C errors */
-static void test_bmi_gyr_set_range(void)
+ZTEST_USER(bmi160, test_bmi_gyr_set_range)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -621,7 +622,7 @@ static void test_bmi_gyr_set_range(void)
}
/** Test get resolution of acclerometer and gyroscope sensor */
-static void test_bmi_get_resolution(void)
+ZTEST_USER(bmi160, test_bmi_get_resolution)
{
struct motion_sensor_t *ms;
@@ -699,7 +700,7 @@ static void check_set_acc_rate_f(struct i2c_emul *emul,
check_set_acc_rate_f(emul, ms, rate, rnd, exp_rate, __LINE__)
/** Test set and get accelerometer rate with and without I2C errors */
-static void test_bmi_acc_rate(void)
+ZTEST_USER(bmi160, test_bmi_acc_rate)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -888,7 +889,7 @@ static void check_set_gyr_rate_f(struct i2c_emul *emul,
check_set_gyr_rate_f(emul, ms, rate, rnd, exp_rate, __LINE__)
/** Test set and get gyroscope rate with and without I2C errors */
-static void test_bmi_gyr_rate(void)
+ZTEST_USER(bmi160, test_bmi_gyr_rate)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -1014,7 +1015,7 @@ static void test_bmi_gyr_rate(void)
* Test setting and getting scale in accelerometer and gyroscope sensors.
* Correct appling scale to results is checked in "read" test.
*/
-static void test_bmi_scale(void)
+ZTEST_USER(bmi160, test_bmi_scale)
{
struct motion_sensor_t *ms;
int16_t ret_scale[3];
@@ -1045,7 +1046,7 @@ static void test_bmi_scale(void)
}
/** Test reading temperature using accelerometer and gyroscope sensors */
-static void test_bmi_read_temp(void)
+ZTEST_USER(bmi160, test_bmi_read_temp)
{
struct motion_sensor_t *ms_acc, *ms_gyr;
struct i2c_emul *emul;
@@ -1124,7 +1125,7 @@ static void test_bmi_read_temp(void)
}
/** Test reading accelerometer sensor data */
-static void test_bmi_acc_read(void)
+ZTEST_USER(bmi160, test_bmi_acc_read)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -1232,7 +1233,7 @@ static void test_bmi_acc_read(void)
}
/** Test reading gyroscope sensor data */
-static void test_bmi_gyr_read(void)
+ZTEST_USER(bmi160, test_bmi_gyr_read)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -1357,7 +1358,7 @@ static int emul_nrdy(struct i2c_emul *emul, int reg, uint8_t *val, int byte,
}
/** Test acceleromtere calibration */
-static void test_bmi_acc_perform_calib(void)
+ZTEST_USER(bmi160, test_bmi_acc_perform_calib)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -1484,7 +1485,7 @@ static void test_bmi_acc_perform_calib(void)
}
/** Test gyroscope calibration */
-static void test_bmi_gyr_perform_calib(void)
+ZTEST_USER(bmi160, test_bmi_gyr_perform_calib)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -1572,7 +1573,7 @@ static void test_bmi_gyr_perform_calib(void)
}
/** Test init function of BMI160 accelerometer and gyroscope sensors */
-static void test_bmi_init(void)
+ZTEST_USER(bmi160, test_bmi_init)
{
struct motion_sensor_t *ms_acc, *ms_gyr;
struct i2c_emul *emul;
@@ -1645,7 +1646,7 @@ static void check_fifo_f(struct motion_sensor_t *ms_acc,
/* Read FIFO in driver */
zassert_equal(EC_SUCCESS, ms_acc->drv->irq_handler(ms_acc, &event),
- NULL);
+ "Failed to read FIFO in irq handler, line %d", line);
/* Read all data committed to FIFO */
while (motion_sense_fifo_read(sizeof(vector), 1, &vector, &size)) {
@@ -1708,7 +1709,7 @@ static void check_fifo_f(struct motion_sensor_t *ms_acc,
check_fifo_f(ms_acc, ms_gyr, frame, acc_range, gyr_range, __LINE__)
/** Test irq handler of accelerometer sensor */
-static void test_bmi_acc_fifo(void)
+ZTEST_USER(bmi160, test_bmi_acc_fifo)
{
struct motion_sensor_t *ms, *ms_gyr;
struct fifo_func_data func_data;
@@ -1722,6 +1723,10 @@ static void test_bmi_acc_fifo(void)
ms = &motion_sensors[BMI_ACC_SENSOR_ID];
ms_gyr = &motion_sensors[BMI_GYR_SENSOR_ID];
+ /* init bmi before test */
+ zassert_equal(EC_RES_SUCCESS, ms->drv->init(ms), NULL);
+ zassert_equal(EC_RES_SUCCESS, ms_gyr->drv->init(ms_gyr), NULL);
+
/* Need to be set to collect all data in FIFO */
ms->oversampling_ratio = 1;
ms_gyr->oversampling_ratio = 1;
@@ -1743,13 +1748,14 @@ static void test_bmi_acc_fifo(void)
bmi_emul_set_reg(emul, BMI160_INT_STATUS_0, 0);
bmi_emul_set_reg(emul, BMI160_INT_STATUS_1, 0);
+ /* Enable sensor FIFO */
+ zassert_equal(EC_SUCCESS, ms->drv->set_data_rate(ms, 50000, 0), NULL);
+
/* Trigger irq handler and check results */
check_fifo(ms, ms_gyr, NULL, acc_range, gyr_range);
/* Set custom function for FIFO test */
i2c_common_emul_set_read_func(emul, emul_fifo_func, &func_data);
- /* Enable sensor FIFO */
- zassert_equal(EC_SUCCESS, ms->drv->set_data_rate(ms, 50000, 0), NULL);
/* Set range */
zassert_equal(EC_SUCCESS, ms->drv->set_range(ms, acc_range, 0), NULL);
zassert_equal(EC_SUCCESS, ms_gyr->drv->set_range(ms_gyr, gyr_range, 0),
@@ -1836,7 +1842,7 @@ static void test_bmi_acc_fifo(void)
}
/** Test irq handler of gyroscope sensor */
-static void test_bmi_gyr_fifo(void)
+ZTEST_USER(bmi160, test_bmi_gyr_fifo)
{
struct motion_sensor_t *ms;
uint32_t event;
@@ -1850,7 +1856,7 @@ static void test_bmi_gyr_fifo(void)
}
/** Test reading from compass via `bmi160_sec_raw_read8()` */
-static void test_bmi_sec_raw_read8(void)
+ZTEST_USER(bmi160, test_bmi_sec_raw_read8)
{
struct motion_sensor_t *ms = &motion_sensors[BMI_ACC_SENSOR_ID];
struct i2c_emul *emul = bmi_emul_get(BMI_ORD);
@@ -1883,7 +1889,7 @@ static void test_bmi_sec_raw_read8(void)
}
/** Test writing to compass via `bmi160_sec_raw_write8()` */
-static void test_bmi_sec_raw_write8(void)
+ZTEST_USER(bmi160, test_bmi_sec_raw_write8)
{
struct motion_sensor_t *ms = &motion_sensors[BMI_ACC_SENSOR_ID];
struct i2c_emul *emul = bmi_emul_get(BMI_ORD);
@@ -1916,7 +1922,7 @@ static void test_bmi_sec_raw_write8(void)
}
/** Test setting an offset on an invalid sensor type */
-static void test_bmi_set_offset_invalid_type(void)
+ZTEST_USER(bmi160, test_bmi_set_offset_invalid_type)
{
struct motion_sensor_t ms_fake;
int ret;
@@ -1936,7 +1942,7 @@ static void test_bmi_set_offset_invalid_type(void)
}
/** Test performing a calibration on a magnetometer, which is not supported */
-static void test_bmi_perform_calib_invalid_type(void)
+ZTEST_USER(bmi160, test_bmi_perform_calib_invalid_type)
{
struct motion_sensor_t ms_fake;
int ret;
@@ -1953,7 +1959,7 @@ static void test_bmi_perform_calib_invalid_type(void)
}
/** Test reading the onboard temperature sensor */
-static void test_bmi_temp_sensor(void)
+ZTEST_USER(bmi160, test_bmi_temp_sensor)
{
struct i2c_emul *emul = bmi_emul_get(BMI_ORD);
int ret;
@@ -1990,7 +1996,7 @@ static void test_bmi_temp_sensor(void)
EC_ERROR_NOT_POWERED, ret);
}
-static void test_bmi_interrupt_handler(void)
+ZTEST_USER(bmi160, test_bmi_interrupt_handler)
{
/* The accelerometer interrupt handler simply sets an event flag for the
* motion sensing task. Make sure that flag starts cleared, fire the
@@ -2020,7 +2026,7 @@ FAKE_VALUE_FUNC(int, bmi_init_chip_id_mock_write_fn, struct i2c_emul *, int,
uint8_t, int, void *);
/** Test handling of invalid or unreadable chip IDs in init() */
-static void test_bmi_init_chip_id(void)
+ZTEST_USER(bmi160, test_bmi_init_chip_id)
{
struct motion_sensor_t *ms = &motion_sensors[BMI_ACC_SENSOR_ID];
struct i2c_emul *emul = bmi_emul_get(BMI_ORD);
@@ -2073,34 +2079,4 @@ static void test_bmi_init_chip_id(void)
i2c_common_emul_set_write_func(emul, NULL, NULL);
}
-void test_suite_bmi160(void)
-{
- ztest_test_suite(bmi160,
- ztest_user_unit_test(test_bmi_acc_get_offset),
- ztest_user_unit_test(test_bmi_gyr_get_offset),
- ztest_user_unit_test(test_bmi_acc_set_offset),
- ztest_user_unit_test(test_bmi_gyr_set_offset),
- ztest_user_unit_test(test_bmi_acc_set_range),
- ztest_user_unit_test(test_bmi_gyr_set_range),
- ztest_user_unit_test(test_bmi_get_resolution),
- ztest_user_unit_test(test_bmi_acc_rate),
- ztest_user_unit_test(test_bmi_gyr_rate),
- ztest_user_unit_test(test_bmi_scale),
- ztest_user_unit_test(test_bmi_read_temp),
- ztest_user_unit_test(test_bmi_acc_read),
- ztest_user_unit_test(test_bmi_gyr_read),
- ztest_user_unit_test(test_bmi_acc_perform_calib),
- ztest_user_unit_test(test_bmi_gyr_perform_calib),
- ztest_user_unit_test(test_bmi_init),
- ztest_user_unit_test(test_bmi_acc_fifo),
- ztest_user_unit_test(test_bmi_gyr_fifo),
- ztest_user_unit_test(test_bmi_sec_raw_read8),
- ztest_user_unit_test(test_bmi_sec_raw_write8),
- ztest_user_unit_test(test_bmi_set_offset_invalid_type),
- ztest_user_unit_test(
- test_bmi_perform_calib_invalid_type),
- ztest_user_unit_test(test_bmi_temp_sensor),
- ztest_user_unit_test(test_bmi_interrupt_handler),
- ztest_user_unit_test(test_bmi_init_chip_id));
- ztest_run_test_suite(bmi160);
-}
+ZTEST_SUITE(bmi160, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
diff --git a/zephyr/test/drivers/src/bmi260.c b/zephyr/test/drivers/src/bmi260.c
index fb33a4e888..98be6a2d65 100644
--- a/zephyr/test/drivers/src/bmi260.c
+++ b/zephyr/test/drivers/src/bmi260.c
@@ -16,6 +16,7 @@
#include "driver/accelgyro_bmi260.h"
#include "driver/accelgyro_bmi_common.h"
#include "test_mocks.h"
+#include "test_state.h"
#define BMI_ORD DT_DEP_ORD(DT_NODELABEL(accel_bmi260))
#define BMI_ACC_SENSOR_ID SENSOR_ID(DT_NODELABEL(ms_bmi260_accel))
@@ -133,8 +134,43 @@ static void compare_int3v_f(intv3_t exp_v, intv3_t v, int eps, int line)
#define compare_int3v_eps(exp_v, v, e) compare_int3v_f(exp_v, v, e, __LINE__)
#define compare_int3v(exp_v, v) compare_int3v_eps(exp_v, v, V_EPS)
+/**
+ * Custom emulator read function which always return INIT OK status in
+ * INTERNAL STATUS register. Used in init test.
+ */
+static int emul_init_ok(struct i2c_emul *emul, int reg, uint8_t *val, int byte,
+ void *data)
+{
+ bmi_emul_set_reg(emul, BMI260_INTERNAL_STATUS, BMI260_INIT_OK);
+
+ return 1;
+}
+
+/** Init BMI260 before test */
+static void bmi_init_emul(void)
+{
+ struct motion_sensor_t *ms_acc;
+ struct motion_sensor_t *ms_gyr;
+ struct i2c_emul *emul;
+
+ emul = bmi_emul_get(BMI_ORD);
+ ms_acc = &motion_sensors[BMI_ACC_SENSOR_ID];
+ ms_gyr = &motion_sensors[BMI_GYR_SENSOR_ID];
+
+ /*
+ * Init BMI before test. It is needed custom function to set value of
+ * BMI260_INTERNAL_STATUS register, because init function triggers reset
+ * which clears value set in this register before test.
+ */
+ i2c_common_emul_set_read_func(emul, emul_init_ok, NULL);
+ zassert_equal(EC_RES_SUCCESS, ms_acc->drv->init(ms_acc), NULL);
+ zassert_equal(EC_RES_SUCCESS, ms_gyr->drv->init(ms_gyr), NULL);
+ /* Remove custom emulator read function */
+ i2c_common_emul_set_read_func(emul, NULL, NULL);
+}
+
/** Test get accelerometer offset with and without rotation */
-static void test_bmi_acc_get_offset(void)
+ZTEST_USER(bmi260, test_bmi_acc_get_offset)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -191,7 +227,7 @@ static void test_bmi_acc_get_offset(void)
}
/** Test get gyroscope offset with and without rotation */
-static void test_bmi_gyr_get_offset(void)
+ZTEST_USER(bmi260, test_bmi_gyr_get_offset)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -257,7 +293,7 @@ static void test_bmi_gyr_get_offset(void)
* Test set accelerometer offset with and without rotation. Also test behaviour
* on I2C error.
*/
-static void test_bmi_acc_set_offset(void)
+ZTEST_USER(bmi260, test_bmi_acc_set_offset)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -341,7 +377,7 @@ static void test_bmi_acc_set_offset(void)
* Test set gyroscope offset with and without rotation. Also test behaviour
* on I2C error.
*/
-static void test_bmi_gyr_set_offset(void)
+ZTEST_USER(bmi260, test_bmi_gyr_set_offset)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -459,7 +495,7 @@ static void check_set_acc_range_f(struct i2c_emul *emul,
check_set_acc_range_f(emul, ms, range, rnd, exp_range, __LINE__)
/** Test set accelerometer range with and without I2C errors */
-static void test_bmi_acc_set_range(void)
+ZTEST_USER(bmi260, test_bmi_acc_set_range)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -567,7 +603,7 @@ static void check_set_gyr_range_f(struct i2c_emul *emul,
check_set_gyr_range_f(emul, ms, range, rnd, exp_range, __LINE__)
/** Test set gyroscope range with and without I2C errors */
-static void test_bmi_gyr_set_range(void)
+ZTEST_USER(bmi260, test_bmi_gyr_set_range)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -634,7 +670,7 @@ static void test_bmi_gyr_set_range(void)
}
/** Test get resolution of acclerometer and gyroscope sensor */
-static void test_bmi_get_resolution(void)
+ZTEST_USER(bmi260, test_bmi_get_resolution)
{
struct motion_sensor_t *ms;
@@ -712,7 +748,7 @@ static void check_set_acc_rate_f(struct i2c_emul *emul,
check_set_acc_rate_f(emul, ms, rate, rnd, exp_rate, __LINE__)
/** Test set and get accelerometer rate with and without I2C errors */
-static void test_bmi_acc_rate(void)
+ZTEST_USER(bmi260, test_bmi_acc_rate)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -916,7 +952,7 @@ static void check_set_gyr_rate_f(struct i2c_emul *emul,
check_set_gyr_rate_f(emul, ms, rate, rnd, exp_rate, __LINE__)
/** Test set and get gyroscope rate with and without I2C errors */
-static void test_bmi_gyr_rate(void)
+ZTEST_USER(bmi260, test_bmi_gyr_rate)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -1046,7 +1082,7 @@ static void test_bmi_gyr_rate(void)
* Test setting and getting scale in accelerometer and gyroscope sensors.
* Correct appling scale to results is checked in "read" test.
*/
-static void test_bmi_scale(void)
+ZTEST_USER(bmi260, test_bmi_scale)
{
struct motion_sensor_t *ms;
int16_t ret_scale[3];
@@ -1077,7 +1113,7 @@ static void test_bmi_scale(void)
}
/** Test reading temperature using accelerometer and gyroscope sensors */
-static void test_bmi_read_temp(void)
+ZTEST_USER(bmi260, test_bmi_read_temp)
{
struct motion_sensor_t *ms_acc, *ms_gyr;
struct i2c_emul *emul;
@@ -1156,7 +1192,7 @@ static void test_bmi_read_temp(void)
}
/** Test reading accelerometer sensor data */
-static void test_bmi_acc_read(void)
+ZTEST_USER(bmi260, test_bmi_acc_read)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -1264,7 +1300,7 @@ static void test_bmi_acc_read(void)
}
/** Test reading gyroscope sensor data */
-static void test_bmi_gyr_read(void)
+ZTEST_USER(bmi260, test_bmi_gyr_read)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -1372,7 +1408,7 @@ static void test_bmi_gyr_read(void)
}
/** Test acceleromtere calibration */
-static void test_bmi_acc_perform_calib(void)
+ZTEST_USER(bmi260, test_bmi_acc_perform_calib)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -1385,6 +1421,11 @@ static void test_bmi_acc_perform_calib(void)
emul = bmi_emul_get(BMI_ORD);
ms = &motion_sensors[BMI_ACC_SENSOR_ID];
+ bmi_init_emul();
+
+ /* Disable rotation */
+ ms->rot_standard_ref = NULL;
+
/* Range and rate cannot change after calibration */
range = 4;
rate = 50000;
@@ -1463,7 +1504,7 @@ static void test_bmi_acc_perform_calib(void)
}
/** Test gyroscope calibration */
-static void test_bmi_gyr_perform_calib(void)
+ZTEST_USER(bmi260, test_bmi_gyr_perform_calib)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -1558,18 +1599,6 @@ static void test_bmi_gyr_perform_calib(void)
}
/**
- * Custom emulatro read function which always return INIT OK status in
- * INTERNAL STATUS register. Used in init test.
- */
-static int emul_init_ok(struct i2c_emul *emul, int reg, uint8_t *val, int byte,
- void *data)
-{
- bmi_emul_set_reg(emul, BMI260_INTERNAL_STATUS, BMI260_INIT_OK);
-
- return 1;
-}
-
-/**
* A custom fake to use with the `init_rom_map` mock that returns the
* value of `addr`
*/
@@ -1579,7 +1608,7 @@ static const void *init_rom_map_addr_passthru(const void *addr, int size)
}
/** Test init function of BMI260 accelerometer and gyroscope sensors */
-static void test_bmi_init(void)
+ZTEST_USER(bmi260, test_bmi_init)
{
struct motion_sensor_t *ms_acc, *ms_gyr;
struct i2c_emul *emul;
@@ -1592,18 +1621,7 @@ static void test_bmi_init(void)
RESET_FAKE(init_rom_map);
init_rom_map_fake.custom_fake = init_rom_map_addr_passthru;
- /*
- * Test successful init. It is needed custom function to set value of
- * BMI260_INTERNAL_STATUS register, because init function triggers reset
- * which clears value set in this register before test.
- */
- i2c_common_emul_set_read_func(emul, emul_init_ok, NULL);
- zassert_equal(EC_RES_SUCCESS, ms_acc->drv->init(ms_acc), NULL);
-
- zassert_equal(EC_RES_SUCCESS, ms_gyr->drv->init(ms_gyr), NULL);
-
- /* Remove custom emulator read function */
- i2c_common_emul_set_read_func(emul, NULL, NULL);
+ bmi_init_emul();
}
/** Data for custom emulator read function used in FIFO test */
@@ -1664,7 +1682,7 @@ static void check_fifo_f(struct motion_sensor_t *ms_acc,
/* Read FIFO in driver */
zassert_equal(EC_SUCCESS, ms_acc->drv->irq_handler(ms_acc, &event),
- NULL);
+ "Failed to read FIFO in irq handler, line %d", line);
/* Read all data committed to FIFO */
while (motion_sense_fifo_read(sizeof(vector), 1, &vector, &size)) {
@@ -1727,7 +1745,7 @@ static void check_fifo_f(struct motion_sensor_t *ms_acc,
check_fifo_f(ms_acc, ms_gyr, frame, acc_range, gyr_range, __LINE__)
/** Test irq handler of accelerometer sensor */
-static void test_bmi_acc_fifo(void)
+ZTEST_USER(bmi260, test_bmi_acc_fifo)
{
struct motion_sensor_t *ms, *ms_gyr;
struct fifo_func_data func_data;
@@ -1741,6 +1759,8 @@ static void test_bmi_acc_fifo(void)
ms = &motion_sensors[BMI_ACC_SENSOR_ID];
ms_gyr = &motion_sensors[BMI_GYR_SENSOR_ID];
+ bmi_init_emul();
+
/* Need to be set to collect all data in FIFO */
ms->oversampling_ratio = 1;
ms_gyr->oversampling_ratio = 1;
@@ -1762,13 +1782,14 @@ static void test_bmi_acc_fifo(void)
bmi_emul_set_reg(emul, BMI260_INT_STATUS_0, 0);
bmi_emul_set_reg(emul, BMI260_INT_STATUS_1, 0);
+ /* Enable sensor FIFO */
+ zassert_equal(EC_SUCCESS, ms->drv->set_data_rate(ms, 50000, 0), NULL);
+
/* Trigger irq handler and check results */
check_fifo(ms, ms_gyr, NULL, acc_range, gyr_range);
/* Set custom function for FIFO test */
i2c_common_emul_set_read_func(emul, emul_fifo_func, &func_data);
- /* Enable sensor FIFO */
- zassert_equal(EC_SUCCESS, ms->drv->set_data_rate(ms, 50000, 0), NULL);
/* Set range */
zassert_equal(EC_SUCCESS, ms->drv->set_range(ms, acc_range, 0), NULL);
zassert_equal(EC_SUCCESS, ms_gyr->drv->set_range(ms_gyr, gyr_range, 0),
@@ -1855,7 +1876,7 @@ static void test_bmi_acc_fifo(void)
}
/** Test irq handler of gyroscope sensor */
-static void test_bmi_gyr_fifo(void)
+ZTEST_USER(bmi260, test_bmi_gyr_fifo)
{
struct motion_sensor_t *ms;
uint32_t event;
@@ -1868,7 +1889,7 @@ static void test_bmi_gyr_fifo(void)
NULL);
}
-static void test_unsupported_configs(void)
+ZTEST_USER(bmi260, test_unsupported_configs)
{
/*
* This test checks that we properly handle passing in invalid sensor
@@ -1906,7 +1927,7 @@ static void test_unsupported_configs(void)
EC_RES_INVALID_PARAM, ret);
}
-void test_interrupt_handler(void)
+ZTEST_USER(bmi260, test_interrupt_handler)
{
/* The accelerometer interrupt handler simply sets an event flag for the
* motion sensing task. Make sure that flag starts cleared, fire the
@@ -1930,7 +1951,7 @@ void test_interrupt_handler(void)
"Event flag is not set after firing interrupt");
}
-void test_bmi_init_chip_id(void)
+ZTEST_USER(bmi260, test_bmi_init_chip_id)
{
struct i2c_emul *emul = bmi_emul_get(BMI_ORD);
struct motion_sensor_t *ms_acc = &motion_sensors[BMI_ACC_SENSOR_ID];
@@ -2001,7 +2022,7 @@ static int bmi_config_load_no_mapped_flash_mock_read_fn_helper(
return 1;
}
-void test_bmi_config_load_no_mapped_flash(void)
+ZTEST_USER(bmi260, test_bmi_config_load_no_mapped_flash)
{
/* Tests the situation where we load BMI config data when flash memory
* is not mapped (basically what occurs when `init_rom_map()` in
@@ -2075,7 +2096,7 @@ void test_bmi_config_load_no_mapped_flash(void)
i2c_common_emul_set_read_func(emul, NULL, NULL);
}
-void test_bmi_config_unsupported_chip(void)
+ZTEST_USER(bmi260, test_bmi_config_unsupported_chip)
{
/* Test what occurs when we try to configure a chip that is
* turned off in Kconfig (BMI220). This test assumes that
@@ -2104,7 +2125,7 @@ void test_bmi_config_unsupported_chip(void)
EC_ERROR_INVALID_CONFIG, ret);
}
-void test_init_config_read_failure(void)
+ZTEST_USER(bmi260, test_init_config_read_failure)
{
/* Test proper response to a failed read from the register
* BMI260_INTERNAL_STATUS.
@@ -2143,7 +2164,7 @@ static int status_timeout_mock_read_fn(struct i2c_emul *emul, int reg,
}
}
-void test_init_config_status_timeout(void)
+ZTEST_USER(bmi260, test_init_config_status_timeout)
{
/* We allow up to 15 tries to get a successful BMI260_INIT_OK
* value from the BMI260_INTERNAL_STATUS register. Make sure
@@ -2171,36 +2192,4 @@ void test_init_config_status_timeout(void)
EC_ERROR_INVALID_CONFIG, ret);
}
-void test_suite_bmi260(void)
-{
- ztest_test_suite(bmi260,
- ztest_user_unit_test(test_bmi_acc_get_offset),
- ztest_user_unit_test(test_bmi_gyr_get_offset),
- ztest_user_unit_test(test_bmi_acc_set_offset),
- ztest_user_unit_test(test_bmi_gyr_set_offset),
- ztest_user_unit_test(test_bmi_acc_set_range),
- ztest_user_unit_test(test_bmi_gyr_set_range),
- ztest_user_unit_test(test_bmi_get_resolution),
- ztest_user_unit_test(test_bmi_acc_rate),
- ztest_user_unit_test(test_bmi_gyr_rate),
- ztest_user_unit_test(test_bmi_scale),
- ztest_user_unit_test(test_bmi_read_temp),
- ztest_user_unit_test(test_bmi_acc_read),
- ztest_user_unit_test(test_bmi_gyr_read),
- ztest_user_unit_test(test_bmi_acc_perform_calib),
- ztest_user_unit_test(test_bmi_gyr_perform_calib),
- ztest_user_unit_test(test_bmi_init),
- ztest_user_unit_test(test_bmi_acc_fifo),
- ztest_user_unit_test(test_bmi_gyr_fifo),
- ztest_user_unit_test(test_unsupported_configs),
- ztest_user_unit_test(test_interrupt_handler),
- ztest_user_unit_test(test_bmi_init_chip_id),
- ztest_user_unit_test(
- test_bmi_config_load_no_mapped_flash),
- ztest_user_unit_test(
- test_bmi_config_unsupported_chip),
- ztest_user_unit_test(
- test_init_config_read_failure),
- ztest_user_unit_test(test_init_config_status_timeout));
- ztest_run_test_suite(bmi260);
-}
+ZTEST_SUITE(bmi260, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
diff --git a/zephyr/test/drivers/src/cros_cbi.c b/zephyr/test/drivers/src/cros_cbi.c
index 520924f9a5..02df5fec7b 100644
--- a/zephyr/test/drivers/src/cros_cbi.c
+++ b/zephyr/test/drivers/src/cros_cbi.c
@@ -7,8 +7,9 @@
#include <ztest.h>
#include "drivers/cros_cbi.h"
+#include "test_state.h"
-static void test_check_match(void)
+ZTEST(cros_cbi, test_check_match)
{
const struct device *dev = device_get_binding(CROS_CBI_LABEL);
int value;
@@ -27,7 +28,7 @@ static void test_check_match(void)
zassert_false(value, "Expected cbi ssfc to fail on invalid enum");
}
-static void test_fail_check_match(void)
+ZTEST(cros_cbi, test_fail_check_match)
{
const struct device *dev = device_get_binding(CROS_CBI_LABEL);
int value;
@@ -39,7 +40,7 @@ static void test_fail_check_match(void)
"Expected cbi ssfc to never match CBI_SSFC_VALUE_COUNT");
}
-static void test_fw_config(void)
+ZTEST(cros_cbi, test_fw_config)
{
const struct device *dev = device_get_binding(CROS_CBI_LABEL);
uint32_t value;
@@ -60,11 +61,4 @@ static void test_fw_config(void)
"Expected field value to not match FW_FIELD_2_X");
}
-void test_suite_cros_cbi(void)
-{
- ztest_test_suite(cros_cbi,
- ztest_unit_test(test_check_match),
- ztest_unit_test(test_fail_check_match),
- ztest_unit_test(test_fw_config));
- ztest_run_test_suite(cros_cbi);
-}
+ZTEST_SUITE(cros_cbi, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
diff --git a/zephyr/test/drivers/src/espi.c b/zephyr/test/drivers/src/espi.c
index 9aa0b53cce..1a476aab72 100644
--- a/zephyr/test/drivers/src/espi.c
+++ b/zephyr/test/drivers/src/espi.c
@@ -8,10 +8,12 @@
#include "ec_commands.h"
#include "host_command.h"
+#include "test_state.h"
+
#define PORT 0
-static void test_host_command_get_protocol_info(void)
+ZTEST_USER(espi, test_host_command_get_protocol_info)
{
struct ec_response_get_protocol_info response;
struct host_cmd_handler_args args =
@@ -29,7 +31,7 @@ static void test_host_command_get_protocol_info(void)
zassert_equal(response.flags, 0, NULL);
}
-static void test_host_command_usb_pd_power_info(void)
+ZTEST_USER(espi, test_host_command_usb_pd_power_info)
{
/* Only test we've enabled the command */
struct ec_response_usb_pd_power_info response;
@@ -43,12 +45,4 @@ static void test_host_command_usb_pd_power_info(void)
zassert_equal(args.response_size, sizeof(response), NULL);
}
-void test_suite_espi(void)
-{
- ztest_test_suite(espi,
- ztest_user_unit_test(
- test_host_command_usb_pd_power_info),
- ztest_user_unit_test(
- test_host_command_get_protocol_info));
- ztest_run_test_suite(espi);
-}
+ZTEST_SUITE(espi, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
diff --git a/zephyr/test/drivers/src/integration_usb.c b/zephyr/test/drivers/src/integration_usb.c
index 7129ab1eed..4205d3fd3e 100644
--- a/zephyr/test/drivers/src/integration_usb.c
+++ b/zephyr/test/drivers/src/integration_usb.c
@@ -21,6 +21,7 @@
#include "tcpm/tcpci.h"
#include "test/usb_pe.h"
#include "utils.h"
+#include "test_state.h"
#define TCPCI_EMUL_LABEL DT_NODELABEL(tcpci_emul)
#define BATTERY_ORD DT_DEP_ORD(DT_NODELABEL(battery))
@@ -28,7 +29,7 @@
#define GPIO_AC_OK_PATH DT_PATH(named_gpios, acok_od)
#define GPIO_AC_OK_PIN DT_GPIO_PIN(GPIO_AC_OK_PATH, gpios)
-static void init_tcpm(void)
+static void integration_usb_before(void *state)
{
const struct emul *tcpci_emul =
emul_get_binding(DT_LABEL(TCPCI_EMUL_LABEL));
@@ -37,6 +38,7 @@ static void init_tcpm(void)
const struct device *gpio_dev =
DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_AC_OK_PATH, gpios));
+ ARG_UNUSED(state);
set_test_runner_tid();
zassert_ok(tcpci_tcpm_init(0), 0);
tcpci_emul_set_rev(tcpci_emul, TCPCI_EMUL_REV1_0_VER1_0);
@@ -52,17 +54,21 @@ static void init_tcpm(void)
zassert_ok(gpio_emul_input_set(gpio_dev, GPIO_AC_OK_PIN, 0), NULL);
}
-static void remove_emulated_devices(void)
+static void integration_usb_after(void *state)
{
const struct emul *tcpci_emul =
emul_get_binding(DT_LABEL(TCPCI_EMUL_LABEL));
+ ARG_UNUSED(state);
+
/* TODO: This function should trigger gpios to signal there is nothing
* attached to the port.
*/
zassert_ok(tcpci_emul_disconnect_partner(tcpci_emul), NULL);
+ /* Give time to actually disconnect */
+ k_sleep(K_SECONDS(1));
}
-static void test_attach_compliant_charger(void)
+ZTEST(integration_usb, test_attach_compliant_charger)
{
const struct emul *tcpci_emul =
emul_get_binding(DT_LABEL(TCPCI_EMUL_LABEL));
@@ -102,7 +108,9 @@ static void test_attach_compliant_charger(void)
/* TODO: Also check voltage, current, etc. */
}
-static void test_attach_pd_charger(void)
+#define BATTERY_ORD DT_DEP_ORD(DT_NODELABEL(battery))
+
+ZTEST(integration_usb, test_attach_pd_charger)
{
const struct emul *tcpci_emul =
emul_get_binding(DT_LABEL(TCPCI_EMUL_LABEL));
@@ -210,12 +218,17 @@ static void test_attach_pd_charger(void)
*/
}
-static void test_attach_sink(void)
+ZTEST(integration_usb, test_attach_sink)
{
const struct emul *tcpci_emul =
emul_get_binding(DT_LABEL(TCPCI_EMUL_LABEL));
struct tcpci_snk_emul my_sink;
+ /*
+ * TODO: investigate why call in integration_usb_before() is not enough
+ */
+ set_test_runner_tid();
+
/* Set chipset to ON, this will set TCPM to DRP */
test_set_chipset_to_s0();
@@ -241,12 +254,17 @@ static void test_attach_sink(void)
zassert_equal(PE_SRC_READY, get_state_pe(USBC_PORT_C0), NULL);
}
-static void test_attach_drp(void)
+ZTEST(integration_usb, test_attach_drp)
{
const struct emul *tcpci_emul =
emul_get_binding(DT_LABEL(TCPCI_EMUL_LABEL));
struct tcpci_drp_emul my_drp;
+ /*
+ * TODO: investigate why call in integration_usb_before() is not enough
+ */
+ set_test_runner_tid();
+
/* Set chipset to ON, this will set TCPM to DRP */
test_set_chipset_to_s0();
@@ -272,20 +290,5 @@ static void test_attach_drp(void)
zassert_equal(PE_SNK_READY, get_state_pe(USBC_PORT_C0), NULL);
}
-void test_suite_integration_usb(void)
-{
- ztest_test_suite(integration_usb,
- ztest_user_unit_test_setup_teardown(
- test_attach_compliant_charger, init_tcpm,
- remove_emulated_devices),
- ztest_user_unit_test_setup_teardown(
- test_attach_pd_charger, init_tcpm,
- remove_emulated_devices),
- ztest_user_unit_test_setup_teardown(
- test_attach_sink, init_tcpm,
- remove_emulated_devices),
- ztest_user_unit_test_setup_teardown(
- test_attach_drp, init_tcpm,
- remove_emulated_devices));
- ztest_run_test_suite(integration_usb);
-}
+ZTEST_SUITE(integration_usb, drivers_predicate_post_main, NULL,
+ integration_usb_before, integration_usb_after, NULL);
diff --git a/zephyr/test/drivers/src/isl923x.c b/zephyr/test/drivers/src/isl923x.c
index 27ce29984a..bac792c8bf 100644
--- a/zephyr/test/drivers/src/isl923x.c
+++ b/zephyr/test/drivers/src/isl923x.c
@@ -16,6 +16,7 @@
#include "emul/emul_isl923x.h"
#include "system.h"
#include "test_mocks.h"
+#include "test_state.h"
BUILD_ASSERT(CONFIG_CHARGER_SENSE_RESISTOR == 10 ||
CONFIG_CHARGER_SENSE_RESISTOR == 5);
@@ -53,7 +54,7 @@ static int mock_write_fn_always_fail(struct i2c_emul *emul, int reg,
return 0;
}
-static void test_isl923x_set_current(void)
+ZTEST(isl329x, test_isl923x_set_current)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -93,7 +94,7 @@ static void test_isl923x_set_current(void)
}
}
-static void test_isl923x_set_voltage(void)
+ZTEST(isl329x, test_isl923x_set_voltage)
{
int expected_voltage_milli_volts[] = { 8, 16, 32, 64,
128, 256, 512, 1024,
@@ -126,7 +127,7 @@ static void test_isl923x_set_voltage(void)
}
}
-static void test_isl923x_set_input_current_limit(void)
+ZTEST(isl329x, test_isl923x_set_input_current_limit)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -192,7 +193,7 @@ static void test_isl923x_set_input_current_limit(void)
}
}
-static void test_manufacturer_id(void)
+ZTEST(isl329x, test_manufacturer_id)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -213,7 +214,7 @@ static void test_manufacturer_id(void)
I2C_COMMON_EMUL_NO_FAIL_REG);
}
-static void test_device_id(void)
+ZTEST(isl329x, test_device_id)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -234,7 +235,7 @@ static void test_device_id(void)
I2C_COMMON_EMUL_NO_FAIL_REG);
}
-static void test_options(void)
+ZTEST(isl329x, test_options)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -275,7 +276,7 @@ static void test_options(void)
"Expected options 0xff7ffffe but got 0x%x", option);
}
-static void test_get_info(void)
+ZTEST(isl329x, test_get_info)
{
const struct charger_info *info = isl923x_drv.get_info(CHARGER_NUM);
@@ -294,7 +295,7 @@ static void test_get_info(void)
NULL);
}
-static void test_status(void)
+ZTEST(isl329x, test_status)
{
int status;
@@ -302,7 +303,7 @@ static void test_status(void)
zassert_equal(CHARGER_LEVEL_2, status, NULL);
}
-static void test_set_mode(void)
+ZTEST(isl329x, test_set_mode)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
@@ -320,12 +321,12 @@ static void test_set_mode(void)
zassert_true(!isl923x_emul_is_learn_mode_enabled(isl923x_emul), NULL);
}
-static void test_post_init(void)
+ZTEST(isl329x, test_post_init)
{
zassert_ok(isl923x_drv.post_init(CHARGER_NUM), NULL);
}
-static void test_set_ac_prochot(void)
+ZTEST(isl329x, test_set_ac_prochot)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
const struct device *i2c_dev = isl923x_emul_get_parent(isl923x_emul);
@@ -386,7 +387,7 @@ static void test_set_ac_prochot(void)
current_milli_amps);
}
}
-static void test_set_dc_prochot(void)
+ZTEST(isl329x, test_set_dc_prochot)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
const struct device *i2c_dev = isl923x_emul_get_parent(isl923x_emul);
@@ -442,7 +443,7 @@ static void test_set_dc_prochot(void)
}
}
-static void test_comparator_inversion(void)
+ZTEST(isl329x, test_comparator_inversion)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
const struct device *i2c_dev = isl923x_emul_get_parent(isl923x_emul);
@@ -489,7 +490,7 @@ static void test_comparator_inversion(void)
zassert_true((reg_value & ISL923X_C2_INVERT_CMOUT) == 0, NULL);
}
-static void test_discharge_on_ac(void)
+ZTEST(isl329x, test_discharge_on_ac)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
const struct device *i2c_dev = isl923x_emul_get_parent(isl923x_emul);
@@ -540,7 +541,7 @@ static void test_discharge_on_ac(void)
zassert_true((reg_value & ISL923X_C1_LEARN_MODE_ENABLE) == 0, NULL);
}
-static void test_get_vbus_voltage(void)
+ZTEST(isl329x, test_get_vbus_voltage)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -569,7 +570,7 @@ static void test_get_vbus_voltage(void)
}
}
-static void test_init(void)
+ZTEST(isl329x, test_init)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -675,7 +676,7 @@ static void test_init(void)
system_jumped_late_mock.ret_val = false;
}
-static void test_isl923x_is_acok(void)
+ZTEST(isl329x, test_isl923x_is_acok)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -712,7 +713,7 @@ static void test_isl923x_is_acok(void)
zassert_false(acok, "AC OK is true");
}
-static void test_isl923x_enable_asgate(void)
+ZTEST(isl329x, test_isl923x_enable_asgate)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -747,10 +748,11 @@ FAKE_VALUE_FUNC(int, hibernate_mock_write_fn, struct i2c_emul *, int, uint8_t,
/**
* @brief Setup function for the hibernate tests.
*/
-static void hibernate_test_setup(void)
+static void isl923x_hibernate_before(void *state)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
+ ARG_UNUSED(state);
/* Reset mocks and make the read/write mocks pass all data through */
RESET_FAKE(hibernate_mock_read_fn);
@@ -771,10 +773,11 @@ static void hibernate_test_setup(void)
/**
* @brief Teardown function for the hibernate tests.
*/
-static void hibernate_test_teardown(void)
+static void isl923x_hibernate_after(void *state)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
+ ARG_UNUSED(state);
/* Clear the mock read/write functions */
i2c_common_emul_set_read_func(i2c_emul, NULL, NULL);
@@ -787,7 +790,7 @@ static void hibernate_test_teardown(void)
I2C_COMMON_EMUL_NO_FAIL_REG);
}
-static void test_isl923x_hibernate__happy_path(void)
+ZTEST(isl923x_hibernate, test_isl923x_hibernate__happy_path)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -844,7 +847,7 @@ static void test_isl923x_hibernate__happy_path(void)
}
}
-static void test_isl923x_hibernate__invalid_charger_number(void)
+ZTEST(isl923x_hibernate, test_isl923x_hibernate__invalid_charger_number)
{
/* Mocks should just be pass-through */
RESET_FAKE(hibernate_mock_read_fn);
@@ -861,7 +864,7 @@ static void test_isl923x_hibernate__invalid_charger_number(void)
"No I2C writes should have happened");
}
-static void test_isl923x_hibernate__fail_at_ISL923X_REG_CONTROL0(void)
+ZTEST(isl923x_hibernate, test_isl923x_hibernate__fail_at_ISL923X_REG_CONTROL0)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -879,7 +882,7 @@ static void test_isl923x_hibernate__fail_at_ISL923X_REG_CONTROL0(void)
MOCK_IGNORE_VALUE);
}
-static void test_isl923x_hibernate__fail_at_ISL923X_REG_CONTROL1(void)
+ZTEST(isl923x_hibernate, test_isl923x_hibernate__fail_at_ISL923X_REG_CONTROL1)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -903,7 +906,7 @@ static void test_isl923x_hibernate__fail_at_ISL923X_REG_CONTROL1(void)
MOCK_IGNORE_VALUE);
}
-static void test_isl923x_hibernate__fail_at_ISL9238_REG_CONTROL3(void)
+ZTEST(isl923x_hibernate, test_isl923x_hibernate__fail_at_ISL9238_REG_CONTROL3)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -927,7 +930,7 @@ static void test_isl923x_hibernate__fail_at_ISL9238_REG_CONTROL3(void)
MOCK_IGNORE_VALUE);
}
-static void test_isl923x_hibernate__fail_at_ISL9238_REG_CONTROL4(void)
+ZTEST(isl923x_hibernate, test_isl923x_hibernate__fail_at_ISL9238_REG_CONTROL4)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -948,7 +951,7 @@ static void test_isl923x_hibernate__fail_at_ISL9238_REG_CONTROL4(void)
ISL9238_REG_CONTROL3, MOCK_IGNORE_VALUE);
}
-static void test_isl923x_hibernate__adc_disable(void)
+ZTEST(isl923x_hibernate, test_isl923x_hibernate__adc_disable)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -968,7 +971,7 @@ static void test_isl923x_hibernate__adc_disable(void)
expected >> 8);
}
-static void test_isl9238c_hibernate(void)
+ZTEST(isl923x_hibernate, test_isl9238c_hibernate)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -1022,7 +1025,7 @@ static void test_isl9238c_hibernate(void)
}
}
-static void test_isl9238c_resume(void)
+ZTEST(isl923x_hibernate, test_isl9238c_resume)
{
const struct emul *isl923x_emul = ISL923X_EMUL;
struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
@@ -1076,50 +1079,7 @@ static void test_isl9238c_resume(void)
}
}
-void test_suite_isl923x(void)
-{
- ztest_test_suite(
- isl923x, ztest_unit_test(test_isl923x_set_current),
- ztest_unit_test(test_isl923x_set_voltage),
- ztest_unit_test(test_isl923x_set_input_current_limit),
- ztest_unit_test(test_manufacturer_id),
- ztest_unit_test(test_device_id), ztest_unit_test(test_options),
- ztest_unit_test(test_get_info), ztest_unit_test(test_status),
- ztest_unit_test(test_set_mode), ztest_unit_test(test_post_init),
- ztest_unit_test(test_set_ac_prochot),
- ztest_unit_test(test_set_dc_prochot),
- ztest_unit_test(test_comparator_inversion),
- ztest_unit_test(test_discharge_on_ac),
- ztest_unit_test(test_get_vbus_voltage),
- ztest_unit_test(test_init),
- ztest_unit_test(test_isl923x_is_acok),
- ztest_unit_test(test_isl923x_enable_asgate),
- ztest_unit_test_setup_teardown(
- test_isl923x_hibernate__happy_path,
- hibernate_test_setup, hibernate_test_teardown),
- ztest_unit_test_setup_teardown(
- test_isl923x_hibernate__invalid_charger_number,
- hibernate_test_setup, hibernate_test_teardown),
- ztest_unit_test_setup_teardown(
- test_isl923x_hibernate__fail_at_ISL923X_REG_CONTROL0,
- hibernate_test_setup, hibernate_test_teardown),
- ztest_unit_test_setup_teardown(
- test_isl923x_hibernate__fail_at_ISL923X_REG_CONTROL1,
- hibernate_test_setup, hibernate_test_teardown),
- ztest_unit_test_setup_teardown(
- test_isl923x_hibernate__fail_at_ISL9238_REG_CONTROL3,
- hibernate_test_setup, hibernate_test_teardown),
- ztest_unit_test_setup_teardown(
- test_isl923x_hibernate__fail_at_ISL9238_REG_CONTROL4,
- hibernate_test_setup, hibernate_test_teardown),
- ztest_unit_test_setup_teardown(
- test_isl923x_hibernate__adc_disable,
- hibernate_test_setup, hibernate_test_teardown),
- ztest_unit_test_setup_teardown(test_isl9238c_hibernate,
- hibernate_test_teardown,
- hibernate_test_teardown),
- ztest_unit_test_setup_teardown(test_isl9238c_resume,
- hibernate_test_teardown,
- hibernate_test_teardown));
- ztest_run_test_suite(isl923x);
-}
+ZTEST_SUITE(isl923x, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
+
+ZTEST_SUITE(isl923x_hibernate, drivers_predicate_post_main, NULL,
+ isl923x_hibernate_before, isl923x_hibernate_after, NULL);
diff --git a/zephyr/test/drivers/src/lis2dw12.c b/zephyr/test/drivers/src/lis2dw12.c
index 24218aea9f..96c0389585 100644
--- a/zephyr/test/drivers/src/lis2dw12.c
+++ b/zephyr/test/drivers/src/lis2dw12.c
@@ -8,6 +8,7 @@
#include "driver/accel_lis2dw12.h"
#include "emul/emul_common_i2c.h"
#include "emul/emul_lis2dw12.h"
+#include "test_state.h"
#define LIS2DW12_NODELABEL DT_NODELABEL(ms_lis2dw12_accel)
#define LIS2DW12_SENSOR_ID SENSOR_ID(LIS2DW12_NODELABEL)
@@ -34,7 +35,7 @@ enum lis2dw12_round_mode {
ROUND_UP,
};
-static void lis2dw12_setup(void)
+static inline void lis2dw12_setup(void)
{
lis2dw12_emul_reset(emul_get_binding(EMUL_LABEL));
@@ -44,7 +45,19 @@ static void lis2dw12_setup(void)
ms->current_range = 0;
}
-static void test_lis2dw12_init__fail_read_who_am_i(void)
+static void lis2dw12_before(void *state)
+{
+ ARG_UNUSED(state);
+ lis2dw12_setup();
+}
+
+static void lis2dw12_after(void *state)
+{
+ ARG_UNUSED(state);
+ lis2dw12_setup();
+}
+
+ZTEST(lis2dw12, test_lis2dw12_init__fail_read_who_am_i)
{
const struct emul *emul = emul_get_binding(EMUL_LABEL);
struct motion_sensor_t *ms = &motion_sensors[LIS2DW12_SENSOR_ID];
@@ -56,7 +69,7 @@ static void test_lis2dw12_init__fail_read_who_am_i(void)
zassert_equal(EC_ERROR_INVAL, rv, NULL);
}
-static void test_lis2dw12_init__fail_who_am_i(void)
+ZTEST(lis2dw12, test_lis2dw12_init__fail_who_am_i)
{
const struct emul *emul = emul_get_binding(EMUL_LABEL);
struct motion_sensor_t *ms = &motion_sensors[LIS2DW12_SENSOR_ID];
@@ -70,7 +83,7 @@ static void test_lis2dw12_init__fail_who_am_i(void)
EC_ERROR_ACCESS_DENIED);
}
-static void test_lis2dw12_init__fail_write_soft_reset(void)
+ZTEST(lis2dw12, test_lis2dw12_init__fail_write_soft_reset)
{
const struct emul *emul = emul_get_binding(EMUL_LABEL);
struct motion_sensor_t *ms = &motion_sensors[LIS2DW12_SENSOR_ID];
@@ -82,7 +95,7 @@ static void test_lis2dw12_init__fail_write_soft_reset(void)
zassert_equal(EC_ERROR_INVAL, rv, NULL);
}
-static void test_lis2dw12_init__timeout_read_soft_reset(void)
+ZTEST(lis2dw12, test_lis2dw12_init__timeout_read_soft_reset)
{
const struct emul *emul = emul_get_binding(EMUL_LABEL);
struct motion_sensor_t *ms = &motion_sensors[LIS2DW12_SENSOR_ID];
@@ -106,7 +119,7 @@ static int lis2dw12_test_mock_write_fail_set_bdu(struct i2c_emul *emul, int reg,
return 1;
}
-static void test_lis2dw12_init__fail_set_bdu(void)
+ZTEST(lis2dw12, test_lis2dw12_init__fail_set_bdu)
{
const struct emul *emul = emul_get_binding(EMUL_LABEL);
struct motion_sensor_t *ms = &motion_sensors[LIS2DW12_SENSOR_ID];
@@ -122,7 +135,7 @@ static void test_lis2dw12_init__fail_set_bdu(void)
"expected at least one soft reset");
}
-static void test_lis2dw12_init__fail_set_lir(void)
+ZTEST(lis2dw12, test_lis2dw12_init__fail_set_lir)
{
const struct emul *emul = emul_get_binding(EMUL_LABEL);
struct motion_sensor_t *ms = &motion_sensors[LIS2DW12_SENSOR_ID];
@@ -150,7 +163,7 @@ static int lis2dw12_test_mock_write_fail_set_power_mode(struct i2c_emul *emul,
return 1;
}
-static void test_lis2dw12_init__fail_set_power_mode(void)
+ZTEST(lis2dw12, test_lis2dw12_init__fail_set_power_mode)
{
const struct emul *emul = emul_get_binding(EMUL_LABEL);
struct motion_sensor_t *ms = &motion_sensors[LIS2DW12_SENSOR_ID];
@@ -167,7 +180,7 @@ static void test_lis2dw12_init__fail_set_power_mode(void)
"expected at least one soft reset");
}
-static void test_lis2dw12_init__success(void)
+ZTEST(lis2dw12, test_lis2dw12_init__success)
{
const struct emul *emul = emul_get_binding(EMUL_LABEL);
struct motion_sensor_t *ms = &motion_sensors[LIS2DW12_SENSOR_ID];
@@ -185,7 +198,7 @@ static void test_lis2dw12_init__success(void)
LIS2DW12_RESOLUTION, drvdata->resol);
}
-static void test_lis2dw12_set_power_mode(void)
+ZTEST(lis2dw12, test_lis2dw12_set_power_mode)
{
const struct emul *emul = emul_get_binding(EMUL_LABEL);
struct motion_sensor_t *ms = &motion_sensors[LIS2DW12_SENSOR_ID];
@@ -211,7 +224,7 @@ static void test_lis2dw12_set_power_mode(void)
EC_ERROR_INVAL, rv);
}
-static void test_lis2dw12_set_range(void)
+ZTEST(lis2dw12, test_lis2dw12_set_range)
{
const struct emul *emul = emul_get_binding(EMUL_LABEL);
struct motion_sensor_t *ms = &motion_sensors[LIS2DW12_SENSOR_ID];
@@ -235,7 +248,7 @@ static void test_lis2dw12_set_range(void)
EC_ERROR_INVAL, rv);
}
-static void test_lis2dw12_set_rate(void)
+ZTEST(lis2dw12, test_lis2dw12_set_rate)
{
const struct emul *emul = emul_get_binding(EMUL_LABEL);
struct i2c_emul *i2c_emul = lis2dw12_emul_to_i2c_emul(emul);
@@ -342,7 +355,7 @@ static void test_lis2dw12_set_rate(void)
}
}
-static void test_lis2dw12_read(void)
+ZTEST(lis2dw12, test_lis2dw12_read)
{
const struct emul *emul = emul_get_binding(EMUL_LABEL);
struct i2c_emul *i2c_emul = lis2dw12_emul_to_i2c_emul(emul);
@@ -428,45 +441,5 @@ static void test_lis2dw12_read(void)
CHECK_XYZ_EQUALS(sample, expected_sample);
}
-void test_suite_lis2dw12(void)
-{
- ztest_test_suite(lis2dw12,
- ztest_unit_test_setup_teardown(
- test_lis2dw12_init__fail_read_who_am_i,
- lis2dw12_setup, lis2dw12_setup),
- ztest_unit_test_setup_teardown(
- test_lis2dw12_init__fail_who_am_i,
- lis2dw12_setup, lis2dw12_setup),
- ztest_unit_test_setup_teardown(
- test_lis2dw12_init__fail_write_soft_reset,
- lis2dw12_setup, lis2dw12_setup),
- ztest_unit_test_setup_teardown(
- test_lis2dw12_init__timeout_read_soft_reset,
- lis2dw12_setup, lis2dw12_setup),
- ztest_unit_test_setup_teardown(
- test_lis2dw12_init__fail_set_bdu,
- lis2dw12_setup, lis2dw12_setup),
- ztest_unit_test_setup_teardown(
- test_lis2dw12_init__fail_set_lir,
- lis2dw12_setup, lis2dw12_setup),
- ztest_unit_test_setup_teardown(
- test_lis2dw12_init__fail_set_power_mode,
- lis2dw12_setup, lis2dw12_setup),
- ztest_unit_test_setup_teardown(
- test_lis2dw12_init__success,
- lis2dw12_setup, lis2dw12_setup),
- ztest_unit_test_setup_teardown(
- test_lis2dw12_set_power_mode,
- lis2dw12_setup, lis2dw12_setup),
- ztest_unit_test_setup_teardown(
- test_lis2dw12_set_range,
- lis2dw12_setup, lis2dw12_setup),
- ztest_unit_test_setup_teardown(
- test_lis2dw12_set_rate,
- lis2dw12_setup, lis2dw12_setup),
- ztest_unit_test_setup_teardown(
- test_lis2dw12_read,
- lis2dw12_setup, lis2dw12_setup)
- );
- ztest_run_test_suite(lis2dw12);
-}
+ZTEST_SUITE(lis2dw12, drivers_predicate_post_main, NULL, lis2dw12_before,
+ lis2dw12_after, NULL);
diff --git a/zephyr/test/drivers/src/ln9310.c b/zephyr/test/drivers/src/ln9310.c
index 8ee397fb8a..e7fdeb47b2 100644
--- a/zephyr/test/drivers/src/ln9310.c
+++ b/zephyr/test/drivers/src/ln9310.c
@@ -13,6 +13,7 @@
#include "emul/emul_ln9310.h"
#include "emul/emul_common_i2c.h"
#include "timer.h"
+#include "test_state.h"
/*
* TODO(b/201420132): Implement approach for tests to immediately schedule work
@@ -27,7 +28,7 @@
#define REQUIRES_CFLY_PRECHARGE_STARTUP_CHIP_REV \
(LN9310_BC_STS_C_CHIP_REV_FIXED - 1)
-static void test_ln9310_read_chip_fails(void)
+ZTEST(ln9310, test_ln9310_read_chip_fails)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -55,7 +56,7 @@ static void test_ln9310_read_chip_fails(void)
I2C_COMMON_EMUL_NO_FAIL_REG);
}
-static void test_ln9310_2s_powers_up(void)
+ZTEST(ln9310, test_ln9310_2s_powers_up)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -80,7 +81,7 @@ static void test_ln9310_2s_powers_up(void)
zassert_true(ln9310_power_good(), NULL);
}
-static void test_ln9310_3s_powers_up(void)
+ZTEST(ln9310, test_ln9310_3s_powers_up)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -131,7 +132,7 @@ static int mock_write_fn_intercept_startup_workaround(struct i2c_emul *emul,
return 1;
}
-static void test_ln9310_2s_cfly_precharge_startup(void)
+ZTEST(ln9310, test_ln9310_2s_cfly_precharge_startup)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -177,7 +178,7 @@ static void test_ln9310_2s_cfly_precharge_startup(void)
i2c_common_emul_set_write_func(emul, NULL, NULL);
}
-static void test_ln9310_3s_cfly_precharge_startup(void)
+ZTEST(ln9310, test_ln9310_3s_cfly_precharge_startup)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -222,7 +223,7 @@ static void test_ln9310_3s_cfly_precharge_startup(void)
i2c_common_emul_set_write_func(emul, NULL, NULL);
}
-static void test_ln9310_cfly_precharge_exceeds_retries(void)
+ZTEST(ln9310, test_ln9310_cfly_precharge_exceeds_retries)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -266,7 +267,7 @@ static void test_ln9310_cfly_precharge_exceeds_retries(void)
i2c_common_emul_set_write_func(emul, NULL, NULL);
}
-static void test_ln9310_battery_unknown(void)
+ZTEST(ln9310, test_ln9310_battery_unknown)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -296,7 +297,7 @@ static void test_ln9310_battery_unknown(void)
zassert_false(ln9310_power_good(), NULL);
}
-static void test_ln9310_2s_battery_read_fails(void)
+ZTEST(ln9310, test_ln9310_2s_battery_read_fails)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -332,7 +333,7 @@ static void test_ln9310_2s_battery_read_fails(void)
I2C_COMMON_EMUL_NO_FAIL_REG);
}
-static void test_ln9310_lion_ctrl_reg_fails(void)
+ZTEST(ln9310, test_ln9310_lion_ctrl_reg_fails)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -394,7 +395,7 @@ static int mock_intercept_startup_ctrl_reg(struct i2c_emul *emul, int reg,
return 1;
}
-static void test_ln9310_cfly_precharge_timesout(void)
+ZTEST(ln9310, test_ln9310_cfly_precharge_timesout)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -458,7 +459,7 @@ static int mock_read_intercept_reg_to_fail(struct i2c_emul *emul, int reg,
return 1;
}
-static void test_ln9310_interrupt_reg_fail(void)
+ZTEST(ln9310, test_ln9310_interrupt_reg_fail)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -506,7 +507,7 @@ static void test_ln9310_interrupt_reg_fail(void)
i2c_common_emul_set_read_func(i2c_emul, NULL, NULL);
}
-static void test_ln9310_sys_sts_reg_fail(void)
+ZTEST(ln9310, test_ln9310_sys_sts_reg_fail)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -562,7 +563,7 @@ static int mock_read_interceptor(struct i2c_emul *emul, int reg, uint8_t *val,
return 1;
}
-static void test_ln9310_reset_explicit_detected_startup(void)
+ZTEST(ln9310, test_ln9310_reset_explicit_detected_startup)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -597,7 +598,7 @@ static void test_ln9310_reset_explicit_detected_startup(void)
i2c_common_emul_set_read_func(i2c_emul, NULL, NULL);
}
-static void test_ln9310_update_startup_seq_fails(void)
+ZTEST(ln9310, test_ln9310_update_startup_seq_fails)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -635,7 +636,7 @@ static void test_ln9310_update_startup_seq_fails(void)
i2c_common_emul_set_read_func(i2c_emul, NULL, NULL);
}
-static void test_ln9310_state_change_only_on_mode_change_interrupt(void)
+ZTEST(ln9310, test_ln9310_state_change_only_on_mode_change_interrupt)
{
const struct emul *emulator =
emul_get_binding(DT_LABEL(DT_NODELABEL(ln9310)));
@@ -670,67 +671,23 @@ static void test_ln9310_state_change_only_on_mode_change_interrupt(void)
i2c_common_emul_set_read_func(i2c_emul, NULL, NULL);
}
-static void reset_ln9310_state(void)
+static inline void reset_ln9310_state(void)
{
ln9310_reset_to_initial_state();
get_time_mock = NULL;
}
-void test_suite_ln9310(void)
+static void ln9310_before(void *state)
{
- ztest_test_suite(
- ln9310,
- ztest_unit_test_setup_teardown(
- test_ln9310_state_change_only_on_mode_change_interrupt,
- reset_ln9310_state,
- reset_ln9310_state),
- ztest_unit_test_setup_teardown(
- test_ln9310_update_startup_seq_fails,
- reset_ln9310_state,
- reset_ln9310_state),
- ztest_unit_test_setup_teardown(
- test_ln9310_reset_explicit_detected_startup,
- reset_ln9310_state,
- reset_ln9310_state),
- ztest_unit_test_setup_teardown(
- test_ln9310_sys_sts_reg_fail,
- reset_ln9310_state,
- reset_ln9310_state),
- ztest_unit_test_setup_teardown(
- test_ln9310_interrupt_reg_fail,
- reset_ln9310_state,
- reset_ln9310_state),
- ztest_unit_test_setup_teardown(
- test_ln9310_cfly_precharge_timesout,
- reset_ln9310_state,
- reset_ln9310_state),
- ztest_unit_test_setup_teardown(test_ln9310_lion_ctrl_reg_fails,
- reset_ln9310_state,
- reset_ln9310_state),
- ztest_unit_test_setup_teardown(
- test_ln9310_2s_battery_read_fails,
- reset_ln9310_state,
- reset_ln9310_state),
- ztest_unit_test_setup_teardown(test_ln9310_battery_unknown,
- reset_ln9310_state,
- reset_ln9310_state),
- ztest_unit_test_setup_teardown(test_ln9310_read_chip_fails,
- reset_ln9310_state,
- reset_ln9310_state),
- ztest_unit_test_setup_teardown(test_ln9310_2s_powers_up,
- reset_ln9310_state,
- reset_ln9310_state),
- ztest_unit_test_setup_teardown(test_ln9310_3s_powers_up,
- reset_ln9310_state,
- reset_ln9310_state),
- ztest_unit_test_setup_teardown(
- test_ln9310_cfly_precharge_exceeds_retries,
- reset_ln9310_state, reset_ln9310_state),
- ztest_unit_test_setup_teardown(
- test_ln9310_2s_cfly_precharge_startup,
- reset_ln9310_state, reset_ln9310_state),
- ztest_unit_test_setup_teardown(
- test_ln9310_3s_cfly_precharge_startup,
- reset_ln9310_state, reset_ln9310_state));
- ztest_run_test_suite(ln9310);
+ ARG_UNUSED(state);
+ reset_ln9310_state();
}
+
+static void ln9310_after(void *state)
+{
+ ARG_UNUSED(state);
+ reset_ln9310_state();
+}
+
+ZTEST_SUITE(ln9310, drivers_predicate_post_main, NULL, ln9310_before,
+ ln9310_after, NULL);
diff --git a/zephyr/test/drivers/src/main.c b/zephyr/test/drivers/src/main.c
index f879982722..b3bb18a4be 100644
--- a/zephyr/test/drivers/src/main.c
+++ b/zephyr/test/drivers/src/main.c
@@ -6,67 +6,33 @@
#include <zephyr.h>
#include <ztest.h>
#include "ec_app_main.h"
+#include "test_state.h"
-extern void test_suite_battery(void);
-extern void test_suite_cbi(void);
-extern void test_suite_smart_battery(void);
-extern void test_suite_thermistor(void);
-extern void test_suite_temp_sensor(void);
-extern void test_suite_bma2x2(void);
-extern void test_suite_bc12(void);
-extern void test_suite_bmi260(void);
-extern void test_suite_bmi160(void);
-extern void test_suite_tcs3400(void);
-extern void test_suite_espi(void);
-extern void test_suite_bb_retimer(void);
-extern void test_suite_ln9310(void);
-extern void test_suite_lis2dw12(void);
-extern void test_suite_stm_mems_common(void);
-extern void test_suite_isl923x(void);
-extern void test_suite_usb_mux(void);
-extern void test_suite_ppc_syv682c(void);
-extern void test_suite_ppc_sn5s330(void);
-extern void test_suite_cros_cbi(void);
-extern void test_suite_tcpci(void);
-extern void test_suite_ps8xxx(void);
-extern void test_suite_integration_usb(void);
-extern void test_suite_power_common(void);
-extern void test_suite_power_common_no_tasks(void);
-extern void test_suite_watchdog(void);
-extern void test_suite_usb_pd_host_cmd(void);
+bool drivers_predicate_pre_main(const void *state)
+{
+ return ((struct test_state *)state)->ec_app_main_run == false;
+}
+
+bool drivers_predicate_post_main(const void *state)
+{
+ return !drivers_predicate_pre_main(state);
+}
void test_main(void)
{
- /* Test suites to run before ec_app_main.*/
- test_suite_power_common_no_tasks();
+ struct test_state state = {
+ .ec_app_main_run = false,
+ };
+
+ /* Run all the suites that depend on main not being called yet */
+ ztest_run_test_suites(&state);
ec_app_main();
+ state.ec_app_main_run = true;
+
+ /* Run all the suites that depend on main being called */
+ ztest_run_test_suites(&state);
- /* Test suites to run after ec_app_main.*/
- test_suite_battery();
- test_suite_cbi();
- test_suite_smart_battery();
- test_suite_thermistor();
- test_suite_temp_sensor();
- test_suite_bma2x2();
- test_suite_bc12();
- test_suite_bmi260();
- test_suite_bmi160();
- test_suite_tcs3400();
- test_suite_espi();
- test_suite_bb_retimer();
- test_suite_ln9310();
- test_suite_lis2dw12();
- test_suite_stm_mems_common();
- test_suite_isl923x();
- test_suite_usb_mux();
- test_suite_ppc_sn5s330();
- test_suite_ppc_syv682c();
- test_suite_cros_cbi();
- test_suite_tcpci();
- test_suite_ps8xxx();
- test_suite_integration_usb();
- test_suite_power_common();
- test_suite_watchdog();
- test_suite_usb_pd_host_cmd();
+ /* Check that every suite ran */
+ ztest_verify_all_test_suites_ran();
}
diff --git a/zephyr/test/drivers/src/power_common.c b/zephyr/test/drivers/src/power_common.c
index 950393ee15..ee055745af 100644
--- a/zephyr/test/drivers/src/power_common.c
+++ b/zephyr/test/drivers/src/power_common.c
@@ -18,6 +18,7 @@
#include "stubs.h"
#include "task.h"
#include "ec_tasks.h"
+#include "test_state.h"
#include "emul/emul_common_i2c.h"
#include "emul/emul_smart_battery.h"
@@ -25,10 +26,10 @@
#include "battery.h"
#include "battery_smart.h"
-#define BATTERY_ORD DT_DEP_ORD(DT_NODELABEL(battery))
+#define BATTERY_ORD DT_DEP_ORD(DT_NODELABEL(battery))
-#define GPIO_ACOK_OD_NODE DT_PATH(named_gpios, acok_od)
-#define GPIO_ACOK_OD_PIN DT_GPIO_PIN(GPIO_ACOK_OD_NODE, gpios)
+#define GPIO_ACOK_OD_NODE DT_PATH(named_gpios, acok_od)
+#define GPIO_ACOK_OD_PIN DT_GPIO_PIN(GPIO_ACOK_OD_NODE, gpios)
/* Description of all power states with chipset state masks */
static struct {
@@ -44,52 +45,52 @@ static struct {
} test_power_state_desc[] = {
{
.p_state = POWER_G3,
- .transition_to = CHIPSET_STATE_HARD_OFF,
+ .transition_to = CHIPSET_STATE_HARD_OFF,
.transition_from = CHIPSET_STATE_HARD_OFF,
},
{
.p_state = POWER_G3S5,
- .transition_to = CHIPSET_STATE_SOFT_OFF,
+ .transition_to = CHIPSET_STATE_SOFT_OFF,
.transition_from = CHIPSET_STATE_HARD_OFF,
},
{
.p_state = POWER_S5G3,
- .transition_to = CHIPSET_STATE_HARD_OFF,
+ .transition_to = CHIPSET_STATE_HARD_OFF,
.transition_from = CHIPSET_STATE_SOFT_OFF,
},
{
.p_state = POWER_S5,
- .transition_to = CHIPSET_STATE_SOFT_OFF,
+ .transition_to = CHIPSET_STATE_SOFT_OFF,
.transition_from = CHIPSET_STATE_SOFT_OFF,
},
{
.p_state = POWER_S5S3,
- .transition_to = CHIPSET_STATE_SUSPEND,
+ .transition_to = CHIPSET_STATE_SUSPEND,
.transition_from = CHIPSET_STATE_SOFT_OFF,
},
{
.p_state = POWER_S3S5,
- .transition_to = CHIPSET_STATE_SOFT_OFF,
+ .transition_to = CHIPSET_STATE_SOFT_OFF,
.transition_from = CHIPSET_STATE_SUSPEND,
},
{
.p_state = POWER_S3,
- .transition_to = CHIPSET_STATE_SUSPEND,
+ .transition_to = CHIPSET_STATE_SUSPEND,
.transition_from = CHIPSET_STATE_SUSPEND,
},
{
.p_state = POWER_S3S0,
- .transition_to = CHIPSET_STATE_ON,
+ .transition_to = CHIPSET_STATE_ON,
.transition_from = CHIPSET_STATE_SUSPEND,
},
{
.p_state = POWER_S0S3,
- .transition_to = CHIPSET_STATE_SUSPEND,
+ .transition_to = CHIPSET_STATE_SUSPEND,
.transition_from = CHIPSET_STATE_ON,
},
{
.p_state = POWER_S0,
- .transition_to = CHIPSET_STATE_ON,
+ .transition_to = CHIPSET_STATE_ON,
.transition_from = CHIPSET_STATE_ON,
},
};
@@ -110,7 +111,7 @@ static int in_state_test_masks[] = {
};
/** Test chipset_in_state() for each state */
-static void test_power_chipset_in_state(void)
+ZTEST(power_common, test_power_chipset_in_state)
{
bool expected_in_state;
bool transition_from;
@@ -128,8 +129,8 @@ static void test_power_chipset_in_state(void)
* Currently tested mask match with state if it match
* with transition_to and from chipset states
*/
- transition_to =
- mask & test_power_state_desc[i].transition_to;
+ transition_to = mask &
+ test_power_state_desc[i].transition_to;
transition_from =
mask & test_power_state_desc[i].transition_from;
expected_in_state = transition_to && transition_from;
@@ -145,7 +146,7 @@ static void test_power_chipset_in_state(void)
}
/** Test chipset_in_or_transitioning_to_state() for each state */
-static void test_power_chipset_in_or_transitioning_to_state(void)
+ZTEST(power_common, test_power_chipset_in_or_transitioning_to_state)
{
bool expected_in_state;
bool in_state;
@@ -179,8 +180,14 @@ static void test_power_chipset_in_or_transitioning_to_state(void)
* way to test the value of want_g3_exit is to set the power state to G3
* and then to see if test_power_common_state() transitions to G3S5 or not.
*/
-static void test_power_exit_hard_off(void)
+ZTEST(power_common_no_tasks, test_power_exit_hard_off)
{
+ /*
+ * Every test runs in a new thread, we need to add this thread to the
+ * dynamic shimmed tasks or this test will fail.
+ */
+ set_test_runner_tid();
+
/* Force initial state */
power_set_state(POWER_G3);
test_power_common_state();
@@ -238,7 +245,7 @@ static void test_power_exit_hard_off(void)
}
/* Test reboot ap on g3 host command is triggering reboot */
-static void test_power_reboot_ap_at_g3(void)
+ZTEST(power_common_no_tasks, test_power_reboot_ap_at_g3)
{
struct ec_params_reboot_ap_on_g3_v1 params;
struct host_cmd_handler_args args = {
@@ -251,6 +258,12 @@ static void test_power_reboot_ap_at_g3(void)
int delay_ms;
int64_t before_time;
+ /*
+ * Every test runs in a new thread, we need to add this thread to the
+ * dynamic shimmed tasks or this test will fail.
+ */
+ set_test_runner_tid();
+
/* Force initial state S0 */
power_set_state(POWER_S0);
test_power_common_state();
@@ -279,7 +292,7 @@ static void test_power_reboot_ap_at_g3(void)
}
/** Test setting cutoff and stay-up battery levels through host command */
-static void test_power_hc_smart_discharge(void)
+ZTEST(power_common, test_power_hc_smart_discharge)
{
struct ec_response_smart_discharge response;
struct ec_params_smart_discharge params;
@@ -373,7 +386,7 @@ static void test_power_hc_smart_discharge(void)
* Test if default board_system_is_idle() recognize cutoff and stay-up
* levels correctly.
*/
-static void test_power_board_system_is_idle(void)
+ZTEST(power_common, test_power_board_system_is_idle)
{
struct ec_response_smart_discharge response;
struct ec_params_smart_discharge params;
@@ -440,7 +453,7 @@ static void test_power_board_system_is_idle(void)
* battery is set in safe zone (which trigger hibernation), power state is
* set to G3 and AC is disabled. system_hibernate mock is reset.
*/
-static void setup_hibernation_delay(void)
+static void setup_hibernation_delay(void *state)
{
struct ec_response_smart_discharge response;
struct ec_params_smart_discharge params;
@@ -450,6 +463,7 @@ static void setup_hibernation_delay(void)
DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_ACOK_OD_NODE, gpios));
struct sbat_emul_bat_data *bat;
struct i2c_emul *emul;
+ ARG_UNUSED(state);
emul = sbat_emul_get_ptr(BATTERY_ORD);
bat = sbat_emul_get_bat_data(emul);
@@ -480,13 +494,12 @@ static void setup_hibernation_delay(void)
}
/** Test setting hibernation delay through host command */
-static void test_power_hc_hibernation_delay(void)
+ZTEST(power_common_hibernation, test_power_hc_hibernation_delay)
{
struct ec_response_hibernation_delay response;
struct ec_params_hibernation_delay params;
- struct host_cmd_handler_args args =
- BUILD_HOST_COMMAND(EC_CMD_HIBERNATION_DELAY, 0, response,
- params);
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
+ EC_CMD_HIBERNATION_DELAY, 0, response, params);
const struct device *acok_dev =
DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_ACOK_OD_NODE, gpios));
uint32_t h_delay;
@@ -500,11 +513,11 @@ static void test_power_hc_hibernation_delay(void)
zassert_equal(0, response.time_g3, "Time from last G3 enter %d != 0",
response.time_g3);
zassert_equal(h_delay, response.time_remaining,
- "Time to hibernation %d != %d",
- response.time_remaining, h_delay);
+ "Time to hibernation %d != %d", response.time_remaining,
+ h_delay);
zassert_equal(h_delay, response.hibernate_delay,
- "Hibernation delay %d != %d",
- h_delay, response.hibernate_delay);
+ "Hibernation delay %d != %d", h_delay,
+ response.hibernate_delay);
/* Kick chipset task to process new hibernation delay */
task_wake(TASK_ID_CHIPSET);
@@ -517,16 +530,16 @@ static void test_power_hc_hibernation_delay(void)
zassert_equal(EC_RES_SUCCESS, host_command_process(&args), NULL);
zassert_equal(sleep_time, response.time_g3,
- "Time from last G3 enter %d != %d",
- response.time_g3, sleep_time);
+ "Time from last G3 enter %d != %d", response.time_g3,
+ sleep_time);
zassert_equal(h_delay - sleep_time, response.time_remaining,
- "Time to hibernation %d != %d",
- response.time_remaining, h_delay - sleep_time);
+ "Time to hibernation %d != %d", response.time_remaining,
+ h_delay - sleep_time);
zassert_equal(h_delay, response.hibernate_delay,
- "Hibernation delay %d != %d",
- h_delay, response.hibernate_delay);
+ "Hibernation delay %d != %d", h_delay,
+ response.hibernate_delay);
zassert_equal(0, system_hibernate_fake.call_count,
- "system_hibernate() shouldn't be called before delay");
+ "system_hibernate() shouldn't be called before delay");
/* Wait to end of the hibenate delay */
k_msleep((h_delay - sleep_time) * 1000);
@@ -536,17 +549,16 @@ static void test_power_hc_hibernation_delay(void)
zassert_equal(EC_RES_SUCCESS, host_command_process(&args), NULL);
zassert_equal(h_delay, response.time_g3,
- "Time from last G3 enter %d != %d",
- response.time_g3, h_delay);
- zassert_equal(0, response.time_remaining,
- "Time to hibernation %d != 0",
+ "Time from last G3 enter %d != %d", response.time_g3,
+ h_delay);
+ zassert_equal(0, response.time_remaining, "Time to hibernation %d != 0",
response.time_remaining);
zassert_equal(h_delay, response.hibernate_delay,
- "Hibernation delay %d != %d",
- h_delay, response.hibernate_delay);
+ "Hibernation delay %d != %d", h_delay,
+ response.hibernate_delay);
zassert_equal(1, system_hibernate_fake.call_count,
- "system_hibernate() should be called after delay %d",
- system_hibernate_fake.call_count);
+ "system_hibernate() should be called after delay %d",
+ system_hibernate_fake.call_count);
/* Wait some more time */
k_msleep(2000);
@@ -556,8 +568,7 @@ static void test_power_hc_hibernation_delay(void)
zassert_equal(EC_RES_SUCCESS, host_command_process(&args), NULL);
/* After hibernation, remaining time shouldn't be negative */
- zassert_equal(0, response.time_remaining,
- "Time to hibernation %d != 0",
+ zassert_equal(0, response.time_remaining, "Time to hibernation %d != 0",
response.time_remaining);
/* Enable AC */
@@ -579,7 +590,7 @@ static void test_power_hc_hibernation_delay(void)
"Time from last G3 enter %d should be 0 on AC",
response.time_g3);
zassert_equal(0, system_hibernate_fake.call_count,
- "system_hibernate() shouldn't be called on AC");
+ "system_hibernate() shouldn't be called on AC");
/* Disable AC */
zassert_ok(gpio_emul_input_set(acok_dev, GPIO_ACOK_OD_PIN, 0), NULL);
@@ -600,7 +611,7 @@ static void test_power_hc_hibernation_delay(void)
}
/** Test setting hibernation delay through UART command */
-static void test_power_cmd_hibernation_delay(void)
+ZTEST(power_common_hibernation, test_power_cmd_hibernation_delay)
{
uint32_t h_delay;
int sleep_time;
@@ -608,18 +619,21 @@ static void test_power_cmd_hibernation_delay(void)
/* Test success on call without argument */
zassert_equal(EC_SUCCESS,
shell_execute_cmd(shell_backend_uart_get_ptr(),
- "hibdelay"), NULL);
+ "hibdelay"),
+ NULL);
/* Test error on hibernation delay argument that is not a number */
zassert_equal(EC_ERROR_PARAM1,
shell_execute_cmd(shell_backend_uart_get_ptr(),
- "hibdelay test1"), NULL);
+ "hibdelay test1"),
+ NULL);
/* Set hibernate delay */
h_delay = 3;
zassert_equal(EC_SUCCESS,
shell_execute_cmd(shell_backend_uart_get_ptr(),
- "hibdelay 3"), NULL);
+ "hibdelay 3"),
+ NULL);
/* Kick chipset task to process new hibernation delay */
task_wake(TASK_ID_CHIPSET);
@@ -628,42 +642,20 @@ static void test_power_cmd_hibernation_delay(void)
k_msleep(sleep_time * 1000);
zassert_equal(0, system_hibernate_fake.call_count,
- "system_hibernate() shouldn't be called before delay");
+ "system_hibernate() shouldn't be called before delay");
/* Wait to end of the hibenate delay */
k_msleep((h_delay - sleep_time) * 1000);
zassert_equal(1, system_hibernate_fake.call_count,
- "system_hibernate() should be called after delay %d",
- system_hibernate_fake.call_count);
+ "system_hibernate() should be called after delay %d",
+ system_hibernate_fake.call_count);
}
-void test_suite_power_common_no_tasks(void)
-{
- ztest_test_suite(
- power_common_no_tasks,
- ztest_unit_test_setup_teardown(test_power_exit_hard_off,
- set_test_runner_tid,
- unit_test_noop),
- ztest_unit_test_setup_teardown(test_power_reboot_ap_at_g3,
- set_test_runner_tid,
- unit_test_noop));
- ztest_run_test_suite(power_common_no_tasks);
-}
+ZTEST_SUITE(power_common_no_tasks, drivers_predicate_pre_main, NULL, NULL, NULL,
+ NULL);
-void test_suite_power_common(void)
-{
- ztest_test_suite(power_common,
- ztest_unit_test(test_power_chipset_in_state),
- ztest_unit_test(
- test_power_chipset_in_or_transitioning_to_state),
- ztest_unit_test(test_power_hc_smart_discharge),
- ztest_unit_test(test_power_board_system_is_idle),
- ztest_unit_test_setup_teardown(
- test_power_hc_hibernation_delay,
- setup_hibernation_delay, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_power_cmd_hibernation_delay,
- setup_hibernation_delay, unit_test_noop));
- ztest_run_test_suite(power_common);
-}
+ZTEST_SUITE(power_common, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
+
+ZTEST_SUITE(power_common_hibernation, drivers_predicate_post_main, NULL,
+ setup_hibernation_delay, NULL, NULL);
diff --git a/zephyr/test/drivers/src/ppc_sn5s330.c b/zephyr/test/drivers/src/ppc_sn5s330.c
index 5af6f1e2aa..f6e062761d 100644
--- a/zephyr/test/drivers/src/ppc_sn5s330.c
+++ b/zephyr/test/drivers/src/ppc_sn5s330.c
@@ -15,6 +15,7 @@
#include "emul/emul_common_i2c.h"
#include "emul/emul_sn5s330.h"
#include "usbc_ppc.h"
+#include "test_state.h"
/** This must match the index of the sn5s330 in ppc_chips[] */
#define SN5S330_PORT 0
@@ -74,7 +75,7 @@ static int fail_until_write_func(struct i2c_emul *emul, int reg, uint8_t val,
return 1;
}
-static void test_fail_once_func_set1(void)
+ZTEST(ppc_sn5s330, test_fail_once_func_set1)
{
const struct emul *emul = EMUL;
struct i2c_emul *i2c_emul = sn5s330_emul_to_i2c_emul(emul);
@@ -90,7 +91,7 @@ static void test_fail_once_func_set1(void)
i2c_common_emul_set_write_func(i2c_emul, NULL, NULL);
}
-static void test_dead_battery_boot_force_pp2_fets_set(void)
+ZTEST(ppc_sn5s330, test_dead_battery_boot_force_pp2_fets_set)
{
const struct emul *emul = EMUL;
struct i2c_emul *i2c_emul = sn5s330_emul_to_i2c_emul(emul);
@@ -122,7 +123,7 @@ static void test_dead_battery_boot_force_pp2_fets_set(void)
zassert_false(sn5s330_drv.is_sourcing_vbus(SN5S330_PORT), NULL);
}
-static void test_enter_low_power_mode(void)
+ZTEST(ppc_sn5s330, test_enter_low_power_mode)
{
const struct emul *emul = EMUL;
@@ -165,7 +166,7 @@ static void test_enter_low_power_mode(void)
zassert_equal(func_set9_reg & SN5S330_FORCE_ON_VBUS_UVP, 0, NULL);
}
-static void test_vbus_source_sink_enable(void)
+ZTEST(ppc_sn5s330, test_vbus_source_sink_enable)
{
const struct emul *emul = EMUL;
uint8_t func_set3_reg;
@@ -191,7 +192,7 @@ static void test_vbus_source_sink_enable(void)
zassert_equal(func_set3_reg & SN5S330_PP2_EN, 0, NULL);
}
-static void test_vbus_discharge(void)
+ZTEST(ppc_sn5s330, test_vbus_discharge)
{
const struct emul *emul = EMUL;
uint8_t func_set3_reg;
@@ -208,7 +209,7 @@ static void test_vbus_discharge(void)
zassert_equal(func_set3_reg & SN5S330_VBUS_DISCH_EN, 0, NULL);
}
-static void test_set_vbus_source_current_limit(void)
+ZTEST(ppc_sn5s330, test_set_vbus_source_current_limit)
{
const struct emul *emul = EMUL;
uint8_t func_set1_reg;
@@ -249,7 +250,7 @@ static void test_set_vbus_source_current_limit(void)
NULL);
}
-static void test_sn5s330_set_sbu(void)
+ZTEST(ppc_sn5s330, test_sn5s330_set_sbu)
#ifdef CONFIG_USBC_PPC_SBU
{
const struct emul *emul = EMUL;
@@ -273,7 +274,7 @@ static void test_sn5s330_set_sbu(void)
}
#endif /* CONFIG_USBC_PPC_SBU */
-static void test_sn5s330_vbus_overcurrent(void)
+ZTEST(ppc_sn5s330, test_sn5s330_vbus_overcurrent)
{
const struct emul *emul = EMUL;
uint8_t int_trip_rise_reg1;
@@ -297,7 +298,7 @@ static void test_sn5s330_vbus_overcurrent(void)
zassert_equal(int_trip_rise_reg1 & SN5S330_ILIM_PP1_MASK, 0, NULL);
}
-static void test_sn5s330_disable_vbus_low_interrupt(void)
+ZTEST(ppc_sn5s330, test_sn5s330_disable_vbus_low_interrupt)
#ifdef CONFIG_USBC_PPC_VCONN
{
const struct emul *emul = EMUL;
@@ -314,7 +315,7 @@ static void test_sn5s330_disable_vbus_low_interrupt(void)
}
#endif /* CONFIG_USBC_PPC_VCONN */
-static void test_sn5s330_set_vconn_fet(void)
+ZTEST(ppc_sn5s330, test_sn5s330_set_vconn_fet)
{
const struct emul *emul = EMUL;
uint8_t func_set4_reg;
@@ -330,7 +331,7 @@ static void test_sn5s330_set_vconn_fet(void)
zassert_not_equal(func_set4_reg & SN5S330_VCONN_EN, 0, NULL);
}
-static void reset_sn5s330_state(void)
+static inline void reset_sn5s330_state(void)
{
struct i2c_emul *i2c_emul = sn5s330_emul_to_i2c_emul(EMUL);
@@ -340,39 +341,17 @@ static void reset_sn5s330_state(void)
RESET_FAKE(sn5s330_emul_interrupt_set_stub);
}
-void test_suite_ppc_sn5s330(void)
+static void ppc_sn5s330_before(void *state)
{
- ztest_test_suite(
- ppc_sn5s330,
- ztest_unit_test_setup_teardown(test_sn5s330_set_vconn_fet,
- reset_sn5s330_state,
- reset_sn5s330_state),
- ztest_unit_test_setup_teardown(
- test_sn5s330_disable_vbus_low_interrupt,
- reset_sn5s330_state, reset_sn5s330_state),
- ztest_unit_test_setup_teardown(test_sn5s330_vbus_overcurrent,
- reset_sn5s330_state,
- reset_sn5s330_state),
- ztest_unit_test_setup_teardown(test_sn5s330_set_sbu,
- reset_sn5s330_state,
- reset_sn5s330_state),
- ztest_unit_test_setup_teardown(
- test_set_vbus_source_current_limit, reset_sn5s330_state,
- reset_sn5s330_state),
- ztest_unit_test_setup_teardown(test_vbus_discharge,
- reset_sn5s330_state,
- reset_sn5s330_state),
- ztest_unit_test_setup_teardown(test_vbus_source_sink_enable,
- reset_sn5s330_state,
- reset_sn5s330_state),
- ztest_unit_test_setup_teardown(test_enter_low_power_mode,
- reset_sn5s330_state,
- reset_sn5s330_state),
- ztest_unit_test_setup_teardown(
- test_dead_battery_boot_force_pp2_fets_set,
- reset_sn5s330_state, reset_sn5s330_state),
- ztest_unit_test_setup_teardown(test_fail_once_func_set1,
- reset_sn5s330_state,
- reset_sn5s330_state));
- ztest_run_test_suite(ppc_sn5s330);
+ ARG_UNUSED(state);
+ reset_sn5s330_state();
}
+
+static void ppc_sn5s330_after(void *state)
+{
+ ARG_UNUSED(state);
+ reset_sn5s330_state();
+}
+
+ZTEST_SUITE(ppc_sn5s330, drivers_predicate_post_main, NULL, ppc_sn5s330_before,
+ ppc_sn5s330_after, NULL);
diff --git a/zephyr/test/drivers/src/ppc_syv682c.c b/zephyr/test/drivers/src/ppc_syv682c.c
index 0b91855a59..5af90fbfdf 100644
--- a/zephyr/test/drivers/src/ppc_syv682c.c
+++ b/zephyr/test/drivers/src/ppc_syv682c.c
@@ -15,15 +15,17 @@
#include "stubs.h"
#include "syv682x.h"
#include "timer.h"
+#include "test_state.h"
#include "usbc_ppc.h"
#define SYV682X_ORD DT_DEP_ORD(DT_NODELABEL(syv682x_emul))
#define GPIO_USB_C1_FRS_EN_PATH DT_PATH(named_gpios, usb_c1_frs_en)
+
#define GPIO_USB_C1_FRS_EN_PORT DT_GPIO_PIN(GPIO_USB_C1_FRS_EN_PATH, gpios)
static const int syv682x_port = 1;
-static void test_board_is_syv682c(void)
+ZTEST(ppc_syv682c, test_board_is_syv682c)
{
zassert_true(syv682x_board_is_syv682c(0), NULL);
}
@@ -49,7 +51,7 @@ static void check_control_1_default_init(uint8_t control_1)
"Default init, but 5V power path selected");
}
-static void test_ppc_syv682x_init(void)
+ZTEST(ppc_syv682c, test_ppc_syv682x_init)
{
struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD);
const struct device *gpio_dev =
@@ -131,15 +133,15 @@ static void test_ppc_syv682x_init(void)
}
-static void test_ppc_syv682x_vbus_enable(void)
+ZTEST(ppc_syv682c, test_ppc_syv682x_vbus_enable)
{
struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD);
uint8_t reg;
zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, &reg),
"Reading CONTROL_1 failed");
- zassert_equal(reg & SYV682X_CONTROL_1_PWR_ENB,
- SYV682X_CONTROL_1_PWR_ENB, "VBUS sourcing disabled");
+ zassert_not_equal(reg & SYV682X_CONTROL_1_PWR_ENB,
+ SYV682X_CONTROL_1_PWR_ENB, "VBUS sourcing disabled");
zassert_false(ppc_is_sourcing_vbus(syv682x_port),
"PPC sourcing VBUS at beginning of test");
@@ -153,11 +155,13 @@ static void test_ppc_syv682x_vbus_enable(void)
"PPC is not sourcing VBUS after VBUS enabled");
}
-static void test_ppc_syv682x_interrupt(void)
+ZTEST(ppc_syv682c, test_ppc_syv682x_interrupt)
{
struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD);
uint8_t reg;
+ zassert_ok(ppc_vbus_source_enable(syv682x_port, true),
+ "VBUS enable failed");
/* An OC event less than 100 ms should not cause VBUS to turn off. */
syv682x_emul_set_condition(emul, SYV682X_STATUS_OC_5V,
SYV682X_CONTROL_4_NONE);
@@ -299,7 +303,7 @@ static void test_ppc_syv682x_interrupt(void)
SYV682X_CONTROL_4_NONE);
}
-static void test_ppc_syv682x_frs(void)
+ZTEST(ppc_syv682c, test_ppc_syv682x_frs)
{
struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD);
const struct device *gpio_dev =
@@ -358,7 +362,7 @@ static void test_ppc_syv682x_frs(void)
SYV682X_CONTROL_4_NONE);
}
-static void test_ppc_syv682x_source_current_limit(void)
+ZTEST(ppc_syv682c, test_ppc_syv682x_source_current_limit)
{
struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD);
uint8_t reg;
@@ -392,7 +396,7 @@ static void test_ppc_syv682x_source_current_limit(void)
"Set 3.0A Rp value, but 5V_ILIM is %d", ilim_val);
}
-static void test_ppc_syv682x_write_busy(void)
+ZTEST(ppc_syv682c, test_ppc_syv682x_write_busy)
{
struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD);
@@ -422,7 +426,7 @@ static void test_ppc_syv682x_write_busy(void)
syv682x_emul_set_busy_reads(emul, 0);
}
-static void test_ppc_syv682x_dev_is_connected(void)
+ZTEST(ppc_syv682c, test_ppc_syv682x_dev_is_connected)
{
struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD);
uint8_t reg;
@@ -445,7 +449,7 @@ static void test_ppc_syv682x_dev_is_connected(void)
"Could not connect device as source");
}
-static void test_ppc_syv682x_vbus_sink_enable(void)
+ZTEST(ppc_syv682c, test_ppc_syv682x_vbus_sink_enable)
{
struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD);
uint8_t reg;
@@ -488,7 +492,7 @@ static void test_ppc_syv682x_vbus_sink_enable(void)
"Sink disabled, but power path enabled");
}
-static void test_ppc_syv682x_ppc_dump(void)
+ZTEST(ppc_syv682c, test_ppc_syv682x_ppc_dump)
{
/*
* The ppc_dump command should succeed for this port. Don't check the
@@ -499,19 +503,4 @@ static void test_ppc_syv682x_ppc_dump(void)
zassert_ok(drv->reg_dump(syv682x_port), "ppc_dump command failed");
}
-void test_suite_ppc_syv682c(void)
-{
- ztest_test_suite(
- ppc_syv682c,
- ztest_unit_test(test_board_is_syv682c),
- ztest_unit_test(test_ppc_syv682x_init),
- ztest_unit_test(test_ppc_syv682x_vbus_enable),
- ztest_unit_test(test_ppc_syv682x_interrupt),
- ztest_unit_test(test_ppc_syv682x_frs),
- ztest_unit_test(test_ppc_syv682x_source_current_limit),
- ztest_unit_test(test_ppc_syv682x_write_busy),
- ztest_unit_test(test_ppc_syv682x_dev_is_connected),
- ztest_unit_test(test_ppc_syv682x_vbus_sink_enable),
- ztest_unit_test(test_ppc_syv682x_ppc_dump));
- ztest_run_test_suite(ppc_syv682c);
-}
+ZTEST_SUITE(ppc_syv682c, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
diff --git a/zephyr/test/drivers/src/ps8xxx.c b/zephyr/test/drivers/src/ps8xxx.c
index 16e1a01763..f4d7e33e76 100644
--- a/zephyr/test/drivers/src/ps8xxx.c
+++ b/zephyr/test/drivers/src/ps8xxx.c
@@ -18,6 +18,7 @@
#include "tcpm/tcpci.h"
#include "driver/tcpm/ps8xxx.h"
#include "driver/tcpm/ps8xxx_public.h"
+#include "test_state.h"
#define PS8XXX_EMUL_LABEL DT_LABEL(DT_NODELABEL(ps8xxx_emul))
@@ -50,11 +51,21 @@ static void test_ps8xxx_init_fail(void)
NULL);
}
+ZTEST(ps8805, test_init_fail)
+{
+ test_ps8xxx_init_fail();
+}
+
+ZTEST(ps8815, test_init_fail)
+{
+ test_ps8xxx_init_fail();
+}
+
/**
* Test PS8805 init and indirectly ps8705_dci_disable which is
* used by PS8805
*/
-static void test_ps8805_init(void)
+ZTEST(ps8805, test_ps8805_init)
{
const struct emul *ps8xxx_emul = emul_get_binding(PS8XXX_EMUL_LABEL);
const struct emul *tcpci_emul = ps8xxx_emul_get_tcpci(ps8xxx_emul);
@@ -93,7 +104,7 @@ static void test_ps8805_init(void)
}
/** Test PS8815 init */
-static void test_ps8815_init(void)
+ZTEST(ps8815, test_ps8815_init)
{
const struct emul *ps8xxx_emul = emul_get_binding(PS8XXX_EMUL_LABEL);
const struct emul *tcpci_emul = ps8xxx_emul_get_tcpci(ps8xxx_emul);
@@ -141,6 +152,16 @@ static void test_ps8xxx_release(void)
"release on FW reg read fail should wait for chip");
}
+ZTEST(ps8805, test_release)
+{
+ test_ps8xxx_release();
+}
+
+ZTEST(ps8815, test_release)
+{
+ test_ps8xxx_release();
+}
+
/**
* Check if PS8815 set_cc write correct value to ROLE_CTRL register and if
* PS8815 specific workaround is applied to RP_DETECT_CONTROL.
@@ -177,7 +198,7 @@ static void check_ps8815_set_cc(enum tcpc_rp_value rp, enum tcpc_cc_pull cc,
}
/** Test PS8815 set cc and device specific workarounds */
-static void test_ps8815_set_cc(void)
+ZTEST(ps8815, test_ps8815_set_cc)
{
const struct emul *ps8xxx_emul = emul_get_binding(PS8XXX_EMUL_LABEL);
const struct emul *tcpci_emul = ps8xxx_emul_get_tcpci(ps8xxx_emul);
@@ -285,6 +306,16 @@ static void test_ps8xxx_set_vconn(void)
"VCONN disable require minimum 10ms delay");
}
+ZTEST(ps8805, test_set_vconn)
+{
+ test_ps8xxx_set_vconn();
+}
+
+ZTEST(ps8815, test_set_vconn)
+{
+ test_ps8xxx_set_vconn();
+}
+
/** Test PS8xxx transmitting message from TCPC */
static void test_ps8xxx_transmit(void)
{
@@ -333,6 +364,16 @@ static void test_ps8xxx_transmit(void)
zassert_equal(exp_cnt, cnt, "0x%llx != 0x%llx", exp_cnt, cnt);
}
+ZTEST(ps8805, test_transmit)
+{
+ test_ps8xxx_transmit();
+}
+
+ZTEST(ps8815, test_transmit)
+{
+ test_ps8xxx_transmit();
+}
+
/** Test PS8805 and PS8815 drp toggle */
static void test_ps88x5_drp_toggle(bool delay_expected)
{
@@ -410,7 +451,7 @@ static void test_ps88x5_drp_toggle(bool delay_expected)
}
/** Test PS8815 drp toggle */
-static void test_ps8815_drp_toggle(void)
+ZTEST(ps8815, test_ps8815_drp_toggle)
{
const struct emul *ps8xxx_emul = emul_get_binding(PS8XXX_EMUL_LABEL);
@@ -432,7 +473,7 @@ static void test_ps8815_drp_toggle(void)
}
/** Test PS8805 drp toggle */
-static void test_ps8805_drp_toggle(void)
+ZTEST(ps8805, test_drp_toggle)
{
test_ps88x5_drp_toggle(false);
}
@@ -555,18 +596,18 @@ static void test_ps8xxx_get_chip_info(uint16_t current_product_id)
zassert_equal(false, check_ps8755_chip(USBC_PORT_C1), NULL);
}
-static void test_ps8805_get_chip_info(void)
+ZTEST(ps8805, test_ps8805_get_chip_info)
{
test_ps8xxx_get_chip_info(PS8805_PRODUCT_ID);
}
-static void test_ps8815_get_chip_info(void)
+ZTEST(ps8815, test_ps8815_get_chip_info)
{
test_ps8xxx_get_chip_info(PS8815_PRODUCT_ID);
}
/** Test PS8805 get chip info and indirectly ps8805_make_device_id */
-static void test_ps8805_get_chip_info_fix_dev_id(void)
+ZTEST(ps8805, test_ps8805_get_chip_info_fix_dev_id)
{
const struct emul *ps8xxx_emul = emul_get_binding(PS8XXX_EMUL_LABEL);
const struct emul *tcpci_emul = ps8xxx_emul_get_tcpci(ps8xxx_emul);
@@ -601,6 +642,11 @@ static void test_ps8805_get_chip_info_fix_dev_id(void)
tcpci_emul_set_reg(tcpci_emul, TCPC_REG_PRODUCT_ID, product);
tcpci_emul_set_reg(tcpci_emul, PS8XXX_REG_FW_REV, fw_rev);
+ /* Set correct power status for this test */
+ tcpci_emul_set_reg(tcpci_emul, TCPC_REG_POWER_STATUS, 0x0);
+ /* Init to allow access to "hidden" I2C ports */
+ zassert_equal(EC_SUCCESS, ps8xxx_tcpm_drv.init(USBC_PORT_C1), NULL);
+
/* Set device id which requires fixing */
device_id = 0x1;
tcpci_emul_set_reg(tcpci_emul, TCPC_REG_BCD_DEV, device_id);
@@ -653,7 +699,7 @@ static void test_ps8805_get_chip_info_fix_dev_id(void)
}
/** Test PS8815 get chip info and indirectly ps8815_make_device_id */
-static void test_ps8815_get_chip_info_fix_dev_id(void)
+ZTEST(ps8815, test_ps8815_get_chip_info_fix_dev_id)
{
const struct emul *ps8xxx_emul = emul_get_binding(PS8XXX_EMUL_LABEL);
const struct emul *tcpci_emul = ps8xxx_emul_get_tcpci(ps8xxx_emul);
@@ -744,9 +790,10 @@ static void test_ps8815_get_chip_info_fix_dev_id(void)
}
/** Test PS8805 get/set gpio */
-static void test_ps8805_gpio(void)
+ZTEST(ps8805, test_ps8805_gpio)
{
const struct emul *ps8xxx_emul = emul_get_binding(PS8XXX_EMUL_LABEL);
+ const struct emul *tcpci_emul = ps8xxx_emul_get_tcpci(ps8xxx_emul);
struct i2c_emul *gpio_i2c_emul =
ps8xxx_emul_get_i2c_emul(ps8xxx_emul, PS8XXX_EMUL_PORT_GPIO);
uint8_t exp_ctrl, gpio_ctrl;
@@ -803,6 +850,13 @@ static void test_ps8805_gpio(void)
},
};
+ /* Set arbitrary FW reg value != 0 for this test */
+ tcpci_emul_set_reg(tcpci_emul, PS8XXX_REG_FW_REV, 0x31);
+ /* Set correct power status for this test */
+ tcpci_emul_set_reg(tcpci_emul, TCPC_REG_POWER_STATUS, 0x0);
+ /* Init to allow access to "hidden" I2C ports */
+ zassert_equal(EC_SUCCESS, ps8xxx_tcpm_drv.init(USBC_PORT_C1), NULL);
+
/* Test fail on invalid signal for gpio control reg */
zassert_equal(EC_ERROR_INVAL,
ps8805_gpio_set_level(USBC_PORT_C1, PS8805_GPIO_NUM, 1),
@@ -880,6 +934,16 @@ static void test_ps8xxx_tcpci_init(void)
test_tcpci_init(tcpci_emul, USBC_PORT_C1);
}
+ZTEST(ps8805, test_tcpci_init)
+{
+ test_ps8xxx_tcpci_init();
+}
+
+ZTEST(ps8815, test_tcpci_init)
+{
+ test_ps8xxx_tcpci_init();
+}
+
/** Test TCPCI release */
static void test_ps8xxx_tcpci_release(void)
{
@@ -889,6 +953,16 @@ static void test_ps8xxx_tcpci_release(void)
test_tcpci_release(tcpci_emul, USBC_PORT_C1);
}
+ZTEST(ps8805, test_tcpci_release)
+{
+ test_ps8xxx_tcpci_release();
+}
+
+ZTEST(ps8815, test_tcpci_release)
+{
+ test_ps8xxx_tcpci_release();
+}
+
/** Test TCPCI get cc */
static void test_ps8xxx_tcpci_get_cc(void)
{
@@ -898,6 +972,16 @@ static void test_ps8xxx_tcpci_get_cc(void)
test_tcpci_get_cc(tcpci_emul, USBC_PORT_C1);
}
+ZTEST(ps8805, test_tcpci_get_cc)
+{
+ test_ps8xxx_tcpci_get_cc();
+}
+
+ZTEST(ps8815, test_tcpci_get_cc)
+{
+ test_ps8xxx_tcpci_get_cc();
+}
+
/** Test TCPCI set cc */
static void test_ps8xxx_tcpci_set_cc(void)
{
@@ -907,6 +991,16 @@ static void test_ps8xxx_tcpci_set_cc(void)
test_tcpci_set_cc(tcpci_emul, USBC_PORT_C1);
}
+ZTEST(ps8805, test_tcpci_set_cc)
+{
+ test_ps8xxx_tcpci_set_cc();
+}
+
+ZTEST(ps8815, test_tcpci_set_cc)
+{
+ test_ps8xxx_tcpci_set_cc();
+}
+
/** Test TCPCI set polarity */
static void test_ps8xxx_tcpci_set_polarity(void)
{
@@ -916,6 +1010,16 @@ static void test_ps8xxx_tcpci_set_polarity(void)
test_tcpci_set_polarity(tcpci_emul, USBC_PORT_C1);
}
+ZTEST(ps8805, test_tcpci_set_polarity)
+{
+ test_ps8xxx_tcpci_set_polarity();
+}
+
+ZTEST(ps8815, test_tcpci_set_polarity)
+{
+ test_ps8xxx_tcpci_set_polarity();
+}
+
/** Test TCPCI set vconn */
static void test_ps8xxx_tcpci_set_vconn(void)
{
@@ -925,6 +1029,16 @@ static void test_ps8xxx_tcpci_set_vconn(void)
test_tcpci_set_vconn(tcpci_emul, USBC_PORT_C1);
}
+ZTEST(ps8805, test_tcpci_set_vconn)
+{
+ test_ps8xxx_tcpci_set_vconn();
+}
+
+ZTEST(ps8815, test_tcpci_set_vconn)
+{
+ test_ps8xxx_tcpci_set_vconn();
+}
+
/** Test TCPCI set msg header */
static void test_ps8xxx_tcpci_set_msg_header(void)
{
@@ -934,6 +1048,16 @@ static void test_ps8xxx_tcpci_set_msg_header(void)
test_tcpci_set_msg_header(tcpci_emul, USBC_PORT_C1);
}
+ZTEST(ps8805, test_tcpci_set_msg_header)
+{
+ test_ps8xxx_tcpci_set_msg_header();
+}
+
+ZTEST(ps8815, test_tcpci_set_msg_header)
+{
+ test_ps8xxx_tcpci_set_msg_header();
+}
+
/** Test TCPCI get raw message */
static void test_ps8xxx_tcpci_get_rx_message_raw(void)
{
@@ -943,6 +1067,16 @@ static void test_ps8xxx_tcpci_get_rx_message_raw(void)
test_tcpci_get_rx_message_raw(tcpci_emul, USBC_PORT_C1);
}
+ZTEST(ps8805, test_tcpci_get_rx_message_raw)
+{
+ test_ps8xxx_tcpci_get_rx_message_raw();
+}
+
+ZTEST(ps8815, test_tcpci_get_rx_message_raw)
+{
+ test_ps8xxx_tcpci_get_rx_message_raw();
+}
+
/** Test TCPCI transmitting message */
static void test_ps8xxx_tcpci_transmit(void)
{
@@ -952,6 +1086,16 @@ static void test_ps8xxx_tcpci_transmit(void)
test_tcpci_transmit(tcpci_emul, USBC_PORT_C1);
}
+ZTEST(ps8805, test_tcpci_transmit)
+{
+ test_ps8xxx_tcpci_transmit();
+}
+
+ZTEST(ps8815, test_tcpci_transmit)
+{
+ test_ps8xxx_tcpci_transmit();
+}
+
/** Test TCPCI alert */
static void test_ps8xxx_tcpci_alert(void)
{
@@ -961,6 +1105,16 @@ static void test_ps8xxx_tcpci_alert(void)
test_tcpci_alert(tcpci_emul, USBC_PORT_C1);
}
+ZTEST(ps8805, test_tcpci_alert)
+{
+ test_ps8xxx_tcpci_alert();
+}
+
+ZTEST(ps8815, test_tcpci_alert)
+{
+ test_ps8xxx_tcpci_alert();
+}
+
/** Test TCPCI alert RX message */
static void test_ps8xxx_tcpci_alert_rx_message(void)
{
@@ -970,6 +1124,16 @@ static void test_ps8xxx_tcpci_alert_rx_message(void)
test_tcpci_alert_rx_message(tcpci_emul, USBC_PORT_C1);
}
+ZTEST(ps8805, test_tcpci_alert_rx_message)
+{
+ test_ps8xxx_tcpci_alert_rx_message();
+}
+
+ZTEST(ps8815, test_tcpci_alert_rx_message)
+{
+ test_ps8xxx_tcpci_alert_rx_message();
+}
+
/** Test TCPCI enter low power mode */
static void test_ps8xxx_tcpci_low_power_mode(void)
{
@@ -986,6 +1150,16 @@ static void test_ps8xxx_tcpci_low_power_mode(void)
test_tcpci_low_power_mode(tcpci_emul, USBC_PORT_C1);
}
+ZTEST(ps8805, test_tcpci_low_power_mode)
+{
+ test_ps8xxx_tcpci_low_power_mode();
+}
+
+ZTEST(ps8815, test_tcpci_low_power_mode)
+{
+ test_ps8xxx_tcpci_low_power_mode();
+}
+
/** Test TCPCI set bist test mode */
static void test_ps8xxx_tcpci_set_bist_mode(void)
{
@@ -995,6 +1169,16 @@ static void test_ps8xxx_tcpci_set_bist_mode(void)
test_tcpci_set_bist_mode(tcpci_emul, USBC_PORT_C1);
}
+ZTEST(ps8805, test_tcpci_set_bist_mode)
+{
+ test_ps8xxx_tcpci_set_bist_mode();
+}
+
+ZTEST(ps8815, test_tcpci_set_bist_mode)
+{
+ test_ps8xxx_tcpci_set_bist_mode();
+}
+
/* Setup no fail for all I2C devices associated with PS8xxx emulator */
static void setup_no_fail_all(void)
{
@@ -1039,9 +1223,10 @@ static void setup_no_fail_all(void)
* Setup PS8xxx emulator to mimic PS8805 and setup no fail for all I2C devices
* associated with PS8xxx emulator
*/
-static void setup_ps8805(void)
+static void ps8805_before(void *state)
{
const struct emul *ps8xxx_emul = emul_get_binding(PS8XXX_EMUL_LABEL);
+ ARG_UNUSED(state);
board_set_ps8xxx_product_id(PS8805_PRODUCT_ID);
ps8xxx_emul_set_product_id(ps8xxx_emul, PS8805_PRODUCT_ID);
@@ -1052,136 +1237,19 @@ static void setup_ps8805(void)
* Setup PS8xxx emulator to mimic PS8815 and setup no fail for all I2C devices
* associated with PS8xxx emulator
*/
-static void setup_ps8815(void)
+static void ps8815_before(void *state)
{
const struct emul *ps8xxx_emul = emul_get_binding(PS8XXX_EMUL_LABEL);
+ ARG_UNUSED(state);
board_set_ps8xxx_product_id(PS8815_PRODUCT_ID);
ps8xxx_emul_set_product_id(ps8xxx_emul, PS8815_PRODUCT_ID);
setup_no_fail_all();
}
-void test_suite_ps8xxx(void)
-{
- ztest_test_suite(ps8805,
- ztest_unit_test_setup_teardown(test_ps8xxx_init_fail,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(test_ps8805_init,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(test_ps8xxx_release,
- setup_no_fail_all, unit_test_noop),
- ztest_unit_test_setup_teardown(test_ps8xxx_set_vconn,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(test_ps8xxx_transmit,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(test_ps8805_drp_toggle,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8805_get_chip_info,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8805_get_chip_info_fix_dev_id,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(test_ps8805_gpio,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(test_ps8xxx_tcpci_init,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_release,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_get_cc,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_set_cc,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_set_polarity,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_set_vconn,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_set_msg_header,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_get_rx_message_raw,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_transmit,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_alert,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_alert_rx_message,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_low_power_mode,
- setup_ps8805, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_set_bist_mode,
- setup_ps8805, unit_test_noop));
- ztest_run_test_suite(ps8805);
-
- ztest_test_suite(ps8815,
- ztest_unit_test_setup_teardown(test_ps8xxx_init_fail,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(test_ps8815_init,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(test_ps8xxx_release,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(test_ps8815_set_cc,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(test_ps8xxx_set_vconn,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(test_ps8xxx_transmit,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(test_ps8815_drp_toggle,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8815_get_chip_info,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8815_get_chip_info_fix_dev_id,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(test_ps8xxx_tcpci_init,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_release,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_get_cc,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_set_cc,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_set_polarity,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_set_vconn,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_set_msg_header,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_get_rx_message_raw,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_transmit,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_alert,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_alert_rx_message,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_low_power_mode,
- setup_ps8815, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_ps8xxx_tcpci_set_bist_mode,
- setup_ps8815, unit_test_noop));
- ztest_run_test_suite(ps8815);
-}
+
+ZTEST_SUITE(ps8805, drivers_predicate_post_main, NULL, ps8805_before, NULL,
+ NULL);
+
+ZTEST_SUITE(ps8815, drivers_predicate_post_main, NULL, ps8815_before, NULL,
+ NULL);
diff --git a/zephyr/test/drivers/src/smart.c b/zephyr/test/drivers/src/smart.c
index 82a2fe3037..70a242abf4 100644
--- a/zephyr/test/drivers/src/smart.c
+++ b/zephyr/test/drivers/src/smart.c
@@ -15,11 +15,12 @@
#include "battery.h"
#include "battery_smart.h"
+#include "test_state.h"
#define BATTERY_ORD DT_DEP_ORD(DT_NODELABEL(battery))
/** Test all simple getters */
-static void test_battery_getters(void)
+ZTEST_USER(smart_battery, test_battery_getters)
{
struct sbat_emul_bat_data *bat;
struct i2c_emul *emul;
@@ -76,7 +77,7 @@ static void test_battery_getters(void)
}
/** Test getting capacity. These functions should force mAh mode */
-static void test_battery_get_capacity(void)
+ZTEST_USER(smart_battery, test_battery_get_capacity)
{
struct sbat_emul_bat_data *bat;
struct i2c_emul *emul;
@@ -114,7 +115,7 @@ static void test_battery_get_capacity(void)
/** Test battery status */
-static void test_battery_status(void)
+ZTEST_USER(smart_battery, test_battery_status)
{
struct sbat_emul_bat_data *bat;
struct i2c_emul *emul;
@@ -140,7 +141,7 @@ static void test_battery_status(void)
}
/** Test wait for stable function */
-static void test_battery_wait_for_stable(void)
+ZTEST_USER(smart_battery, test_battery_wait_for_stable)
{
struct i2c_emul *emul;
@@ -156,7 +157,7 @@ static void test_battery_wait_for_stable(void)
}
/** Test manufacture date */
-static void test_battery_manufacture_date(void)
+ZTEST_USER(smart_battery, test_battery_manufacture_date)
{
struct sbat_emul_bat_data *bat;
struct i2c_emul *emul;
@@ -180,7 +181,7 @@ static void test_battery_manufacture_date(void)
}
/** Test time at rate */
-static void test_battery_time_at_rate(void)
+ZTEST_USER(smart_battery, test_battery_time_at_rate)
{
struct sbat_emul_bat_data *bat;
struct i2c_emul *emul;
@@ -238,7 +239,7 @@ static void test_battery_time_at_rate(void)
}
/** Test battery get params */
-static void test_battery_get_params(void)
+ZTEST_USER(smart_battery, test_battery_get_params)
{
struct sbat_emul_bat_data *bat;
struct batt_params batt;
@@ -347,7 +348,7 @@ static int mfgacc_read_func(struct i2c_emul *emul, int reg, uint8_t *val,
}
/** Test battery manufacturer access */
-static void test_battery_mfacc(void)
+ZTEST_USER(smart_battery, test_battery_mfacc)
{
struct sbat_emul_bat_data *bat;
struct mfgacc_data mfacc_conf;
@@ -418,7 +419,7 @@ static void test_battery_mfacc(void)
}
/** Test battery fake charge level set and read */
-static void test_battery_fake_charge(void)
+ZTEST_USER(smart_battery, test_battery_fake_charge)
{
struct sbat_emul_bat_data *bat;
struct batt_params batt;
@@ -497,7 +498,7 @@ static void test_battery_fake_charge(void)
}
/** Test battery fake temperature set and read */
-static void test_battery_fake_temperature(void)
+ZTEST_USER(smart_battery, test_battery_fake_temperature)
{
struct sbat_emul_bat_data *bat;
struct batt_params batt;
@@ -554,18 +555,4 @@ static void test_battery_fake_temperature(void)
bat->temp, batt.temperature);
}
-void test_suite_smart_battery(void)
-{
- ztest_test_suite(smart_battery,
- ztest_user_unit_test(test_battery_getters),
- ztest_user_unit_test(test_battery_get_capacity),
- ztest_user_unit_test(test_battery_status),
- ztest_user_unit_test(test_battery_wait_for_stable),
- ztest_user_unit_test(test_battery_manufacture_date),
- ztest_user_unit_test(test_battery_time_at_rate),
- ztest_user_unit_test(test_battery_get_params),
- ztest_user_unit_test(test_battery_mfacc),
- ztest_user_unit_test(test_battery_fake_charge),
- ztest_user_unit_test(test_battery_fake_temperature));
- ztest_run_test_suite(smart_battery);
-}
+ZTEST_SUITE(smart_battery, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
diff --git a/zephyr/test/drivers/src/stm_mems_common.c b/zephyr/test/drivers/src/stm_mems_common.c
index c7cd5e9005..19d3e0f43d 100644
--- a/zephyr/test/drivers/src/stm_mems_common.c
+++ b/zephyr/test/drivers/src/stm_mems_common.c
@@ -13,6 +13,7 @@
#include "emul/emul_common_i2c.h"
#include "emul/i2c_mock.h"
#include "i2c/i2c.h"
+#include "test_state.h"
#define MOCK_EMUL emul_get_binding(DT_LABEL(DT_NODELABEL(i2c_mock)))
@@ -21,11 +22,6 @@ struct mock_properties {
int call_count;
};
-static void setup(void)
-{
- i2c_mock_reset(MOCK_EMUL);
-}
-
static int mock_read_fn(struct i2c_emul *emul, int reg, uint8_t *val, int bytes,
void *data)
{
@@ -52,7 +48,7 @@ static int mock_write_fn(struct i2c_emul *emul, int reg, uint8_t val, int bytes,
return ztest_get_return_value();
}
-static void test_st_raw_read_n(void)
+ZTEST(stm_mems_common, test_st_raw_read_n)
{
const struct emul *emul = MOCK_EMUL;
struct i2c_emul *i2c_emul = i2c_mock_to_i2c_emul(emul);
@@ -73,7 +69,7 @@ static void test_st_raw_read_n(void)
EC_ERROR_INVAL);
}
-static void test_st_raw_read_n_noinc(void)
+ZTEST(stm_mems_common, test_st_raw_read_n_noinc)
{
const struct emul *emul = MOCK_EMUL;
struct i2c_emul *i2c_emul = i2c_mock_to_i2c_emul(emul);
@@ -95,7 +91,7 @@ static void test_st_raw_read_n_noinc(void)
EC_ERROR_INVAL);
}
-static void test_st_write_data_with_mask(void)
+ZTEST(stm_mems_common, test_st_write_data_with_mask)
{
const struct emul *emul = MOCK_EMUL;
struct i2c_emul *i2c_emul = i2c_mock_to_i2c_emul(emul);
@@ -172,7 +168,7 @@ static void test_st_write_data_with_mask(void)
"mock_write_fn was not called.");
}
-static void test_st_get_resolution(void)
+ZTEST(stm_mems_common, test_st_get_resolution)
{
int expected_resolution = 123;
int rv;
@@ -190,7 +186,7 @@ static void test_st_get_resolution(void)
expected_resolution);
}
-static void test_st_set_offset(void)
+ZTEST(stm_mems_common, test_st_set_offset)
{
int16_t expected_offset[3] = { 123, 456, 789 };
@@ -214,7 +210,7 @@ static void test_st_set_offset(void)
expected_offset[Z]);
}
-static void test_st_get_offset(void)
+ZTEST(stm_mems_common, test_st_get_offset)
{
struct stprivate_data driver_data = {
.offset = { [X] = 123, [Y] = 456, [Z] = 789 },
@@ -246,7 +242,7 @@ static void test_st_get_offset(void)
driver_data.offset[Z]);
}
-static void test_st_get_data_rate(void)
+ZTEST(stm_mems_common, test_st_get_data_rate)
{
int expected_data_rate = 456;
int rv;
@@ -266,7 +262,7 @@ static void test_st_get_data_rate(void)
expected_data_rate);
}
-static void test_st_normalize(void)
+ZTEST(stm_mems_common, test_st_normalize)
{
struct stprivate_data driver_data = {
.resol = 12, /* 12 bits of useful data (arbitrary) */
@@ -331,20 +327,11 @@ static void test_st_normalize(void)
expected_output[Z]);
}
-void test_suite_stm_mems_common(void)
+static void stm_mems_common_before(void *state)
{
- ztest_test_suite(
- stm_mems_common,
- ztest_unit_test_setup_teardown(test_st_raw_read_n, setup,
- unit_test_noop),
- ztest_unit_test_setup_teardown(test_st_raw_read_n_noinc, setup,
- unit_test_noop),
- ztest_unit_test_setup_teardown(test_st_write_data_with_mask,
- setup, unit_test_noop),
- ztest_unit_test(test_st_get_resolution),
- ztest_unit_test(test_st_set_offset),
- ztest_unit_test(test_st_get_offset),
- ztest_unit_test(test_st_get_data_rate),
- ztest_unit_test(test_st_normalize));
- ztest_run_test_suite(stm_mems_common);
+ ARG_UNUSED(state);
+ i2c_mock_reset(MOCK_EMUL);
}
+
+ZTEST_SUITE(stm_mems_common, drivers_predicate_post_main, NULL,
+ stm_mems_common_before, NULL, NULL);
diff --git a/zephyr/test/drivers/src/tcpci.c b/zephyr/test/drivers/src/tcpci.c
index cdc13861ab..b6eab298cc 100644
--- a/zephyr/test/drivers/src/tcpci.c
+++ b/zephyr/test/drivers/src/tcpci.c
@@ -18,11 +18,12 @@
#include "tcpci_test_common.h"
#include "tcpm/tcpci.h"
+#include "test_state.h"
#define EMUL_LABEL DT_NODELABEL(tcpci_emul)
/** Test TCPCI init and vbus level */
-static void test_generic_tcpci_init(void)
+ZTEST(tcpci, test_generic_tcpci_init)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -30,7 +31,7 @@ static void test_generic_tcpci_init(void)
}
/** Test TCPCI release */
-static void test_generic_tcpci_release(void)
+ZTEST(tcpci, test_generic_tcpci_release)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -38,7 +39,7 @@ static void test_generic_tcpci_release(void)
}
/** Test TCPCI get cc */
-static void test_generic_tcpci_get_cc(void)
+ZTEST(tcpci, test_generic_tcpci_get_cc)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -46,7 +47,7 @@ static void test_generic_tcpci_get_cc(void)
}
/** Test TCPCI set cc */
-static void test_generic_tcpci_set_cc(void)
+ZTEST(tcpci, test_generic_tcpci_set_cc)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -54,7 +55,7 @@ static void test_generic_tcpci_set_cc(void)
}
/** Test TCPCI set polarity */
-static void test_generic_tcpci_set_polarity(void)
+ZTEST(tcpci, test_generic_tcpci_set_polarity)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -62,7 +63,7 @@ static void test_generic_tcpci_set_polarity(void)
}
/** Test TCPCI set vconn */
-static void test_generic_tcpci_set_vconn(void)
+ZTEST(tcpci, test_generic_tcpci_set_vconn)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -70,7 +71,7 @@ static void test_generic_tcpci_set_vconn(void)
}
/** Test TCPCI set msg header */
-static void test_generic_tcpci_set_msg_header(void)
+ZTEST(tcpci, test_generic_tcpci_set_msg_header)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -78,7 +79,7 @@ static void test_generic_tcpci_set_msg_header(void)
}
/** Test TCPCI rx and sop prime enable */
-static void test_generic_tcpci_set_rx_detect(void)
+ZTEST(tcpci, test_generic_tcpci_set_rx_detect)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -86,7 +87,7 @@ static void test_generic_tcpci_set_rx_detect(void)
}
/** Test TCPCI get raw message from TCPC revision 2.0 */
-static void test_generic_tcpci_get_rx_message_raw_rev2(void)
+ZTEST(tcpci, test_generic_tcpci_get_rx_message_raw_rev2)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -97,7 +98,7 @@ static void test_generic_tcpci_get_rx_message_raw_rev2(void)
}
/** Test TCPCI get raw message from TCPC revision 1.0 */
-static void test_generic_tcpci_get_rx_message_raw_rev1(void)
+ZTEST(tcpci, test_generic_tcpci_get_rx_message_raw_rev1)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -108,7 +109,7 @@ static void test_generic_tcpci_get_rx_message_raw_rev1(void)
}
/** Test TCPCI transmitting message from TCPC revision 2.0 */
-static void test_generic_tcpci_transmit_rev2(void)
+ZTEST(tcpci, test_generic_tcpci_transmit_rev2)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -119,7 +120,7 @@ static void test_generic_tcpci_transmit_rev2(void)
}
/** Test TCPCI transmitting message from TCPC revision 1.0 */
-static void test_generic_tcpci_transmit_rev1(void)
+ZTEST(tcpci, test_generic_tcpci_transmit_rev1)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -130,7 +131,7 @@ static void test_generic_tcpci_transmit_rev1(void)
}
/** Test TCPCI alert */
-static void test_generic_tcpci_alert(void)
+ZTEST(tcpci, test_generic_tcpci_alert)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -139,7 +140,7 @@ static void test_generic_tcpci_alert(void)
/** Test TCPCI alert RX message */
-static void test_generic_tcpci_alert_rx_message(void)
+ZTEST(tcpci, test_generic_tcpci_alert_rx_message)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -147,7 +148,7 @@ static void test_generic_tcpci_alert_rx_message(void)
}
/** Test TCPCI auto discharge on disconnect */
-static void test_generic_tcpci_auto_discharge(void)
+ZTEST(tcpci, test_generic_tcpci_auto_discharge)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -155,7 +156,7 @@ static void test_generic_tcpci_auto_discharge(void)
}
/** Test TCPCI drp toggle */
-static void test_generic_tcpci_drp_toggle(void)
+ZTEST(tcpci, test_generic_tcpci_drp_toggle)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -163,7 +164,7 @@ static void test_generic_tcpci_drp_toggle(void)
}
/** Test TCPCI get chip info */
-static void test_generic_tcpci_get_chip_info(void)
+ZTEST(tcpci, test_generic_tcpci_get_chip_info)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -171,7 +172,7 @@ static void test_generic_tcpci_get_chip_info(void)
}
/** Test TCPCI enter low power mode */
-static void test_generic_tcpci_low_power_mode(void)
+ZTEST(tcpci, test_generic_tcpci_low_power_mode)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -179,7 +180,7 @@ static void test_generic_tcpci_low_power_mode(void)
}
/** Test TCPCI set bist test mode */
-static void test_generic_tcpci_set_bist_mode(void)
+ZTEST(tcpci, test_generic_tcpci_set_bist_mode)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
@@ -187,7 +188,7 @@ static void test_generic_tcpci_set_bist_mode(void)
}
/** Test TCPCI discharge vbus */
-void test_generic_tcpci_discharge_vbus(void)
+ZTEST(tcpci, test_generic_tcpci_discharge_vbus)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
uint8_t exp_ctrl, initial_ctrl;
@@ -209,7 +210,7 @@ void test_generic_tcpci_discharge_vbus(void)
}
/** Test TCPC xfer */
-static void test_tcpc_xfer(void)
+ZTEST(tcpci, test_tcpc_xfer)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
uint16_t val, exp_val;
@@ -228,7 +229,7 @@ static void test_tcpc_xfer(void)
}
/** Test TCPCI debug accessory enable/disable */
-static void test_generic_tcpci_debug_accessory(void)
+ZTEST(tcpci, test_generic_tcpci_debug_accessory)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
uint8_t exp_val, initial_val;
@@ -264,7 +265,7 @@ static void set_usb_mux_tcpc(void)
}
/** Test TCPCI mux init */
-static void test_generic_tcpci_mux_init(void)
+ZTEST(tcpci, test_generic_tcpci_mux_init)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
struct i2c_emul *i2c_emul = tcpci_emul_get_i2c_emul(emul);
@@ -323,7 +324,7 @@ static void test_generic_tcpci_mux_init(void)
}
/** Test TCPCI mux enter low power mode */
-static void test_generic_tcpci_mux_enter_low_power(void)
+ZTEST(tcpci, test_generic_tcpci_mux_enter_low_power)
{
const struct emul *emul = emul_get_binding(DT_LABEL(EMUL_LABEL));
struct i2c_emul *i2c_emul = tcpci_emul_get_i2c_emul(emul);
@@ -463,45 +464,25 @@ static void test_generic_tcpci_mux_set_get(void)
mux_state, mux_state_get);
}
-void test_suite_tcpci(void)
+ZTEST(tcpci, test_generic_tcpci_mux_set_get)
+{
+ test_generic_tcpci_mux_set_get();
+}
+
+ZTEST(tcpci, test_generic_tcpci_mux_set_get__not_tcpc)
+{
+ set_usb_mux_not_tcpc();
+ test_generic_tcpci_mux_set_get();
+ set_usb_mux_tcpc();
+}
+
+static void *tcpci_setup(void)
{
/* This test suite assumes that first usb mux for port C0 is TCPCI */
__ASSERT(usb_muxes[USBC_PORT_C0].driver == &tcpci_tcpm_usb_mux_driver,
"Invalid config of usb_muxes in test/drivers/src/stubs.c");
- ztest_test_suite(tcpci,
- ztest_unit_test(test_generic_tcpci_init),
- ztest_unit_test(test_generic_tcpci_release),
- ztest_unit_test(test_generic_tcpci_get_cc),
- ztest_unit_test(test_generic_tcpci_set_cc),
- ztest_unit_test(test_generic_tcpci_set_polarity),
- ztest_unit_test(test_generic_tcpci_set_vconn),
- ztest_unit_test(test_generic_tcpci_set_msg_header),
- ztest_unit_test(test_generic_tcpci_set_rx_detect),
- ztest_unit_test(
- test_generic_tcpci_get_rx_message_raw_rev2),
- ztest_unit_test(test_generic_tcpci_transmit_rev2),
- ztest_unit_test(
- test_generic_tcpci_get_rx_message_raw_rev1),
- ztest_unit_test(test_generic_tcpci_transmit_rev1),
- ztest_unit_test(test_generic_tcpci_alert),
- ztest_unit_test(test_generic_tcpci_alert_rx_message),
- ztest_unit_test(test_generic_tcpci_auto_discharge),
- ztest_unit_test(test_generic_tcpci_drp_toggle),
- ztest_unit_test(test_generic_tcpci_get_chip_info),
- ztest_unit_test(test_generic_tcpci_low_power_mode),
- ztest_unit_test(test_generic_tcpci_set_bist_mode),
- ztest_unit_test(test_generic_tcpci_discharge_vbus),
- ztest_unit_test(test_tcpc_xfer),
- ztest_unit_test(test_generic_tcpci_debug_accessory),
- ztest_unit_test(test_generic_tcpci_mux_init),
- ztest_unit_test(
- test_generic_tcpci_mux_enter_low_power),
- /* Test set/get with usb mux and without TCPC */
- ztest_unit_test_setup_teardown(
- test_generic_tcpci_mux_set_get,
- set_usb_mux_not_tcpc, set_usb_mux_tcpc),
- /* Test set/get with usb mux and TCPC */
- ztest_unit_test(test_generic_tcpci_mux_set_get));
- ztest_run_test_suite(tcpci);
+ return NULL;
}
+
+ZTEST_SUITE(tcpci, drivers_predicate_post_main, tcpci_setup, NULL, NULL, NULL);
diff --git a/zephyr/test/drivers/src/tcpci_test_common.c b/zephyr/test/drivers/src/tcpci_test_common.c
index a2925bf3be..3ab671a07c 100644
--- a/zephyr/test/drivers/src/tcpci_test_common.c
+++ b/zephyr/test/drivers/src/tcpci_test_common.c
@@ -628,7 +628,6 @@ void test_tcpci_alert(const struct emul *emul, enum usbc_port port)
drv->tcpc_alert(port);
}
-
/** Test TCPCI alert RX message */
void test_tcpci_alert_rx_message(const struct emul *emul, enum usbc_port port)
{
@@ -642,6 +641,8 @@ void test_tcpci_alert_rx_message(const struct emul *emul, enum usbc_port port)
tcpc_config[port].flags = TCPC_FLAGS_TCPCI_REV2_0;
tcpci_emul_set_rev(emul, TCPCI_EMUL_REV2_0_VER1_1);
+ tcpci_emul_set_reg(emul, TCPC_REG_DEV_CAP_2,
+ TCPC_REG_DEV_CAP_2_LONG_MSG);
for (i = 0; i < 32; i++) {
buf1[i] = i + 1;
@@ -703,6 +704,8 @@ void test_tcpci_alert_rx_message(const struct emul *emul, enum usbc_port port)
/* Test with too long first message */
msg1.cnt = 32;
+ tcpci_emul_set_reg(emul, TCPC_REG_DEV_CAP_2,
+ TCPC_REG_DEV_CAP_2_LONG_MSG);
zassert_ok(tcpci_emul_add_rx_msg(emul, &msg1, true),
"Failed to setup emulator message");
zassert_ok(tcpci_emul_add_rx_msg(emul, &msg2, true),
diff --git a/zephyr/test/drivers/src/tcs3400.c b/zephyr/test/drivers/src/tcs3400.c
index c20137c1ad..58b4f05608 100644
--- a/zephyr/test/drivers/src/tcs3400.c
+++ b/zephyr/test/drivers/src/tcs3400.c
@@ -14,6 +14,7 @@
#include "motion_sense.h"
#include "motion_sense_fifo.h"
#include "driver/als_tcs3400.h"
+#include "test_state.h"
#define TCS_ORD DT_DEP_ORD(DT_NODELABEL(tcs_emul))
#define TCS_CLR_SENSOR_ID SENSOR_ID(DT_NODELABEL(tcs3400_clear))
@@ -25,7 +26,7 @@
#define V_EPS 8
/** Test initialization of light sensor driver and device */
-static void test_tcs_init(void)
+ZTEST_USER(tcs3400, test_tcs_init)
{
struct motion_sensor_t *ms, *ms_rgb;
struct i2c_emul *emul;
@@ -58,7 +59,7 @@ static void test_tcs_init(void)
}
/** Test if read function leaves device in correct mode to accuire data */
-static void test_tcs_read(void)
+ZTEST_USER(tcs3400, test_tcs_read)
{
struct motion_sensor_t *ms;
struct i2c_emul *emul;
@@ -120,11 +121,14 @@ static void check_fifo_empty_f(struct motion_sensor_t *ms,
if (ms - motion_sensors == vector.sensor_num) {
zassert_unreachable(
- "Unexpected frame for clear sensor");
+ "Unexpected frame for clear sensor @line: %d",
+ line);
}
if (ms_rgb - motion_sensors == vector.sensor_num) {
- zassert_unreachable("Unexpected frame for rgb sensor");
+ zassert_unreachable(
+ "Unexpected frame for rgb sensor @line: %d",
+ line);
}
}
}
@@ -135,7 +139,7 @@ static void check_fifo_empty_f(struct motion_sensor_t *ms,
* Test different conditions where irq handler fail or commit no data
* to fifo
*/
-static void test_tcs_irq_handler_fail(void)
+ZTEST_USER(tcs3400, test_tcs_irq_handler_fail)
{
struct motion_sensor_t *ms, *ms_rgb;
struct i2c_emul *emul;
@@ -223,7 +227,7 @@ static void check_fifo_f(struct motion_sensor_t *ms,
check_fifo_f(ms, ms_rgb, exp_v, eps, __LINE__)
/** Test calibration mode reading of light sensor values */
-static void test_tcs_read_calibration(void)
+ZTEST_USER(tcs3400, test_tcs_read_calibration)
{
struct motion_sensor_t *ms, *ms_rgb;
struct i2c_emul *emul;
@@ -335,7 +339,7 @@ static void set_emul_val_from_exp(int *exp_v, uint16_t *scale,
}
/** Test normal mode reading of light sensor values */
-static void test_tcs_read_xyz(void)
+ZTEST_USER(tcs3400, test_tcs_read_xyz)
{
struct motion_sensor_t *ms, *ms_rgb;
struct i2c_emul *emul;
@@ -413,7 +417,7 @@ static void test_tcs_read_xyz(void)
* Test getting and setting scale of light sensor. Checks if collected values
* are scaled properly.
*/
-static void test_tcs_scale(void)
+ZTEST_USER(tcs3400, test_tcs_scale)
{
struct motion_sensor_t *ms, *ms_rgb;
struct i2c_emul *emul;
@@ -525,7 +529,7 @@ static void test_tcs_scale(void)
}
/** Test setting and getting data rate of light sensor */
-static void test_tcs_data_rate(void)
+ZTEST_USER(tcs3400, test_tcs_data_rate)
{
struct motion_sensor_t *ms, *ms_rgb;
struct i2c_emul *emul;
@@ -587,7 +591,7 @@ static void test_tcs_data_rate(void)
}
/** Test set range function of clear and RGB sensors */
-static void test_tcs_set_range(void)
+ZTEST_USER(tcs3400, test_tcs_set_range)
{
struct motion_sensor_t *ms, *ms_rgb;
struct i2c_emul *emul;
@@ -607,16 +611,4 @@ static void test_tcs_set_range(void)
zassert_equal(0x10000, ms->current_range, NULL);
}
-void test_suite_tcs3400(void)
-{
- ztest_test_suite(tcs3400,
- ztest_user_unit_test(test_tcs_init),
- ztest_user_unit_test(test_tcs_read),
- ztest_user_unit_test(test_tcs_irq_handler_fail),
- ztest_user_unit_test(test_tcs_read_calibration),
- ztest_user_unit_test(test_tcs_read_xyz),
- ztest_user_unit_test(test_tcs_scale),
- ztest_user_unit_test(test_tcs_data_rate),
- ztest_user_unit_test(test_tcs_set_range));
- ztest_run_test_suite(tcs3400);
-}
+ZTEST_SUITE(tcs3400, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
diff --git a/zephyr/test/drivers/src/temp_sensor.c b/zephyr/test/drivers/src/temp_sensor.c
index 83a343e572..acb2f1ac60 100644
--- a/zephyr/test/drivers/src/temp_sensor.c
+++ b/zephyr/test/drivers/src/temp_sensor.c
@@ -15,6 +15,7 @@
#include "common.h"
#include "temp_sensor.h"
#include "temp_sensor/temp_sensor.h"
+#include "test_state.h"
#define GPIO_PG_EC_DSW_PWROK_PATH DT_PATH(named_gpios, pg_ec_dsw_pwrok)
#define GPIO_PG_EC_DSW_PWROK_PORT DT_GPIO_PIN(GPIO_PG_EC_DSW_PWROK_PATH, gpios)
@@ -23,7 +24,7 @@
#define ADC_CHANNELS_NUM DT_PROP(DT_NODELABEL(adc0), nchannels)
/** Test error code when invalid sensor is passed to temp_sensor_read() */
-static void test_temp_sensor_wrong_id(void)
+ZTEST_USER(temp_sensor, test_temp_sensor_wrong_id)
{
int temp;
@@ -33,7 +34,7 @@ static void test_temp_sensor_wrong_id(void)
}
/** Test error code when temp_sensor_read() is called with powered off ADC */
-static void test_temp_sensor_adc_error(void)
+ZTEST_USER(temp_sensor, test_temp_sensor_adc_error)
{
const struct device *gpio_dev =
DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_PG_EC_DSW_PWROK_PATH, gpios));
@@ -94,7 +95,7 @@ static void check_valid_temperature(const struct device *adc_dev, int sensor)
}
/** Test if temp_sensor_read() returns temperature on success */
-static void test_temp_sensor_read(void)
+ZTEST_USER(temp_sensor, test_temp_sensor_read)
{
const struct device *adc_dev = DEVICE_DT_GET(ADC_DEVICE_NODE);
int chan;
@@ -121,7 +122,7 @@ static void test_temp_sensor_read(void)
}
}
-void test_suite_temp_sensor(void)
+static void *temp_sensor_setup(void)
{
const struct device *dev =
DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_PG_EC_DSW_PWROK_PATH, gpios));
@@ -131,9 +132,8 @@ void test_suite_temp_sensor(void)
zassert_ok(gpio_emul_input_set(dev, GPIO_PG_EC_DSW_PWROK_PORT, 1),
NULL);
- ztest_test_suite(temp_sensor,
- ztest_user_unit_test(test_temp_sensor_wrong_id),
- ztest_user_unit_test(test_temp_sensor_adc_error),
- ztest_user_unit_test(test_temp_sensor_read));
- ztest_run_test_suite(temp_sensor);
+ return NULL;
}
+
+ZTEST_SUITE(temp_sensor, drivers_predicate_post_main, temp_sensor_setup, NULL,
+ NULL, NULL);
diff --git a/zephyr/test/drivers/src/test_rules.c b/zephyr/test/drivers/src/test_rules.c
new file mode 100644
index 0000000000..0266fa3cdf
--- /dev/null
+++ b/zephyr/test/drivers/src/test_rules.c
@@ -0,0 +1,17 @@
+/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <ztest.h>
+
+#include "motion_sense_fifo.h"
+
+static void motion_sense_fifo_reset_before(const struct ztest_unit_test *test,
+ void *data)
+{
+ ARG_UNUSED(test);
+ ARG_UNUSED(data);
+ motion_sense_fifo_reset();
+}
+ZTEST_RULE(motion_sense_fifo_reset, motion_sense_fifo_reset_before, NULL);
diff --git a/zephyr/test/drivers/src/thermistor.c b/zephyr/test/drivers/src/thermistor.c
index a7137d5f19..591faa9436 100644
--- a/zephyr/test/drivers/src/thermistor.c
+++ b/zephyr/test/drivers/src/thermistor.c
@@ -14,6 +14,7 @@
#include "common.h"
#include "../driver/temp_sensor/thermistor.h"
#include "temp_sensor/temp_sensor.h"
+#include "test_state.h"
#define GPIO_PG_EC_DSW_PWROK_PATH DT_PATH(named_gpios, pg_ec_dsw_pwrok)
@@ -39,7 +40,7 @@
* Test if get temp function return expected error when ADC is not powered
* (indicated as GPIO pin set to low) and return success after powering on ADC.
*/
-static void test_thermistor_power_pin(void)
+ZTEST_USER(thermistor, test_thermistor_power_pin)
{
int temp;
int sensor_idx;
@@ -96,7 +97,7 @@ static int adc_error_func(const struct device *dev, unsigned int channel,
}
/** Test if get temp function return expected error on ADC malfunction */
-static void test_thermistor_adc_read_error(void)
+ZTEST_USER(thermistor, test_thermistor_adc_read_error)
{
int temp;
int sensor_idx;
@@ -250,7 +251,7 @@ static void do_thermistor_test(const struct temp_sensor_t *temp_sensor,
[ZSHIM_TEMP_SENSOR_ID(node_id)] = DT_PROP( \
DT_PHANDLE(node_id, thermistor), steinhart_reference_res),
-static void test_thermistors_adc_temperature_conversion(void)
+ZTEST_USER(thermistor, test_thermistors_adc_temperature_conversion)
{
int sensor_idx;
@@ -265,7 +266,7 @@ static void test_thermistors_adc_temperature_conversion(void)
reference_res_arr[sensor_idx]);
}
-static void test_device_nodes_enabled(void)
+ZTEST_USER(thermistor, test_device_nodes_enabled)
{
zassert_equal(NAMED_TEMP_SENSORS_SIZE, TEMP_SENSORS_ENABLED_SIZE,
"Temperature sensors in device tree and "
@@ -274,7 +275,7 @@ static void test_device_nodes_enabled(void)
/* Thermistor nodes being enabled are already tested by compilation. */
}
-void test_suite_thermistor(void)
+static void *thermistor_setup(void)
{
const struct device *dev =
DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_PG_EC_DSW_PWROK_PATH, gpios));
@@ -284,12 +285,8 @@ void test_suite_thermistor(void)
zassert_ok(gpio_emul_input_set(dev, GPIO_PG_EC_DSW_PWROK_PORT, 1),
NULL);
- ztest_test_suite(thermistor,
- ztest_user_unit_test(test_device_nodes_enabled),
- ztest_user_unit_test(test_thermistor_power_pin),
- ztest_user_unit_test(test_thermistor_adc_read_error),
- ztest_user_unit_test(
- test_thermistors_adc_temperature_conversion));
-
- ztest_run_test_suite(thermistor);
+ return NULL;
}
+
+ZTEST_SUITE(thermistor, drivers_predicate_post_main, thermistor_setup, NULL,
+ NULL, NULL);
diff --git a/zephyr/test/drivers/src/usb_mux.c b/zephyr/test/drivers/src/usb_mux.c
index 4c5cf6d281..f63bc94b5d 100644
--- a/zephyr/test/drivers/src/usb_mux.c
+++ b/zephyr/test/drivers/src/usb_mux.c
@@ -26,6 +26,7 @@
#include "usb_tc_sm.h"
#include "usb_mux.h"
+#include "test_state.h"
/** Copy of original usb_muxes[USB_PORT_C1] */
struct usb_mux usb_mux_c1;
@@ -394,9 +395,13 @@ static void restore_usb_mux_chain(void)
} while (0)
/** Test usb_mux init */
-static void test_usb_mux_init(void)
+ZTEST(usb_uninit_mux, test_usb_mux_init)
{
int fail_on_2nd_ret[] = {EC_SUCCESS, EC_ERROR_NOT_POWERED};
+ /*
+ * TODO: investigate why call in usb_uninit_mux_before() is not enough
+ */
+ set_test_runner_tid();
/* Set AP to normal state to init BB retimer */
power_set_state(POWER_S0);
@@ -428,10 +433,14 @@ static void test_usb_mux_init(void)
}
/** Test usb_mux setting mux mode */
-static void test_usb_mux_set(void)
+ZTEST(usb_uninit_mux, test_usb_mux_set)
{
int fail_on_2nd_ret[] = {EC_SUCCESS, EC_ERROR_UNKNOWN};
mux_state_t exp_mode;
+ /*
+ * TODO: investigate why call in usb_uninit_mux_before() is not enough
+ */
+ set_test_runner_tid();
/* Set flag for usb mux 1 to disable polarity setting */
proxy_chain_1.flags = USB_MUX_FLAG_SET_WITHOUT_FLIP;
@@ -486,9 +495,13 @@ static void test_usb_mux_set(void)
}
/** Test usb_mux reset in g3 when required flag is set */
-static void test_usb_mux_reset_in_g3(void)
+ZTEST(usb_uninit_mux, test_usb_mux_reset_in_g3)
{
mux_state_t exp_mode = USB_PD_MUX_USB_ENABLED;
+ /*
+ * TODO: investigate why call in usb_uninit_mux_before() is not enough
+ */
+ set_test_runner_tid();
/* Test that init is called */
reset_proxy_fakes();
@@ -510,10 +523,14 @@ static void test_usb_mux_reset_in_g3(void)
}
/** Test usb_mux getting mux mode */
-static void test_usb_mux_get(void)
+ZTEST(usb_uninit_mux, test_usb_mux_get)
{
int fail_on_2nd_ret[] = {EC_SUCCESS, EC_ERROR_UNKNOWN};
mux_state_t exp_mode, mode;
+ /*
+ * TODO: investigate why call in usb_uninit_mux_before() is not enough
+ */
+ set_test_runner_tid();
/* Test getting mux mode */
exp_mode = USB_PD_MUX_USB_ENABLED;
@@ -547,11 +564,14 @@ static void test_usb_mux_get(void)
}
/** Test usb_mux entering and exiting low power mode */
-static void test_usb_mux_low_power_mode(void)
+ZTEST(usb_init_mux, test_usb_mux_low_power_mode)
{
int fail_on_2nd_ret[] = {EC_SUCCESS, EC_ERROR_NOT_POWERED};
mux_state_t exp_mode, mode;
+ /* TODO: investigate why call in usb_init_mux_before() is not enough */
+ set_test_runner_tid();
+
/* Test enter to low power mode */
exp_mode = USB_PD_MUX_NONE;
usb_mux_set(USBC_PORT_C1, exp_mode, USB_SWITCH_DISCONNECT,
@@ -613,9 +633,13 @@ static void test_usb_mux_low_power_mode(void)
}
/** Test usb_mux flip */
-static void test_usb_mux_flip(void)
+ZTEST(usb_uninit_mux, test_usb_mux_flip)
{
mux_state_t exp_mode;
+ /*
+ * TODO: investigate why call in usb_uninit_mux_before() is not enough
+ */
+ set_test_runner_tid();
/* Set flag for usb mux 1 to disable polarity setting */
proxy_chain_1.flags = USB_MUX_FLAG_SET_WITHOUT_FLIP;
@@ -647,9 +671,13 @@ static void test_usb_mux_flip(void)
CHECK_PROXY_FAKE_CALL_CNT_MUX_STATE(proxy_set, NUM_OF_PROXY, exp_mode);
}
-void test_usb_mux_hpd_update(void)
+ZTEST(usb_uninit_mux, test_usb_mux_hpd_update)
{
mux_state_t exp_mode, mode, virt_mode;
+ /*
+ * TODO: investigate why call in usb_uninit_mux_before() is not enough
+ */
+ set_test_runner_tid();
/* Get current state of virtual usb mux and set mock */
usbc1_virtual_usb_mux.driver->get(&usbc1_virtual_usb_mux, &virt_mode);
@@ -715,7 +743,7 @@ void test_usb_mux_hpd_update(void)
mode, 0);
}
-void test_usb_mux_fw_update_port_info(void)
+ZTEST(usb_init_mux, test_usb_mux_fw_update_port_info)
{
int port_info;
@@ -724,15 +752,17 @@ void test_usb_mux_fw_update_port_info(void)
"fw update for port C1 should be set");
}
-void test_usb_mux_chipset_reset(void)
+ZTEST(usb_init_mux, test_usb_mux_chipset_reset)
{
+ /* TODO: investigate why call in usb_init_mux_before() is not enough */
+ set_test_runner_tid();
/* After this hook chipset reset functions should be called */
hook_notify(HOOK_CHIPSET_RESET);
CHECK_PROXY_FAKE_CALL_CNT(proxy_chipset_reset, NUM_OF_PROXY);
}
/* Test host command get mux info */
-static void test_usb_mux_hc_mux_info(void)
+ZTEST(usb_init_mux, test_usb_mux_hc_mux_info)
{
struct ec_response_usb_pd_mux_info response;
struct ec_params_usb_pd_mux_info params;
@@ -740,6 +770,9 @@ static void test_usb_mux_hc_mux_info(void)
BUILD_HOST_COMMAND(EC_CMD_USB_PD_MUX_INFO, 0, response, params);
mux_state_t exp_mode;
+ /* TODO: investigate why call in usb_init_mux_before() is not enough */
+ set_test_runner_tid();
+
/* Test invalid port parameter */
params.port = 5;
zassert_equal(EC_RES_INVALID_PARAM, host_command_process(&args), NULL);
@@ -777,9 +810,11 @@ static void test_usb_mux_hc_mux_info(void)
}
/** Test typec console command */
-static void test_usb_mux_typec_command(void)
+ZTEST(usb_init_mux, test_usb_mux_typec_command)
{
mux_state_t exp_mode;
+ /* TODO: investigate why call in usb_init_mux_before() is not enough */
+ set_test_runner_tid();
/* Test error on command with no argument */
zassert_equal(EC_ERROR_PARAM_COUNT,
@@ -853,8 +888,9 @@ static void test_usb_mux_typec_command(void)
}
/** Setup proxy chain and uninit usb muxes */
-void setup_uninit_mux(void)
+void usb_uninit_mux_before(void *state)
{
+ ARG_UNUSED(state);
setup_usb_mux_proxy_chain();
set_test_runner_tid();
@@ -864,9 +900,16 @@ void setup_uninit_mux(void)
reset_proxy_fakes();
}
+void usb_uninit_mux_after(void *state)
+{
+ ARG_UNUSED(state);
+ restore_usb_mux_chain();
+}
+
/** Setup proxy chain and init usb muxes */
-void setup_init_mux(void)
+void usb_init_mux_before(void *state)
{
+ ARG_UNUSED(state);
setup_usb_mux_proxy_chain();
set_test_runner_tid();
@@ -875,36 +918,14 @@ void setup_init_mux(void)
reset_proxy_fakes();
}
-void test_suite_usb_mux(void)
+void usb_init_mux_after(void *state)
{
- ztest_test_suite(usb_mux,
- ztest_unit_test_setup_teardown(test_usb_mux_init,
- setup_uninit_mux, restore_usb_mux_chain),
- ztest_unit_test_setup_teardown(test_usb_mux_set,
- setup_uninit_mux, restore_usb_mux_chain),
- ztest_unit_test_setup_teardown(
- test_usb_mux_reset_in_g3,
- setup_uninit_mux, restore_usb_mux_chain),
- ztest_unit_test_setup_teardown(test_usb_mux_get,
- setup_uninit_mux, restore_usb_mux_chain),
- ztest_unit_test_setup_teardown(
- test_usb_mux_low_power_mode,
- setup_init_mux, restore_usb_mux_chain),
- ztest_unit_test_setup_teardown(test_usb_mux_flip,
- setup_uninit_mux, restore_usb_mux_chain),
- ztest_unit_test_setup_teardown(test_usb_mux_hpd_update,
- setup_uninit_mux, restore_usb_mux_chain),
- ztest_unit_test_setup_teardown(
- test_usb_mux_fw_update_port_info,
- setup_init_mux, restore_usb_mux_chain),
- ztest_unit_test_setup_teardown(
- test_usb_mux_chipset_reset,
- setup_init_mux, restore_usb_mux_chain),
- ztest_unit_test_setup_teardown(
- test_usb_mux_hc_mux_info,
- setup_init_mux, restore_usb_mux_chain),
- ztest_unit_test_setup_teardown(
- test_usb_mux_typec_command,
- setup_init_mux, restore_usb_mux_chain));
- ztest_run_test_suite(usb_mux);
+ ARG_UNUSED(state);
+ restore_usb_mux_chain();
}
+
+ZTEST_SUITE(usb_uninit_mux, drivers_predicate_post_main, NULL,
+ usb_uninit_mux_before, usb_uninit_mux_after, NULL);
+
+ZTEST_SUITE(usb_init_mux, drivers_predicate_post_main, NULL,
+ usb_init_mux_before, usb_init_mux_after, NULL);
diff --git a/zephyr/test/drivers/src/usb_pd_host_cmd.c b/zephyr/test/drivers/src/usb_pd_host_cmd.c
index 61f2915ec5..5f8097e7ff 100644
--- a/zephyr/test/drivers/src/usb_pd_host_cmd.c
+++ b/zephyr/test/drivers/src/usb_pd_host_cmd.c
@@ -8,8 +8,9 @@
#include "ec_commands.h"
#include "host_command.h"
+#include "test_state.h"
-static void test_host_command_hc_pd_ports(void)
+ZTEST_USER(usb_pd_host_cmd, test_host_command_hc_pd_ports)
{
struct ec_response_usb_pd_ports response;
struct host_cmd_handler_args args =
@@ -23,10 +24,5 @@ static void test_host_command_hc_pd_ports(void)
CONFIG_PLATFORM_EC_USB_PD_PORT_MAX_COUNT, NULL);
}
-void test_suite_usb_pd_host_cmd(void)
-{
- ztest_test_suite(usb_pd_host_cmd,
- ztest_user_unit_test(
- test_host_command_hc_pd_ports));
- ztest_run_test_suite(usb_pd_host_cmd);
-}
+ZTEST_SUITE(usb_pd_host_cmd, drivers_predicate_post_main, NULL, NULL, NULL,
+ NULL);
diff --git a/zephyr/test/drivers/src/watchdog.c b/zephyr/test/drivers/src/watchdog.c
index 483912aad7..86df3f14f3 100644
--- a/zephyr/test/drivers/src/watchdog.c
+++ b/zephyr/test/drivers/src/watchdog.c
@@ -21,6 +21,7 @@
#include "hooks.h"
#include "stubs.h"
#include "watchdog.h"
+#include "test_state.h"
/**
* @brief Default watchdog timeout plus some time for it to expire.
@@ -41,8 +42,9 @@ K_TIMER_DEFINE(ktimer, NULL, NULL);
/**
* @brief Watchdog test setup handler.
*/
-static void setup_watchdog(void)
+static void watchdog_before(void *state)
{
+ ARG_UNUSED(state);
set_test_runner_tid();
wdt_warning_triggered = false;
}
@@ -50,8 +52,9 @@ static void setup_watchdog(void)
/**
* @brief Watchdog test teardown handler.
*/
-static void teardown_watchdog(void)
+static void watchdog_after(void *state)
{
+ ARG_UNUSED(state);
wdt_warning_triggered = false;
}
@@ -65,7 +68,7 @@ static void teardown_watchdog(void)
* - Successful on first init.
* - Failure on second init.
*/
-static void test_watchdog_init(void)
+ZTEST(watchdog, test_watchdog_init)
{
int retval = EC_SUCCESS;
@@ -89,7 +92,7 @@ static void test_watchdog_init(void)
* Expected Results
* - watchdog warning handler function is never triggered
*/
-static void test_watchdog_reload(void)
+ZTEST(watchdog, test_watchdog_reload)
{
int i;
int safe_wait_ms = DEFAULT_WDT_EXPIRY_MS / 2;
@@ -115,7 +118,7 @@ static void test_watchdog_reload(void)
* Expected Results
* - Validate watchdog warning handler function is triggered.
*/
-static void test_wdt_warning_handler(void)
+ZTEST(watchdog, test_wdt_warning_handler)
{
zassert_false(wdt_warning_triggered, "Watchdog timer expired early.");
@@ -129,18 +132,5 @@ static void test_wdt_warning_handler(void)
/**
* @brief Test Suite: Verifies watchdog functionality.
*/
-void test_suite_watchdog(void)
-{
- ztest_test_suite(watchdog,
- ztest_unit_test_setup_teardown(test_watchdog_init,
- setup_watchdog,
- teardown_watchdog),
- ztest_unit_test_setup_teardown(test_watchdog_reload,
- setup_watchdog,
- teardown_watchdog),
- ztest_unit_test_setup_teardown(
- test_wdt_warning_handler, setup_watchdog,
- teardown_watchdog));
-
- ztest_run_test_suite(watchdog);
-}
+ZTEST_SUITE(watchdog, drivers_predicate_post_main, NULL, watchdog_before,
+ watchdog_after, NULL);