aboutsummaryrefslogtreecommitdiff
path: root/src/systemcmds/tests
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2014-01-16 08:37:50 +0100
committerLorenz Meier <lm@inf.ethz.ch>2014-01-16 08:37:50 +0100
commitc304ea25077e1fd4675ef1d053cfc81e7e877b4b (patch)
treef40c6590ac3e29086e09732d05ff4b7a2b54a689 /src/systemcmds/tests
parente5ad3c31e01680ccd18fe64d113ecf05de080e71 (diff)
downloadpx4-firmware-c304ea25077e1fd4675ef1d053cfc81e7e877b4b.tar.gz
px4-firmware-c304ea25077e1fd4675ef1d053cfc81e7e877b4b.tar.bz2
px4-firmware-c304ea25077e1fd4675ef1d053cfc81e7e877b4b.zip
Teached MTD test how to write back 0xFF after destructive test
Diffstat (limited to 'src/systemcmds/tests')
-rw-r--r--src/systemcmds/tests/test_mtd.c120
1 files changed, 15 insertions, 105 deletions
diff --git a/src/systemcmds/tests/test_mtd.c b/src/systemcmds/tests/test_mtd.c
index bcd24e5c9..8a626b65c 100644
--- a/src/systemcmds/tests/test_mtd.c
+++ b/src/systemcmds/tests/test_mtd.c
@@ -180,117 +180,27 @@ test_mtd(int argc, char *argv[])
}
+
close(fd);
printf("RESULT: OK! No readback errors.\n\n");
+ }
- // /*
- // * ALIGNED WRITES AND UNALIGNED READS
- // */
-
-
- // fd = open(PARAM_FILE_NAME, O_WRONLY);
-
- // warnx("testing aligned writes - please wait.. (CTRL^C to abort)");
-
- // start = hrt_absolute_time();
- // for (unsigned i = 0; i < iterations; i++) {
- // int wret = write(fd, write_buf, chunk_sizes[c]);
-
- // if (wret != chunk_sizes[c]) {
- // warnx("WRITE ERROR!");
- // return 1;
- // }
-
- // if (!check_user_abort(fd))
- // return OK;
-
- // }
-
- // fsync(fd);
-
- // warnx("reading data aligned..");
-
- // close(fd);
- // fd = open(PARAM_FILE_NAME, O_RDONLY);
-
- // bool align_read_ok = true;
-
- // /* read back data unaligned */
- // for (unsigned i = 0; i < iterations; i++) {
- // int rret = read(fd, read_buf, chunk_sizes[c]);
-
- // if (rret != chunk_sizes[c]) {
- // warnx("READ ERROR!");
- // return 1;
- // }
-
- // /* compare value */
- // bool compare_ok = true;
-
- // for (int j = 0; j < chunk_sizes[c]; 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 (!check_user_abort(fd))
- // return OK;
- // }
-
- // if (!align_read_ok) {
- // warnx("ABORTING FURTHER COMPARISON DUE TO ERROR");
- // return 1;
- // }
-
- // }
-
- // warnx("align read result: %s\n", (align_read_ok) ? "OK" : "ERROR");
-
- // warnx("reading data unaligned..");
-
- // close(fd);
- // fd = open(PARAM_FILE_NAME, O_RDONLY);
-
- // bool unalign_read_ok = true;
- // int unalign_read_err_count = 0;
-
- // memset(read_buf, 0, sizeof(read_buf));
-
- // /* read back data unaligned */
- // for (unsigned i = 0; i < iterations; i++) {
- // int rret = read(fd, read_buf + a, chunk_sizes[c]);
-
- // if (rret != chunk_sizes[c]) {
- // warnx("READ ERROR!");
- // return 1;
- // }
-
- // for (int j = 0; j < chunk_sizes[c]; j++) {
-
- // if ((read_buf + a)[j] != write_buf[j]) {
- // warnx("COMPARISON ERROR: byte %d, align shift: %d: %u != %u", j, a, (unsigned int)read_buf[j + a], (unsigned int)write_buf[j]);
- // unalign_read_ok = false;
- // unalign_read_err_count++;
-
- // if (unalign_read_err_count > 10)
- // break;
- // }
-
- // if (!check_user_abort(fd))
- // return OK;
- // }
-
- // if (!unalign_read_ok) {
- // warnx("ABORTING FURTHER COMPARISON DUE TO ERROR");
- // return 1;
- // }
-
- // }
+ /* fill the file with 0xFF to make it look new again */
+ char ffbuf[64];
+ memset(ffbuf, 0xFF, sizeof(ffbuf));
+ int fd = open(PARAM_FILE_NAME, O_WRONLY);
+ for (int i = 0; i < file_size / sizeof(ffbuf); i++) {
+ int ret = write(fd, ffbuf, sizeof(ffbuf));
- // close(fd);
+ if (ret) {
+ warnx("ERROR! Could not fill file with 0xFF");
+ close(fd);
+ return 1;
+ }
}
+ (void)close(fd);
+
return 0;
}