From dace4f8d53875eb8cdf1af8c063750185a7b1db5 Mon Sep 17 00:00:00 2001 From: batt Date: Sun, 27 Sep 2009 13:22:57 +0000 Subject: [PATCH] Refactor kfile_test to use the new kfile_mem module. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2977 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/kern/kfile_test.c | 76 ++++------------------------------------ test/run_tests.sh | 2 +- 2 files changed, 8 insertions(+), 70 deletions(-) diff --git a/bertos/kern/kfile_test.c b/bertos/kern/kfile_test.c index d2eba87d..36fde490 100644 --- a/bertos/kern/kfile_test.c +++ b/bertos/kern/kfile_test.c @@ -41,6 +41,7 @@ #include "kfile.h" +#include #include "cfg/cfg_kfile.h" #include @@ -63,73 +64,11 @@ MOD_DEFINE(kfile_test); #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]; -fake_t test_disk[BUF_TEST_LEN]; +uint8_t test_buf[BUF_TEST_LEN]; +uint8_t test_buf_save[BUF_TEST_LEN]; -KFile fd; - -/* - * Beckend to use kfile structure on pc. - */ -static int fake_close(KFile *fd) -{ - (void)fd; - return 0; -} - -static size_t fake_read(KFile *fd, void *buf, size_t size) -{ - fake_t *dest = (fake_t *)buf; - size_t rd_len; - - rd_len = MIN((kfile_off_t)size, fd->size - fd->seek_pos); - - memcpy(dest, test_disk, size); - fd->seek_pos += rd_len; - - LOG_INFO("Read: real[%zd] expected[%zd]\n", rd_len, size); - - return rd_len; -} - -static size_t fake_write(KFile *fd, const void *buf, size_t size) -{ - const fake_t *src = (const fake_t *)buf; - size_t wr_len; - - wr_len = MIN((kfile_off_t)size, fd->size - fd->seek_pos); - - memcpy(test_disk, src, wr_len); - fd->seek_pos += wr_len; - - LOG_INFO("Write: real[%zd] expected[%zd]\n", wr_len, size); - - return wr_len; -} - -static int fake_flush(KFile *fd) -{ - (void)fd; - - return 0; -} - -static void fake_kfileInit(void) -{ - // Setup data flash programming functions. - fd.reopen = kfile_genericReopen; - fd.close = fake_close; - fd.read = fake_read; - fd.write = fake_write; - fd.seek = kfile_genericSeek; - fd.flush = fake_flush; - - fd.seek_pos = 0; - fd.size = BUF_TEST_LEN; - -} +uint8_t test_disk[BUF_TEST_LEN]; +KFileMem mem; /* * Help function to init disk and the buffers. @@ -299,7 +238,6 @@ int kfile_testRunGeneric(KFile *fd, uint8_t *test_buf, uint8_t *save_buf, size_t /* TEST 3 BEGIN. */ LOG_INFO("Test 3: write outside of fd->size limit [%ld]\n", fd->size); - LOG_INFO("This test should FAIL!, you must see an assertion fail message.\n"); /* * Go to the Flash end @@ -361,7 +299,7 @@ int kfile_testSetup(void) LOG_INFO("Mod init..ok\n"); // Init our backend and the buffers - fake_kfileInit(); + kfilemem_init(&mem, test_disk, BUF_TEST_LEN); init_testBuf(); return 0; @@ -369,7 +307,7 @@ int kfile_testSetup(void) int kfile_testRun(void) { - return kfile_testRunGeneric(&fd, test_buf, test_buf_save, BUF_TEST_LEN); + return kfile_testRunGeneric(&mem.fd, test_buf, test_buf_save, BUF_TEST_LEN); } /** diff --git a/test/run_tests.sh b/test/run_tests.sh index e925ebcb..b9325d58 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -28,7 +28,7 @@ TESTS=${TESTS:-`find . \ -o -name "*_test.c" -print` } TESTOUT="testout" -SRC_LIST="bertos/algo/ramp.c bertos/drv/kdebug.c bertos/drv/timer.c bertos/fs/battfs.c bertos/kern/coop.c bertos/kern/idle.c bertos/kern/kfile.c bertos/kern/monitor.c bertos/kern/proc.c bertos/kern/signal.c bertos/kern/sem.c bertos/mware/event.c bertos/mware/formatwr.c bertos/mware/hex.c bertos/mware/sprintf.c bertos/os/hptime.c bertos/struct/kfile_fifo.c bertos/fs/fatfs/ff.c bertos/emul/diskio_emul.c bertos/fs/fat.c bertos/emul/switch_ctx_emul.S bertos/mware/ini_reader.c bertos/emul/kfile_posix.c bertos/algo/crc_ccitt.c bertos/algo/crc.c" +SRC_LIST="bertos/algo/ramp.c bertos/drv/kdebug.c bertos/drv/timer.c bertos/fs/battfs.c bertos/kern/coop.c bertos/kern/idle.c bertos/kern/kfile.c bertos/kern/monitor.c bertos/kern/proc.c bertos/kern/signal.c bertos/kern/sem.c bertos/mware/event.c bertos/mware/formatwr.c bertos/mware/hex.c bertos/mware/sprintf.c bertos/os/hptime.c bertos/struct/kfile_fifo.c bertos/fs/fatfs/ff.c bertos/emul/diskio_emul.c bertos/fs/fat.c bertos/emul/switch_ctx_emul.S bertos/mware/ini_reader.c bertos/emul/kfile_posix.c bertos/algo/crc_ccitt.c bertos/algo/crc.c bertos/struct/kfile_mem.c" buildout='/dev/null' runout='/dev/null' -- 2.25.1