From 2812d9d74c79b3bfbca9b565064e137d21fa3171 Mon Sep 17 00:00:00 2001 From: batt Date: Fri, 19 Sep 2008 19:22:07 +0000 Subject: [PATCH] Add first write test. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1820 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/fs/battfs_test.c | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/bertos/fs/battfs_test.c b/bertos/fs/battfs_test.c index 1bcb037e..2204a216 100644 --- a/bertos/fs/battfs_test.c +++ b/bertos/fs/battfs_test.c @@ -537,6 +537,52 @@ static void test12(BattFsSuper *disk) } +static void test13(BattFsSuper *disk) +{ + BattFs fd1; + uint8_t buf[16]; + + kprintf("Test13: write file test\n"); + + fp = fopen(test_filename, "w+"); + + unsigned int PAGE_FILL = PAGE_SIZE - BATTFS_HEADER_LEN; + unsigned int INODE = 0; + unsigned int INODE2 = 4; + unsigned int MODE = 0; + + disk->erase(disk, 0); + battfs_writeTestBlock(disk, 1, INODE, 0, PAGE_FILL, 0); + battfs_writeTestBlock(disk, 2, INODE, 3, PAGE_FILL, 1); + battfs_writeTestBlock(disk, 3, INODE, 0, PAGE_FILL, 1); + disk->erase(disk, 4); + battfs_writeTestBlock(disk, 5, INODE2, 0, PAGE_FILL, 0); + battfs_writeTestBlock(disk, 6, INODE2, 1, PAGE_FILL, 1); + battfs_writeTestBlock(disk, 7, INODE2, 0, PAGE_FILL, 1); + + fclose(fp); + + for (size_t i = 0; i < sizeof(buf); i++) + buf[i] = i; + + ASSERT(battfs_init(disk)); + ASSERT(battfs_fileopen(disk, &fd1, INODE, MODE)); + ASSERT(kfile_write(&fd1.fd, buf, sizeof(buf)) == sizeof(buf)); + ASSERT(fd1.fd.seek_pos == sizeof(buf)); + ASSERT(kfile_seek(&fd1.fd, 0, KSM_SEEK_SET) == 0); + ASSERT(fd1.fd.seek_pos == 0); + memset(buf, 0, sizeof(buf)); + ASSERT(kfile_read(&fd1.fd, buf, sizeof(buf)) == sizeof(buf)); + + for (size_t i = 0; i < sizeof(buf); i++) + ASSERT(buf[i] == i); + + ASSERT(kfile_close(&fd1.fd) == 0); + ASSERT(battfs_close(disk)); + + kprintf("Test13: passed\n"); +} + int battfs_testRun(void) { BattFsSuper disk; @@ -560,6 +606,7 @@ int battfs_testRun(void) test10(&disk); test11(&disk); test12(&disk); + test13(&disk); kprintf("All tests passed!\n"); return 0; -- 2.25.1