aboutsummaryrefslogtreecommitdiff
path: root/src/systemcmds
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2013-09-27 09:24:49 +0200
committerLorenz Meier <lm@inf.ethz.ch>2013-09-27 09:24:49 +0200
commit2c54e827eddef56ff36798159fd119d94627a6eb (patch)
tree6b11dd5e48cafe4a7dc1af25d77eb20e253cac19 /src/systemcmds
parentf7090db7081922cc61e79fce800fb6bce84a3836 (diff)
downloadpx4-firmware-2c54e827eddef56ff36798159fd119d94627a6eb.tar.gz
px4-firmware-2c54e827eddef56ff36798159fd119d94627a6eb.tar.bz2
px4-firmware-2c54e827eddef56ff36798159fd119d94627a6eb.zip
Hotfix: Improved file test
Diffstat (limited to 'src/systemcmds')
-rw-r--r--src/systemcmds/tests/tests_file.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/src/systemcmds/tests/tests_file.c b/src/systemcmds/tests/tests_file.c
index 588d648bd..f36c28061 100644
--- a/src/systemcmds/tests/tests_file.c
+++ b/src/systemcmds/tests/tests_file.c
@@ -38,7 +38,9 @@
*/
#include <sys/stat.h>
+#include <dirent.h>
#include <stdio.h>
+#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>
#include <systemlib/err.h>
@@ -52,7 +54,7 @@
int
test_file(int argc, char *argv[])
{
- const iterations = 10;
+ const iterations = 200;
/* check if microSD card is mounted */
struct stat buffer;
@@ -63,15 +65,52 @@ test_file(int argc, char *argv[])
uint8_t buf[512];
hrt_abstime start, end;
- perf_counter_t wperf = perf_alloc(PC_ELAPSED, "SD writes");
+ perf_counter_t wperf = perf_alloc(PC_ELAPSED, "SD writes (aligned)");
int fd = open("/fs/microsd/testfile", O_TRUNC | O_WRONLY | O_CREAT);
memset(buf, 0, sizeof(buf));
+ warnx("aligned write - please wait..");
+
+ if ((0x3 & (uintptr_t)buf))
+ warnx("memory is unaligned!");
+
start = hrt_absolute_time();
for (unsigned i = 0; i < iterations; i++) {
perf_begin(wperf);
write(fd, buf, sizeof(buf));
+ fsync(fd);
+ perf_end(wperf);
+ }
+ end = hrt_absolute_time();
+
+ warnx("%dKiB in %llu microseconds", iterations / 2, end - start);
+
+ perf_print_counter(wperf);
+ perf_free(wperf);
+
+ int ret = unlink("/fs/microsd/testfile");
+
+ if (ret)
+ err(1, "UNLINKING FILE FAILED");
+
+ warnx("unaligned write - please wait..");
+
+ struct {
+ uint8_t byte;
+ uint8_t unaligned[512];
+ } unaligned_buf;
+
+ if ((0x3 & (uintptr_t)unaligned_buf.unaligned) == 0)
+ warnx("creating unaligned memory failed.");
+
+ wperf = perf_alloc(PC_ELAPSED, "SD writes (unaligned)");
+
+ start = hrt_absolute_time();
+ for (unsigned i = 0; i < iterations; i++) {
+ perf_begin(wperf);
+ write(fd, unaligned_buf.unaligned, sizeof(unaligned_buf.unaligned));
+ fsync(fd);
perf_end(wperf);
}
end = hrt_absolute_time();
@@ -79,9 +118,29 @@ test_file(int argc, char *argv[])
close(fd);
warnx("%dKiB in %llu microseconds", iterations / 2, end - start);
+
perf_print_counter(wperf);
perf_free(wperf);
+ /* list directory */
+ DIR *d;
+ struct dirent *dir;
+ d = opendir("/fs/microsd");
+ if (d) {
+
+ while ((dir = readdir(d)) != NULL) {
+ //printf("%s\n", dir->d_name);
+ }
+
+ closedir(d);
+
+ warnx("directory listing ok (FS mounted and readable)");
+
+ } else {
+ /* failed opening dir */
+ err(1, "FAILED LISTING MICROSD ROOT DIRECTORY");
+ }
+
return 0;
}
#if 0