From 8bb6586942ab1c96fa1c52c7ebb04a6eb84e4923 Mon Sep 17 00:00:00 2001 From: wuyangyong Date: Thu, 17 Mar 2011 14:01:01 +0000 Subject: add test git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1334 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- examples/test/fs_test.c | 278 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 examples/test/fs_test.c (limited to 'examples/test/fs_test.c') diff --git a/examples/test/fs_test.c b/examples/test/fs_test.c new file mode 100644 index 0000000000..ab0b64ce14 --- /dev/null +++ b/examples/test/fs_test.c @@ -0,0 +1,278 @@ +/* + * File : fs_test.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2011, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://openlab.rt-thread.com/license/LICENSE. + * + * Change Logs: + * Date Author Notes + * 2011-01-02 aozima the first version. + * 2011-03-17 aozima fix some bug. + */ + +#include +#include + +static rt_uint32_t stop_flag = 0; + +#define fsrw1_fn "/test1.dat" +#define fsrw1_data_len 120 /* Less than 256 */ + +static struct rt_thread fsrw1_thread; +static rt_uint32_t fsrw1_stack[1024/sizeof(rt_uint32_t)]; +static void fsrw1_thread_entry(void* parameter) +{ + int fd; + int index,length; + rt_uint32_t round; + rt_uint32_t tick_start,tick_end,read_speed,write_speed; + + static rt_uint8_t write_data1[fsrw1_data_len]; + static rt_uint8_t read_data1[fsrw1_data_len]; + + round = 1; + + while(1) + { + if( stop_flag ) + { + rt_kprintf("thread fsrw2 error,thread fsrw1 quit!\r\n"); + return; + } + + /* creat file */ + fd = open(fsrw1_fn, O_WRONLY | O_CREAT | O_TRUNC, 0); + if (fd < 0) + { + rt_kprintf("fsrw1 open file for write failed\n"); + stop_flag = 1; + return; + } + + /* plan write data */ + for (index = 0; index < fsrw1_data_len; index ++) + { + write_data1[index] = index; + } + + /* write 8000 times */ + tick_start = rt_tick_get(); + for(index=0; index<8000; index++) + { + length = write(fd, write_data1, fsrw1_data_len); + if (length != fsrw1_data_len) + { + rt_kprintf("fsrw1 write data failed\n"); + close(fd); + stop_flag = 1; + return; + } + } + tick_end = rt_tick_get(); + write_speed = fsrw1_data_len*8000UL*RT_TICK_PER_SECOND/(tick_end-tick_start); + + /* close file */ + close(fd); + + /* open file read only */ + fd = open(fsrw1_fn, O_RDONLY, 0); + if (fd < 0) + { + rt_kprintf("fsrw1 open file for read failed\n"); + stop_flag = 1; + return; + } + + /* verify data */ + tick_start = rt_tick_get(); + for(index=0; index<8000; index++) + { + rt_uint32_t i; + + length = read(fd, read_data1, fsrw1_data_len); + if (length != fsrw1_data_len) + { + rt_kprintf("fsrw1 read file failed\r\n"); + close(fd); + stop_flag = 1; + return; + } + for(i=0; i +FINSH_FUNCTION_EXPORT(fs_test, file system R/W test. e.g: fs_test(3)); +#endif -- cgit v1.3.1