Skip to content

Commit

Permalink
tests: fast_pair: crypto: Migrate to new ztest API
Browse files Browse the repository at this point in the history
Change migrates test to new ztest API. The old API is deprecated.

Jira: NCSDK-20431

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
  • Loading branch information
MarekPieta authored and nordicjm committed Jun 30, 2023
1 parent 21b47ec commit 75e6458
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
2 changes: 2 additions & 0 deletions tests/subsys/bluetooth/fast_pair/crypto/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
#

CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_ZTEST_SHUFFLE=y
CONFIG_BT_FAST_PAIR_CRYPTO_OBERON=y
2 changes: 2 additions & 0 deletions tests/subsys/bluetooth/fast_pair/crypto/prj_mbedtls.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
#

CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_ZTEST_SHUFFLE=y
CONFIG_BT_FAST_PAIR_CRYPTO_MBEDTLS=y
CONFIG_MBEDTLS_HEAP_SIZE=16384
2 changes: 2 additions & 0 deletions tests/subsys/bluetooth/fast_pair/crypto/prj_tinycrypt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
#

CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_ZTEST_SHUFFLE=y
CONFIG_BT_FAST_PAIR_CRYPTO_TINYCRYPT=y
32 changes: 9 additions & 23 deletions tests/subsys/bluetooth/fast_pair/crypto/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "fp_crypto.h"
#include "fp_common.h"

static void test_sha256(void)
ZTEST(suite_crypto, test_sha256)
{
static const uint8_t input_data[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};

Expand All @@ -27,7 +27,7 @@ static void test_sha256(void)
"Invalid hashing result.");
}

static void test_hmac_sha256(void)
ZTEST(suite_crypto, test_hmac_sha256)
{
static const uint8_t input_data[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xEE,
0x4A, 0x24, 0x83, 0x73, 0x80, 0x52, 0xE4, 0x4E, 0x9B,
Expand All @@ -53,7 +53,7 @@ static void test_hmac_sha256(void)
"Invalid hashing result.");
}

static void test_aes128_ecb(void)
ZTEST(suite_crypto, test_aes128_ecb)
{
static const uint8_t plaintext[] = {0xF3, 0x0F, 0x4E, 0x78, 0x6C, 0x59, 0xA7, 0xBB, 0xF3,
0x87, 0x3B, 0x5A, 0x49, 0xBA, 0x97, 0xEA};
Expand All @@ -77,7 +77,7 @@ static void test_aes128_ecb(void)
zassert_mem_equal(result_buf, plaintext, sizeof(plaintext), "Invalid decryption result.");
}

static void test_aes128_ctr(void)
ZTEST(suite_crypto, test_aes128_ctr)
{
static const uint8_t plaintext[] = {0x53, 0x6F, 0x6D, 0x65, 0x6F, 0x6E, 0x65, 0x27, 0x73,
0x20, 0x47, 0x6F, 0x6F, 0x67, 0x6C, 0x65, 0x20, 0x48,
Expand Down Expand Up @@ -107,7 +107,7 @@ static void test_aes128_ctr(void)
zassert_mem_equal(result_buf, plaintext, sizeof(plaintext), "Invalid decryption result.");
}

static void test_ecdh(void)
ZTEST(suite_crypto, test_ecdh)
{
static const uint8_t bobs_private_key[] = {0x02, 0xB4, 0x37, 0xB0, 0xED, 0xD6, 0xBB, 0xD4,
0x29, 0x06, 0x4A, 0x4E, 0x52, 0x9F, 0xCB, 0xF1,
Expand Down Expand Up @@ -164,7 +164,7 @@ static void test_ecdh(void)
"Invalid key on Alice's side.");
}

static void test_aes_key_from_ecdh_shared_secret(void)
ZTEST(suite_crypto, test_aes_key_from_ecdh_shared_secret)
{
static const uint8_t ecdh_shared_key[] = {0x9D, 0xAD, 0xE4, 0xF8, 0x6A, 0xC3, 0x48, 0x8B,
0xBA, 0xC2, 0xAC, 0x34, 0xB5, 0xFE, 0x68, 0xA0,
Expand All @@ -182,7 +182,7 @@ static void test_aes_key_from_ecdh_shared_secret(void)
zassert_mem_equal(result_buf, aes_key, sizeof(aes_key), "Invalid resulting key.");
}

static void test_bloom_filter(void)
ZTEST(suite_crypto, test_bloom_filter)
{
static const uint16_t salt = 0xC7C8;

Expand Down Expand Up @@ -253,7 +253,7 @@ static void test_bloom_filter(void)
"Invalid resulting filter.");
}

static void test_additional_data_packet(void)
ZTEST(suite_crypto, test_additional_data_packet)
{
static const uint8_t input_data[] = {0x53, 0x6F, 0x6D, 0x65, 0x6F, 0x6E, 0x65, 0x27, 0x73,
0x20, 0x47, 0x6F, 0x6F, 0x67, 0x6C, 0x65, 0x20, 0x48,
Expand Down Expand Up @@ -303,18 +303,4 @@ static void test_additional_data_packet(void)
0, "Expected error during decoding non-integral packet.");
}

void test_main(void)
{
ztest_test_suite(fast_pair_crypto_tests,
ztest_unit_test(test_sha256),
ztest_unit_test(test_hmac_sha256),
ztest_unit_test(test_aes128_ecb),
ztest_unit_test(test_aes128_ctr),
ztest_unit_test(test_ecdh),
ztest_unit_test(test_aes_key_from_ecdh_shared_secret),
ztest_unit_test(test_bloom_filter),
ztest_unit_test(test_additional_data_packet)
);

ztest_run_test_suite(fast_pair_crypto_tests);
}
ZTEST_SUITE(suite_crypto, NULL, NULL, NULL, NULL, NULL);

0 comments on commit 75e6458

Please sign in to comment.