summaryrefslogtreecommitdiff
path: root/zephyr/test/jump_tags
diff options
context:
space:
mode:
authorYH Lin <yueherngl@google.com>2022-11-30 21:44:08 +0000
committerYH Lin <yueherngl@google.com>2022-11-30 21:44:08 +0000
commitaf25602b15b22b9ef5821dcba9934311f2157c48 (patch)
treed0c89ae8814c2ba35c238c6c0644ec6b1602c63a /zephyr/test/jump_tags
parent54462f034b635260dd09173b3d082e47fc960ef3 (diff)
parentaa40b859b3a73e5a205bc561c1a29eff38485461 (diff)
downloadchrome-ec-af25602b15b22b9ef5821dcba9934311f2157c48.tar.gz
Merge remote-tracking branch cros/main into factory-brya-14517.B-main
Generated by: util/update_release_branch.py --baseboard brya --relevant_paths_file baseboard/brya/relevant-paths.txt factory-brya-14517.B-main Relevant changes: git log --oneline 54462f034b..aa40b859b3 -- baseboard/brya board/agah board/anahera board/banshee board/brya board/crota board/felwinter board/gimble board/kano board/mithrax board/osiris board/primus board/redrix board/taeko board/taniks board/vell board/volmar driver/bc12/pi3usb9201_public.* driver/charger/bq25710.* driver/ppc/nx20p348x.* driver/ppc/syv682x_public.* driver/retimer/bb_retimer_public.* driver/tcpm/nct38xx.* driver/tcpm/ps8xxx_public.* driver/tcpm/tcpci.* include/power/alderlake* include/intel_x86.h power/alderlake* power/intel_x86.c util/getversion.sh e6da633c38 driver: Sort header files 234a87ae2d tcpci: Add FRS enable to driver structure a56be59ccd tcpm_header: add test for tcpm_dump_registers 57b3256963 Rename CONFIG_CHARGER_INPUT_CURRENT to _CHARGER_DEFAULT_CURRENT_LIMIT e420c8ff9a marasov: Modify TypeC and TypeA configuration. 43b53e0045 Add default implementation of board_set_charge_limit b75dc90677 Add CONFIG_CHARGER_MIN_INPUT_CURRENT_LIMIT f1b563c350 baseboard: Sort header files 7d01b1e58d driver/retimer/ps8818.h: Add I2C ADDR FLAGS 0x30, 0x58, 0x70 ec31407993 Add CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 8f89f69a5b crota: disable lid angle sensor for clamshell BRANCH=None BUG=b:259002141 b:255184961 b:247100970 b:259354679 b:260630630 BUG=b:163093572 b:254328661 TEST=`emerge-brya chromeos-ec` Force-Relevant-Builds: all Change-Id: Ia85a701fbf6b8e67ec214b9e25e0e55e980a6f47 Signed-off-by: YH Lin <yueherngl@google.com>
Diffstat (limited to 'zephyr/test/jump_tags')
-rw-r--r--zephyr/test/jump_tags/CMakeLists.txt13
-rw-r--r--zephyr/test/jump_tags/boards/native_posix.overlay33
-rw-r--r--zephyr/test/jump_tags/prj.conf14
-rw-r--r--zephyr/test/jump_tags/src/jump_tags.c176
-rw-r--r--zephyr/test/jump_tags/testcase.yaml13
5 files changed, 249 insertions, 0 deletions
diff --git a/zephyr/test/jump_tags/CMakeLists.txt b/zephyr/test/jump_tags/CMakeLists.txt
new file mode 100644
index 0000000000..710195275e
--- /dev/null
+++ b/zephyr/test/jump_tags/CMakeLists.txt
@@ -0,0 +1,13 @@
+# 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.
+
+cmake_minimum_required(VERSION 3.20.0)
+find_package(Zephyr REQUIRED HINTS "${ZEPHYR_BASE}")
+project(jump_tags)
+
+# Include FFF fakes
+add_subdirectory(${PLATFORM_EC}/zephyr/test/test_utils test_utils)
+
+FILE(GLOB test_sources src/*.c)
+target_sources(app PRIVATE ${test_sources})
diff --git a/zephyr/test/jump_tags/boards/native_posix.overlay b/zephyr/test/jump_tags/boards/native_posix.overlay
new file mode 100644
index 0000000000..9f3238d076
--- /dev/null
+++ b/zephyr/test/jump_tags/boards/native_posix.overlay
@@ -0,0 +1,33 @@
+/* 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 <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";
+ 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/jump_tags/prj.conf b/zephyr/test/jump_tags/prj.conf
new file mode 100644
index 0000000000..4e39830c0a
--- /dev/null
+++ b/zephyr/test/jump_tags/prj.conf
@@ -0,0 +1,14 @@
+# 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.
+
+CONFIG_CROS_EC=y
+CONFIG_FLASH=y
+CONFIG_PLATFORM_EC_CONSOLE_CMD_CHARGEN=n
+CONFIG_PLATFORM_EC=y
+CONFIG_SERIAL=y
+CONFIG_SHELL_BACKEND_DUMMY=y
+CONFIG_SHELL_BACKEND_SERIAL=n
+CONFIG_SHIMMED_TASKS=y
+CONFIG_ZTEST_NEW_API=y
+CONFIG_ZTEST=y
diff --git a/zephyr/test/jump_tags/src/jump_tags.c b/zephyr/test/jump_tags/src/jump_tags.c
new file mode 100644
index 0000000000..a2a377bb35
--- /dev/null
+++ b/zephyr/test/jump_tags/src/jump_tags.c
@@ -0,0 +1,176 @@
+/* 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 "ec_commands.h"
+#include "hooks.h"
+#include "host_command.h"
+#include "sysjump.h"
+#include "system.h"
+#include "system_fake.h"
+
+#include <setjmp.h>
+
+#include <zephyr/kernel.h>
+#include <zephyr/ztest.h>
+
+#define TEST_BASIC_JUMP_TAG 0x9901
+#define TEST_MISSING_JUMP_TAG 0x9902
+#define TEST_MAX_JUMP_TAG 0x9903
+#define TEST_TOO_BIG_JUMP_TAG 0x9904
+
+#define TEST_JUMP_TAG_VERSION 1
+
+#define SOME_STR_VAL "JumpTagTest"
+
+void (*add_tag_func)(void);
+
+struct test_basic_jump_data_struct {
+ char some_str[32];
+};
+
+struct test_max_jump_data_struct {
+ char some_str[JUMP_TAG_MAX_SIZE];
+};
+
+struct test_too_big_jump_data_struct {
+ char some_str[JUMP_TAG_MAX_SIZE + 1];
+};
+
+static void system_before(void *data)
+{
+ add_tag_func = NULL;
+ system_common_pre_init();
+ system_set_shrspi_image_copy(EC_IMAGE_RO);
+}
+
+static void do_fake_sysjump(void)
+{
+ jmp_buf env;
+ enum ec_image target_image = system_get_image_copy() == EC_IMAGE_RO ?
+ EC_IMAGE_RW :
+ EC_IMAGE_RO;
+
+ if (!setjmp(env)) {
+ system_fake_setenv(&env);
+ system_run_image_copy(target_image);
+ zassert_unreachable();
+ }
+
+ system_set_shrspi_image_copy(target_image);
+ zassert_equal(system_get_image_copy(), target_image);
+}
+
+static void add_max_jump_tag(void)
+{
+ struct test_max_jump_data_struct max_tag = {
+ .some_str = SOME_STR_VAL,
+ };
+ zassert_ok(system_add_jump_tag(TEST_MAX_JUMP_TAG, TEST_JUMP_TAG_VERSION,
+ sizeof(max_tag), &max_tag));
+}
+
+static void add_too_big_jump_tag(void)
+{
+ struct test_too_big_jump_data_struct too_big_tag = {
+ .some_str = SOME_STR_VAL,
+ };
+ zassert_equal(system_add_jump_tag(TEST_TOO_BIG_JUMP_TAG,
+ TEST_JUMP_TAG_VERSION,
+ sizeof(too_big_tag), &too_big_tag),
+ EC_ERROR_INVAL);
+}
+
+static void add_too_many_jump_tags(void)
+{
+ int rv;
+ struct test_max_jump_data_struct max_tag = {
+ .some_str = SOME_STR_VAL,
+ };
+ /* Ensure at least one tag can be added, but not 10 */
+ for (int i = 0; i < 10; i++) {
+ rv = system_add_jump_tag(TEST_MAX_JUMP_TAG,
+ TEST_JUMP_TAG_VERSION, sizeof(max_tag),
+ &max_tag);
+ if (rv != 0) {
+ zassert_equal(rv, EC_ERROR_INVAL);
+ zassert_true(i > 0);
+ return;
+ }
+ }
+ zassert_unreachable(
+ "Adding too many jump tags failed to result in an error");
+}
+
+static void add_basic_jump_tag(void)
+{
+ struct test_basic_jump_data_struct basic_tag = {
+ .some_str = SOME_STR_VAL,
+ };
+ zassert_ok(system_add_jump_tag(TEST_BASIC_JUMP_TAG,
+ TEST_JUMP_TAG_VERSION, sizeof(basic_tag),
+ &basic_tag));
+}
+
+static void test_sysjump_hook(void)
+{
+ if (add_tag_func)
+ add_tag_func();
+}
+DECLARE_HOOK(HOOK_SYSJUMP, test_sysjump_hook, HOOK_PRIO_DEFAULT);
+
+static void check_for_jump_tag(int jump_tag, int expected_size)
+{
+ int version;
+ int size;
+ const unsigned char *data;
+
+ data = system_get_jump_tag(jump_tag, &version, &size);
+ zassert_equal(size, expected_size);
+ zassert_equal(version, TEST_JUMP_TAG_VERSION);
+ zassert_equal(strcmp(data, SOME_STR_VAL), 0);
+}
+
+ZTEST(jump_tags, test_get_missing_jump_tag)
+{
+ int version;
+ int size;
+ struct test_jump_data_struct *data;
+
+ data = (struct test_jump_data_struct *)system_get_jump_tag(
+ TEST_MISSING_JUMP_TAG, &version, &size);
+ zassert_equal(data, NULL);
+}
+
+ZTEST(jump_tags, test_add_max_jump_tag)
+{
+ add_tag_func = add_max_jump_tag;
+ do_fake_sysjump();
+ check_for_jump_tag(TEST_MAX_JUMP_TAG,
+ sizeof(struct test_max_jump_data_struct));
+}
+
+ZTEST(jump_tags, test_too_big_jump_tag)
+{
+ add_tag_func = add_too_big_jump_tag;
+ do_fake_sysjump();
+}
+
+ZTEST(jump_tags, test_too_many_jump_tags)
+{
+ add_tag_func = add_too_many_jump_tags;
+ do_fake_sysjump();
+ check_for_jump_tag(TEST_MAX_JUMP_TAG,
+ sizeof(struct test_max_jump_data_struct));
+}
+
+ZTEST(jump_tags, test_add_basic_jump_tag)
+{
+ add_tag_func = add_basic_jump_tag;
+ do_fake_sysjump();
+ check_for_jump_tag(TEST_BASIC_JUMP_TAG,
+ sizeof(struct test_basic_jump_data_struct));
+}
+
+ZTEST_SUITE(jump_tags, NULL, NULL, system_before, NULL, NULL);
diff --git a/zephyr/test/jump_tags/testcase.yaml b/zephyr/test/jump_tags/testcase.yaml
new file mode 100644
index 0000000000..11ef8d73ec
--- /dev/null
+++ b/zephyr/test/jump_tags/testcase.yaml
@@ -0,0 +1,13 @@
+# 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.
+
+common:
+ platform_allow: native_posix
+tests:
+ jump_tags.default:
+ extra_configs:
+ - CONFIG_PLATFORM_EC_PRESERVED_END_OF_RAM_SIZE=1024
+ tags:
+ common
+ system