-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
settings: add test for commit priority
Add a test to validate commit priorities Signed-off-by: Laczen JMS <[email protected]>
- Loading branch information
Showing
5 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(test_settings_commit_prio) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.. _settings_commit_prio_test: | ||
|
||
Settings Subsystem commit priority Test Sample | ||
############################################## | ||
|
||
Overview | ||
******** | ||
|
||
This test sample is used to test the Settings Subsystem commit priority. | ||
|
||
Building and Testing | ||
******************** | ||
|
||
This application can be built and executed on native_sim as follows: | ||
|
||
.. code-block:: console | ||
$ ./scripts/twister -p native_sim -T tests/subsys/settings_commit_prio | ||
To build for another board, change "native_sim" above to that board's name. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CONFIG_TEST=y | ||
CONFIG_ZTEST=y | ||
CONFIG_LOG=y | ||
CONFIG_SETTINGS=y | ||
CONFIG_SETTINGS_DYNAMIC_HANDLERS=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (c) 2024 Laczen | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <zephyr/settings/settings.h> | ||
#include <zephyr/ztest.h> | ||
#include <zephyr/logging/log.h> | ||
|
||
LOG_MODULE_REGISTER(test); | ||
|
||
static int prio; | ||
|
||
int commit0(void) | ||
{ | ||
LOG_INF("%s Called", __func__); | ||
if (prio != 0) { | ||
return -EINVAL; | ||
} | ||
|
||
prio++; | ||
return 0; | ||
} | ||
|
||
int commit1(void) | ||
{ | ||
LOG_INF("%s Called", __func__); | ||
if (prio != 1) { | ||
return -EINVAL; | ||
} | ||
|
||
prio++; | ||
return 0; | ||
} | ||
|
||
int commit2(void) | ||
{ | ||
LOG_INF("%s Called", __func__); | ||
if (prio != 2) { | ||
return -EINVAL; | ||
} | ||
|
||
prio++; | ||
return 0; | ||
} | ||
|
||
int commit3(void) | ||
{ | ||
LOG_INF("%s Called", __func__); | ||
if (prio != 3) { | ||
return -EINVAL; | ||
} | ||
|
||
prio++; | ||
return 0; | ||
} | ||
|
||
int commit5(void) | ||
{ | ||
LOG_INF("%s Called", __func__); | ||
if (prio > 1) { | ||
return -EINVAL; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
SETTINGS_STATIC_HANDLER_DEFINE_WITH_CPRIO(h0, "h0", NULL, NULL, commit0, NULL, 0); | ||
SETTINGS_STATIC_HANDLER_DEFINE_WITH_CPRIO(h2, "h2", NULL, NULL, commit2, NULL, 2); | ||
|
||
static struct settings_handler h1 = { | ||
.name = "h1", | ||
.h_commit = commit1, | ||
}; | ||
|
||
static struct settings_handler h3 = { | ||
.name = "h3", | ||
.h_commit = commit3, | ||
}; | ||
|
||
SETTINGS_STATIC_HANDLER_DEFINE_WITH_CPRIO(h5, "h5", NULL, NULL, commit5, NULL, -1); | ||
|
||
/** | ||
* @brief Test Settings commit order | ||
* | ||
* This test verifies the settings commit order. | ||
*/ | ||
ZTEST(settings_commit_prio, test_commit_order) | ||
{ | ||
int rc; | ||
|
||
prio = 0; | ||
rc = settings_register_with_cprio(&h1, 1); | ||
zassert_equal(rc, 0, "Failed to register handler"); | ||
rc = settings_register_with_cprio(&h3, 3); | ||
zassert_equal(rc, 0, "Failed to register handler"); | ||
|
||
rc = settings_commit(); | ||
zassert_equal(rc, 0, "Commit failed with code [%d]", rc); | ||
zassert_equal(prio, 4, "Incorrect prio level reached [%d]", prio); | ||
} | ||
|
||
ZTEST_SUITE(settings_commit_prio, NULL, NULL, NULL, NULL, NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
tests: | ||
settings.settings_commit_prio: | ||
platform_allow: native_sim | ||
tags: settings |