Skip to content

Commit

Permalink
WIP: EEPROM tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjaeger committed Mar 6, 2024
1 parent db5573f commit f997dc1
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/storage_eeprom/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
4 changes: 4 additions & 0 deletions tests/storage_eeprom/boards/native_posix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

CONFIG_EMUL=y
CONFIG_I2C_EMUL=y
CONFIG_EEPROM_AT2X_EMUL=y
20 changes: 20 additions & 0 deletions tests/storage_eeprom/boards/native_posix.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

/ {
chosen {
thingset,eeprom = &eeprom1;
};

};

&i2c0 {
status = "okay";
eeprom1: eeprom@53 {
status = "okay";
compatible = "atmel,at24";
reg=<0x53>;
size = <DT_SIZE_K(64)>;
timeout = <5>;
pagesize = <16>;
address-width = <16>;
};
};
18 changes: 18 additions & 0 deletions tests/storage_eeprom/prj.conf
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions tests/storage_eeprom/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) The ThingSet Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdlib.h>

#include <zephyr/ztest.h>

#include <thingset.h>
#include <thingset/sdk.h>
#include <thingset/storage.h>

/* 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);
7 changes: 7 additions & 0 deletions tests/storage_eeprom/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: Apache-2.0

tests:
thingset_sdk.storage_eeprom:
integration_platforms:
- native_posix
# extra_args: EXTRA_CFLAGS=-Werror

0 comments on commit f997dc1

Please sign in to comment.