summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlschyi <lschyi@google.com>2022-08-24 21:13:08 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-08-25 14:25:04 +0000
commit1fe7098722d4c3a17eb4f1e1a8b0357bfa7d3a2e (patch)
treeaacc758b1ecfc0bd6e35aef40bb4d4a0888fbd0c
parent604b237e3d3aa361dad876f8c52141b390548376 (diff)
downloadchrome-ec-1fe7098722d4c3a17eb4f1e1a8b0357bfa7d3a2e.tar.gz
test: add tests for the i2c_portmap and check argument number
Add tests for the console command `i2c_portmap`, and also fix the logic if the supplied argument number does not match to the function. BRANCH=none BUG=b:236074892 TEST=twister -T zephyr/test/drivers Signed-off-by: lschyi <lschyi@google.com> Change-Id: I26384d39f12e787e9c7cad63a0da6fbe54443008 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3854304 Commit-Queue: Sung-Chi Li <lschyi@chromium.org> Tested-by: Sung-Chi Li <lschyi@chromium.org> Reviewed-by: Tomasz Michalec <tmichalec@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--zephyr/shim/src/i2c.c4
-rw-r--r--zephyr/test/drivers/default/CMakeLists.txt1
-rw-r--r--zephyr/test/drivers/default/src/console_cmd/i2c_portmap.c27
3 files changed, 32 insertions, 0 deletions
diff --git a/zephyr/shim/src/i2c.c b/zephyr/shim/src/i2c.c
index eb2e637bc4..346665f0c2 100644
--- a/zephyr/shim/src/i2c.c
+++ b/zephyr/shim/src/i2c.c
@@ -79,6 +79,10 @@ static int command_i2c_portmap(int argc, char **argv)
{
int i;
+ if (argc > 1) {
+ return EC_ERROR_PARAM_COUNT;
+ }
+
ccprintf("Zephyr remote I2C ports (%d):\n", I2C_PORT_COUNT);
for (i = 0; i < I2C_PORT_COUNT; i++) {
ccprintf(" %d : %d\n", i, i2c_remote_ports[i]);
diff --git a/zephyr/test/drivers/default/CMakeLists.txt b/zephyr/test/drivers/default/CMakeLists.txt
index 98327490de..41a015b2e5 100644
--- a/zephyr/test/drivers/default/CMakeLists.txt
+++ b/zephyr/test/drivers/default/CMakeLists.txt
@@ -21,6 +21,7 @@ target_sources(app PRIVATE
src/console_cmd/accelres.c
src/console_cmd/cutoff.c
src/console_cmd/gpio.c
+ src/console_cmd/i2c_portmap.c
src/console_cmd/md.c
src/console_cmd/panic_output.c
src/console_cmd/port80.c
diff --git a/zephyr/test/drivers/default/src/console_cmd/i2c_portmap.c b/zephyr/test/drivers/default/src/console_cmd/i2c_portmap.c
new file mode 100644
index 0000000000..4c364b606d
--- /dev/null
+++ b/zephyr/test/drivers/default/src/console_cmd/i2c_portmap.c
@@ -0,0 +1,27 @@
+/* Copyright 2022 The ChromiumOS Authors.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <zephyr/shell/shell.h>
+#include <zephyr/ztest.h>
+
+#include "console.h"
+#include "ec_commands.h"
+#include "test/drivers/test_state.h"
+
+ZTEST_SUITE(console_cmd_i2c_portmap, drivers_predicate_post_main, NULL, NULL,
+ NULL, NULL);
+
+ZTEST_USER(console_cmd_i2c_portmap, test_too_many_args)
+{
+ int rv = shell_execute_cmd(get_ec_shell(), "i2c_portmap arg1");
+
+ zassert_equal(rv, EC_ERROR_PARAM_COUNT, "Expected %d, but got %d",
+ EC_ERROR_PARAM_COUNT, rv);
+}
+
+ZTEST_USER(console_cmd_i2c_portmap, test_get_i2c_portmap)
+{
+ zassert_ok(shell_execute_cmd(get_ec_shell(), "i2c_portmap"), NULL);
+}