summaryrefslogtreecommitdiff
path: root/zephyr/test/system_shim
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/test/system_shim')
-rw-r--r--zephyr/test/system_shim/CMakeLists.txt10
-rw-r--r--zephyr/test/system_shim/boards/native_posix.overlay45
-rw-r--r--zephyr/test/system_shim/prj.conf11
-rw-r--r--zephyr/test/system_shim/test_system.c56
-rw-r--r--zephyr/test/system_shim/testcase.yaml4
5 files changed, 126 insertions, 0 deletions
diff --git a/zephyr/test/system_shim/CMakeLists.txt b/zephyr/test/system_shim/CMakeLists.txt
new file mode 100644
index 0000000000..2f8b61cda8
--- /dev/null
+++ b/zephyr/test/system_shim/CMakeLists.txt
@@ -0,0 +1,10 @@
+# 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.
+
+cmake_minimum_required(VERSION 3.13.1)
+find_package(Zephyr REQUIRED HINTS "${ZEPHYR_BASE}")
+project(system_shim_test)
+
+target_sources(app PRIVATE test_system.c
+ ${PLATFORM_EC}/zephyr/shim/src/system.c)
diff --git a/zephyr/test/system_shim/boards/native_posix.overlay b/zephyr/test/system_shim/boards/native_posix.overlay
new file mode 100644
index 0000000000..0bcda0f513
--- /dev/null
+++ b/zephyr/test/system_shim/boards/native_posix.overlay
@@ -0,0 +1,45 @@
+/* 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>
+
+/ {
+ chosen {
+ cros-ec,bbram = &bbram;
+ };
+
+ bbram: test-bbram-dev {
+ compatible = "zephyr,bbram-emul";
+ size = <64>;
+ };
+
+ named-bbram-regions {
+ compatible = "named-bbram-regions";
+ pd0 {
+ offset = <0x00>;
+ size = <0x01>;
+ };
+ pd1 {
+ offset = <0x01>;
+ size = <0x02>;
+ };
+ try_slot {
+ offset = <0x03>;
+ size = <0x04>;
+ };
+ pd2 {
+ offset = <0x07>;
+ size = <0x05>;
+ };
+ scratchpad {
+ offset = <0x0c>;
+ size = <0x04>;
+ };
+ saved-reset-flags {
+ offset = <0x10>;
+ size = <0x04>;
+ };
+ };
+};
diff --git a/zephyr/test/system_shim/prj.conf b/zephyr/test/system_shim/prj.conf
new file mode 100644
index 0000000000..fa7bd9fc04
--- /dev/null
+++ b/zephyr/test/system_shim/prj.conf
@@ -0,0 +1,11 @@
+# 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_LOG=y
+CONFIG_BBRAM=y
+CONFIG_BBRAM_EMUL=y
diff --git a/zephyr/test/system_shim/test_system.c b/zephyr/test/system_shim/test_system.c
new file mode 100644
index 0000000000..d8b92e9504
--- /dev/null
+++ b/zephyr/test/system_shim/test_system.c
@@ -0,0 +1,56 @@
+/* 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 <zephyr/device.h>
+#include <zephyr/drivers/bbram.h>
+#include <zephyr/logging/log.h>
+#include <zephyr/ztest_assert.h>
+#include <zephyr/ztest_test_new.h>
+
+#include "system.h"
+
+LOG_MODULE_REGISTER(test);
+
+#define BBRAM_REGION_OFF(name) \
+ DT_PROP(DT_PATH(named_bbram_regions, name), offset)
+#define BBRAM_REGION_SIZE(name) \
+ DT_PROP(DT_PATH(named_bbram_regions, name), size)
+
+static char mock_data[64] =
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@";
+
+ZTEST_SUITE(system, NULL, NULL, NULL, NULL, NULL);
+
+ZTEST(system, test_bbram_get)
+{
+ const struct device *const bbram_dev =
+ DEVICE_DT_GET(DT_CHOSEN(cros_ec_bbram));
+ uint8_t output[10];
+ int rc;
+
+ /* Write expected data to read back */
+ rc = bbram_write(bbram_dev, 0, ARRAY_SIZE(mock_data), mock_data);
+ zassert_ok(rc, NULL);
+
+ rc = system_get_bbram(SYSTEM_BBRAM_IDX_PD0, output);
+ zassert_ok(rc, NULL);
+ zassert_mem_equal(output, mock_data + BBRAM_REGION_OFF(pd0),
+ BBRAM_REGION_SIZE(pd0), NULL);
+
+ rc = system_get_bbram(SYSTEM_BBRAM_IDX_PD1, output);
+ zassert_ok(rc, NULL);
+ zassert_mem_equal(output, mock_data + BBRAM_REGION_OFF(pd1),
+ BBRAM_REGION_SIZE(pd1), NULL);
+
+ rc = system_get_bbram(SYSTEM_BBRAM_IDX_PD2, output);
+ zassert_ok(rc, NULL);
+ zassert_mem_equal(output, mock_data + BBRAM_REGION_OFF(pd2),
+ BBRAM_REGION_SIZE(pd2), NULL);
+
+ rc = system_get_bbram(SYSTEM_BBRAM_IDX_TRY_SLOT, output);
+ zassert_ok(rc, NULL);
+ zassert_mem_equal(output, mock_data + BBRAM_REGION_OFF(try_slot),
+ BBRAM_REGION_SIZE(try_slot), NULL);
+}
diff --git a/zephyr/test/system_shim/testcase.yaml b/zephyr/test/system_shim/testcase.yaml
new file mode 100644
index 0000000000..85df1de33a
--- /dev/null
+++ b/zephyr/test/system_shim/testcase.yaml
@@ -0,0 +1,4 @@
+common:
+ platform_allow: native_posix
+tests:
+ system_shim.default: {}