1 /*
2 * Copyright (c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "fcb_test.h"
8
fcb_pretest_crc_disabled_after_enabled(void)9 static void fcb_pretest_crc_disabled_after_enabled(void)
10 {
11 int rc;
12 struct fcb_entry loc;
13 uint8_t test_data[128];
14 int i;
15 int j;
16 int var_cnt;
17
18 for (i = 0; i < sizeof(test_data); i++) {
19 for (j = 0; j < i; j++) {
20 test_data[j] = fcb_test_append_data(i, j);
21 }
22 rc = fcb_append(&test_fcb, i, &loc);
23 zassert_true(rc == 0, "fcb_append call failure");
24 rc = flash_area_write(test_fcb.fap, FCB_ENTRY_FA_DATA_OFF(loc),
25 test_data, i);
26 zassert_true(rc == 0, "flash_area_write call failure");
27 rc = fcb_append_finish(&test_fcb, &loc);
28 zassert_true(rc == 0, "fcb_append_finish call failure");
29 }
30
31 test_fcb_crc_disabled.f_erase_value = test_fcb.f_erase_value;
32 test_fcb_crc_disabled.f_sector_cnt = test_fcb.f_sector_cnt;
33 test_fcb_crc_disabled.f_sectors = test_fcb.f_sectors;
34
35 rc = fcb_init(TEST_FCB_FLASH_AREA_ID, &test_fcb_crc_disabled);
36 if (rc != 0) {
37 printf("%s rc == %xm, %d\n", __func__, rc, rc);
38 zassert_true(rc == 0, "fbc initialization failure");
39 }
40
41 var_cnt = 0;
42 rc = fcb_walk(&test_fcb_crc_disabled, 0, fcb_test_data_walk_cb, &var_cnt);
43 zassert_true(rc == 0, "fcb_walk call failure");
44 printk("var_cnt: %d", var_cnt);
45 zassert_true(var_cnt == sizeof(test_data),
46 "fetched data size not match to wrote data size");
47 }
48
49
ZTEST(fcb_test_with_2sectors_set,test_fcb_crc_disabled_after_enabled)50 ZTEST(fcb_test_with_2sectors_set, test_fcb_crc_disabled_after_enabled)
51 {
52 fcb_pretest_crc_disabled_after_enabled();
53 }
54