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