projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
New icon for the Wizard.
[bertos.git]
/
bertos
/
kern
/
kfile_test.c
diff --git
a/bertos/kern/kfile_test.c
b/bertos/kern/kfile_test.c
index 21fc3d3bf73255aa8f4537c97dc67a50f5387b6b..d2eba87d5543d4165dde1094ec7083c49a2b9a33 100644
(file)
--- a/
bertos/kern/kfile_test.c
+++ b/
bertos/kern/kfile_test.c
@@
-58,8
+58,11
@@
MOD_DEFINE(kfile_test);
MOD_DEFINE(kfile_test);
+// Size of the "virtual" disk that
+// we want to test.
#define BUF_TEST_LEN 3209
#define BUF_TEST_LEN 3209
+// Buffer for test
typedef uint8_t fake_t;
fake_t test_buf[BUF_TEST_LEN];
fake_t test_buf_save[BUF_TEST_LEN];
typedef uint8_t fake_t;
fake_t test_buf[BUF_TEST_LEN];
fake_t test_buf_save[BUF_TEST_LEN];
@@
-67,6
+70,9
@@
fake_t test_disk[BUF_TEST_LEN];
KFile fd;
KFile fd;
+/*
+ * Beckend to use kfile structure on pc.
+ */
static int fake_close(KFile *fd)
{
(void)fd;
static int fake_close(KFile *fd)
{
(void)fd;
@@
-83,14
+89,14
@@
static size_t fake_read(KFile *fd, void *buf, size_t size)
memcpy(dest, test_disk, size);
fd->seek_pos += rd_len;
memcpy(dest, test_disk, size);
fd->seek_pos += rd_len;
- LOG_INFO("Read: real[%
ld] expected[%l
d]\n", rd_len, size);
+ LOG_INFO("Read: real[%
zd] expected[%z
d]\n", rd_len, size);
return rd_len;
}
static size_t fake_write(KFile *fd, const void *buf, size_t size)
{
return rd_len;
}
static size_t fake_write(KFile *fd, const void *buf, size_t size)
{
-
fake_t *src = (
fake_t *)buf;
+
const fake_t *src = (const
fake_t *)buf;
size_t wr_len;
wr_len = MIN((kfile_off_t)size, fd->size - fd->seek_pos);
size_t wr_len;
wr_len = MIN((kfile_off_t)size, fd->size - fd->seek_pos);
@@
-98,19
+104,19
@@
static size_t fake_write(KFile *fd, const void *buf, size_t size)
memcpy(test_disk, src, wr_len);
fd->seek_pos += wr_len;
memcpy(test_disk, src, wr_len);
fd->seek_pos += wr_len;
- LOG_INFO("Write: real[%
ld] expected[%l
d]\n", wr_len, size);
+ LOG_INFO("Write: real[%
zd] expected[%z
d]\n", wr_len, size);
return wr_len;
}
return wr_len;
}
-int fake_flush(KFile *fd)
+
static
int fake_flush(KFile *fd)
{
(void)fd;
return 0;
}
{
(void)fd;
return 0;
}
-void fake_kfileInit(void)
+
static
void fake_kfileInit(void)
{
// Setup data flash programming functions.
fd.reopen = kfile_genericReopen;
{
// Setup data flash programming functions.
fd.reopen = kfile_genericReopen;
@@
-125,14
+131,16
@@
void fake_kfileInit(void)
}
}
+/*
+ * Help function to init disk and the buffers.
+ */
static void init_testBuf(void)
{
static void init_testBuf(void)
{
- #include <stdlib.h>
kprintf("Init fake buffer..\n");
for (int i = 0; i < BUF_TEST_LEN; i++)
{
kprintf("Init fake buffer..\n");
for (int i = 0; i < BUF_TEST_LEN; i++)
{
- test_disk[i] =
random()
;
+ test_disk[i] =
i
;
kprintf("%d ", test_disk[i]);
}
kprintf("\nend\n");
kprintf("%d ", test_disk[i]);
}
kprintf("\nend\n");
@@
-212,7
+220,7
@@
int kfile_testRunGeneric(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t
*/
if (save_buf)
{
*/
if (save_buf)
{
- LOG_INFO("Saved content..form [%d] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
+ LOG_INFO("Saved content..form [%
l
d] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
kfile_read(fd, save_buf, size);
}
kfile_read(fd, save_buf, size);
}
@@
-243,12
+251,12
@@
int kfile_testRunGeneric(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t
if (kfile_write(fd, save_buf, size) != size)
goto kfile_test_end;
if (kfile_write(fd, save_buf, size) != size)
goto kfile_test_end;
- LOG_INFO("Restore content..form [%d] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
+ LOG_INFO("Restore content..form [%
l
d] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
}
/* TEST 1 END. */
/* TEST 2 BEGIN. */
}
/* TEST 1 END. */
/* TEST 2 BEGIN. */
- LOG_INFO("Test 2: write from pos [%d] to [%ld]\n", fd->size/2 , fd->size/2 + size);
+ LOG_INFO("Test 2: write from pos [%
l
d] to [%ld]\n", fd->size/2 , fd->size/2 + size);
/*
* Go to half test size.
/*
* Go to half test size.
@@
-263,7
+271,7
@@
int kfile_testRunGeneric(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t
{
kfile_read(fd, save_buf, size);
kfile_seek(fd, -(kfile_off_t)size, KSM_SEEK_CUR);
{
kfile_read(fd, save_buf, size);
kfile_seek(fd, -(kfile_off_t)size, KSM_SEEK_CUR);
- LOG_INFO("Saved content..form [%d] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
+ LOG_INFO("Saved content..form [%
l
d] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
}
/*
}
/*
@@
-284,13
+292,13
@@
int kfile_testRunGeneric(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t
if (kfile_write(fd, save_buf, size) != size)
goto kfile_test_end;
if (kfile_write(fd, save_buf, size) != size)
goto kfile_test_end;
- LOG_INFO("Restore content..form [%d] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
+ LOG_INFO("Restore content..form [%
l
d] to [%ld]\n", fd->seek_pos, fd->seek_pos + size);
}
/* TEST 2 END. */
/* TEST 3 BEGIN. */
}
/* TEST 2 END. */
/* TEST 3 BEGIN. */
- LOG_INFO("Test 3: write outside of fd->size limit [%d]\n", fd->size);
+ LOG_INFO("Test 3: write outside of fd->size limit [%
l
d]\n", fd->size);
LOG_INFO("This test should FAIL!, you must see an assertion fail message.\n");
/*
LOG_INFO("This test should FAIL!, you must see an assertion fail message.\n");
/*
@@
-306,7
+314,7
@@
int kfile_testRunGeneric(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t
{
kfile_read(fd, save_buf, len);
kfile_seek(fd, -len, KSM_SEEK_CUR);
{
kfile_read(fd, save_buf, len);
kfile_seek(fd, -len, KSM_SEEK_CUR);
- LOG_INFO("Saved content..form [%
d] to [%
d]\n", fd->seek_pos, fd->seek_pos + len);
+ LOG_INFO("Saved content..form [%
ld] to [%l
d]\n", fd->seek_pos, fd->seek_pos + len);
}
/*
}
/*
@@
-327,7
+335,7
@@
int kfile_testRunGeneric(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t
if ((kfile_off_t)kfile_write(fd, save_buf, len) != len)
goto kfile_test_end;
if ((kfile_off_t)kfile_write(fd, save_buf, len) != len)
goto kfile_test_end;
- LOG_INFO("Restore content..form [%
d] to [%
d]\n", fd->seek_pos, fd->seek_pos + len);
+ LOG_INFO("Restore content..form [%
ld] to [%l
d]\n", fd->seek_pos, fd->seek_pos + len);
}
/* TEST 3 END. */
}
/* TEST 3 END. */
@@
-352,6
+360,7
@@
int kfile_testSetup(void)
MOD_INIT(kfile_test);
LOG_INFO("Mod init..ok\n");
MOD_INIT(kfile_test);
LOG_INFO("Mod init..ok\n");
+ // Init our backend and the buffers
fake_kfileInit();
init_testBuf();
fake_kfileInit();
init_testBuf();
@@
-373,3
+382,4
@@
int kfile_testTearDown(void)
}
TEST_MAIN(kfile);
}
TEST_MAIN(kfile);
+