diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2014-01-08 18:07:08 +0100 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2014-01-08 18:07:08 +0100 |
commit | 4e4e5a0323e586e5b7c28e3fbc29ef69185518d6 (patch) | |
tree | a210ba4570f73d819e51276046d8690bb81b9f0a /src/systemcmds/tests | |
parent | ab407a82bad3da5c7f4912f78dd69d466a4b4e0d (diff) | |
parent | 184f4a29eb010413a27cabedbcbc348ef1af7100 (diff) | |
download | px4-firmware-4e4e5a0323e586e5b7c28e3fbc29ef69185518d6.tar.gz px4-firmware-4e4e5a0323e586e5b7c28e3fbc29ef69185518d6.tar.bz2 px4-firmware-4e4e5a0323e586e5b7c28e3fbc29ef69185518d6.zip |
Merge branch 'master' into mount_tests
Diffstat (limited to 'src/systemcmds/tests')
-rw-r--r-- | src/systemcmds/tests/test_file.c | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/systemcmds/tests/test_file.c b/src/systemcmds/tests/test_file.c index 419e8d5e9..7206b87d6 100644 --- a/src/systemcmds/tests/test_file.c +++ b/src/systemcmds/tests/test_file.c @@ -40,6 +40,7 @@ */ #include <sys/stat.h> +#include <poll.h> #include <dirent.h> #include <stdio.h> #include <stddef.h> @@ -53,6 +54,38 @@ #include "tests.h" +int check_user_abort(); + +int check_user_abort() { + /* check if user wants to abort */ + char c; + + struct pollfd fds; + int ret; + fds.fd = 0; /* stdin */ + fds.events = POLLIN; + ret = poll(&fds, 1, 0); + + if (ret > 0) { + + read(0, &c, 1); + + switch (c) { + case 0x03: // ctrl-c + case 0x1b: // esc + case 'c': + case 'q': + { + warnx("Test aborted."); + return OK; + /* not reached */ + } + } + } + + return 1; +} + int test_file(int argc, char *argv[]) { @@ -108,6 +141,9 @@ test_file(int argc, char *argv[]) fsync(fd); + if (!check_user_abort()) + return OK; + } end = hrt_absolute_time(); @@ -139,6 +175,9 @@ test_file(int argc, char *argv[]) return 1; } + if (!check_user_abort()) + return OK; + } /* @@ -149,7 +188,7 @@ test_file(int argc, char *argv[]) int ret = unlink("/fs/microsd/testfile"); fd = open("/fs/microsd/testfile", O_TRUNC | O_WRONLY | O_CREAT); - warnx("testing aligned writes - please wait.."); + warnx("testing aligned writes - please wait.. (CTRL^C to abort)"); start = hrt_absolute_time(); for (unsigned i = 0; i < iterations; i++) { @@ -160,6 +199,9 @@ test_file(int argc, char *argv[]) return 1; } + if (!check_user_abort()) + return OK; + } fsync(fd); @@ -189,6 +231,9 @@ test_file(int argc, char *argv[]) align_read_ok = false; break; } + + if (!check_user_abort()) + return OK; } if (!align_read_ok) { @@ -229,6 +274,9 @@ test_file(int argc, char *argv[]) if (unalign_read_err_count > 10) break; } + + if (!check_user_abort()) + return OK; } if (!unalign_read_ok) { |