Skip to content

Commit c03f256

Browse files
de-nordickartben
authored andcommitted
tests/drivers/flash: Add test case for flash_get_size
Add flash_get_size commit and Kconfig option for test to set the expected size of device. Signed-off-by: Dominik Ermel <[email protected]>
1 parent 852c992 commit c03f256

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

tests/drivers/flash/common/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2024, Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Device/scenario dependent information that is not available in
5+
# other ways.
6+
7+
config TEST_DRIVER_FLASH_SIZE
8+
int "Size of flash device under test"
9+
default -1
10+
help
11+
Expected flash device size the test will validate against. If the flash driver does not
12+
support the get_size() API, leave this set as -1 to skip the test.
13+
14+
source "Kconfig.zephyr"

tests/drivers/flash/common/src/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,19 @@ static bool flash_callback(const struct flash_pages_info *info, void *data)
325325
return true;
326326
}
327327

328+
ZTEST(flash_driver, test_get_size)
329+
{
330+
#if CONFIG_TEST_DRIVER_FLASH_SIZE != -1
331+
uint64_t size;
332+
333+
zassert_ok(flash_get_size(flash_dev, &size));
334+
zassert_equal(size, CONFIG_TEST_DRIVER_FLASH_SIZE, "Unexpected size");
335+
#else
336+
/* The test is sipped only because there is no uniform way to get device size */
337+
ztest_test_skip();
338+
#endif
339+
}
340+
328341
ZTEST(flash_driver, test_flash_page_layout)
329342
{
330343
int rc;

0 commit comments

Comments
 (0)