summaryrefslogtreecommitdiff
path: root/zephyr/test/system
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2021-01-15 12:06:31 -0700
committerCommit Bot <commit-bot@chromium.org>2021-02-03 23:49:02 +0000
commit41f52b709177f7ddff01f5b7a568c663bc495897 (patch)
tree147857c0886e21b1a8d62c2eef0b8c24dd548ce5 /zephyr/test/system
parent236e03723b4eb389a7846257ac5b6fb9e2faab5c (diff)
downloadchrome-ec-41f52b709177f7ddff01f5b7a568c663bc495897.tar.gz
zephyr: flash/system: enable common/flash.c & common/system.c
Bring both flash.c and system.c into the build. zephyr/shim/src/system.c now includes only code that is needed to stub out the chip specific system.c implementation in platform/ec (which is now using the devicetree values). BRANCH=none BUG=b:176828988, b:174481378 TEST=zmake testall TEST=build volteer, flash, and test flashinfo. Cq-Depend: chromium:2631353 Change-Id: I5c542fca01dcc4af98401bcbbf402e579cd45e36 Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2649463 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'zephyr/test/system')
-rw-r--r--zephyr/test/system/CMakeLists.txt4
-rw-r--r--zephyr/test/system/test_system.c274
2 files changed, 50 insertions, 228 deletions
diff --git a/zephyr/test/system/CMakeLists.txt b/zephyr/test/system/CMakeLists.txt
index 2afa9d6301..f91786841e 100644
--- a/zephyr/test/system/CMakeLists.txt
+++ b/zephyr/test/system/CMakeLists.txt
@@ -6,5 +6,5 @@ cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(system_test)
-FILE(GLOB app_sources *.c)
-target_sources(app PRIVATE ${app_sources})
+target_sources(app PRIVATE test_system.c
+ ${PLATFORM_EC}/zephyr/shim/src/system.c)
diff --git a/zephyr/test/system/test_system.c b/zephyr/test/system/test_system.c
index e16a43193e..3dc9f95a0f 100644
--- a/zephyr/test/system/test_system.c
+++ b/zephyr/test/system/test_system.c
@@ -3,251 +3,73 @@
* found in the LICENSE file.
*/
-#include <ztest.h>
+#include <device.h>
+#include <drivers/cros_bbram.h>
#include <logging/log.h>
-#include "ec_commands.h"
-#include "system.h"
-#include "sysjump.h"
-LOG_MODULE_REGISTER(test);
-
-#define JUMP_TAG_TOTAL_SIZE 512
-
-struct jump_memory {
- uint8_t jump_tag_memory[JUMP_TAG_TOTAL_SIZE];
- struct jump_data jdata;
-};
-
-static struct jump_memory jump_memory;
-
-static void setup(void)
-{
- system_common_reset_state();
- memset(&jump_memory, 0, sizeof(struct jump_memory));
-}
-
-static void test_set_reset_flags(void)
-{
- zassert_equal(system_get_reset_flags(), 0,
- "system_get_reset_flags() should be 0 at the start");
- system_set_reset_flags(EC_RESET_FLAG_OTHER);
- zassert_equal(
- system_get_reset_flags(), EC_RESET_FLAG_OTHER,
- "system_get_reset_flags() should match exactly to EC_RESET_FLAG_OTHER");
-}
-
-static void test_clear_reset_flags(void)
-{
- uint32_t flags = EC_RESET_FLAG_OTHER | EC_RESET_FLAG_STAY_IN_RO;
-
- system_set_reset_flags(flags);
- zassert_not_equal(system_get_reset_flags(), 0,
- "system_get_reset_flags() should be non-zero");
- /* Remove the reset hard flag. */
- system_clear_reset_flags(EC_RESET_FLAG_OTHER);
- zassert_equal(system_get_reset_flags(), EC_RESET_FLAG_STAY_IN_RO,
- "system_get_reset_flags() should have removed "
- "EC_RESET_FLAG_OTHER after reset.");
-}
-
-static void test_encode_save_flags_preserve(void)
-{
- const uint32_t expected_flags = EC_RESET_FLAG_OTHER |
- EC_RESET_FLAG_USB_RESUME |
- EC_RESET_FLAG_EFS;
- uint32_t save_flags;
-
- system_set_reset_flags(expected_flags);
-
- /*
- * Preserve the existing flags, should add EC_RESET_FLAG_PRESERVED and
- * EC_RESET_FLAG_SOFT.
- */
- system_encode_save_flags(SYSTEM_RESET_PRESERVE_FLAGS, &save_flags);
- zassert_equal(save_flags,
- expected_flags | EC_RESET_FLAG_PRESERVED |
- EC_RESET_FLAG_SOFT,
- "All the reset flags should have been restored.");
-}
-
-static void test_encode_save_flags_translate_system_to_ec(void)
-{
- uint32_t save_flags;
-
- system_encode_save_flags(SYSTEM_RESET_LEAVE_AP_OFF, &save_flags);
- zassert_equal(
- save_flags, EC_RESET_FLAG_AP_OFF | EC_RESET_FLAG_SOFT,
- "Expected save flags to be EC_RESET_FLAG_AP_OFF | EC_RESET_FLAG_SOFT");
-
- system_encode_save_flags(SYSTEM_RESET_STAY_IN_RO, &save_flags);
- zassert_equal(
- save_flags, EC_RESET_FLAG_STAY_IN_RO | EC_RESET_FLAG_SOFT,
- "Expected save flags to be EC_RESET_FLAG_STAY_IN_RO | EC_RESET_FLAG_SOFT");
-
- system_encode_save_flags(SYSTEM_RESET_HARD, &save_flags);
- zassert_equal(save_flags, EC_RESET_FLAG_HARD,
- "Expected save flags to be EC_RESET_FLAG_HARD");
-
- system_encode_save_flags(SYSTEM_RESET_WAIT_EXT, &save_flags);
- zassert_equal(save_flags, EC_RESET_FLAG_HARD,
- "Expected save flags to be EC_RESET_FLAG_HARD");
-}
+#include <ztest.h>
-static void test_common_pre_init_fail_matching_magic_number(void)
-{
- /* Put garbage values in test_jdata. */
- jump_memory.jdata.struct_size = sizeof(struct jump_data);
- jump_memory.jdata.reset_flags = 0xff;
- jump_memory.jdata.version = 3;
- jump_memory.jdata.magic = 12345;
+#include "bbram.h"
+#include "system.h"
- system_override_jdata(&jump_memory.jdata);
- system_common_pre_init();
+LOG_MODULE_REGISTER(test);
- /* Verify that test_jdata was zeroed out. */
- for (size_t i = 0; i < sizeof(struct jump_data); ++i) {
- zassert_equal(((uint8_t *)&jump_memory.jdata)[i], 0,
- "Expecting byte %d of jdata to be 0.", i);
- }
-}
+static char mock_data[64] =
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@";
-static void test_common_pre_init_with_delta_struct_size(void)
+static int mock_bbram_read(const struct device *unused, int offset, int size,
+ char *data)
{
- /* Set the old struct size to be 1 smaller than the current one. */
- jump_memory.jdata.struct_size = sizeof(struct jump_data) - 1;
- jump_memory.jdata.version = JUMP_DATA_VERSION;
- jump_memory.jdata.magic = JUMP_DATA_MAGIC;
- jump_memory.jdata.jump_tag_total = JUMP_TAG_TOTAL_SIZE;
-
- /*
- * Since we're telling the system component that the size is 1 smaller
- * than it really is it should calculate that the delta is 1 and shift
- * all the tags by 1 byte to the left.
- */
- jump_memory.jump_tag_memory[1] = 0xff;
-
- system_override_jdata(&jump_memory.jdata);
- system_common_pre_init();
-
- zassert_equal(
- jump_memory.jump_tag_memory[0], 0xff,
- "Expected byte 0 to have the value from previous position 1 in "
- "jump tag memory");
- zassert_equal(jump_memory.jump_tag_memory[1], 0,
- "Expected byte 1 to have moved to position 0 in jump tag "
- "memory");
+ if (offset < 0 || offset + size >= ARRAY_SIZE(mock_data))
+ return -1;
+ memcpy(data, mock_data + offset, size);
+ return EC_SUCCESS;
}
-static void test_common_pre_init_resets_jdata_not_jump_tags(void)
-{
- jump_memory.jdata.struct_size = sizeof(struct jump_data);
- jump_memory.jdata.version = JUMP_DATA_VERSION;
- jump_memory.jdata.magic = JUMP_DATA_MAGIC;
- jump_memory.jdata.jump_tag_total = JUMP_TAG_TOTAL_SIZE;
- jump_memory.jdata.reserved0 = 0xf0;
-
- for (size_t i = 0; i < JUMP_TAG_TOTAL_SIZE; ++i)
- jump_memory.jump_tag_memory[i] = i & 0xff;
-
- system_override_jdata(&jump_memory.jdata);
- system_common_pre_init();
-
- zassert_equal(jump_memory.jdata.jump_tag_total, 0,
- "Expected jump_tag_total to be reset to 0");
- zassert_equal(jump_memory.jdata.struct_size, sizeof(struct jump_data),
- "Expected struct_size to match sizeof(struct jump_data)");
- zassert_equal(jump_memory.jdata.reserved0, 0,
- "Expected the reseved field to be reset to 0");
- zassert_equal(jump_memory.jdata.magic, 0,
- "Expected the magic number to be reset to 0");
-
- for (size_t i = 0; i < JUMP_TAG_TOTAL_SIZE; ++i) {
- zassert_equal(
- jump_memory.jump_tag_memory[i], i & 0xff,
- "Expected jump_tag_memory[%d] to remain unchanged.", i);
- }
-}
+static const struct cros_bbram_driver_api bbram_api = {
+ .ibbr = NULL,
+ .reset_ibbr = NULL,
+ .vsby = NULL,
+ .reset_vsby = NULL,
+ .vcc1 = NULL,
+ .reset_vcc1 = NULL,
+ .read = mock_bbram_read,
+ .write = NULL,
+};
-static void test_add_jump_tag_fail_no_init(void)
-{
- zassert_equal(
- system_add_jump_tag(0, 0, 0, NULL), -EINVAL,
- "Can't set a jump tag without calling common_pre_init first.");
+static const struct device bbram_dev_instance = {
+ .name = "TEST_BBRAM_DEV",
+ .config = NULL,
+ .api = &bbram_api,
+ .data = NULL,
+};
- system_override_jdata(&jump_memory.jdata);
- system_common_pre_init();
- zassert_equal(system_add_jump_tag(0, 0, 0, NULL), -EINVAL,
- "Can't set a jump tag without valid jdata.");
-}
+const struct device *bbram_dev = &bbram_dev_instance;
-static void test_add_jump_tag_fail_size_out_of_bounds(void)
+static void test_bbram_get(void)
{
- system_override_jdata(&jump_memory.jdata);
- system_common_pre_init();
- jump_memory.jdata.magic = JUMP_DATA_MAGIC;
+ uint8_t output[10];
+ int rc;
- zassert_equal(system_add_jump_tag(0, 0, -1, NULL), -EINVAL,
- "Can't set jump tag with negative size");
- zassert_equal(system_add_jump_tag(0, 0, 256, NULL), -EINVAL,
- "Can't set jump tag with size > 255");
-}
-
-static void test_add_jump_tag(void)
-{
- const uint16_t data = 0x1234;
- uint16_t tag = 0;
- int version = 1;
- const uint8_t *returned_data;
- int returned_size;
+ rc = system_get_bbram(SYSTEM_BBRAM_IDX_PD0, output);
+ zassert_equal(rc, 0, NULL);
+ zassert_mem_equal(output, mock_data + BBRM_DATA_INDEX_PD0, 1, NULL);
- system_override_jdata(&jump_memory.jdata);
- system_common_pre_init();
- jump_memory.jdata.magic = JUMP_DATA_MAGIC;
+ rc = system_get_bbram(SYSTEM_BBRAM_IDX_PD1, output);
+ zassert_equal(rc, 0, NULL);
+ zassert_mem_equal(output, mock_data + BBRM_DATA_INDEX_PD1, 1, NULL);
- zassert_equal(system_add_jump_tag(tag, version, sizeof(uint16_t),
- &data),
- 0, "Expected add_jump_tag to return 0");
+ rc = system_get_bbram(SYSTEM_BBRAM_IDX_PD2, output);
+ zassert_equal(rc, 0, NULL);
+ zassert_mem_equal(output, mock_data + BBRM_DATA_INDEX_PD2, 1, NULL);
- returned_data = system_get_jump_tag(tag, &version, &returned_size);
- zassert_not_null(returned_data, "Failed to get tag data for tag <%u>",
- tag);
- zassert_equal(version, 1, "Expected version to be 1 but got <%d>",
- version);
- zassert_equal(returned_size, sizeof(uint16_t),
- "Expected returned size to be %u but got <%u>",
- sizeof(uint16_t), returned_size);
- zassert_equal(*((uint16_t *)returned_data), data,
- "Expected returned data to be %u but got <%u>", data,
- *((uint16_t *)returned_data));
+ rc = system_get_bbram(SYSTEM_BBRAM_IDX_TRY_SLOT, output);
+ zassert_equal(rc, 0, NULL);
+ zassert_mem_equal(output, mock_data + BBRM_DATA_INDEX_TRY_SLOT, 1,
+ NULL);
}
void test_main(void)
{
- ztest_test_suite(
- system,
- ztest_unit_test_setup_teardown(test_set_reset_flags, setup,
- unit_test_noop),
- ztest_unit_test_setup_teardown(test_clear_reset_flags, setup,
- unit_test_noop),
- ztest_unit_test_setup_teardown(test_encode_save_flags_preserve,
- setup, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_encode_save_flags_translate_system_to_ec, setup,
- unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_common_pre_init_fail_matching_magic_number, setup,
- unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_common_pre_init_with_delta_struct_size, setup,
- unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_common_pre_init_resets_jdata_not_jump_tags, setup,
- unit_test_noop),
- ztest_unit_test_setup_teardown(test_add_jump_tag_fail_no_init,
- setup, unit_test_noop),
- ztest_unit_test_setup_teardown(
- test_add_jump_tag_fail_size_out_of_bounds, setup,
- unit_test_noop),
- ztest_unit_test_setup_teardown(test_add_jump_tag, setup,
- unit_test_noop));
+ ztest_test_suite(system, ztest_unit_test(test_bbram_get));
ztest_run_test_suite(system);
}