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