test: bc12: cleanup naming
Cleanup some internal names. Remove references to the pi3usb9201 device as the test should work with all BC1.2 driver/emulators. Signed-off-by: Keith Short <keithshort@google.com>
This commit is contained in:
parent
3981b8f827
commit
824d021377
|
@ -8,6 +8,8 @@
|
|||
* @defgroup driver_bc12_tests
|
||||
* @ingroup all_tests
|
||||
* @{
|
||||
* @defgroup t_bc12_portable_device
|
||||
* @brief TestPurpose: Verify BC1.2 devices in portable device mode.
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
@ -17,38 +19,38 @@
|
|||
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#define LOG_MODULE_NAME test_bc12
|
||||
#define LOG_MODULE_NAME test_bc12_pd_mode
|
||||
LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF);
|
||||
|
||||
struct bc12_pi3usb9201_fixture {
|
||||
struct bc12_pd_mode_fixture {
|
||||
const struct device *bc12_dev;
|
||||
const struct emul *bc12_emul;
|
||||
int callback_count;
|
||||
bool disconnect_detected;
|
||||
struct bc12_partner_state charging_partner;
|
||||
struct bc12_partner_state partner_state;
|
||||
};
|
||||
|
||||
static void bc12_test_result_cb(const struct device *dev, struct bc12_partner_state *state,
|
||||
void *user_data)
|
||||
{
|
||||
struct bc12_pi3usb9201_fixture *fixture = user_data;
|
||||
struct bc12_pd_mode_fixture *fixture = user_data;
|
||||
|
||||
fixture->callback_count++;
|
||||
|
||||
if (state) {
|
||||
LOG_INF("callback: type %d, voltage %d, current %d", state->type, state->voltage_uv,
|
||||
state->current_ua);
|
||||
fixture->charging_partner = *state;
|
||||
fixture->partner_state = *state;
|
||||
} else {
|
||||
LOG_INF("callback: partner disconnect");
|
||||
fixture->disconnect_detected = true;
|
||||
fixture->charging_partner.type = BC12_TYPE_NONE;
|
||||
fixture->charging_partner.current_ua = 0;
|
||||
fixture->charging_partner.voltage_uv = 0;
|
||||
fixture->partner_state.type = BC12_TYPE_NONE;
|
||||
fixture->partner_state.current_ua = 0;
|
||||
fixture->partner_state.voltage_uv = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ZTEST_USER_F(bc12_pi3usb9201, test_bc12_no_charging_partner)
|
||||
ZTEST_USER_F(bc12_pd_mode, test_bc12_no_charging_partner)
|
||||
{
|
||||
bc12_emul_set_charging_partner(fixture->bc12_emul, BC12_TYPE_NONE);
|
||||
|
||||
|
@ -60,7 +62,7 @@ ZTEST_USER_F(bc12_pi3usb9201, test_bc12_no_charging_partner)
|
|||
zassert_equal(fixture->callback_count, 0);
|
||||
}
|
||||
|
||||
ZTEST_USER_F(bc12_pi3usb9201, test_bc12_sdp_charging_partner)
|
||||
ZTEST_USER_F(bc12_pd_mode, test_bc12_sdp_charging_partner)
|
||||
{
|
||||
/* Connect a SDP charging partner to the emulator */
|
||||
bc12_emul_set_charging_partner(fixture->bc12_emul, BC12_TYPE_SDP);
|
||||
|
@ -78,9 +80,9 @@ ZTEST_USER_F(bc12_pi3usb9201, test_bc12_sdp_charging_partner)
|
|||
* for SDP ports or when BC1.2 detection fails.
|
||||
*/
|
||||
zassert_equal(fixture->callback_count, 1);
|
||||
zassert_equal(fixture->charging_partner.type, BC12_TYPE_SDP);
|
||||
zassert_equal(fixture->charging_partner.current_ua, 2500);
|
||||
zassert_equal(fixture->charging_partner.voltage_uv, 5000 * 1000);
|
||||
zassert_equal(fixture->partner_state.type, BC12_TYPE_SDP);
|
||||
zassert_equal(fixture->partner_state.current_ua, 2500);
|
||||
zassert_equal(fixture->partner_state.voltage_uv, 5000 * 1000);
|
||||
|
||||
/* Remove the charging partner */
|
||||
fixture->callback_count = 0;
|
||||
|
@ -93,12 +95,12 @@ ZTEST_USER_F(bc12_pi3usb9201, test_bc12_sdp_charging_partner)
|
|||
|
||||
/* The BC1.2 driver should invoke the callback on disconnects */
|
||||
zassert_equal(fixture->callback_count, 1);
|
||||
zassert_equal(fixture->charging_partner.type, BC12_TYPE_NONE);
|
||||
zassert_equal(fixture->charging_partner.current_ua, 0);
|
||||
zassert_equal(fixture->charging_partner.voltage_uv, 0);
|
||||
zassert_equal(fixture->partner_state.type, BC12_TYPE_NONE);
|
||||
zassert_equal(fixture->partner_state.current_ua, 0);
|
||||
zassert_equal(fixture->partner_state.voltage_uv, 0);
|
||||
}
|
||||
|
||||
ZTEST_USER_F(bc12_pi3usb9201, test_bc12_cdp_charging_partner)
|
||||
ZTEST_USER_F(bc12_pd_mode, test_bc12_cdp_charging_partner)
|
||||
{
|
||||
bc12_emul_set_charging_partner(fixture->bc12_emul, BC12_TYPE_CDP);
|
||||
|
||||
|
@ -107,9 +109,9 @@ ZTEST_USER_F(bc12_pi3usb9201, test_bc12_cdp_charging_partner)
|
|||
k_sleep(K_MSEC(100));
|
||||
|
||||
zassert_equal(fixture->callback_count, 1);
|
||||
zassert_equal(fixture->charging_partner.type, BC12_TYPE_CDP);
|
||||
zassert_equal(fixture->charging_partner.current_ua, 1500 * 1000);
|
||||
zassert_equal(fixture->charging_partner.voltage_uv, 5000 * 1000);
|
||||
zassert_equal(fixture->partner_state.type, BC12_TYPE_CDP);
|
||||
zassert_equal(fixture->partner_state.current_ua, 1500 * 1000);
|
||||
zassert_equal(fixture->partner_state.voltage_uv, 5000 * 1000);
|
||||
|
||||
/* Remove the charging partner */
|
||||
fixture->callback_count = 0;
|
||||
|
@ -123,12 +125,12 @@ ZTEST_USER_F(bc12_pi3usb9201, test_bc12_cdp_charging_partner)
|
|||
/* The BC1.2 driver should invoke the callback on disconnects */
|
||||
zassert_equal(fixture->callback_count, 1);
|
||||
zassert_true(fixture->disconnect_detected);
|
||||
zassert_equal(fixture->charging_partner.type, BC12_TYPE_NONE);
|
||||
zassert_equal(fixture->charging_partner.current_ua, 0);
|
||||
zassert_equal(fixture->charging_partner.voltage_uv, 0);
|
||||
zassert_equal(fixture->partner_state.type, BC12_TYPE_NONE);
|
||||
zassert_equal(fixture->partner_state.current_ua, 0);
|
||||
zassert_equal(fixture->partner_state.voltage_uv, 0);
|
||||
}
|
||||
|
||||
ZTEST_USER_F(bc12_pi3usb9201, test_bc12_sdp_to_dcp_charging_partner)
|
||||
ZTEST_USER_F(bc12_pd_mode, test_bc12_sdp_to_dcp_charging_partner)
|
||||
{
|
||||
bc12_emul_set_charging_partner(fixture->bc12_emul, BC12_TYPE_SDP);
|
||||
|
||||
|
@ -137,9 +139,9 @@ ZTEST_USER_F(bc12_pi3usb9201, test_bc12_sdp_to_dcp_charging_partner)
|
|||
k_sleep(K_MSEC(100));
|
||||
|
||||
zassert_equal(fixture->callback_count, 1);
|
||||
zassert_equal(fixture->charging_partner.type, BC12_TYPE_SDP);
|
||||
zassert_equal(fixture->charging_partner.current_ua, 2500);
|
||||
zassert_equal(fixture->charging_partner.voltage_uv, 5000 * 1000);
|
||||
zassert_equal(fixture->partner_state.type, BC12_TYPE_SDP);
|
||||
zassert_equal(fixture->partner_state.current_ua, 2500);
|
||||
zassert_equal(fixture->partner_state.voltage_uv, 5000 * 1000);
|
||||
|
||||
/* Change the partner type to DCP */
|
||||
fixture->callback_count = 0;
|
||||
|
@ -152,27 +154,27 @@ ZTEST_USER_F(bc12_pi3usb9201, test_bc12_sdp_to_dcp_charging_partner)
|
|||
|
||||
/* The BC1.2 driver should invoke the callback once to report the new state. */
|
||||
zassert_equal(fixture->callback_count, 1);
|
||||
zassert_equal(fixture->charging_partner.type, BC12_TYPE_DCP);
|
||||
zassert_equal(fixture->charging_partner.current_ua, 1500 * 1000);
|
||||
zassert_equal(fixture->charging_partner.voltage_uv, 5000 * 1000);
|
||||
zassert_equal(fixture->partner_state.type, BC12_TYPE_DCP);
|
||||
zassert_equal(fixture->partner_state.current_ua, 1500 * 1000);
|
||||
zassert_equal(fixture->partner_state.voltage_uv, 5000 * 1000);
|
||||
}
|
||||
|
||||
static void bc12_before(void *data)
|
||||
{
|
||||
struct bc12_pi3usb9201_fixture *fixture = data;
|
||||
struct bc12_pd_mode_fixture *fixture = data;
|
||||
|
||||
fixture->callback_count = 0;
|
||||
fixture->disconnect_detected = 0;
|
||||
fixture->charging_partner.type = BC12_TYPE_NONE;
|
||||
fixture->charging_partner.current_ua = 0;
|
||||
fixture->charging_partner.voltage_uv = 0;
|
||||
fixture->partner_state.type = BC12_TYPE_NONE;
|
||||
fixture->partner_state.current_ua = 0;
|
||||
fixture->partner_state.voltage_uv = 0;
|
||||
|
||||
bc12_set_result_cb(fixture->bc12_dev, &bc12_test_result_cb, fixture);
|
||||
}
|
||||
|
||||
static void bc12_after(void *data)
|
||||
{
|
||||
struct bc12_pi3usb9201_fixture *fixture = data;
|
||||
struct bc12_pd_mode_fixture *fixture = data;
|
||||
|
||||
bc12_set_result_cb(fixture->bc12_dev, NULL, NULL);
|
||||
bc12_set_role(fixture->bc12_dev, BC12_DISCONNECTED);
|
||||
|
@ -180,7 +182,7 @@ static void bc12_after(void *data)
|
|||
|
||||
static void *bc12_setup(void)
|
||||
{
|
||||
static struct bc12_pi3usb9201_fixture fixture = {
|
||||
static struct bc12_pd_mode_fixture fixture = {
|
||||
.bc12_dev = DEVICE_DT_GET(DT_ALIAS(bc12)),
|
||||
.bc12_emul = EMUL_DT_GET(DT_ALIAS(bc12)),
|
||||
};
|
||||
|
@ -192,4 +194,4 @@ static void *bc12_setup(void)
|
|||
return &fixture;
|
||||
}
|
||||
|
||||
ZTEST_SUITE(bc12_pi3usb9201, NULL, bc12_setup, bc12_before, bc12_after, NULL);
|
||||
ZTEST_SUITE(bc12_pd_mode, NULL, bc12_setup, bc12_before, bc12_after, NULL);
|
||||
|
|
Loading…
Reference in a new issue