mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-11-01 00:38:29 +01:00
117 lines
2.4 KiB
Plaintext
117 lines
2.4 KiB
Plaintext
/// AUTOGENERATED TEST ///
|
|
#include "lfs2.h"
|
|
#include "emubd/lfs2_emubd.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
|
|
// test stuff
|
|
static void test_log(const char *s, uintmax_t v) {{
|
|
printf("%s: %jd\n", s, v);
|
|
}}
|
|
|
|
static void test_assert(const char *file, unsigned line,
|
|
const char *s, uintmax_t v, uintmax_t e) {{
|
|
static const char *last[6] = {{0, 0}};
|
|
if (v != e || !(last[0] == s || last[1] == s ||
|
|
last[2] == s || last[3] == s ||
|
|
last[4] == s || last[5] == s)) {{
|
|
test_log(s, v);
|
|
last[0] = last[1];
|
|
last[1] = last[2];
|
|
last[2] = last[3];
|
|
last[3] = last[4];
|
|
last[4] = last[5];
|
|
last[5] = s;
|
|
}}
|
|
|
|
if (v != e) {{
|
|
fprintf(stderr, "\033[31m%s:%u: assert %s failed with %jd, "
|
|
"expected %jd\033[0m\n", file, line, s, v, e);
|
|
exit(-2);
|
|
}}
|
|
}}
|
|
|
|
#define test_assert(s, v, e) test_assert(__FILE__, __LINE__, s, v, e)
|
|
|
|
|
|
// utility functions for traversals
|
|
static int __attribute__((used)) test_count(void *p, lfs2_block_t b) {{
|
|
(void)b;
|
|
unsigned *u = (unsigned*)p;
|
|
*u += 1;
|
|
return 0;
|
|
}}
|
|
|
|
|
|
// lfs2 declarations
|
|
lfs2_t lfs2;
|
|
lfs2_emubd_t bd;
|
|
lfs2_file_t file[4];
|
|
lfs2_dir_t dir[4];
|
|
struct lfs2_info info;
|
|
|
|
uint8_t buffer[1024];
|
|
uint8_t wbuffer[1024];
|
|
uint8_t rbuffer[1024];
|
|
lfs2_size_t size;
|
|
lfs2_size_t wsize;
|
|
lfs2_size_t rsize;
|
|
|
|
uintmax_t test;
|
|
|
|
#ifndef LFS2_READ_SIZE
|
|
#define LFS2_READ_SIZE 16
|
|
#endif
|
|
|
|
#ifndef LFS2_PROG_SIZE
|
|
#define LFS2_PROG_SIZE LFS2_READ_SIZE
|
|
#endif
|
|
|
|
#ifndef LFS2_BLOCK_SIZE
|
|
#define LFS2_BLOCK_SIZE 512
|
|
#endif
|
|
|
|
#ifndef LFS2_BLOCK_COUNT
|
|
#define LFS2_BLOCK_COUNT 1024
|
|
#endif
|
|
|
|
#ifndef LFS2_BLOCK_CYCLES
|
|
#define LFS2_BLOCK_CYCLES 1024
|
|
#endif
|
|
|
|
#ifndef LFS2_CACHE_SIZE
|
|
#define LFS2_CACHE_SIZE 64
|
|
#endif
|
|
|
|
#ifndef LFS2_LOOKAHEAD_SIZE
|
|
#define LFS2_LOOKAHEAD_SIZE 16
|
|
#endif
|
|
|
|
const struct lfs2_config cfg = {{
|
|
.context = &bd,
|
|
.read = &lfs2_emubd_read,
|
|
.prog = &lfs2_emubd_prog,
|
|
.erase = &lfs2_emubd_erase,
|
|
.sync = &lfs2_emubd_sync,
|
|
|
|
.read_size = LFS2_READ_SIZE,
|
|
.prog_size = LFS2_PROG_SIZE,
|
|
.block_size = LFS2_BLOCK_SIZE,
|
|
.block_count = LFS2_BLOCK_COUNT,
|
|
.block_cycles = LFS2_BLOCK_CYCLES,
|
|
.cache_size = LFS2_CACHE_SIZE,
|
|
.lookahead_size = LFS2_LOOKAHEAD_SIZE,
|
|
}};
|
|
|
|
|
|
// Entry point
|
|
int main(void) {{
|
|
lfs2_emubd_create(&cfg, "blocks");
|
|
|
|
{tests}
|
|
|
|
lfs2_emubd_destroy(&cfg);
|
|
}}
|