Skip to content

Commit 35f6a5c

Browse files
committed
Extend channel sounding tests
1 parent 6455b2d commit 35f6a5c

File tree

5 files changed

+642
-115
lines changed

5 files changed

+642
-115
lines changed

ProjectAnalysisReport.md

+132-6
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,140 @@ Dakle, ima smisla udubiti se u kod i razmisljati na drugi nacin, odnosno ne samo
191191

192192
Kao sto smo vec spomenuli, mozemo se fokusirati na nekoliko funkcija za koje smo vec napisali testove. Za ovo cemo napraviti novi folder channel_sounding_behavior u koji cemo smestiti spomenuta prosirenja. Pogledajmo prvo `bt_le_cs_security_enable` funkciju i njeno ocekivano ponasanje. Funkcija pravi bafer HCI komande, popunjava ga sa pokazivacem na konekciju i salje komandu sinhrono. Vec smo pokrili tzv. happy path, odnosno slucaj u kome je sve kao sto ocekujemo. Uz to, testirali smo i slucaj u kome `bt_hci_cmd_create` funkcija vrati nepravilan bafer (NULL). Slucajevi koje bismo jos mogli pokriti jesu kada se kao pokazivac na konekciju prosledi NULL vrednost kao i slucaj kada `bt_hci_cmd_send_sync` funkcija pukne. Ova dva slucaja su pokrivena testovima `test_sec_enable_hci_cmd_fail_null_conn` i `test_sec_enable_cmd_send_fail`. Na slican nacun su dodati i sledeci testovi:
193193

194-
TODO(avra): pobrojati testove i dodati kratak opis
195-
*
196-
*
197-
*
194+
TODO(avra): pobrojati testove i dodati kratak opis (mozda tabela)
195+
* `test_read_remote_supported_capabilities_complete_null_buf` - Provera ponasanja funkcije sa prosledjenim nevalidnim baferom (Ocekivano ponasanje - vraca gresku)
196+
* `test_read_remote_supported_capabilities_complete_invalid_buf_len` - Provera ponasanja funkcije sa pogresnom velicinom ulaznog bafera (Ocekivano ponasanje - funkcija se zavrsava ranim izlaskom)
197+
* `test_read_remote_supported_capabilities_complete_evt_status_fail` - Provera ponasanja funkcije kada `bt_conn_lookup_handle` vrati dogadjaj sa statusom greske (Ocekivano ponasanje - funkcija se zavrsava ranim izlaskom)
198+
* `test_read_remote_supported_capabilities_complete_conn_lookup_handle_fail` - Provera ponasanja funkcije kada `bt_conn_lookup_handle` vrati NULL pokazivac (Ocekivano ponasanje - funkcija se zavrsava ranim izlaskom)
199+
* `test_read_remote_fae_table_hci_cmd_fail` - Provera ponasanja funkcije kada
200+
* `test_read_remote_fae_table_send_sync_failed` -
198201

199-
Pokrenimo najpre skriptu sa opcijom no-coverage posto ocekujemo da ovog puta nece svi testovi proci.
200202

