Skip to content

Commit af61634

Browse files
committed
Add integration test app skeleton
1 parent aefae80 commit af61634

File tree

5 files changed

+146
-2
lines changed

5 files changed

+146
-2
lines changed

ProjectAnalysisReport.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -408,15 +408,33 @@ Navedeni testovi su implementirani u novom izvornom fajlu `error_handling.c`.
408408
#### Integration tests
409409
410410
Limitations
411+
Za razliku od testova jedinica koda, integracioni testovi testiraju ponasanje vise komponenti odjednom (ne nuzno jedinica koda). Dakle, za integraciono testiranje oslanjamo se na citave komponente (koje mogu biti unit testirane) i koriscenje mock i stub implementacija je manje, odnosno koriste se prave implementacije.
412+
413+
Primer implementiranog jednostavnog integracionog testa dat je u `samples/subsys/testsuite/integration` folderu (pogledati [Zephyr dokumentaciju](psa_set_key_usage_flags) za vise detalja). U implementaciji samog testa (u `main.c`) ne vidimo nista drasticno drugacije u odnosu na unit testove, tj. koriste se slicne funkcije za pretpostavke `zasser_`. Vecu razliku mozemo primetiti u okviru `testcase.yaml` fajla, gde se eksplicitno navode platforme za koje je dozvoljeno izvrsavanje testa:
414+
415+
```bash
416+
platform_allow:
417+
- native_posix
418+
- native_sim
419+
```
420+
421+
Ovo sledi iz cinjenice da koristimo prave implementacije modula, i da, ukoliko oni zavise od nekih hardverskih komponenti, moramo uzeti to u obzir i ograniciti izvrsavanje samo na one platforme koje hardverski podrzavaju module koje testiramo. Jos jedna napomena je da vidimo `build_only: true` direktivu. Ovo znaci da primer testa nije podoban za ispitivanje funkcionalnosti koda, vec da jedino proverava da li se kod prevodi. Jasno je da cemo ovu liniju izbaciti iz nase implementacije. Takodje nam je zanimljiva i sledeca konfiguracija:
422+
423+
```bash
424+
integration_platforms:
425+
- native_sim
426+
```
427+
428+
koja u ovom slucaju znaci da se, prilikom pokretanja `twister` alata sa opcijom `--integration`, testovi izvrsavaju samo na `native_sim` platformi. Naravno, moguce je dodati listu platformi na kojima ce se testovi izvrsavati.
429+
430+
411431
412432
#### Valgrind
413433
414434
Valgrind description.
415435
416436
Limitations in context of ZephyrOS and running natively on POSIX platform.
417437
418-
Valgrind setup and dir structure
419-
420438
U ovom projektu bice korisceni sledeci valgrind alati:
421439
422440
* `memcheck`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(integration)
6+
7+
# include_directories(BEFORE
8+
# ${ZEPHYR_BASE}/tests/bluetooth/host/cs/channel_sounding/mocks_unit_tests
9+
# )
10+
11+
FILE(GLOB app_sources src/*.c)
12+
target_sources(app PRIVATE ${app_sources})
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
CONFIG_ZTEST=y
2+
3+
# Mbed TLS
4+
CONFIG_MBEDTLS=y
5+
CONFIG_MBEDTLS_BUILTIN=y
6+
CONFIG_MBEDTLS_ENABLE_HEAP=y
7+
CONFIG_MBEDTLS_HEAP_SIZE=32768
8+
# CONFIG_MBEDTLS_USER_CONFIG_ENABLE=y
9+
# CONFIG_MBEDTLS_USER_CONFIG_FILE="config_mbedtls.h"
10+
11+
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
12+
CONFIG_PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY=y
13+
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT=y
14+
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT=y
15+
CONFIG_PSA_WANT_ECC_SECP_R1_256=y
16+
CONFIG_PSA_WANT_ALG_ECDSA=y
17+
CONFIG_PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY=y
18+
CONFIG_MBEDTLS_ENTROPY_C=y
19+
CONFIG_MBEDTLS_ECP_C=y
20+
CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED=y
21+
CONFIG_MBEDTLS_ECDSA_C=y
22+
CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_ENABLED=y
23+
CONFIG_MBEDTLS_PK_WRITE_C=y
24+
25+
# Debugging
26+
CONFIG_PSA_CRYPTO_LOG_LEVEL_DBG=y
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 2016 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/ztest.h>
8+
9+
#include <psa/crypto.h>
10+
11+
12+
ZTEST_SUITE(framework_tests, NULL, NULL, NULL, NULL, NULL);
13+
14+
/**
15+
* @brief Test Asserts
16+
*
17+
* This test verifies various assert macros provided by ztest.
18+
*
19+
*/
20+
ZTEST(framework_tests, test_assert)
21+
{
22+
23+
psa_status_t init_val = psa_crypto_init();
24+
zassert_equal(init_val, PSA_SUCCESS);
25+
zassert_true(1, "1 was false");
26+
zassert_false(0, "0 was true");
27+
zassert_is_null(NULL, "NULL was not NULL");
28+
zassert_not_null("foo", "\"foo\" was NULL");
29+
zassert_equal(1, 1, "1 was not equal to 1");
30+
zassert_equal_ptr(NULL, NULL, "NULL was not equal to NULL");
31+
}
32+
33+
#define SAMPLE_KEY_ID PSA_KEY_ID_USER_MIN
34+
#define SAMPLE_KEY_TYPE PSA_KEY_TYPE_AES
35+
#define SAMPLE_ALG PSA_ALG_CTR
36+
#define SAMPLE_KEY_BITS 256
37+
38+
ZTEST(framework_tests, test_psa) {
39+
psa_key_handle_t priv_key;
40+
uint8_t peer_pub_key[64] = { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; // Example peer key
41+
uint8_t shared_secret[32];
42+
size_t olen;
43+
44+
/* Initialize PSA Crypto */
45+
zassert_equal(psa_crypto_init(), PSA_SUCCESS, "PSA init failed");
46+
47+
/* Generate ECC key for Secure Pairing */
48+
psa_key_attributes_t attr = PSA_KEY_ATTRIBUTES_INIT;
49+
psa_set_key_algorithm(&attr, SAMPLE_ALG);//PSA_ALG_ECDH(PSA_ALG_SHA_256));
50+
psa_set_key_type(&attr, PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1));
51+
psa_set_key_bits(&attr, 256);
52+
psa_status_t keygen_status = psa_generate_key(&attr, &priv_key);
53+
zassert_equal(keygen_status, PSA_SUCCESS, "Key gen failed: %d", keygen_status);
54+
55+
/* Simulate SMP key exchange (PSA computes shared secret) */
56+
zassert_equal(
57+
psa_raw_key_agreement(
58+
PSA_ALG_ECDH, priv_key,
59+
peer_pub_key, sizeof(peer_pub_key),
60+
shared_secret, sizeof(shared_secret), &olen
61+
),
62+
PSA_SUCCESS,
63+
"ECDH failed"
64+
);
65+
66+
/* Verify shared secret is non-zero */
67+
bool all_zeros = true;
68+
for (int i = 0; i < olen; i++) {
69+
if (shared_secret[i] != 0) {
70+
all_zeros = false;
71+
break;
72+
}
73+
}
74+
zassert_false(all_zeros, "Shared secret is zero");
75+
76+
/* Cleanup */
77+
psa_destroy_key(priv_key);
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tests:
2+
# section.subsection
3+
sample.testing.ztest:
4+
# build_only: true
5+
platform_allow:
6+
- native_posix
7+
- native_sim
8+
integration_platforms:
9+
- native_sim
10+
tags: test_framework

0 commit comments

Comments
 (0)