projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Refactoring code, start to implement specific variables directly in
[bertos.git]
/
bertos
/
kern
/
kfile_test.c
diff --git
a/bertos/kern/kfile_test.c
b/bertos/kern/kfile_test.c
index 76e78092869f9b726d7c5d5fef11ee889ede7f4e..c5a996e0862052ef5d49f033797f87ad0f3acba6 100644
(file)
--- a/
bertos/kern/kfile_test.c
+++ b/
bertos/kern/kfile_test.c
@@
-41,12
+41,25
@@
#include "kfile.h"
#include "kfile.h"
-#include <appconfig.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_VERBOSITY KFILE_LOG_VERBOSITY
+#include <cfg/log.h>
+
#include <mware/formatwr.h>
#include <mware/formatwr.h>
+
#include <string.h>
#include <string.h>
+
+
+MOD_DEFINE(kfile_test);
+
+
/**
* KFile read/write subtest.
* Try to write/read in the same \a f file location \a size bytes.
/**
* KFile read/write subtest.
* Try to write/read in the same \a f file location \a size bytes.
@@
-83,21
+96,34
@@
static bool kfile_rwTest(KFile *f, uint8_t *buf, size_t size)
/*
* Check test result
*/
/*
* 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 true;
}
return false;
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
@@
-107,8
+133,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,
@@
-117,11
+143,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 [%lu] to [%lu]\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 [%lu]\n", size);
/*
* Seek to addr 0.
/*
* Seek to addr 0.
@@
-135,7
+161,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.
@@
-147,12
+173,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.
@@
-167,7
+193,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);
}
/*
}
/*
@@
-176,7
+202,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.
@@
-188,14
+214,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
@@
-210,7
+236,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);
}
/*
}
/*
@@
-228,21
+254,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 fail!\n");
+ return EOF;
}
}
-
-
+/**
+ * End a dataflash Test.
+ * (Unused)
+ */
+int kfile_testTearDown(void)
+{
+ /* */
+ return 0;
+}