Merge branch 'bugfix/fatfs_perf_test' into 'master'

fatfs: bypass newlib buffering in performance test

See merge request idf/esp-idf!4076
This commit is contained in:
Ivan Grokhotkov 2019-01-11 14:05:58 +08:00
commit da15be6dd0

View file

@ -696,20 +696,20 @@ void test_fatfs_concurrent(const char* filename_prefix)
vSemaphoreDelete(args4.done);
}
void test_fatfs_rw_speed(const char* filename, void* buf, size_t buf_size, size_t file_size, bool write)
void test_fatfs_rw_speed(const char* filename, void* buf, size_t buf_size, size_t file_size, bool is_write)
{
const size_t buf_count = file_size / buf_size;
FILE* f = fopen(filename, (write) ? "wb" : "rb");
FILE* f = fopen(filename, (is_write) ? "wb" : "rb");
TEST_ASSERT_NOT_NULL(f);
struct timeval tv_start;
gettimeofday(&tv_start, NULL);
for (size_t n = 0; n < buf_count; ++n) {
if (write) {
TEST_ASSERT_EQUAL(1, fwrite(buf, buf_size, 1, f));
if (is_write) {
TEST_ASSERT_EQUAL(buf_size, write(fileno(f), buf, buf_size));
} else {
if (fread(buf, buf_size, 1, f) != 1) {
if (read(fileno(f), buf, buf_size) != buf_size) {
printf("reading at n=%d, eof=%d", n, feof(f));
TEST_FAIL();
}
@ -723,6 +723,6 @@ void test_fatfs_rw_speed(const char* filename, void* buf, size_t buf_size, size_
float t_s = tv_end.tv_sec - tv_start.tv_sec + 1e-6f * (tv_end.tv_usec - tv_start.tv_usec);
printf("%s %d bytes (block size %d) in %.3fms (%.3f MB/s)\n",
(write)?"Wrote":"Read", file_size, buf_size, t_s * 1e3,
(is_write)?"Wrote":"Read", file_size, buf_size, t_s * 1e3,
file_size / (1024.0f * 1024.0f * t_s));
}