9 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
22 printf(
"# test_flashsim\n");
32 memset(data, 0x5a, 16);
36 for (
int i=0; i<16; i++)
37 ck_assert_int_eq(buf[i], 0xff);
38 for (
int i=16; i<32; i++)
39 ck_assert_int_eq(buf[i], 0x5a);
40 for (
int i=32; i<48; i++)
41 ck_assert_int_eq(buf[i], 0xff);
43 memset(data, 0x01, 16);
45 memset(data, 0x10, 16);
50 for (
int i=0; i<16; i++)
51 ck_assert_int_eq(buf[i], 0x01);
52 for (
int i=16; i<32; i++)
53 ck_assert_int_eq(buf[i], 0xff);
54 for (
int i=32; i<48; i++)
55 ck_assert_int_eq(buf[i], 0x10);
93 printf(
"# test_ringfs_format\n");
97 printf(
"## ringfs_init()\n");
99 printf(
"## ringfs_format()\n");
106 printf(
"# test_ringfs_scan\n");
111 printf(
"## ringfs_init()\n");
113 printf(
"## ringfs_format()\n");
118 printf(
"## ringfs_init()\n");
120 printf(
"## ringfs_scan()\n");
125 ck_assert_int_eq(fs2.
read.sector, 0);
126 ck_assert_int_eq(fs2.
read.slot, 0);
127 ck_assert_int_eq(fs2.
write.sector, 0);
128 ck_assert_int_eq(fs2.
write.slot, 0);
129 ck_assert_int_eq(fs2.
cursor.sector, 0);
130 ck_assert_int_eq(fs2.
cursor.slot, 0);
138 printf(
"## ringfs_scan()\n");
146 printf(
"## ringfs_init()\n");
148 printf(
"## ringfs_scan()\n");
155 printf(
"# test_ringfs_append\n");
160 printf(
"## ringfs_init()\n");
162 printf(
"## ringfs_format()\n");
166 for (
int i=0; i<3; i++) {
167 printf(
"## ringfs_append()\n");
171 ck_assert_int_eq(fs.
write.slot, i+1);
176 for (
int i=0; i<3; i++) {
177 printf(
"## ringfs_fetch()\n");
179 ck_assert_int_eq(obj, 0x11*(i+1));
182 ck_assert_int_eq(fs.
cursor.slot, i+1);
189 ck_assert_int_eq(fs.
cursor.slot, 0);
192 for (
int i=0; i<3; i++) {
193 printf(
"## ringfs_fetch()\n");
195 ck_assert_int_eq(obj, 0x11*(i+1));
202 printf(
"# test_ringfs_discard\n");
206 printf(
"## ringfs_init()\n");
208 printf(
"## ringfs_format()\n");
212 for (
int i=0; i<4; i++) {
213 printf(
"## ringfs_append()\n");
218 for (
int i=0; i<2; i++) {
219 printf(
"## ringfs_fetch()\n");
221 ck_assert_int_eq(obj, 0x11*(i+1));
226 ck_assert_int_eq(fs.
read.slot, 2);
227 ck_assert_int_eq(fs.
cursor.slot, 2);
228 ck_assert_int_eq(fs.
write.slot, 4);
231 for (
int i=2; i<4; i++) {
232 printf(
"## ringfs_fetch()\n");
234 ck_assert_int_eq(obj, 0x11*(i+1));
238 ck_assert_int_eq(fs.
read.slot, 4);
239 ck_assert_int_eq(fs.
cursor.slot, 4);
240 ck_assert_int_eq(fs.
write.slot, 4);
246 printf(
"# test_ringfs_capacity\n");
254 ck_assert_int_eq(
ringfs_capacity(&fs), (sectors-1) * slots_per_sector);
260 printf(
"# test_ringfs_count\n");
269 printf(
"## write some records\n");
270 for (
int i=0; i<10; i++)
275 printf(
"## rescan\n");
280 printf(
"## append more records\n");
281 for (
int i=10; i<13; i++)
286 printf(
"## fetch some objects without discard\n");
287 for (
int i=0; i<4; i++) {
289 ck_assert_int_eq(obj, 0x11*(i+1));
294 printf(
"## rescan\n");
299 printf(
"## fetch some objects with discard\n");
300 for (
int i=0; i<4; i++) {
302 ck_assert_int_eq(obj, 0x11*(i+1));
310 printf(
"## fill the segment\n");
312 for (
int i=0; i<count; i++)
317 printf(
"## extra synthetic tests for estimation\n");
320 fs.
write = (
struct ringfs_loc) { 0, 0 };
327 Suite *s = suite_create (
"ringfs");
330 tc = tcase_create(
"flashsim");
331 tcase_add_test(tc, test_flashsim);
332 suite_add_tcase(s, tc);
334 tc = tcase_create(
"ringfs");
335 tcase_add_test(tc, test_ringfs_format);
336 tcase_add_test(tc, test_ringfs_scan);
337 tcase_add_test(tc, test_ringfs_append);
338 tcase_add_test(tc, test_ringfs_discard);
339 tcase_add_test(tc, test_ringfs_capacity);
340 tcase_add_test(tc, test_ringfs_count);
341 suite_add_tcase(s, tc);
350 SRunner *sr = srunner_create(s);
351 srunner_run_all(sr, CK_NORMAL);
352 number_failed = srunner_ntests_failed(sr);
354 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
int sector_size
Sector size, in bytes.
int ringfs_format(struct ringfs *fs)
Format the flash memory.
void flashsim_program(struct flashsim *sim, int addr, const uint8_t *buf, int len)
int ringfs_capacity(struct ringfs *fs)
Calculate maximum RingFS capacity.
int ringfs_init(struct ringfs *fs, const struct ringfs_flash_partition *flash, uint32_t version, int object_size)
Initialize a RingFS instance.
void flashsim_read(struct flashsim *sim, int addr, uint8_t *buf, int len)
Flash memory+parition descriptor.
void flashsim_sector_erase(struct flashsim *sim, int addr)
struct flashsim * flashsim_open(const char *name, int size, int sector_size)
int ringfs_count_exact(struct ringfs *fs)
Calculate exact object count.
int ringfs_count_estimate(struct ringfs *fs)
Calculate approximate object count.
static ssize_t op_read(int address, void *data, size_t size)
int ringfs_discard(struct ringfs *fs)
Discard all fetched objects up to the read cursor.
int ringfs_scan(struct ringfs *fs)
Scan the flash memory for a valid filesystem.
static END_TEST struct flashsim * sim
int ringfs_fetch(struct ringfs *fs, void *object)
Fetch next object from the ring, oldest-first.
START_TEST(test_flashsim)
static const struct ringfs_flash_partition flash
END_TEST Suite * ringfs_suite(void)
static ssize_t op_program(int address, const void *data, size_t size)
int ringfs_rewind(struct ringfs *fs)
Rewind the read cursor back to the oldest object.
static int op_sector_erase(int address)
int ringfs_append(struct ringfs *fs, const void *object)
Append an object at the end of the ring.