diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2013-10-10 08:34:08 +0200 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2013-10-10 08:34:08 +0200 |
commit | e0e708241b965f364fd49fa0d2270de5ad517a70 (patch) | |
tree | 6391b563650cc4ac2148c3d5514833c038fea483 | |
parent | 8407677f20ecc7ea5374a0ded41263ede019d9f6 (diff) | |
download | px4-firmware-e0e708241b965f364fd49fa0d2270de5ad517a70.tar.gz px4-firmware-e0e708241b965f364fd49fa0d2270de5ad517a70.tar.bz2 px4-firmware-e0e708241b965f364fd49fa0d2270de5ad517a70.zip |
More testing output
-rw-r--r-- | src/systemcmds/tests/tests_file.c | 126 |
1 files changed, 112 insertions, 14 deletions
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; |