2010-02-10 13:03:36 +08:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2010-01-20 07:30:28 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
#include <dfs_posix.h>
|
|
|
|
|
|
|
|
void readspeed(const char* filename, int block_size)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
char *buff_ptr;
|
|
|
|
rt_size_t total_length;
|
|
|
|
rt_tick_t tick;
|
|
|
|
|
2010-02-11 23:59:25 +08:00
|
|
|
fd = open(filename, 0, O_RDONLY);
|
2010-01-20 07:30:28 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
tick = rt_tick_get();
|
|
|
|
total_length = 0;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
length = read(fd, buff_ptr, block_size);
|
|
|
|
|
2010-02-11 23:59:25 +08:00
|
|
|
if (length <= 0) break;
|
2010-01-20 07:30:28 +08:00
|
|
|
total_length += length;
|
|
|
|
}
|
|
|
|
tick = rt_tick_get() - tick;
|
|
|
|
|
|
|
|
/* close file and release memory */
|
|
|
|
close(fd);
|
|
|
|
rt_free(buff_ptr);
|
|
|
|
|
|
|
|
/* calculate read speed */
|
2012-01-11 19:19:41 +08:00
|
|
|
rt_kprintf("File read speed: %d byte/s\n", total_length /tick * RT_TICK_PER_SECOND);
|
2010-01-20 07:30:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RT_USING_FINSH
|
|
|
|
#include <finsh.h>
|
|
|
|
FINSH_FUNCTION_EXPORT(readspeed, perform file read test);
|
|
|
|
#endif
|