forked from Archive/PX4-Autopilot
More testing output
This commit is contained in:
parent
8407677f20
commit
e0e708241b
|
@ -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);
|
||||
|
||||
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");
|
||||
|
||||
close(fd);
|
||||
|
||||
/* list directory */
|
||||
DIR *d;
|
||||
struct dirent *dir;
|
||||
|
|
Loading…
Reference in New Issue