projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add the getSystemPath function that returns a list of string containig the path
[bertos.git]
/
bertos
/
kern
/
kfile_test.c
diff --git
a/bertos/kern/kfile_test.c
b/bertos/kern/kfile_test.c
index b01ba4469c3dfdd5f43359d4f707b602005abe01..8874209c0facae2874e132a846a7610173858927 100644
(file)
--- a/
bertos/kern/kfile_test.c
+++ b/
bertos/kern/kfile_test.c
@@
-31,25
+31,33
@@
* -->
*
* \brief Test suite for virtual KFile I/O interface.
* -->
*
* \brief Test suite for virtual KFile I/O interface.
+ *
* This module implements a test for some generic I/O interfaces for kfile.
*
* \version $Id$
* \author Francesco Sacchi <batt@develer.com>
* \author Daniele Basile <asterix@develer.com>
* This module implements a test for some generic I/O interfaces for kfile.
*
* \version $Id$
* \author Francesco Sacchi <batt@develer.com>
* \author Daniele Basile <asterix@develer.com>
- *
*/
#include "kfile.h"
*/
#include "kfile.h"
-#include
<cfg/cfg_kfile.h>
+#include
"cfg/cfg_kfile.h"
#include <cfg/debug.h>
#include <cfg/debug.h>
+#include <cfg/module.h>
+
+// Define logging setting (for cfg/log.h module).
+#define LOG_LEVEL KFILE_LOG_LEVEL
+#define LOG_FORMAT KFILE_LOG_FORMAT
+#include <cfg/log.h>
#include <mware/formatwr.h>
#include <string.h>
#include <mware/formatwr.h>
#include <string.h>
-#warning TODO:Refactor this module..
+
+MOD_DEFINE(kfile_test);
+
/**
* KFile read/write subtest.
/**
* KFile read/write subtest.
@@
-82,26
+90,39
@@
static bool kfile_rwTest(KFile *f, uint8_t *buf, size_t size)
*/
if (kfile_read(f, buf, size) != size)
return false;
*/
if (kfile_read(f, buf, size) != size)
return false;
+
kfile_seek(f, -(kfile_off_t)size, KSM_SEEK_CUR);
/*
* Check test result
*/
kfile_seek(f, -(kfile_off_t)size, KSM_SEEK_CUR);
/*
* Check test result
*/
- for (size_t i = 0; i < size; i++)
- if (buf[i] != (i & 0xff))
+ for (size_t i = 0; i < size; i++)
+ if (buf[i] != (i & 0xff))
return false;
return false;
-
return true;
}
return true;
}
+/**
+ * Setup all needed for kfile test
+ */
+int kfile_testSetUp(void)
+{
+ MOD_INIT(kfile_test);
+ LOG_INFO("Mod init..ok\n");
+
+ return 0;
+}
+
+
/**
* KFile read/write test.
* This function write and read \a test_buf long \a size
* on \a fd handler.
* \a save_buf can be NULL or a buffer where to save previous file content.
*/
/**
* KFile read/write test.
* This function write and read \a test_buf long \a size
* on \a fd handler.
* \a save_buf can be NULL or a buffer where to save previous file content.
*/
-
bool kfile_test
(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size)
+
int kfile_testRun
(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size)
{
{
+
/*
* Part of test buf size that you would write.
* This var is used in test 3 to check kfile_write
/*
* Part of test buf size that you would write.
* This var is used in test 3 to check kfile_write
@@
-111,8
+132,8
@@
bool kfile_test(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size)
/* Fill test buffer */
/* Fill test buffer */
- for (size_t i = 0; i < size; i++)
- test_buf[i] = (i & 0xff);
+ for (size_t i = 0; i < size; i++)
+ test_buf[i] = (i & 0xff);
/*
* If necessary, user can save content,
/*
* If necessary, user can save content,
@@
-121,11
+142,11
@@
bool kfile_test(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size)
if (save_buf)
{
kfile_read(fd, save_buf, size);
if (save_buf)
{
kfile_read(fd, save_buf, size);
-
kprintf("Saved content..form [%lu] to [%lu
]\n", fd->seek_pos, fd->seek_pos + size);
+
LOG_INFO("Saved content..form [%ld] to [%ld
]\n", fd->seek_pos, fd->seek_pos + size);
}
/* TEST 1 BEGIN. */
}
/* TEST 1 BEGIN. */
-
kprintf("Test 1: write from pos 0 to [%lu]\n",
size);
+
LOG_INFO("Test 1: write from pos 0 to [%ld]\n", (long)
size);
/*
* Seek to addr 0.
/*
* Seek to addr 0.
@@
-139,7
+160,7
@@
bool kfile_test(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size)
if (!kfile_rwTest(fd, test_buf, size))
goto kfile_test_end;
if (!kfile_rwTest(fd, test_buf, size))
goto kfile_test_end;
-
kprintf
("Test 1: ok!\n");
+
LOG_INFO
("Test 1: ok!\n");
/*
* Restore previous read content.
/*
* Restore previous read content.
@@
-151,12
+172,12
@@
bool kfile_test(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size)
if (kfile_write(fd, save_buf, size) != size)
goto kfile_test_end;
if (kfile_write(fd, save_buf, size) != size)
goto kfile_test_end;
-
kprintf
("Restore content..form [%lu] to [%lu]\n", fd->seek_pos, fd->seek_pos + size);
+
LOG_INFO
("Restore content..form [%lu] to [%lu]\n", fd->seek_pos, fd->seek_pos + size);
}
/* TEST 1 END. */
/* TEST 2 BEGIN. */
}
/* TEST 1 END. */
/* TEST 2 BEGIN. */
-
kprintf
("Test 2: write from pos [%lu] to [%lu]\n", fd->size/2 , fd->size/2 + size);
+
LOG_INFO
("Test 2: write from pos [%lu] to [%lu]\n", fd->size/2 , fd->size/2 + size);
/*
* Go to half test size.
/*
* Go to half test size.
@@
-171,7
+192,7
@@
bool kfile_test(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size)
{
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);
-
kprintf
("Saved content..form [%lu] to [%lu]\n", fd->seek_pos, fd->seek_pos + size);
+
LOG_INFO
("Saved content..form [%lu] to [%lu]\n", fd->seek_pos, fd->seek_pos + size);
}
/*
}
/*
@@
-180,7
+201,7
@@
bool kfile_test(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size)
if (!kfile_rwTest(fd, test_buf, size))
goto kfile_test_end;
if (!kfile_rwTest(fd, test_buf, size))
goto kfile_test_end;
-
kprintf
("Test 2: ok!\n");
+
LOG_INFO
("Test 2: ok!\n");
/*
* Restore previous content.
/*
* Restore previous content.
@@
-192,14
+213,14
@@
bool kfile_test(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size)
if (kfile_write(fd, save_buf, size) != size)
goto kfile_test_end;
if (kfile_write(fd, save_buf, size) != size)
goto kfile_test_end;
-
kprintf
("Restore content..form [%lu] to [%lu]\n", fd->seek_pos, fd->seek_pos + size);
+
LOG_INFO
("Restore content..form [%lu] to [%lu]\n", fd->seek_pos, fd->seek_pos + size);
}
/* TEST 2 END. */
/* TEST 3 BEGIN. */
}
/* TEST 2 END. */
/* TEST 3 BEGIN. */
-
kprintf
("Test 3: write outside of fd->size limit [%lu]\n", fd->size);
-
kprintf
("This test should FAIL!, you must see an assertion fail message.\n");
+
LOG_INFO
("Test 3: write outside of fd->size limit [%lu]\n", fd->size);
+
LOG_INFO
("This test should FAIL!, you must see an assertion fail message.\n");
/*
* Go to the Flash end
/*
* Go to the Flash end
@@
-214,7
+235,7
@@
bool kfile_test(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size)
{
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);
-
kprintf
("Saved content..form [%lu] to [%lu]\n", fd->seek_pos, fd->seek_pos + len);
+
LOG_INFO
("Saved content..form [%lu] to [%lu]\n", fd->seek_pos, fd->seek_pos + len);
}
/*
}
/*
@@
-232,21
+253,29
@@
bool kfile_test(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size)
{
kfile_seek(fd, -len, KSM_SEEK_END);
{
kfile_seek(fd, -len, KSM_SEEK_END);
- if (kfile_write(fd, save_buf, len) != len)
+ if (
(kfile_off_t)
kfile_write(fd, save_buf, len) != len)
goto kfile_test_end;
goto kfile_test_end;
-
kprintf
("Restore content..form [%lu] to [%lu]\n", fd->seek_pos, fd->seek_pos + len);
+
LOG_INFO
("Restore content..form [%lu] to [%lu]\n", fd->seek_pos, fd->seek_pos + len);
}
/* TEST 3 END. */
kfile_close(fd);
}
/* TEST 3 END. */
kfile_close(fd);
- return
true
;
+ return
0
;
kfile_test_end:
kfile_close(fd);
kfile_test_end:
kfile_close(fd);
- return false;
+ LOG_ERR("One kfile_test failed!\n");
+ return EOF;
}
}
-
-
+/**
+ * End a dataflash Test.
+ * (Unused)
+ */
+int kfile_testTearDown(void)
+{
+ /* */
+ return 0;
+}