diff --git a/examples/file/listdir.c b/examples/file/listdir.c new file mode 100644 index 0000000000..86279163e5 --- /dev/null +++ b/examples/file/listdir.c @@ -0,0 +1,55 @@ +/* + * File : listdir.c + * This file is part of RT-TestCase in RT-Thread RTOS + * COPYRIGHT (C) 2010, 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://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2010-02-10 Bernard first version + */ +#include +#include + +void list_dir(const char* path) +{ + DIR *dir; + + dir = opendir(path); + if (dir != RT_NULL) + { + struct dfs_dirent* dirent; + struct dfs_stat s; + + do + { + dirent = readdir(dir); + if (dirent == RT_NULL) break; + rt_memset(&s, 0, sizeof(struct dfs_stat)); + + /* build full path for each file */ + rt_sprintf(fullpath, "/%s", dirent->d_name); + + stat(fullpath, &s); + if ( s.st_mode & DFS_S_IFDIR ) + { + rt_kprintf("%s\t\t\n", dirent->d_name); + } + else + { + rt_kprintf("%s\t\t%lu\n", dirent->d_name, s.st_size); + } + } while (dirent != RT_NULL); + + closedir(dir); + } + else rt_kprintf("open %s directory failed\n", path); +} + +#ifdef RT_USING_FINSH +#include +FINSH_FUNCTION_EXPORT(list_dir, list directory); +#endif diff --git a/examples/file/readspeed.c b/examples/file/readspeed.c index e76471fb47..5d22756365 100644 --- a/examples/file/readspeed.c +++ b/examples/file/readspeed.c @@ -1,3 +1,17 @@ +/* + * File : readspeed.c + * This file is part of RT-TestCase in RT-Thread RTOS + * COPYRIGHT (C) 2010, 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://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2010-02-10 Bernard first version + */ + #include #include diff --git a/examples/file/readwrite.c b/examples/file/readwrite.c new file mode 100644 index 0000000000..b4086cf056 --- /dev/null +++ b/examples/file/readwrite.c @@ -0,0 +1,34 @@ +/* + * File : readwrite.c + * This file is part of RT-TestCase in RT-Thread RTOS + * COPYRIGHT (C) 2010, 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://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2010-02-10 Bernard first version + */ +#include +#include + +/* 文件读写测试 */ +void readwrite(const char* filename) +{ + int fd; + + /* 只写打开 */ + + /* 只写并在末尾添加打开 */ + + /* 只读打开进行数据校验 */ + + /* lseek测试,读出并校验数据 */ +} + +#ifdef RT_USING_FINSH +#include +FINSH_FUNCTION_EXPORT(readwrite, perform file read and write test); +#endif diff --git a/examples/file/writespeed.c b/examples/file/writespeed.c new file mode 100644 index 0000000000..d829d9977b --- /dev/null +++ b/examples/file/writespeed.c @@ -0,0 +1,56 @@ +/* + * File : writespeed.c + * This file is part of RT-TestCase in RT-Thread RTOS + * COPYRIGHT (C) 2010, 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://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2010-02-10 Bernard first version + */ +#include +#include + +void writespeed(const char* filename, int total_length, int block_size) +{ + int fd; + char *buff_ptr; + rt_tick_t tick; + + fd = open(filename, 0, O_WRONLY); + if (fd < 0) + { + rt_kprintf("open file:%s failed\n", filename); + return; + } + + buff_ptr = rt_malloc(block_size); + if (buff_ptr == RT_NULL) + { + rt_kprintf("no memory\n"); + close(fd); + + return; + } + + /* prepare write data */ + + tick = rt_tick_get(); + + tick = rt_tick_get() - tick; + + /* close file and release memory */ + close(fd); + rt_free(buff_ptr); + + /* calculate write speed */ + rt_kprintf("File write speed: %d byte/s\n", total_length/ (tick/RT_TICK_PER_SECOND)); +} + +#ifdef RT_USING_FINSH +#include +FINSH_FUNCTION_EXPORT(writespeed, perform file write test); +#endif