201-
Kao sto je i bilo ocekivano vidimo da je dosta testova palo (izvestaj)
203+
_Napomena_: kod funkcija koje se zavrsavaju ranije ocekujemo da neke podfunkcije nikada nece biti pozvane. Ovaj uslov eksplicitno ukljucujemo u ocekivanja testa pomocu `zasser_` funkcija.
204+
205+
Navedeni testovi su implementirani u novom izvornom fajlu `error_handling.c`.
206+
207+
Pokrenimo najpre skriptu sa opcijom no-coverage posto ocekujemo da ovog puta nece svi testovi proci:
208+
209+
```bash
210+
./run_tests.sh channel_sounding_behavior --no-coverage
211+
```
212+
213+
Vec pri pokretanju skripte, vidimo da se javlja segmentation fault:
214+
215+
```bash
216+
...
217+
INFO - 1/1 unit_testing/unit_testing tests/bluetooth/host/cs/channel_sounding_behavior/bluetooth.host.cs.channel_sounding_behavior FAILED Failed (rc=-11) (unit 0.334s)
218+
ERROR - see: path_to_test_results/build.log
219+
...
220+
INFO - The following issues were found (showing the top 10 items):
221+
INFO - 1) tests/bluetooth/host/cs/channel_sounding_behavior/bluetooth.host.cs.channel_sounding_behavior on unit_testing/unit_testing failed (Failed (rc=-11))
222+
...
223+
```
224+
225+
Mozemo pokrenuti `gdb` debager sa putanjom `path_to_test_results` koju dobijemo pokretanjem skripte i potraziti razlog za ovo ponasanje:
226+
227+
```bash
228+
gdb path_to_test_results/testbinary
229+
...
230+
(gdb) run
231+
Starting program: path_to_test_results/testbinary
232+
[Thread debugging using libthread_db enabled]
233+
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
234+
Running TESTSUITE channel_sounding_tests
235+
===================================================================
236+
START - test_bt_le_cs_read_remote_supported_capabilities
237+
Mock net_buf_simple_add called! len=2
238+
PASS - test_bt_le_cs_read_remote_supported_capabilities in 0.000 seconds
239+
===================================================================
240+
START - test_read_remote_fae_table
241+
Mock net_buf_simple_add called! len=2
242+
PASS - test_read_remote_fae_table in 0.000 seconds
243+
===================================================================
244+
START - test_read_remote_supported_capabilities_complete
245+
PASS - test_read_remote_supported_capabilities_complete in 0.000 seconds
246+
===================================================================
247+
START - test_read_remote_supported_capabilities_complete_null_buf
248+
249+
Program received signal SIGSEGV, Segmentation fault.
250+
0x56559e2e in bt_hci_le_cs_read_remote_supported_capabilities_complete (buf=0x0) at /home/aleksandar/2023_Analysis_zephyr/zephyr/subsys/bluetooth/host/cs.c:300
251+
300 if (buf->len < sizeof(*evt)) {
252+
```
253+
254+
Jasno je da se segmentation fault javlja zbog pristupa `NULL` memoriji u navedenom mestu u source kodu. Pre nego sto pristupimo popravci ovog propusta, napisacemo druge testove koji testiraju ponasanje funkcija u radu sa greskama, odnosno test `test_read_remote_supported_capabilities_complete_null_buf` cemo zakomentarisati i ponovo pokrenuti skriptu. Isto cemo uraditi i za test `test_read_remote_fae_table_null_conn`. Rezultat pokretanja dat je ispod:
255+
256+
```bash
257+
Running TESTSUITE channel_sounding_tests
258+
===================================================================
259+
START - test_bt_le_cs_read_remote_supported_capabilities
260+
Mock net_buf_simple_add called! len=2
261+
PASS - test_bt_le_cs_read_remote_supported_capabilities in 0.000 seconds
262+
===================================================================
263+
START - test_read_remote_fae_table
264+
Mock net_buf_simple_add called! len=2
265+
PASS - test_read_remote_fae_table in 0.000 seconds
266+
===================================================================
267+
START - test_read_remote_supported_capabilities_complete
268+
PASS - test_read_remote_supported_capabilities_complete in 0.000 seconds
269+
===================================================================
270+
START - test_sec_enable_cmd_send_fail
271+
Mock net_buf_simple_add called! len=2
272+
PASS - test_sec_enable_cmd_send_fail in 0.000 seconds
273+
===================================================================
274+
START - test_sec_enable_success
275+
Mock net_buf_simple_add called! len=2
276+
PASS - test_sec_enable_success in 0.000 seconds
277+
===================================================================
278+
TESTSUITE channel_sounding_tests succeeded
279+
Running TESTSUITE channel_sounding_tests_error_handling
280+
===================================================================
281+
START - test_read_remote_supported_capabilities_complete_conn_lookup_handle_fail
282+
E: Could not lookup connection handle when reading remote CS capabilities
283+
PASS - test_read_remote_supported_capabilities_complete_conn_lookup_handle_fail in 0.000 seconds
284+
===================================================================
285+
START - test_read_remote_supported_capabilities_complete_evt_status_fail
286+
W: Read Remote Supported Capabilities failed (status 0x01)
287+
PASS - test_read_remote_supported_capabilities_complete_evt_status_fail in 0.000 seconds
288+
===================================================================
289+
START - test_read_remote_supported_capabilities_complete_invalid_buf_len
290+
E: Unexpected end of buffer
291+
PASS - test_read_remote_supported_capabilities_complete_invalid_buf_len in 0.000 seconds
292+
===================================================================
293+
START - test_sec_enable_hci_cmd_fail
294+
PASS - test_sec_enable_hci_cmd_fail in 0.000 seconds
295+
===================================================================
296+
START - test_sec_enable_hci_cmd_fail_null_conn
297+
298+
Assertion failed at /home/aleksandar/2023_Analysis_zephyr/zephyr/tests/bluetooth/host/cs/channel_sounding_behavior/src/error_handling.c:60: channel_sounding_tests_error_handling_test_sec_enable_hci_cmd_fail_null_conn: bt_hci_cmd_create_fake.call_count not equal to 0
299+
300+
at test function
301+
FAIL - test_sec_enable_hci_cmd_fail_null_conn in 0.000 seconds
302+
===================================================================
303+
TESTSUITE channel_sounding_tests_error_handling failed.
304+
305+
------ TESTSUITE SUMMARY START ------
306+
307+
SUITE PASS - 100.00% [channel_sounding_tests]: pass = 5, fail = 0, skip = 0, total = 5 duration = 0.000 seconds
308+
- PASS - [channel_sounding_tests.test_bt_le_cs_read_remote_supported_capabilities] duration = 0.000 seconds
309+
- PASS - [channel_sounding_tests.test_read_remote_fae_table] duration = 0.000 seconds
310+
- PASS - [channel_sounding_tests.test_read_remote_supported_capabilities_complete] duration = 0.000 seconds
311+
- PASS - [channel_sounding_tests.test_sec_enable_cmd_send_fail] duration = 0.000 seconds
312+
- PASS - [channel_sounding_tests.test_sec_enable_success] duration = 0.000 seconds
313+
314+
SUITE FAIL - 80.00% [channel_sounding_tests_error_handling]: pass = 4, fail = 1, skip = 0, total = 5 duration = 0.000 seconds
315+
- PASS - [channel_sounding_tests_error_handling.test_read_remote_supported_capabilities_complete_conn_lookup_handle_fail] duration = 0.000 seconds
316+
- PASS - [channel_sounding_tests_error_handling.test_read_remote_supported_capabilities_complete_evt_status_fail] duration = 0.000 seconds
317+
- PASS - [channel_sounding_tests_error_handling.test_read_remote_supported_capabilities_complete_invalid_buf_len] duration = 0.000 seconds
318+
- PASS - [channel_sounding_tests_error_handling.test_sec_enable_hci_cmd_fail] duration = 0.000 seconds
319+
- FAIL - [channel_sounding_tests_error_handling.test_sec_enable_hci_cmd_fail_null_conn] duration = 0.000 seconds
320+
321+
------ TESTSUITE SUMMARY END ------
322+
323+
===================================================================
324+
PROJECT EXECUTION FAILED
325+
```
326+
327+
Ovog puta nismo dobili veliki broj palih testova, ali dobijamo indikaciju da mozda treba obratiti paznju na baratanje neispravnim ulaznim vrednostima u funkcije.
202328
203329
Vidimo da nije svuda rigorozno proveravano da li se prosledjuju ispravne vrednosti, tako da cemo tu proveru dodati u izvorni kod i ponovo pokrenuti testove. Izmene koje su dodate ticu se uglavnom provere ulaznih argumenata funkcija (TODO dodati ako je jos nesto nadjeno) i mogu se pogledati u <patch_name.patch>. Nakon primene izmena, ponovo je pokrenuta skripta i vidimo da sada svi testovi prolaze. Mozemo nastaviti sa generisanjem izvestaja pokrivenosti za ispravljene testove. Krajnji rezultati su prikazani na slici ispod:
204330

testing/unit/channel_sounding_behavior/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ target_link_libraries(testbinary PRIVATE mocks host_mocks)
1818
target_sources(testbinary
1919
PRIVATE
2020
src/main.c
21+
src/error_handling.c
2122

2223
${ZEPHYR_BASE}/subsys/bluetooth/host/cs.c
2324
${ZEPHYR_BASE}/subsys/logging/log_minimal.c

0 commit comments

Comments
 (0)