tests: subsys: fs: nvs: use DEVICE_DT_GET

The flash device can be obtained at compile time using DEVICE_DT_GET.
Make the flash device a module global so that it can be re-used (no need
to query/check for the device every time).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-03-23 15:31:27 +01:00 committed by Carles Cufí
commit e6b0d2121c

View file

@ -30,6 +30,7 @@
#define TEST_DATA_ID 1
#define TEST_SECTOR_COUNT 5U
static const struct device *flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller));
static struct nvs_fs fs;
struct stats_hdr *sim_stats;
struct stats_hdr *sim_thresholds;
@ -608,14 +609,10 @@ void test_delete(void)
void test_nvs_gc_corrupt_close_ate(void)
{
struct nvs_ate ate, close_ate;
const struct device *flash_dev;
uint32_t data;
ssize_t len;
int err;
flash_dev = device_get_binding(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL);
zassert_true(flash_dev != NULL, "device_get_binding failure");
close_ate.id = 0xffff;
close_ate.offset = fs.sector_size - sizeof(struct nvs_ate) * 5;
close_ate.len = 0;
@ -667,12 +664,8 @@ void test_nvs_gc_corrupt_close_ate(void)
void test_nvs_gc_corrupt_ate(void)
{
struct nvs_ate corrupt_ate, close_ate;
const struct device *flash_dev;
int err;
flash_dev = device_get_binding(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL);
zassert_true(flash_dev != NULL, "device_get_binding failure");
close_ate.id = 0xffff;
close_ate.offset = fs.sector_size / 2;
close_ate.len = 0;
@ -709,6 +702,8 @@ void test_nvs_gc_corrupt_ate(void)
void test_main(void)
{
__ASSERT_NO_MSG(device_is_ready(flash_dev));
ztest_test_suite(test_nvs,
ztest_unit_test_setup_teardown(test_nvs_mount, setup,
teardown),