|
18 | 18 | #include <cmocka.h>
|
19 | 19 |
|
20 | 20 | #include <memory/memory.h>
|
| 21 | +#include <memory/memory_shared.h> |
21 | 22 |
|
22 | 23 | #include <stdint.h>
|
23 | 24 | #include <stdio.h>
|
24 | 25 | #include <string.h>
|
25 | 26 |
|
26 |
| -#define CHUNK_SIZE (16 * 512) // 8kB. |
27 |
| - |
28 | 27 | #define FLASH_APP_DATA_LEN (0x000010000)
|
29 |
| -#define FLASH_SHARED_DATA_START (0xe000) |
30 | 28 |
|
31 | 29 | // chunk 0
|
32 | 30 | static const int _addr_factory_setup_done = 0;
|
@@ -386,10 +384,45 @@ static void _test_memory_get_device_name_default(void** state)
|
386 | 384 | EMPTYCHUNK(empty_chunk);
|
387 | 385 | expect_value(__wrap_memory_read_chunk_mock, chunk_num, 1);
|
388 | 386 | will_return(__wrap_memory_read_chunk_mock, empty_chunk);
|
| 387 | + |
| 388 | + EMPTYCHUNK(empty_shared_chunk); |
| 389 | + will_return(__wrap_memory_read_shared_bootdata_mock, empty_shared_chunk); |
| 390 | + |
389 | 391 | memory_get_device_name(name_out);
|
390 | 392 | assert_string_equal(MEMORY_DEFAULT_DEVICE_NAME, name_out);
|
391 | 393 | }
|
392 | 394 |
|
| 395 | +// For Bluetooth devices (BitBox02+), the default name is "BitBox ABCD" where ABCD are four random |
| 396 | +// uppercase letters. |
| 397 | +static void _test_memory_get_device_name_default_bluetooth(void** state) |
| 398 | +{ |
| 399 | + uint8_t entropy[32] = {0}; |
| 400 | + memcpy(entropy, "\x00\x19\xFE\xFF", 4); |
| 401 | + |
| 402 | + char name_out[MEMORY_DEVICE_NAME_MAX_LEN] = {0}; |
| 403 | + EMPTYCHUNK(empty_chunk); |
| 404 | + expect_value(__wrap_memory_read_chunk_mock, chunk_num, 1); |
| 405 | + will_return(__wrap_memory_read_chunk_mock, empty_chunk); |
| 406 | + |
| 407 | + EMPTYCHUNK(empty_shared_chunk); |
| 408 | + chunk_shared_t shared_chunk = {0}; |
| 409 | + memcpy(shared_chunk.bytes, empty_shared_chunk, CHUNK_SIZE); |
| 410 | + shared_chunk.fields.platform = MEMORY_PLATFORM_BITBOX02_PLUS; |
| 411 | + will_return(__wrap_memory_read_shared_bootdata_mock, shared_chunk.bytes); |
| 412 | + |
| 413 | + will_return(_mock_random_32_bytes, entropy); |
| 414 | + |
| 415 | + memory_get_device_name(name_out); |
| 416 | + assert_string_equal("BitBox AZUV", name_out); |
| 417 | + |
| 418 | + // Calling it again does not re-generate a new random name but reuses the already generated one. |
| 419 | + expect_value(__wrap_memory_read_chunk_mock, chunk_num, 1); |
| 420 | + will_return(__wrap_memory_read_chunk_mock, empty_chunk); |
| 421 | + will_return(__wrap_memory_read_shared_bootdata_mock, shared_chunk.bytes); |
| 422 | + memory_get_device_name(name_out); |
| 423 | + assert_string_equal("BitBox AZUV", name_out); |
| 424 | +} |
| 425 | + |
393 | 426 | static void _test_memory_get_device_name(void** state)
|
394 | 427 | {
|
395 | 428 | char name_out[MEMORY_DEVICE_NAME_MAX_LEN] = {0};
|
@@ -527,6 +560,7 @@ int main(void)
|
527 | 560 | cmocka_unit_test(_test_memory_set_mnemonic_passphrase_enabled),
|
528 | 561 | cmocka_unit_test(_test_memory_reset_hww),
|
529 | 562 | cmocka_unit_test(_test_memory_get_device_name_default),
|
| 563 | + cmocka_unit_test(_test_memory_get_device_name_default_bluetooth), |
530 | 564 | cmocka_unit_test(_test_memory_get_device_name),
|
531 | 565 | cmocka_unit_test(_test_memory_device_name),
|
532 | 566 | cmocka_unit_test(_test_memory_set_seed_birthdate),
|
|
0 commit comments