summaryrefslogtreecommitdiff
path: root/zephyr
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr')
-rw-r--r--zephyr/app/ec/CMakeLists.txt4
-rw-r--r--zephyr/app/ec/ec_app_main.c (renamed from zephyr/app/ec/main.c)6
-rw-r--r--zephyr/app/ec/include/ec_app_main.h6
-rw-r--r--zephyr/app/ec/main_shim.c13
-rw-r--r--zephyr/test/ec_app/CMakeLists.txt10
-rw-r--r--zephyr/test/ec_app/prj.conf7
-rw-r--r--zephyr/test/ec_app/src/main.c127
-rw-r--r--zephyr/test/ec_app/zmake.yaml10
8 files changed, 181 insertions, 2 deletions
diff --git a/zephyr/app/ec/CMakeLists.txt b/zephyr/app/ec/CMakeLists.txt
index 43f4ff2fe2..f12067a5b5 100644
--- a/zephyr/app/ec/CMakeLists.txt
+++ b/zephyr/app/ec/CMakeLists.txt
@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+zephyr_library_include_directories(include)
+zephyr_library_sources(ec_app_main.c)
if(NOT DEFINED CONFIG_ZTEST)
- zephyr_library_sources(main.c)
+ zephyr_library_sources(main_shim.c)
endif()
diff --git a/zephyr/app/ec/main.c b/zephyr/app/ec/ec_app_main.c
index 44f272e0d6..ad8498efc6 100644
--- a/zephyr/app/ec/main.c
+++ b/zephyr/app/ec/ec_app_main.c
@@ -16,8 +16,12 @@
#include "vboot.h"
#include "watchdog.h"
#include "zephyr_espi_shim.h"
+#include "ec_app_main.h"
-void main(void)
+/* For testing purposes this is not named main. See main_shim.c for the real
+ * main() function.
+ */
+void ec_app_main(void)
{
printk("Hello from a Chrome EC!\n");
printk(" BOARD=%s\n", CONFIG_BOARD);
diff --git a/zephyr/app/ec/include/ec_app_main.h b/zephyr/app/ec/include/ec_app_main.h
new file mode 100644
index 0000000000..a5043be84a
--- /dev/null
+++ b/zephyr/app/ec/include/ec_app_main.h
@@ -0,0 +1,6 @@
+/* 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.
+ */
+
+void ec_app_main(void);
diff --git a/zephyr/app/ec/main_shim.c b/zephyr/app/ec/main_shim.c
new file mode 100644
index 0000000000..83e58e67b8
--- /dev/null
+++ b/zephyr/app/ec/main_shim.c
@@ -0,0 +1,13 @@
+/* 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.
+ */
+
+#include "ec_app_main.h"
+
+/** A stub main to call the real ec app main function. LCOV_EXCL_START */
+void main(void)
+{
+ ec_app_main();
+}
+/* LCOV_EXCL_STOP */
diff --git a/zephyr/test/ec_app/CMakeLists.txt b/zephyr/test/ec_app/CMakeLists.txt
new file mode 100644
index 0000000000..8ee9a554a7
--- /dev/null
+++ b/zephyr/test/ec_app/CMakeLists.txt
@@ -0,0 +1,10 @@
+# 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.
+
+cmake_minimum_required(VERSION 3.13.1)
+find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
+project(ec_app)
+
+FILE(GLOB app_sources src/*.c)
+target_sources(app PRIVATE ${app_sources})
diff --git a/zephyr/test/ec_app/prj.conf b/zephyr/test/ec_app/prj.conf
new file mode 100644
index 0000000000..b398d0dd8c
--- /dev/null
+++ b/zephyr/test/ec_app/prj.conf
@@ -0,0 +1,7 @@
+# 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.
+
+CONFIG_ZTEST=y
+CONFIG_PLATFORM_EC=y
+CONFIG_CROS_EC=y
diff --git a/zephyr/test/ec_app/src/main.c b/zephyr/test/ec_app/src/main.c
new file mode 100644
index 0000000000..d173fa106d
--- /dev/null
+++ b/zephyr/test/ec_app/src/main.c
@@ -0,0 +1,127 @@
+/* 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.
+ */
+
+#include <ztest.h>
+#include "ec_app_main.h"
+#include "hooks.h"
+
+static void test_init_reset_log(void)
+{
+#ifdef CONFIG_CMD_AP_RESET_LOG
+ zassert_unreachable("TODO: Implement this test.");
+#else
+ ztest_test_skip();
+#endif
+}
+
+static void test_lpc_init_mask(void)
+{
+#ifdef CONFIG_HOSTCMD_X86
+ zassert_unreachable("TODO: Implement this test.");
+#else
+ ztest_test_skip();
+#endif
+}
+
+static void test_keyboard_scan_init(void)
+{
+#ifdef HAS_TASK_KEYSCAN
+ zassert_unreachable("TODO: Implement this test.");
+#else
+ ztest_test_skip();
+#endif
+}
+
+static void test_button_init(void)
+{
+#if defined(CONFIG_DEDICATED_RECOVERY_BUTTON) || defined(CONFIG_VOLUME_BUTTONS)
+ zassert_unreachable("TODO: Implement this test.");
+#else
+ ztest_test_skip();
+#endif
+}
+
+static void test_setup_espi(void)
+{
+#ifdef CONFIG_PLATFORM_EC_ESPI
+ zassert_unreachable("TODO: Implement this test.");
+#else
+ ztest_test_skip();
+#endif
+}
+
+static void test_watchdog_init(void)
+{
+#ifdef CONFIG_PLATFORM_EC_WATCHDOG
+ zassert_unreachable("TODO: Implement this test.");
+#else
+ ztest_test_skip();
+#endif
+}
+
+static void test_vboot_main(void)
+{
+#ifdef CONFIG_PLATFORM_EC_VBOOT
+ zassert_unreachable("TODO: Implement this test.");
+#else
+ ztest_test_skip();
+#endif
+}
+
+#ifdef CONFIG_PLATFORM_EC_HOOKS
+static int sample_init_hook_count;
+/**
+ * Just a sample hook.
+ */
+static void sample_init_hook(void)
+{
+ printk("Running hook.\n");
+ sample_init_hook_count++;
+}
+DECLARE_HOOK(HOOK_INIT, sample_init_hook, HOOK_PRIO_DEFAULT);
+
+/**
+ * @brief Test EC App main runs hooks of type HOOK_INIT.
+ *
+ * This test installs a hook, runs main and verifies that the hook ran.
+ *
+ */
+static void test_hook_notify_init(void)
+{
+ 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)
+{
+ ztest_test_skip();
+}
+#endif
+
+static void test_start_ec_tasks(void)
+{
+#ifdef CONFIG_SHIMMED_TASKS
+ zassert_unreachable("TODO: Implement this test.");
+#else
+ ztest_test_skip();
+#endif
+}
+
+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);
+}
diff --git a/zephyr/test/ec_app/zmake.yaml b/zephyr/test/ec_app/zmake.yaml
new file mode 100644
index 0000000000..4804127f1b
--- /dev/null
+++ b/zephyr/test/ec_app/zmake.yaml
@@ -0,0 +1,10 @@
+# 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.
+
+board: native_posix
+supported-zephyr-versions:
+ - v2.5
+toolchain: llvm
+output-type: elf
+is-test: true