From: asterix Date: Thu, 5 Jun 2008 17:33:09 +0000 (+0000) Subject: Refactor module using log module and comply to bertos test policy. X-Git-Tag: 2.0.0~516 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=d228df76a6221d2ef84239ab225e8dd4afb9c96d;p=bertos.git Refactor module using log module and comply to bertos test policy. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1418 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cfg/cfg_kfile.h b/bertos/cfg/cfg_kfile.h index 6dad0a0c..8e2bc926 100644 --- a/bertos/cfg/cfg_kfile.h +++ b/bertos/cfg/cfg_kfile.h @@ -40,8 +40,24 @@ #ifndef CFG_KFILE_H #define CFG_KFILE_H +/** + * Logging level definition. + * + * Use 0 to log only the error messages + * Use 1 to log the error and warning messages + * Use 2 to log all messages + */ +#define KFILE_LOG_LEVEL 2 + +/** + * Set logging verbosity. + * + * If verbosity is zero print short log messages. + */ +#define KFILE_LOG_VERBOSITY 1 + /// TODO: -#define CONFIG_KFILE_GETS 1 +#define CONFIG_KFILE_GETS 0 #endif /* CFG_KFILE_H */ diff --git a/bertos/kern/kfile.h b/bertos/kern/kfile.h index dc8a3041..ccaeb802 100644 --- a/bertos/kern/kfile.h +++ b/bertos/kern/kfile.h @@ -262,6 +262,8 @@ INLINE void kfile_clearerr(struct KFile *fd) /** * Kfile test function. */ -bool kfile_test(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size); +int kfile_testSetup(void); +int kfile_testRun(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size); +int kfile_testTearDown(void); #endif /* KERN_KFILE_H */ diff --git a/bertos/kern/kfile_test.c b/bertos/kern/kfile_test.c index 526ccf62..e54edb2f 100644 --- a/bertos/kern/kfile_test.c +++ b/bertos/kern/kfile_test.c @@ -44,12 +44,21 @@ #include "cfg/cfg_kfile.h" #include +#include + +// Define logging setting (for cfg/log.h module). +#define LOG_LEVEL KFILE_LOG_LEVEL +#define LOG_VERBOSITY KFILE_LOG_VERBOSITY +#include #include #include -#warning TODO:Refactor this module.. + + +MOD_DEFINE(kfile_test); + /** * KFile read/write subtest. @@ -94,14 +103,28 @@ static bool kfile_rwTest(KFile *f, uint8_t *buf, size_t size) 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. */ -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) { + kfile_testSetup(); + /* * Part of test buf size that you would write. * This var is used in test 3 to check kfile_write @@ -121,11 +144,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); - 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. */ - 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. @@ -139,7 +162,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; - kprintf("Test 1: ok!\n"); + LOG_INFO("Test 1: ok!\n"); /* * Restore previous read content. @@ -151,12 +174,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; - 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. */ - 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. @@ -171,7 +194,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); - 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 +203,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; - kprintf("Test 2: ok!\n"); + LOG_INFO("Test 2: ok!\n"); /* * Restore previous content. @@ -192,14 +215,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; - 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. */ - 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 @@ -214,7 +237,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); - 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 +255,29 @@ bool kfile_test(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t size) { 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; - 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); - return true; + return 0; 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; +}