summaryrefslogtreecommitdiff
path: root/zephyr/test
diff options
context:
space:
mode:
authorAbe Levkoy <alevkoy@chromium.org>2021-09-01 12:15:29 -0600
committerCommit Bot <commit-bot@chromium.org>2021-09-15 22:42:36 +0000
commitf47bf498f741c04bdfdd6b961f4e579f34279096 (patch)
treeef18a5d94244b37c6f7316fe495e5b79e45a326e /zephyr/test
parentd7884389d0c8d4c29719cf75a1efc3ca3fc02bf7 (diff)
downloadchrome-ec-f47bf498f741c04bdfdd6b961f4e579f34279096.tar.gz
zephyr: Test SYV682 5V_OC interrupt handling
Simulate a 5V OC condition and verify that the driver turns VBUS off. Support status interrupt conditions and clear-on-read registers in SYV682x emulator. Increase line coverage of syv682x.c from 37.9% to 52.8%. BUG=b:190519131 TEST=zmake -l DEBUG configure --test zephyr/test/drivers BRANCH=none Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Change-Id: I9c5b419057cf4ccb1531527a71760533240d1f47 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3059218 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Diffstat (limited to 'zephyr/test')
-rw-r--r--zephyr/test/drivers/CMakeLists.txt2
-rw-r--r--zephyr/test/drivers/src/ppc.c45
2 files changed, 41 insertions, 6 deletions
diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt
index 20d9a53cec..c90b334e60 100644
--- a/zephyr/test/drivers/CMakeLists.txt
+++ b/zephyr/test/drivers/CMakeLists.txt
@@ -7,7 +7,9 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(drivers)
# Include the local test directory for shimmed_test_tasks.h
+zephyr_include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
zephyr_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
+zephyr_include_directories("${PLATFORM_EC}/driver/ppc/")
FILE(GLOB test_sources src/*.c)
target_sources(app PRIVATE ${test_sources})
diff --git a/zephyr/test/drivers/src/ppc.c b/zephyr/test/drivers/src/ppc.c
index d4d067ad27..dced25c227 100644
--- a/zephyr/test/drivers/src/ppc.c
+++ b/zephyr/test/drivers/src/ppc.c
@@ -10,37 +10,70 @@
#include "emul/emul_syv682x.h"
#include "stubs.h"
+#include "syv682x.h"
+#include "timer.h"
#include "usbc_ppc.h"
#define SYV682X_ORD DT_DEP_ORD(DT_NODELABEL(syv682x_emul))
+static const int syv682x_port = 1;
+
static void test_ppc_syv682x_vbus_enable(void)
{
struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD);
- const int port = 1;
uint8_t reg;
- zassert_ok(ppc_init(port), "PPC init failed");
-
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_false(ppc_is_sourcing_vbus(port),
+ zassert_false(ppc_is_sourcing_vbus(syv682x_port),
"PPC sourcing VBUS at beginning of test");
- zassert_ok(ppc_vbus_source_enable(port, true), "VBUS enable failed");
+ zassert_ok(ppc_vbus_source_enable(syv682x_port, true),
+ "VBUS enable failed");
zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, &reg),
"Reading CONTROL_1 failed");
zassert_equal(reg & SYV682X_CONTROL_1_PWR_ENB, 0,
"VBUS sourcing disabled");
- zassert_true(ppc_is_sourcing_vbus(port),
+ zassert_true(ppc_is_sourcing_vbus(syv682x_port),
"PPC is not sourcing VBUS after VBUS enabled");
}
+static void test_ppc_syv682x_interrupt(void)
+{
+ struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD);
+
+ syv682x_emul_set_status(emul, SYV682X_STATUS_OC_5V);
+ syv682x_interrupt(syv682x_port);
+
+ /* An OC event less than 100 ms should not cause VBUS to turn off. */
+ msleep(50);
+ syv682x_interrupt(syv682x_port);
+ zassert_true(ppc_is_sourcing_vbus(syv682x_port),
+ "PPC is not sourcing VBUS after 50 ms OC");
+ /* But one greater than 100 ms should. */
+ msleep(60);
+ syv682x_interrupt(syv682x_port);
+ zassert_false(ppc_is_sourcing_vbus(syv682x_port),
+ "PPC is sourcing VBUS after 100 ms OC");
+
+ syv682x_emul_set_status(emul, 0x0);
+ /*
+ * TODO(b/190519131): Organize the tests to be more hermetic and avoid
+ * the following issue: The driver triggers overcurrent protection. If
+ * overcurrent protection is triggered 3 times, the TC won't turn the
+ * port back on without a detach. This could frustrate efforts to test
+ * the TC.
+ */
+}
+
static void test_ppc_syv682x(void)
{
+ zassert_ok(ppc_init(syv682x_port), "PPC init failed");
+
test_ppc_syv682x_vbus_enable();
+ test_ppc_syv682x_interrupt();
}
void test_suite_ppc(void)