Fixed error handling logic, we want to return, not exit

This commit is contained in:
Lorenz Meier 2014-01-07 08:02:47 +01:00
parent 4f95ce3dc2
commit 9886a384ff
1 changed files with 22 additions and 20 deletions

View File

@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
* Copyright (c) 2012-2014 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -35,6 +35,8 @@
* @file test_file.c
*
* File write test.
*
* @author Lorenz Meier <lm@inf.ethz.ch>
*/
#include <sys/stat.h>
@ -86,7 +88,6 @@ test_file(int argc, char *argv[])
uint8_t read_buf[chunk_sizes[c] + alignments] __attribute__((aligned(64)));
hrt_abstime start, end;
//perf_counter_t wperf = perf_alloc(PC_ELAPSED, "SD writes (aligned)");
int fd = open("/fs/microsd/testfile", O_TRUNC | O_WRONLY | O_CREAT);
@ -94,29 +95,22 @@ test_file(int argc, char *argv[])
start = hrt_absolute_time();
for (unsigned i = 0; i < iterations; i++) {
//perf_begin(wperf);
int wret = write(fd, write_buf + a, chunk_sizes[c]);
if (wret != chunk_sizes[c]) {
warn("WRITE ERROR!");
if ((0x3 & (uintptr_t)(write_buf + a)))
errx(1, "memory is unaligned, align shift: %d", a);
warnx("memory is unaligned, align shift: %d", a);
return 1;
}
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);
close(fd);
fd = open("/fs/microsd/testfile", O_RDONLY);
@ -125,7 +119,8 @@ test_file(int argc, char *argv[])
int rret = read(fd, read_buf, chunk_sizes[c]);
if (rret != chunk_sizes[c]) {
errx(1, "READ ERROR!");
warnx("READ ERROR!");
return 1;
}
/* compare value */
@ -161,7 +156,8 @@ test_file(int argc, char *argv[])
int wret = write(fd, write_buf, chunk_sizes[c]);
if (wret != chunk_sizes[c]) {
err(1, "WRITE ERROR!");
warnx("WRITE ERROR!");
return 1;
}
}
@ -180,7 +176,8 @@ test_file(int argc, char *argv[])
int rret = read(fd, read_buf, chunk_sizes[c]);
if (rret != chunk_sizes[c]) {
err(1, "READ ERROR!");
warnx("READ ERROR!");
return 1;
}
/* compare value */
@ -195,7 +192,8 @@ test_file(int argc, char *argv[])
}
if (!align_read_ok) {
errx(1, "ABORTING FURTHER COMPARISON DUE TO ERROR");
warnx("ABORTING FURTHER COMPARISON DUE TO ERROR");
return 1;
}
}
@ -217,7 +215,8 @@ test_file(int argc, char *argv[])
int rret = read(fd, read_buf + a, chunk_sizes[c]);
if (rret != chunk_sizes[c]) {
err(1, "READ ERROR!");
warnx("READ ERROR!");
return 1;
}
for (int j = 0; j < chunk_sizes[c]; j++) {
@ -233,7 +232,8 @@ test_file(int argc, char *argv[])
}
if (!unalign_read_ok) {
errx(1, "ABORTING FURTHER COMPARISON DUE TO ERROR");
warnx("ABORTING FURTHER COMPARISON DUE TO ERROR");
return 1;
}
}
@ -241,9 +241,10 @@ test_file(int argc, char *argv[])
ret = unlink("/fs/microsd/testfile");
close(fd);
if (ret)
err(1, "UNLINKING FILE FAILED");
if (ret) {
warnx("UNLINKING FILE FAILED");
return 1;
}
}
}
@ -263,7 +264,8 @@ test_file(int argc, char *argv[])
} else {
/* failed opening dir */
err(1, "FAILED LISTING MICROSD ROOT DIRECTORY");
warnx("FAILED LISTING MICROSD ROOT DIRECTORY");
return 1;
}
return 0;