1 /*
2  * Copyright (c) 2018 Nordic Semiconductor ASA
3  * Copyright (c) 2015 Runtime Inc
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include "settings_test.h"
9 #include "settings/settings_fcb.h"
10 
11 #ifdef TEST_LONG
12 #define TESTS_S3_FCB_ITERATIONS 4096
13 #else
14 #define TESTS_S3_FCB_ITERATIONS 100
15 #endif
16 
ZTEST(settings_config_fcb,test_config_save_3_fcb)17 ZTEST(settings_config_fcb, test_config_save_3_fcb)
18 {
19 	int rc;
20 	struct settings_fcb cf;
21 	int i;
22 
23 	rc = settings_register(&c_test_handlers[2]);
24 	zassert_true(rc == 0 || rc == -EEXIST, "settings_register fail");
25 	config_wipe_srcs();
26 	config_wipe_fcb(fcb_sectors, ARRAY_SIZE(fcb_sectors));
27 
28 	cf.cf_fcb.f_magic = CONFIG_SETTINGS_FCB_MAGIC;
29 	cf.cf_fcb.f_sectors = fcb_sectors;
30 	cf.cf_fcb.f_sector_cnt = 4;
31 
32 	rc = settings_fcb_src(&cf);
33 	zassert_true(rc == 0, "can't register FCB as configuration source");
34 
35 	rc = settings_fcb_dst(&cf);
36 	zassert_true(rc == 0,
37 		     "can't register FCB as configuration destination");
38 
39 	for (i = 0; i < TESTS_S3_FCB_ITERATIONS; i++) {
40 		val32 = i;
41 
42 		rc = settings_save();
43 		zassert_true(rc == 0, "fcb write error");
44 
45 		val32 = 0U;
46 
47 		rc = settings_load();
48 		zassert_true(rc == 0, "fcb read error");
49 		zassert_true(val32 == i, "bad value read");
50 	}
51 	settings_unregister(&c_test_handlers[2]);
52 }
53