Skip to content

Commit acfa2e8

Browse files
committed
Add unit test
1 parent 83eb596 commit acfa2e8

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
set(BOARD native_posix_64)
3+
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(bt_crypto_tests)
6+
7+
target_sources(app PRIVATE src/test_crypto.c)
8+
9+
target_link_libraries(app PRIVATE zephyr)
10+
11+
# Ensure the Zephyr include directory is included
12+
include_directories($ENV{ZEPHYR_BASE}/include)
13+
14+
# include_directories($ENV{ZEPHYR_BASE}/tests/bluetooth/host/crypto)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CONFIG_TEST=y
2+
CONFIG_ZTEST=y
3+
CONFIG_ZTEST_NEW_API=y
4+
5+
CONFIG_BT=y
6+
CONFIG_BT_CTLR=n
7+
CONFIG_BT_NO_DRIVER=y
8+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// test_crypto.c
2+
#include <zephyr/bluetooth/crypto.h>
3+
#include <zephyr/ztest.h>
4+
// #include "mocks/aes.h"
5+
6+
ZTEST_SUITE(bt_host_crypto_test, NULL, NULL, NULL, NULL, NULL);
7+
8+
ZTEST(bt_host_crypto_test, test_null_ct) {
9+
const uint8_t key[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
10+
0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF};
11+
12+
const uint8_t pt[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
13+
0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF};
14+
15+
zassert_equal(-EINVAL, bt_encrypt_le(key, pt, NULL));
16+
}
17+
18+
ZTEST(bt_host_crypto_test, test_null_pt) {
19+
const uint8_t key[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
20+
0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF};
21+
22+
uint8_t ct[16];
23+
24+
zassert_equal(-EINVAL, bt_encrypt_le(key, NULL, ct));
25+
}
26+
27+
ZTEST(bt_host_crypto_test, test_null_key) {
28+
const uint8_t pt[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
29+
0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF};
30+
31+
uint8_t ct[16];
32+
33+
zassert_equal(-EINVAL, bt_encrypt_le(NULL, pt, ct));
34+
}
35+
36+
ZTEST(bt_host_crypto_test, test_test_ok) {
37+
const uint8_t key[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
38+
0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF};
39+
40+
const uint8_t pt[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
41+
0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF};
42+
43+
uint8_t ct[16];
44+
45+
// const uint8_t expected_ct[] = {0xd7, 0xe5, 0xe0, 0x8c, 0x58, 0x8e,
46+
// 0xe9, 0x67, 0xdf, 0x9c, 0x32, 0x6e,
47+
// 0xce, 0xc3, 0xee, 0x7e};
48+
49+
// zassert_mem_equal(ct, expected_ct, sizeof(ct),
50+
// "Expected and actual CTs don't match!");
51+
zassert_equal(0, bt_encrypt_le(key, pt, ct));
52+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
tests:
2+
integration.bt_crypto:
3+
platform_allow: native_posix_64 native_posix
4+
tags: bluetooth crypto
5+
integration_platforms:
6+
- native_posix_64
7+
- native_posix

0 commit comments

Comments
 (0)