summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Massey <aaronmassey@google.com>2022-11-01 09:42:50 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-02 06:48:34 +0000
commit8ea47c5e9f9f87bb78dafc3cbafa26838fbdb3bd (patch)
treef14d5710906c2cd6e4af1c3e05aed4018640e709
parent8e7ebd6575a61fb969733a2416e3e76db37a0d06 (diff)
downloadchrome-ec-8ea47c5e9f9f87bb78dafc3cbafa26838fbdb3bd.tar.gz
test: dps console cmd with active charging port
Add a test that runs the "dps" console command when there is an active charging port and weakly validate its contents. BRANCH=none BUG=none TEST=twister -i -s zephyr/test/drivers/drivers.default Signed-off-by: Aaron Massey <aaronmassey@google.com> Change-Id: Iff01bc621cf4472de77bc86322d48c8f9cbe45d0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3995817 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Tested-by: Yuval Peress <peress@google.com> Reviewed-by: Yuval Peress <peress@google.com> Commit-Queue: Yuval Peress <peress@google.com>
-rw-r--r--zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c b/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c
index a780277d05..c2b603e6ad 100644
--- a/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c
+++ b/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c
@@ -3,6 +3,7 @@
* found in the LICENSE file.
*/
+#include <zephyr/shell/shell_dummy.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/sys/slist.h>
#include <zephyr/ztest.h>
@@ -24,6 +25,8 @@
#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)
+#define TEST_PORT 0
+
struct usb_attach_5v_3a_pd_source_fixture {
struct tcpci_partner_data source_5v_3a;
struct tcpci_src_emul_data src_ext;
@@ -36,8 +39,8 @@ static void *usb_attach_5v_3a_pd_source_setup(void)
static struct usb_attach_5v_3a_pd_source_fixture test_fixture;
/* Get references for the emulators */
- test_fixture.tcpci_emul = EMUL_GET_USBC_BINDING(0, tcpc);
- test_fixture.charger_emul = EMUL_GET_USBC_BINDING(0, chg);
+ test_fixture.tcpci_emul = EMUL_GET_USBC_BINDING(TEST_PORT, tcpc);
+ test_fixture.charger_emul = EMUL_GET_USBC_BINDING(TEST_PORT, chg);
/* Initialized the charger to supply 5V and 3A */
tcpci_partner_init(&test_fixture.source_5v_3a, PD_REV20);
@@ -90,7 +93,8 @@ ZTEST(usb_attach_5v_3a_pd_source, test_battery_is_charging)
ZTEST(usb_attach_5v_3a_pd_source, test_charge_state)
{
- struct ec_response_charge_state state = host_cmd_charge_state(0);
+ struct ec_response_charge_state state =
+ host_cmd_charge_state(TEST_PORT);
zassert_true(state.get_state.ac, "AC_OK not triggered");
zassert_true(state.get_state.chg_voltage > 0,
@@ -161,7 +165,7 @@ ZTEST_F(usb_attach_5v_3a_pd_source, test_disconnect_charge_state)
struct ec_response_charge_state charge_state;
disconnect_source_from_port(fixture->tcpci_emul, fixture->charger_emul);
- charge_state = host_cmd_charge_state(0);
+ charge_state = host_cmd_charge_state(TEST_PORT);
zassert_false(charge_state.get_state.ac, "AC_OK not triggered");
zassert_equal(charge_state.get_state.chg_current, 0,
@@ -321,3 +325,39 @@ ZTEST_F(usb_attach_5v_3a_pd_source, test_dps_enable)
dps_enable(true);
zassert_true(dps_is_enabled());
}
+
+ZTEST_F(usb_attach_5v_3a_pd_source, test_dps_info)
+{
+ const struct shell *shell_zephyr = get_ec_shell();
+
+ const char *outbuffer;
+ uint32_t buffer_size;
+ /* Arbitrary array size for sprintf should not need this amount */
+ char format_buffer[100];
+
+ shell_backend_dummy_clear_output(shell_zephyr);
+
+ /* Print current status to console */
+ zassert_ok(shell_execute_cmd(shell_zephyr, "dps"), NULL);
+ outbuffer = shell_backend_dummy_get_output(shell_zephyr, &buffer_size);
+
+ /* Should include extra information about the charging port */
+ /* Charging Port */
+ sprintf(format_buffer, "C%d", TEST_PORT);
+ zassert_not_null(strstr(outbuffer, format_buffer));
+ /* We are a sink to a 5v3a source, so check requested mv/ma */
+ sprintf(format_buffer, "Requested: %dmV/%dmA", 5000, 3000);
+ zassert_not_null(strstr(outbuffer, format_buffer));
+ /*
+ * Measured input power is shown (values vary so not asserting on
+ * numbers)
+ */
+ zassert_not_null(strstr(outbuffer, "Measured:"));
+ /* Efficient Voltage - Value varies based on battery*/
+ zassert_not_null(strstr(outbuffer, "Efficient:"));
+ /* Battery Design Voltage (varies based on battery) */
+ zassert_not_null(strstr(outbuffer, "Batt:"));
+ /* PDMaxMV */
+ sprintf(format_buffer, "PDMaxMV: %dmV", pd_get_max_voltage());
+ zassert_not_null(strstr(outbuffer, format_buffer));
+}