1 /*
2  * Copyright (c) 2017-2023 Nordic Semiconductor ASA
3  * Copyright (c) 2015 Runtime Inc
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include "fcb_test.h"
9 
test_fcb_append(struct fcb * _fcb)10 static void test_fcb_append(struct fcb *_fcb)
11 {
12 	int rc;
13 	struct fcb_entry loc;
14 	uint8_t test_data[128];
15 	int i;
16 	int j;
17 	int var_cnt;
18 
19 	for (i = 0; i < sizeof(test_data); i++) {
20 		for (j = 0; j < i; j++) {
21 			test_data[j] = fcb_test_append_data(i, j);
22 		}
23 		rc = fcb_append(_fcb, i, &loc);
24 		zassert_true(rc == 0, "fcb_append call failure");
25 		rc = flash_area_write(_fcb->fap, FCB_ENTRY_FA_DATA_OFF(loc),
26 				      test_data, i);
27 		zassert_true(rc == 0, "flash_area_write call failure");
28 		rc = fcb_append_finish(_fcb, &loc);
29 		zassert_true(rc == 0, "fcb_append_finish call failure");
30 	}
31 
32 	var_cnt = 0;
33 	rc = fcb_walk(_fcb, 0, fcb_test_data_walk_cb, &var_cnt);
34 	zassert_true(rc == 0, "fcb_walk call failure");
35 	zassert_true(var_cnt == sizeof(test_data),
36 		     "fetched data size not match to wrote data size");
37 }
38 
ZTEST(fcb_test_with_2sectors_set,test_fcb_append_2sectors)39 ZTEST(fcb_test_with_2sectors_set, test_fcb_append_2sectors)
40 {
41 	test_fcb_append(&test_fcb);
42 }
43 
ZTEST(fcb_test_crc_disabled,test_fcb_append_crc_disabled)44 ZTEST(fcb_test_crc_disabled, test_fcb_append_crc_disabled)
45 {
46 	test_fcb_append(&test_fcb_crc_disabled);
47 }
48