From f997dc1ef757f3952adc4da1b04253993e03f306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Wed, 6 Mar 2024 21:04:41 +0100 Subject: [PATCH] WIP: EEPROM tests --- tests/storage_eeprom/CMakeLists.txt | 9 ++++ tests/storage_eeprom/boards/native_posix.conf | 4 ++ .../boards/native_posix.overlay | 20 +++++++++ tests/storage_eeprom/prj.conf | 18 ++++++++ tests/storage_eeprom/src/main.c | 42 +++++++++++++++++++ tests/storage_eeprom/testcase.yaml | 7 ++++ 6 files changed, 100 insertions(+) create mode 100644 tests/storage_eeprom/CMakeLists.txt create mode 100644 tests/storage_eeprom/boards/native_posix.conf create mode 100644 tests/storage_eeprom/boards/native_posix.overlay create mode 100644 tests/storage_eeprom/prj.conf create mode 100644 tests/storage_eeprom/src/main.c create mode 100644 tests/storage_eeprom/testcase.yaml diff --git a/tests/storage_eeprom/CMakeLists.txt b/tests/storage_eeprom/CMakeLists.txt new file mode 100644 index 0000000..1bdcb3b --- /dev/null +++ b/tests/storage_eeprom/CMakeLists.txt @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(thingset_sdk_storage_eeprom_test) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/storage_eeprom/boards/native_posix.conf b/tests/storage_eeprom/boards/native_posix.conf new file mode 100644 index 0000000..2e40485 --- /dev/null +++ b/tests/storage_eeprom/boards/native_posix.conf @@ -0,0 +1,4 @@ + +CONFIG_EMUL=y +CONFIG_I2C_EMUL=y +CONFIG_EEPROM_AT2X_EMUL=y diff --git a/tests/storage_eeprom/boards/native_posix.overlay b/tests/storage_eeprom/boards/native_posix.overlay new file mode 100644 index 0000000..50ff2f3 --- /dev/null +++ b/tests/storage_eeprom/boards/native_posix.overlay @@ -0,0 +1,20 @@ + +/ { + chosen { + thingset,eeprom = &eeprom1; + }; + +}; + +&i2c0 { + status = "okay"; + eeprom1: eeprom@53 { + status = "okay"; + compatible = "atmel,at24"; + reg=<0x53>; + size = ; + timeout = <5>; + pagesize = <16>; + address-width = <16>; + }; +}; diff --git a/tests/storage_eeprom/prj.conf b/tests/storage_eeprom/prj.conf new file mode 100644 index 0000000..7e5bde6 --- /dev/null +++ b/tests/storage_eeprom/prj.conf @@ -0,0 +1,18 @@ +# Copyright (c) The ThingSet Project Contributors +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_ZTEST_SUMMARY=n + +CONFIG_I2C=y +CONFIG_EEPROM=y +CONFIG_ENTROPY_GENERATOR=y + +CONFIG_THINGSET=y +CONFIG_THINGSET_SDK=y +CONFIG_THINGSET_SDK_LOG_LEVEL_DBG=y +CONFIG_THINGSET_STORAGE=y + +# enable click-able absolute paths in assert messages +CONFIG_BUILD_OUTPUT_STRIP_PATHS=n diff --git a/tests/storage_eeprom/src/main.c b/tests/storage_eeprom/src/main.c new file mode 100644 index 0000000..1342ef2 --- /dev/null +++ b/tests/storage_eeprom/src/main.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) The ThingSet Project Contributors + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +#include +#include +#include + +/* test data objects */ +static float test_float = 1234.56; +static char test_string[] = "Hello World!"; + +THINGSET_ADD_GROUP(THINGSET_ID_ROOT, 0x200, "Test", THINGSET_NO_CALLBACK); +THINGSET_ADD_ITEM_FLOAT(0x200, 0x201, "wFloat", &test_float, 1, THINGSET_ANY_RW, TS_SUBSET_LIVE); +THINGSET_ADD_ITEM_STRING(0x200, 0x202, "wString", test_string, sizeof(test_string), THINGSET_ANY_RW, + TS_SUBSET_NVM); + +ZTEST(thingset_storage_eeprom, test_save_load) +{ + int err; + + err = thingset_storage_save(); + zassert_equal(err, 0); + + err = thingset_storage_load(); + zassert_equal(err, 0); +} + +static void *thingset_storage_eeprom_setup(void) +{ + thingset_init_global(&ts); + + return NULL; +} + +ZTEST_SUITE(thingset_storage_eeprom, NULL, thingset_storage_eeprom_setup, NULL, NULL, NULL); diff --git a/tests/storage_eeprom/testcase.yaml b/tests/storage_eeprom/testcase.yaml new file mode 100644 index 0000000..1d0cc86 --- /dev/null +++ b/tests/storage_eeprom/testcase.yaml @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 + +tests: + thingset_sdk.storage_eeprom: + integration_platforms: + - native_posix +# extra_args: EXTRA_CFLAGS=-Werror