From 21dcdf11cf8f05d94b17cd0b5cce058b45ee3923 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Thu, 10 Oct 2013 00:14:03 +0200 Subject: WIP, typo fix --- src/systemcmds/tests/tests_file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/systemcmds/tests/tests_file.c b/src/systemcmds/tests/tests_file.c index e9db4716d..58eeb6fdf 100644 --- a/src/systemcmds/tests/tests_file.c +++ b/src/systemcmds/tests/tests_file.c @@ -82,7 +82,7 @@ test_file(int argc, char *argv[]) start = hrt_absolute_time(); for (unsigned i = 0; i < iterations; i++) { perf_begin(wperf); - int wret = write(fd, write_buf + (i % 64), 512); + int wret = write(fd, write_buf + 1/*+ (i % 64)*/, 512); if (wret != 512) { warn("WRITE ERROR!"); @@ -109,7 +109,7 @@ test_file(int argc, char *argv[]) /* read back data for validation */ for (unsigned i = 0; i < iterations; i++) { - int rret = read(fd, read_buf, 512); + int rret = read(fd, read_buf + 0, 512); if (rret != 512) { warn("READ ERROR!"); @@ -120,7 +120,7 @@ test_file(int argc, char *argv[]) bool compare_ok = true; for (int j = 0; j < 512; j++) { - if (read_buf[j] != write_buf[j + 1/*+ (i % 64)*/]) { + if ((read_buf + 0)[j] != write_buf[j + 1/*+ (i % 64)*/]) { warnx("COMPARISON ERROR: byte %d, align shift: %d", j, (i % 64)); compare_ok = false; break; -- cgit v1.2.3 From 8407677f20ecc7ea5374a0ded41263ede019d9f6 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Thu, 10 Oct 2013 00:15:39 +0200 Subject: Updated error message --- src/systemcmds/tests/tests_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/systemcmds/tests/tests_file.c b/src/systemcmds/tests/tests_file.c index 58eeb6fdf..ab3dd7830 100644 --- a/src/systemcmds/tests/tests_file.c +++ b/src/systemcmds/tests/tests_file.c @@ -121,7 +121,7 @@ test_file(int argc, char *argv[]) for (int j = 0; j < 512; j++) { if ((read_buf + 0)[j] != write_buf[j + 1/*+ (i % 64)*/]) { - warnx("COMPARISON ERROR: byte %d, align shift: %d", j, (i % 64)); + warnx("COMPARISON ERROR: byte %d, align shift: %d", j, 1/*(i % 64)*/); compare_ok = false; break; } -- cgit v1.2.3 From e0e708241b965f364fd49fa0d2270de5ad517a70 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Thu, 10 Oct 2013 08:34:08 +0200 Subject: More testing output --- src/systemcmds/tests/tests_file.c | 126 +++++++++++++++++++++++++++++++++----- 1 file changed, 112 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/systemcmds/tests/tests_file.c b/src/systemcmds/tests/tests_file.c index ab3dd7830..aa0e163d7 100644 --- a/src/systemcmds/tests/tests_file.c +++ b/src/systemcmds/tests/tests_file.c @@ -77,7 +77,7 @@ test_file(int argc, char *argv[]) int fd = open("/fs/microsd/testfile", O_TRUNC | O_WRONLY | O_CREAT); - warnx("testing aligned and unaligned writes - please wait.."); + warnx("testing unaligned writes - please wait.."); start = hrt_absolute_time(); for (unsigned i = 0; i < iterations; i++) { @@ -104,12 +104,11 @@ test_file(int argc, char *argv[]) perf_free(wperf); close(fd); - fd = open("/fs/microsd/testfile", O_RDONLY); /* read back data for validation */ for (unsigned i = 0; i < iterations; i++) { - int rret = read(fd, read_buf + 0, 512); + int rret = read(fd, read_buf, 512); if (rret != 512) { warn("READ ERROR!"); @@ -120,7 +119,7 @@ test_file(int argc, char *argv[]) bool compare_ok = true; for (int j = 0; j < 512; j++) { - if ((read_buf + 0)[j] != write_buf[j + 1/*+ (i % 64)*/]) { + if (read_buf[j] != write_buf[j + 1/*+ (i % 64)*/]) { warnx("COMPARISON ERROR: byte %d, align shift: %d", j, 1/*(i % 64)*/); compare_ok = false; break; @@ -134,22 +133,121 @@ test_file(int argc, char *argv[]) } - /* read back data for alignment checks */ - // for (unsigned i = 0; i < iterations; i++) { - // perf_begin(wperf); - // int rret = read(fd, buf + (i % 64), sizeof(buf)); - // fsync(fd); - // perf_end(wperf); - - // } + /* + * ALIGNED WRITES AND UNALIGNED READS + */ int ret = unlink("/fs/microsd/testfile"); + fd = open("/fs/microsd/testfile", O_TRUNC | O_WRONLY | O_CREAT); - if (ret) - err(1, "UNLINKING FILE FAILED"); + warnx("testing aligned writes - please wait.."); + + start = hrt_absolute_time(); + for (unsigned i = 0; i < iterations; i++) { + perf_begin(wperf); + int wret = write(fd, write_buf, 512); + + if (wret != 512) { + warn("WRITE ERROR!"); + } + + perf_end(wperf); + + } + + fsync(fd); + + warnx("reading data aligned.."); + + close(fd); + fd = open("/fs/microsd/testfile", O_RDONLY); + + bool align_read_ok = true; + + /* read back data unaligned */ + for (unsigned i = 0; i < iterations; i++) { + int rret = read(fd, read_buf, 512); + + if (rret != 512) { + warn("READ ERROR!"); + break; + } + + /* compare value */ + bool compare_ok = true; + + for (int j = 0; j < 512; j++) { + if (read_buf[j] != write_buf[j]) { + warnx("COMPARISON ERROR: byte %d: %u != %u", j, (unsigned int)read_buf[j], (unsigned int)write_buf[j]); + align_read_ok = false; + break; + } + } + + if (!align_read_ok) { + warnx("ABORTING FURTHER COMPARISON DUE TO ERROR"); + break; + } + + } + + warnx("align read result: %s\n", (align_read_ok) ? "OK" : "ERROR"); + + warnx("reading data unaligned.."); + + close(fd); + fd = open("/fs/microsd/testfile", O_RDONLY); + + bool unalign_read_ok = true; + int unalign_read_err_count = 0; + + memset(read_buf, 0, sizeof(read_buf)); + read_buf[0] = 0; + + warnx("printing first 10 pairs:"); + + uint8_t *read_ptr = &read_buf[1]; + + /* read back data unaligned */ + for (unsigned i = 0; i < iterations; i++) { + int rret = read(fd, read_ptr, 512); + + warnx("first byte: %u (should be zero)", (unsigned int)read_buf[0]); + + if (rret != 512) { + warn("READ ERROR!"); + break; + } + + for (int j = 0; j < 512; j++) { + + if (i == 0 && j < 10) { + warnx("read: %u, expect: %u", (unsigned int)(read_buf + 1)[j], (unsigned int)write_buf[j]); + } + + if ((read_buf + 1)[j] != write_buf[j]) { + warnx("COMPARISON ERROR: byte %d, align shift: %d: %u != %u", j, 1/*(i % 64)*/, (unsigned int)read_buf[j], (unsigned int)write_buf[j]); + unalign_read_ok = false; + unalign_read_err_count++; + + if (unalign_read_err_count > 10) + break; + } + } + if (!unalign_read_ok) { + warnx("ABORTING FURTHER COMPARISON DUE TO ERROR"); + break; + } + + } + + ret = unlink("/fs/microsd/testfile"); close(fd); + if (ret) + err(1, "UNLINKING FILE FAILED"); + /* list directory */ DIR *d; struct dirent *dir; -- cgit v1.2.3 From 6ffa2955b919a18abd94dd990c3447dfc68dd5c2 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Thu, 10 Oct 2013 08:37:24 +0200 Subject: Typo in debug output --- src/systemcmds/tests/tests_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/systemcmds/tests/tests_file.c b/src/systemcmds/tests/tests_file.c index aa0e163d7..14532e48c 100644 --- a/src/systemcmds/tests/tests_file.c +++ b/src/systemcmds/tests/tests_file.c @@ -226,7 +226,7 @@ test_file(int argc, char *argv[]) } if ((read_buf + 1)[j] != write_buf[j]) { - warnx("COMPARISON ERROR: byte %d, align shift: %d: %u != %u", j, 1/*(i % 64)*/, (unsigned int)read_buf[j], (unsigned int)write_buf[j]); + warnx("COMPARISON ERROR: byte %d, align shift: %d: %u != %u", j, 1/*(i % 64)*/, (unsigned int)read_ptr[j], (unsigned int)write_buf[j]); unalign_read_ok = false; unalign_read_err_count++; -- cgit v1.2.3 From 6745a910718b2a5fed313187f77a04de383aa8f7 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Thu, 10 Oct 2013 08:42:54 +0200 Subject: Added alignment attribute --- src/systemcmds/tests/tests_file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/systemcmds/tests/tests_file.c b/src/systemcmds/tests/tests_file.c index 14532e48c..3c0c48cfe 100644 --- a/src/systemcmds/tests/tests_file.c +++ b/src/systemcmds/tests/tests_file.c @@ -63,7 +63,7 @@ test_file(int argc, char *argv[]) return 1; } - uint8_t write_buf[512 + 64]; + uint8_t write_buf[512 + 64] __attribute__((aligned(64))); /* fill write buffer with known values */ for (int i = 0; i < sizeof(write_buf); i++) { @@ -71,7 +71,7 @@ test_file(int argc, char *argv[]) write_buf[i] = i+11; } - uint8_t read_buf[512 + 64]; + uint8_t read_buf[512 + 64] __attribute__((aligned(64))); hrt_abstime start, end; perf_counter_t wperf = perf_alloc(PC_ELAPSED, "SD writes (aligned)"); @@ -87,8 +87,8 @@ test_file(int argc, char *argv[]) if (wret != 512) { warn("WRITE ERROR!"); - if ((0x3 & (uintptr_t)(write_buf + (i % 64)))) - warnx("memory is unaligned, align shift: %d", (i % 64)); + if ((0x3 & (uintptr_t)(write_buf + 1 /* (i % 64)*/))) + warnx("memory is unaligned, align shift: %d", 1/*(i % 64)*/); } -- cgit v1.2.3