Skip to content

Commit 187204a

Browse files
nordic-krchkartben
authored andcommitted
tests: unit: util: Add test for bitmask_find_gap
Add test for new util function. Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 53c2d58 commit 187204a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

tests/unit/util/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ target_sources(testbinary
1111
main.c
1212
${ZEPHYR_BASE}/lib/utils/dec.c
1313
${ZEPHYR_BASE}/lib/utils/utf8.c
14+
${ZEPHYR_BASE}/lib/utils/bitmask.c
1415
)
1516

1617
if(CONFIG_CPP)

tests/unit/util/main.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,4 +1081,27 @@ ZTEST(util, test_util_memeq)
10811081
zassert_false(mem_area_matching_2);
10821082
}
10831083

1084+
static void test_single_bitmask_find_gap(uint32_t mask, size_t num_bits, size_t total_bits,
1085+
bool first_match, int exp_rv, int line)
1086+
{
1087+
int rv;
1088+
1089+
rv = bitmask_find_gap(mask, num_bits, total_bits, first_match);
1090+
zassert_equal(rv, exp_rv, "%d Unexpected rv:%d (exp:%d)", line, rv, exp_rv);
1091+
}
1092+
1093+
ZTEST(util, test_bitmask_find_gap)
1094+
{
1095+
test_single_bitmask_find_gap(0x0F0F070F, 6, 32, true, -1, __LINE__);
1096+
test_single_bitmask_find_gap(0x0F0F070F, 5, 32, true, 11, __LINE__);
1097+
test_single_bitmask_find_gap(0x030F070F, 5, 32, true, 26, __LINE__);
1098+
test_single_bitmask_find_gap(0x030F070F, 5, 32, false, 11, __LINE__);
1099+
test_single_bitmask_find_gap(0x0F0F070F, 5, 32, true, 11, __LINE__);
1100+
test_single_bitmask_find_gap(0x030F070F, 5, 32, true, 26, __LINE__);
1101+
test_single_bitmask_find_gap(0x030F070F, 5, 32, false, 11, __LINE__);
1102+
test_single_bitmask_find_gap(0x0, 1, 32, true, 0, __LINE__);
1103+
test_single_bitmask_find_gap(0x1F1F071F, 4, 32, true, 11, __LINE__);
1104+
test_single_bitmask_find_gap(0x0000000F, 2, 6, false, 4, __LINE__);
1105+
}
1106+
10841107
ZTEST_SUITE(util, NULL, NULL, NULL, NULL, NULL);

0 commit comments

Comments
 (0)