1 /*
2  * Copyright (c) 2020 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <limits.h>
8 #include <zephyr/device.h>
9 #include <zephyr/fs/fs.h>
10 #include <zephyr/ztest.h>
11 #include <zephyr/storage/flash_map.h>
12 
13 #define TEST_PARTITION		storage_partition
14 #define TEST_PARTITION_ID	FIXED_PARTITION_ID(TEST_PARTITION)
15 
check_file_dir_exists(const char * fpath)16 int check_file_dir_exists(const char *fpath)
17 {
18 	int res;
19 	struct fs_dirent entry;
20 
21 	res = fs_stat(fpath, &entry);
22 
23 	return !res;
24 }
25 
test_clear_flash(void)26 void test_clear_flash(void)
27 {
28 	int rc;
29 	const struct flash_area *fap;
30 
31 	rc = flash_area_open(TEST_PARTITION_ID, &fap);
32 	zassert_equal(rc, 0, "Opening flash area for erase [%d]\n", rc);
33 
34 	rc = flash_area_erase(fap, 0, fap->fa_size);
35 	zassert_equal(rc, 0, "Erasing flash area [%d]\n", rc);
36 }
37