summaryrefslogtreecommitdiff
path: root/zephyr/test/ec_app
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/test/ec_app')
-rw-r--r--zephyr/test/ec_app/BUILD.py7
-rw-r--r--zephyr/test/ec_app/CMakeLists.txt4
-rw-r--r--zephyr/test/ec_app/boards/native_posix.overlay37
-rw-r--r--zephyr/test/ec_app/prj.conf16
-rw-r--r--zephyr/test/ec_app/src/main.c109
-rw-r--r--zephyr/test/ec_app/testcase.yaml4
6 files changed, 105 insertions, 72 deletions
diff --git a/zephyr/test/ec_app/BUILD.py b/zephyr/test/ec_app/BUILD.py
deleted file mode 100644
index eeb85c0e46..0000000000
--- a/zephyr/test/ec_app/BUILD.py
+++ /dev/null
@@ -1,7 +0,0 @@
-# Copyright 2021 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.
-
-"""Register zmake project for ec_app test."""
-
-register_host_test("ec_app")
diff --git a/zephyr/test/ec_app/CMakeLists.txt b/zephyr/test/ec_app/CMakeLists.txt
index 8ee9a554a7..83daf93e67 100644
--- a/zephyr/test/ec_app/CMakeLists.txt
+++ b/zephyr/test/ec_app/CMakeLists.txt
@@ -1,9 +1,9 @@
-# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Copyright 2021 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
cmake_minimum_required(VERSION 3.13.1)
-find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
+find_package(Zephyr REQUIRED HINTS "${ZEPHYR_BASE}")
project(ec_app)
FILE(GLOB app_sources src/*.c)
diff --git a/zephyr/test/ec_app/boards/native_posix.overlay b/zephyr/test/ec_app/boards/native_posix.overlay
new file mode 100644
index 0000000000..69bf044ec6
--- /dev/null
+++ b/zephyr/test/ec_app/boards/native_posix.overlay
@@ -0,0 +1,37 @@
+/* Copyright 2020 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <board-overlays/native_posix.dts>
+#include <cros/binman.dtsi>
+
+/ {
+ chosen {
+ cros-ec,flash = &flash1;
+ cros-ec,flash-controller = &cros_flash;
+ };
+ aliases {
+ gpio-wp = &gpio_wp_l;
+ };
+ named-gpios {
+ compatible = "named-gpios";
+ ec_gsc_packet_mode {
+ gpios = <&gpio0 2 GPIO_OUTPUT_LOW>;
+ enum-name = "GPIO_PACKET_MODE_EN";
+ };
+ gpio_wp_l: wp_l {
+ gpios = <&gpio0 3 (GPIO_INPUT | GPIO_ACTIVE_LOW)>;
+ };
+ };
+ cros_flash: cros-flash {
+ compatible = "cros-ec,flash-emul";
+ };
+ flash1: flash@64000000 {
+ reg = <0x64000000 DT_SIZE_K(512)>;
+ };
+};
+
+&gpio0 {
+ ngpios = <4>;
+};
diff --git a/zephyr/test/ec_app/prj.conf b/zephyr/test/ec_app/prj.conf
index b398d0dd8c..3b44c56b6b 100644
--- a/zephyr/test/ec_app/prj.conf
+++ b/zephyr/test/ec_app/prj.conf
@@ -1,7 +1,21 @@
-# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Copyright 2021 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
CONFIG_ZTEST=y
+CONFIG_ZTEST_NEW_API=y
CONFIG_PLATFORM_EC=y
CONFIG_CROS_EC=y
+CONFIG_SHIMMED_TASKS=y
+CONFIG_FLASH=y
+CONFIG_SHELL_BACKEND_DUMMY=y
+CONFIG_SHELL_BACKEND_SERIAL=n
+CONFIG_SERIAL=y
+CONFIG_RING_BUFFER=y
+
+CONFIG_EMUL_CROS_FLASH=y
+CONFIG_PLATFORM_EC_VBOOT_EFS2=y
+CONFIG_PLATFORM_EC_VBOOT_HASH=y
+CONFIG_PLATFORM_EC_HOSTCMD=y
+CONFIG_PLATFORM_EC_BACKLIGHT_LID=n
+CONFIG_PLATFORM_EC_SWITCH=n
diff --git a/zephyr/test/ec_app/src/main.c b/zephyr/test/ec_app/src/main.c
index 47aecc7eca..b106754d47 100644
--- a/zephyr/test/ec_app/src/main.c
+++ b/zephyr/test/ec_app/src/main.c
@@ -1,74 +1,71 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-#include <ztest.h>
+#include <zephyr/ztest_assert.h>
+#include <zephyr/ztest_test_new.h>
+#include <zephyr/shell/shell_dummy.h>
+
#include "ec_app_main.h"
#include "hooks.h"
+#include "task.h"
-static void test_init_reset_log(void)
-{
#ifdef CONFIG_CMD_AP_RESET_LOG
+ZTEST(ec_app_tests, test_init_reset_log)
+{
zassert_unreachable("TODO: Implement this test.");
-#else
- ztest_test_skip();
-#endif
}
+#endif
-static void test_lpc_init_mask(void)
-{
#ifdef CONFIG_HOSTCMD_X86
+ZTEST(ec_app_tests, test_lpc_init_mask)
+{
zassert_unreachable("TODO: Implement this test.");
-#else
- ztest_test_skip();
-#endif
}
+#endif
-static void test_keyboard_scan_init(void)
-{
#ifdef HAS_TASK_KEYSCAN
+ZTEST(ec_app_tests, test_keyboard_scan_init)
+{
zassert_unreachable("TODO: Implement this test.");
-#else
- ztest_test_skip();
-#endif
}
+#endif
-static void test_button_init(void)
-{
#if defined(CONFIG_DEDICATED_RECOVERY_BUTTON) || defined(CONFIG_VOLUME_BUTTONS)
+ZTEST(ec_app_tests, test_button_init)
+{
zassert_unreachable("TODO: Implement this test.");
-#else
- ztest_test_skip();
-#endif
}
+#endif
-static void test_setup_espi(void)
-{
#ifdef CONFIG_PLATFORM_EC_HOST_INTERFACE_ESPI
+ZTEST(ec_app_tests, test_setup_espi)
+{
zassert_unreachable("TODO: Implement this test.");
-#else
- ztest_test_skip();
-#endif
}
+#endif
-static void test_watchdog_init(void)
-{
#ifdef CONFIG_PLATFORM_EC_WATCHDOG
+ZTEST(ec_app_tests, test_watchdog_init)
+{
zassert_unreachable("TODO: Implement this test.");
-#else
- ztest_test_skip();
-#endif
}
+#endif
-static void test_vboot_main(void)
-{
#ifdef CONFIG_PLATFORM_EC_VBOOT_EFS2
- zassert_unreachable("TODO: Implement this test.");
-#else
- ztest_test_skip();
-#endif
+ZTEST(ec_app_tests, test_vboot_main)
+{
+ const struct shell *shell_zephyr = get_ec_shell();
+ const char *outbuffer;
+ size_t buffer_size;
+
+ /* vboot_main logs the message "VB Verifying hash" */
+ outbuffer = shell_backend_dummy_get_output(shell_zephyr, &buffer_size);
+ zassert_true(strstr(outbuffer, "VB Verifying hash") != NULL,
+ "'VB Verifying hash' not found in %s", outbuffer);
}
+#endif
#ifdef CONFIG_PLATFORM_EC_HOOKS
static int sample_init_hook_count;
@@ -88,40 +85,28 @@ DECLARE_HOOK(HOOK_INIT, sample_init_hook, HOOK_PRIO_DEFAULT);
* This test installs a hook, runs main and verifies that the hook ran.
*
*/
-static void test_hook_notify_init(void)
+ZTEST(ec_app_tests, test_hook_notify_init)
{
- sample_init_hook_count = 0;
- ec_app_main();
zassert_equal(1, sample_init_hook_count,
"Expected sample_init_hook to run once.");
}
-#else
-static void test_hook_notify_init(void)
+#endif
+
+#ifdef CONFIG_SHIMMED_TASKS
+ZTEST(ec_app_tests, test_start_ec_tasks)
{
- ztest_test_skip();
+ zassert_equal(task_start_called(), 1, "Tasks did not start.");
}
#endif
-static void test_start_ec_tasks(void)
+/* Does setup for all of the test cases. */
+void *ec_app_setup(void)
{
#ifdef CONFIG_SHIMMED_TASKS
- zassert_unreachable("TODO: Implement this test.");
-#else
- ztest_test_skip();
+ zassert_equal(task_start_called(), 0, "Tasks have already started.");
#endif
+ ec_app_main();
+ return NULL;
}
-void test_main(void)
-{
- ztest_test_suite(ec_app_tests, ztest_unit_test(test_init_reset_log),
- ztest_unit_test(test_lpc_init_mask),
- ztest_unit_test(test_keyboard_scan_init),
- ztest_unit_test(test_button_init),
- ztest_unit_test(test_setup_espi),
- ztest_unit_test(test_watchdog_init),
- ztest_unit_test(test_vboot_main),
- ztest_unit_test(test_hook_notify_init),
- ztest_unit_test(test_start_ec_tasks));
-
- ztest_run_test_suite(ec_app_tests);
-}
+ZTEST_SUITE(ec_app_tests, NULL, ec_app_setup, NULL, NULL, NULL);
diff --git a/zephyr/test/ec_app/testcase.yaml b/zephyr/test/ec_app/testcase.yaml
new file mode 100644
index 0000000000..4f21d64207
--- /dev/null
+++ b/zephyr/test/ec_app/testcase.yaml
@@ -0,0 +1,4 @@
+common:
+ platform_allow: native_posix
+tests:
+ ec_app.default: {}