From a3a28f011a181958e917fb5a60477bbb10924ef4 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Wed, 17 Aug 2022 09:16:37 +0000 Subject: zephyr: test: rename system to system_shim The current tests in shim link against shim/src/system.c, so this directory is somewhat limited to tests against the shim implementation. Rename it to reflect that, will create tests against common code in a different one. BRANCH=none BUG=b:236074111 TEST=./twister -v -T zephyr/test/system_shim Signed-off-by: Fabio Baltieri Change-Id: I3d93af3001be8d56cc6cf18d2d3b12ceace1c897 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3835564 Reviewed-by: Simon Glass Reviewed-by: Yuval Peress Code-Coverage: Zoss --- zephyr/test/system/CMakeLists.txt | 10 ---- zephyr/test/system/boards/native_posix.overlay | 46 ------------------ zephyr/test/system/prj.conf | 11 ----- zephyr/test/system/test_system.c | 56 ---------------------- zephyr/test/system/testcase.yaml | 4 -- zephyr/test/system_shim/CMakeLists.txt | 10 ++++ .../test/system_shim/boards/native_posix.overlay | 46 ++++++++++++++++++ zephyr/test/system_shim/prj.conf | 11 +++++ zephyr/test/system_shim/test_system.c | 56 ++++++++++++++++++++++ zephyr/test/system_shim/testcase.yaml | 4 ++ 10 files changed, 127 insertions(+), 127 deletions(-) delete mode 100644 zephyr/test/system/CMakeLists.txt delete mode 100644 zephyr/test/system/boards/native_posix.overlay delete mode 100644 zephyr/test/system/prj.conf delete mode 100644 zephyr/test/system/test_system.c delete mode 100644 zephyr/test/system/testcase.yaml create mode 100644 zephyr/test/system_shim/CMakeLists.txt create mode 100644 zephyr/test/system_shim/boards/native_posix.overlay create mode 100644 zephyr/test/system_shim/prj.conf create mode 100644 zephyr/test/system_shim/test_system.c create mode 100644 zephyr/test/system_shim/testcase.yaml diff --git a/zephyr/test/system/CMakeLists.txt b/zephyr/test/system/CMakeLists.txt deleted file mode 100644 index 2113b3a9cf..0000000000 --- a/zephyr/test/system/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright 2020 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 "${ZEPHYR_BASE}") -project(system_test) - -target_sources(app PRIVATE test_system.c - ${PLATFORM_EC}/zephyr/shim/src/system.c) diff --git a/zephyr/test/system/boards/native_posix.overlay b/zephyr/test/system/boards/native_posix.overlay deleted file mode 100644 index 82c3f7e757..0000000000 --- a/zephyr/test/system/boards/native_posix.overlay +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright 2020 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 - -/ { - chosen { - cros-ec,bbram = &bbram; - }; - - bbram: test-bbram-dev { - compatible = "zephyr,bbram-emul"; - label = "TEST_BBRAM_DEV"; - 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/prj.conf b/zephyr/test/system/prj.conf deleted file mode 100644 index 201c2feacc..0000000000 --- a/zephyr/test/system/prj.conf +++ /dev/null @@ -1,11 +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. - -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/test_system.c b/zephyr/test/system/test_system.c deleted file mode 100644 index 45aed5dfff..0000000000 --- a/zephyr/test/system/test_system.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright 2020 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 -#include -#include -#include -#include - -#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/testcase.yaml b/zephyr/test/system/testcase.yaml deleted file mode 100644 index d6977dbb6a..0000000000 --- a/zephyr/test/system/testcase.yaml +++ /dev/null @@ -1,4 +0,0 @@ -common: - platform_allow: native_posix -tests: - system.default: {} diff --git a/zephyr/test/system_shim/CMakeLists.txt b/zephyr/test/system_shim/CMakeLists.txt new file mode 100644 index 0000000000..104058557a --- /dev/null +++ b/zephyr/test/system_shim/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright 2020 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 "${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..82c3f7e757 --- /dev/null +++ b/zephyr/test/system_shim/boards/native_posix.overlay @@ -0,0 +1,46 @@ +/* Copyright 2020 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 + +/ { + chosen { + cros-ec,bbram = &bbram; + }; + + bbram: test-bbram-dev { + compatible = "zephyr,bbram-emul"; + label = "TEST_BBRAM_DEV"; + 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..201c2feacc --- /dev/null +++ b/zephyr/test/system_shim/prj.conf @@ -0,0 +1,11 @@ +# 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_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..45aed5dfff --- /dev/null +++ b/zephyr/test/system_shim/test_system.c @@ -0,0 +1,56 @@ +/* Copyright 2020 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 +#include +#include +#include +#include + +#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: {} -- cgit v1.2.1