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 
ZTEST(settings_config_fcb,test_config_save_1_fcb)11 ZTEST(settings_config_fcb, test_config_save_1_fcb)
12 {
13 	int rc;
14 	struct settings_fcb cf;
15 
16 	rc = settings_register(&c_test_handlers[0]);
17 	zassert_true(rc == 0 || rc == -EEXIST, "settings_register fail");
18 
19 	config_wipe_srcs();
20 	config_wipe_fcb(fcb_sectors, ARRAY_SIZE(fcb_sectors));
21 
22 	cf.cf_fcb.f_magic = CONFIG_SETTINGS_FCB_MAGIC;
23 	cf.cf_fcb.f_sectors = fcb_sectors;
24 	cf.cf_fcb.f_sector_cnt = ARRAY_SIZE(fcb_sectors);
25 
26 	rc = settings_fcb_src(&cf);
27 	zassert_true(rc == 0, "can't register FCB as configuration source");
28 
29 	settings_mount_fcb_backend(&cf);
30 
31 	rc = settings_fcb_dst(&cf);
32 	zassert_true(rc == 0,
33 		     "can't register FCB as configuration destination");
34 
35 	val8 = 33U;
36 	rc = settings_save();
37 	zassert_true(rc == 0, "fcb write error");
38 
39 	val8 = 0U;
40 
41 	rc = settings_load();
42 	zassert_true(rc == 0, "fcb redout error");
43 	zassert_true(val8 == 33U, "bad value read");
44 
45 	val8 = 15U;
46 	rc = settings_save();
47 	zassert_true(rc == 0, "fcb write error");
48 	settings_unregister(&c_test_handlers[0]);
49 }
50