tests: bluetooth: host: Add UT for prng_init()

Unit test project for prng_init().
This is part of subsys/bluetooth/host/crypto.c unit testing.

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
This commit is contained in:
Ahmed Moheb 2022-12-29 11:08:36 +02:00 committed by Carles Cufí
commit ebf96f4148
4 changed files with 20 additions and 18 deletions

View file

@ -2,10 +2,12 @@
cmake_minimum_required(VERSION 3.20.0)
FILE(GLOB SOURCES src/*.c)
set(SOURCES
src/main.c
src/test_suite_invalid_inputs.c
)
project(prng_init)
add_compile_definitions(test_unit_name="${PROJECT_NAME}")
find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE})

View file

@ -7,7 +7,3 @@ CONFIG_ASSERT=y
CONFIG_ASSERT_LEVEL=2
CONFIG_ASSERT_VERBOSE=y
CONFIG_ASSERT_ON_ERRORS=y
CONFIG_LOG=n
CONFIG_BT_DEBUG_LOG=n
CONFIG_TEST_LOGGING_DEFAULTS=n

View file

@ -4,14 +4,16 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/fff.h>
#include <host/crypto.h>
#include "mocks/crypto_help_utils.h"
#include "mocks/hci_core.h"
#include "mocks/hci_core_expects.h"
#include "mocks/hmac_prng.h"
#include "mocks/hmac_prng_expects.h"
#include "mocks/crypto_help_utils.h"
#include <zephyr/fff.h>
#include <zephyr/kernel.h>
#include <host/crypto.h>
DEFINE_FFF_GLOBALS;
@ -52,5 +54,5 @@ ZTEST(prng_init, test_prng_init_succeeds)
expect_single_call_tc_hmac_prng_init(hmac_prng, 8);
expect_single_call_tc_hmac_prng_reseed(hmac_prng, 32, sizeof(int64_t));
zassert_ok(err, "'%s()' returned unexpected error code %d", test_unit_name, err);
zassert_ok(err, "Unexpected error code '%d' was returned", err);
}

View file

@ -4,14 +4,16 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <host/crypto.h>
#include "host_mocks/assert.h"
#include "mocks/crypto_help_utils.h"
#include "mocks/hci_core.h"
#include "mocks/hci_core_expects.h"
#include "mocks/hmac_prng.h"
#include "mocks/hmac_prng_expects.h"
#include "mocks/crypto_help_utils.h"
#include "host_mocks/assert.h"
#include <zephyr/kernel.h>
#include <host/crypto.h>
ZTEST_SUITE(prng_init_invalid_cases, NULL, NULL, NULL, NULL, NULL);
@ -35,7 +37,7 @@ ZTEST(prng_init_invalid_cases, test_bt_hci_le_rand_fails)
expect_call_count_bt_hci_le_rand(1, expected_args_history);
zassert_true(err < 0, "'%s()' returned unexpected error code %d", test_unit_name, err);
zassert_true(err < 0, "Unexpected error code '%d' was returned", err);
}
/*
@ -62,7 +64,7 @@ ZTEST(prng_init_invalid_cases, test_tc_hmac_prng_init_fails)
expect_call_count_bt_hci_le_rand(1, expected_args_history);
expect_single_call_tc_hmac_prng_init(hmac_prng, 8);
zassert_true(err == -EIO, "'%s()' returned unexpected error code %d", test_unit_name, err);
zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err);
}
/*
@ -92,5 +94,5 @@ ZTEST(prng_init_invalid_cases, test_prng_reseed_fails)
expect_single_call_tc_hmac_prng_init(hmac_prng, 8);
expect_single_call_tc_hmac_prng_reseed(hmac_prng, 32, sizeof(int64_t));
zassert_true(err == -EIO, "'%s()' returned unexpected error code %d", test_unit_name, err);
zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err);
}