From 90f3a07ec855d9bf82367d00f262c478434993d5 Mon Sep 17 00:00:00 2001 From: batt Date: Sat, 16 Feb 2008 10:43:43 +0000 Subject: [PATCH] Add file open test. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1111 38d2e660-2303-0410-9eaa-f027e97ec537 --- app/battfs/appconfig.h | 9 ++-- app/battfs/battfs_test.c | 102 ++++++++++++++++++++++++++++---------- app/battfs/battfs_test.mk | 3 +- 3 files changed, 83 insertions(+), 31 deletions(-) diff --git a/app/battfs/appconfig.h b/app/battfs/appconfig.h index 4361d0f0..102d5602 100644 --- a/app/battfs/appconfig.h +++ b/app/battfs/appconfig.h @@ -143,9 +143,6 @@ /** Default baud rate (set to 0 to disable) */ #define CONFIG_SER_DEFBAUDRATE 0 - /** Enable ser_gets() and ser_gets_echo() */ - #define CONFIG_SER_GETS 0 - /** Enable second serial port in emulator. */ #define CONFIG_EMUL_UART1 0 @@ -224,4 +221,10 @@ /// Turn on or off timer support in Randpool. #define CONFIG_RANDPOOL_TIMER 1 +/** Enable kfile_gets() and kfile_gets_echo() */ +#define CONFIG_KFILE_GETS 1 + +#define CONFIG_TEST 0 + + #endif /* APPCONFIG_H */ diff --git a/app/battfs/battfs_test.c b/app/battfs/battfs_test.c index 8fe38a3f..183d6c8a 100644 --- a/app/battfs/battfs_test.c +++ b/app/battfs/battfs_test.c @@ -98,39 +98,33 @@ static bool disk_close(struct BattFsSuper *d) static void testCheck(BattFsSuper *disk, pgcnt_t *reference) { - if (battfs_init(disk)) + ASSERT(battfs_init(disk)); + + for (int i = 0; i < disk->page_count; i++) { - for (int i = 0; i < disk->page_count; i++) + if (disk->page_array[i] != reference[i]) { - if (disk->page_array[i] != reference[i]) + kprintf("Error at addr %d: page_array read", i); + for (pgcnt_t i = 0; i < disk->page_count; i++) { - kprintf("Error at addr %d: page_array read", i); - for (pgcnt_t i = 0; i < disk->page_count; i++) - { - if (!(i % 16)) - kputchar('\n'); - kprintf("%04d ", disk->page_array[i]); - } - kputchar('\n'); - kprintf("Expected:"); - for (pgcnt_t i = 0; i < disk->page_count; i++) - { - if (!(i % 16)) - kputchar('\n'); - kprintf("%04d ", reference[i]); - } - kputchar('\n'); - battfs_close(disk); - exit(2); + if (!(i % 16)) + kputchar('\n'); + kprintf("%04d ", disk->page_array[i]); } + kputchar('\n'); + kprintf("Expected:"); + for (pgcnt_t i = 0; i < disk->page_count; i++) + { + if (!(i % 16)) + kputchar('\n'); + kprintf("%04d ", reference[i]); + } + kputchar('\n'); + battfs_close(disk); + exit(2); } - battfs_close(disk); - } - else - { - kprintf("Error in battfs_init\n"); - exit(1); } + battfs_close(disk); } static void test1(BattFsSuper *disk) @@ -355,6 +349,59 @@ static void test9(BattFsSuper *disk) kprintf("Test9: passed\n"); } +static void test10(BattFsSuper *disk) +{ + KFileBattFs fd1; + KFileBattFs fd2; + kprintf("Test10: open file test, inode 0 and inode 4\n"); + + fp = fopen(test_filename, "w+"); + + #define PAGE_FILL 116 + #define INODE 0 + #define INODE2 4 + #define MODE 0 + + battfs_writeTestBlock(disk, 0, INODE, 0, PAGE_FILL, 0, 1235); + battfs_writeTestBlock(disk, 1, INODE, 0, PAGE_FILL, 0, MARK_PAGE_VALID); + battfs_writeTestBlock(disk, 2, INODE, 3, PAGE_FILL, 1, MARK_PAGE_VALID); + battfs_writeTestBlock(disk, 3, INODE, 0, PAGE_FILL, 1, MARK_PAGE_VALID); + battfs_writeTestBlock(disk, 4, INODE2, 0, PAGE_FILL, 0, 1236); + battfs_writeTestBlock(disk, 5, INODE2, 0, PAGE_FILL, 0, MARK_PAGE_VALID); + battfs_writeTestBlock(disk, 6, INODE2, 1, PAGE_FILL, 1, MARK_PAGE_VALID); + battfs_writeTestBlock(disk, 7, INODE2, 0, PAGE_FILL, 1, MARK_PAGE_VALID); + + fclose(fp); + + ASSERT(battfs_init(disk)); + + ASSERT(battfs_fileopen(disk, &fd1, INODE, MODE)); + ASSERT(fd1.fd.size == PAGE_FILL * 2); + ASSERT(fd1.fd.seek_pos == 0); + ASSERT(fd1.mode == MODE); + ASSERT(fd1.inode == INODE); + ASSERT(fd1.start == &disk->page_array[0]); + ASSERT(fd1.disk == disk); + ASSERT(LIST_HEAD(&disk->file_opened_list) == &fd1.link); + + ASSERT(battfs_fileopen(disk, &fd2, INODE2, MODE)); + ASSERT(fd2.fd.size == PAGE_FILL * 2); + ASSERT(fd2.fd.seek_pos == 0); + ASSERT(fd2.mode == MODE); + ASSERT(fd2.inode == INODE2); + ASSERT(fd2.start == &disk->page_array[2]); + ASSERT(fd2.disk == disk); + ASSERT(LIST_HEAD(&disk->file_opened_list)->succ == &fd2.link); + + ASSERT(kfile_close(&fd1.fd) == 0); + ASSERT(kfile_close(&fd2.fd) == 0); + ASSERT(LIST_EMPTY(&disk->file_opened_list)); + ASSERT(battfs_close(disk)); + + kprintf("Test10: passed\n"); +} + + @@ -376,6 +423,7 @@ int main(void) test7(&disk); test8(&disk); test9(&disk); + test10(&disk); kprintf("All test passed!\n"); return 0; diff --git a/app/battfs/battfs_test.mk b/app/battfs/battfs_test.mk index 5df84bf7..434128e7 100644 --- a/app/battfs/battfs_test.mk +++ b/app/battfs/battfs_test.mk @@ -17,7 +17,8 @@ TRG += battfs_test battfs_test_CSRC = \ fs/battfs.c \ - app/battfs/battfs_test.c + app/battfs/battfs_test.c \ + kern/kfile.c battfs_test_CFLAGS = -O0 -D'ARCH=ARCH_EMUL' -D_EMUL -Iapp/battfs -Ihw -g3 -- 2.34.1