Skip to content

Commit a774314

Browse files
ahmedmoheb-nordiccarlescufi
authored andcommitted
tests: bluetooth: host: Add UT for bt_pub_key_is_debug()
Unit test project for bt_pub_key_is_debug(). This is part of subsys/bluetooth/host/ecc.c unit testing. Signed-off-by: Ahmed Moheb <[email protected]>
1 parent 3c76bd0 commit a774314

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
set(SOURCES
6+
src/main.c
7+
)
8+
9+
project(bt_pub_key_is_debug)
10+
11+
find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE})
12+
13+
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks)
14+
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/ecc mocks)
15+
16+
target_link_libraries(testbinary PRIVATE mocks host_mocks)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_ZTEST_NEW_API=y
3+
CONFIG_BT=y
4+
CONFIG_BT_CENTRAL=y
5+
CONFIG_BT_MAX_PAIRED=7
6+
CONFIG_ASSERT=y
7+
CONFIG_ASSERT_LEVEL=2
8+
CONFIG_ASSERT_VERBOSE=y
9+
CONFIG_ASSERT_ON_ERRORS=y
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2022 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "mocks/ecc_help_utils.h"
8+
9+
#include <zephyr/fff.h>
10+
#include <zephyr/kernel.h>
11+
12+
#include <host/ecc.h>
13+
14+
DEFINE_FFF_GLOBALS;
15+
16+
ZTEST_SUITE(bt_pub_key_is_debug, NULL, NULL, NULL, NULL, NULL);
17+
18+
/*
19+
* Test bt_pub_key_is_debug() returns 'true' if key passed matches the internal debug key
20+
*
21+
* Constraints:
22+
* - The key passed matches the internal debug key
23+
*
24+
* Expected behaviour:
25+
* - bt_pub_key_is_debug() returns 'true'
26+
*/
27+
ZTEST(bt_pub_key_is_debug, test_key_matches_internal_key)
28+
{
29+
bool result;
30+
uint8_t const *internal_dbg_public_key = bt_ecc_get_internal_debug_public_key();
31+
uint8_t testing_public_key[BT_PUB_KEY_LEN] = {0};
32+
33+
memcpy(testing_public_key, internal_dbg_public_key, BT_PUB_KEY_LEN);
34+
35+
result = bt_pub_key_is_debug(testing_public_key);
36+
37+
zassert_true(result, "Unexpected error code '%d' was returned", result);
38+
}
39+
40+
/*
41+
* Test bt_pub_key_is_debug() returns 'false' if key passed doesn't match the internal debug key
42+
*
43+
* Constraints:
44+
* - The key passed doesn't match the internal debug key
45+
*
46+
* Expected behaviour:
47+
* - bt_pub_key_is_debug() returns 'false'
48+
*/
49+
ZTEST(bt_pub_key_is_debug, test_key_mismatches_internal_key)
50+
{
51+
bool result;
52+
uint8_t testing_public_key[BT_PUB_KEY_LEN] = {0};
53+
54+
result = bt_pub_key_is_debug(testing_public_key);
55+
56+
zassert_false(result, "Unexpected error code '%d' was returned", result);
57+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
common:
2+
tags: test_framework bluetooth host
3+
tests:
4+
bluetooth.host.bt_pub_key_is_debug.default:
5+
type: unit

0 commit comments

Comments
 (0)