Skip to content

Commit 80b014a

Browse files
committed
tests: subsys: fs: add bm_zms_unity tests
Adds `bm_zms` Unity unit tests. Signed-off-by: Mirko Covizzi <[email protected]>
1 parent 1c9e2db commit 80b014a

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

subsys/fs/bm_zms/bm_zms.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#define NRFX_CRITICAL_SECTION_EXIT(...)
2828
#endif
2929

30+
#if CONFIG_UNITY
31+
#define __ALIGN(x) __aligned(x)
32+
#endif
33+
3034
LOG_MODULE_REGISTER(bm_zms, CONFIG_BM_ZMS_LOG_LEVEL);
3135

3236
static zms_op_t cur_op; /* Current bm_zms operation. */
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
11+
project(bm_zms_unity)
12+
13+
target_include_directories(app PRIVATE ${ZEPHYR_NRF_BM_MODULE_DIR}/include)
14+
15+
target_compile_definitions(app PRIVATE
16+
CONFIG_BM_ZMS_MAX_USERS=8
17+
CONFIG_BM_ZMS_OP_QUEUE_SIZE=16
18+
)
19+
20+
# Generate and add test file
21+
test_runner_generate(src/unity_test.c)
22+
target_sources(app PRIVATE src/unity_test.c)
23+
24+
# Unit under test
25+
target_sources(app PRIVATE ${ZEPHYR_NRF_BM_MODULE_DIR}/subsys/fs/bm_zms/bm_zms.c)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
CONFIG_UNITY=y
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
#include <unity.h>
7+
#include <errno.h>
8+
9+
#include <bm/fs/bm_zms.h>
10+
11+
void bm_zms_callback(bm_zms_evt_t const *p_evt)
12+
{
13+
}
14+
15+
void test_bm_zms_register_einval(void)
16+
{
17+
int err;
18+
19+
struct bm_zms_fs fs = { 0 };
20+
21+
err = bm_zms_register(NULL, NULL);
22+
TEST_ASSERT_EQUAL(-EINVAL, err);
23+
24+
err = bm_zms_register(&fs, NULL);
25+
TEST_ASSERT_EQUAL(-EINVAL, err);
26+
27+
err = bm_zms_register(NULL, bm_zms_callback);
28+
TEST_ASSERT_EQUAL(-EINVAL, err);
29+
}
30+
31+
void test_bm_zms_register(void)
32+
{
33+
int err;
34+
35+
struct bm_zms_fs fs = { 0 };
36+
37+
err = bm_zms_register(&fs, bm_zms_callback);
38+
TEST_ASSERT_EQUAL(0, err);
39+
}
40+
41+
void setUp(void)
42+
{
43+
}
44+
45+
void tearDown(void)
46+
{
47+
}
48+
49+
extern int unity_main(void);
50+
51+
int main(void)
52+
{
53+
return unity_main();
54+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
tests:
2+
lib.bm_zms_unity:
3+
platform_allow: native_sim
4+
tags: unittest

0 commit comments

Comments
 (0)