40 #include <px4_platform_common/px4_config.h> 41 #include <px4_platform_common/posix.h> 67 ret = poll(&fds, 1, 0);
78 warnx(
"Test aborted.");
93 const unsigned iterations = 100;
94 const unsigned alignments = 65;
99 if (stat(PX4_STORAGEDIR
"/", &buffer)) {
100 warnx(
"no microSD card mounted, aborting file test");
105 int chunk_sizes[] = {1, 5, 8, 13, 16, 32, 33, 64, 70, 128, 133, 256, 300, 512, 555, 1024, 1500};
107 for (
unsigned c = 0; c < (
sizeof(chunk_sizes) /
sizeof(chunk_sizes[0])); c++) {
109 printf(
"\n====== FILE TEST: %u bytes chunks ======\n", chunk_sizes[c]);
111 for (
unsigned a = 0; a < alignments; a++) {
114 warnx(
"----- alignment test: %u bytes -----", a);
116 uint8_t write_buf[chunk_sizes[c] + alignments]
__attribute__((aligned(64)));
119 for (
size_t i = 0; i <
sizeof(write_buf); i++) {
121 write_buf[i] = i + 11;
124 uint8_t read_buf[chunk_sizes[c] + alignments]
__attribute__((aligned(64)));
127 int fd =
px4_open(PX4_STORAGEDIR
"/testfile", O_TRUNC | O_WRONLY | O_CREAT);
129 warnx(
"testing unaligned writes - please wait..");
133 for (
unsigned i = 0; i < iterations; i++) {
134 int wret =
write(fd, write_buf + a, chunk_sizes[c]);
136 if (wret != chunk_sizes[c]) {
137 warn(
"WRITE ERROR!");
139 if ((0x3 & (uintptr_t)(write_buf + a))) {
140 warnx(
"memory is unaligned, align shift: %d", a);
156 warnx(
"write took %" PRIu64
" us", (end - start));
159 fd = open(PX4_STORAGEDIR
"/testfile", O_RDONLY);
162 for (
unsigned i = 0; i < iterations; i++) {
163 int rret =
read(fd, read_buf, chunk_sizes[c]);
165 if (rret != chunk_sizes[c]) {
166 warnx(
"READ ERROR!");
171 bool compare_ok =
true;
173 for (
int j = 0; j < chunk_sizes[c]; j++) {
174 if (read_buf[j] != write_buf[j + a]) {
175 warnx(
"COMPARISON ERROR: byte %d, align shift: %d", j, a);
182 warnx(
"ABORTING FURTHER COMPARISON DUE TO ERROR");
197 int ret = unlink(PX4_STORAGEDIR
"/testfile");
198 fd =
px4_open(PX4_STORAGEDIR
"/testfile", O_TRUNC | O_WRONLY | O_CREAT);
200 warnx(
"testing aligned writes - please wait.. (CTRL^C to abort)");
202 for (
unsigned i = 0; i < iterations; i++) {
203 int wret =
write(fd, write_buf, chunk_sizes[c]);
205 if (wret != chunk_sizes[c]) {
206 warnx(
"WRITE ERROR!");
218 warnx(
"reading data aligned..");
221 fd = open(PX4_STORAGEDIR
"/testfile", O_RDONLY);
223 bool align_read_ok =
true;
226 for (
unsigned i = 0; i < iterations; i++) {
227 int rret =
read(fd, read_buf, chunk_sizes[c]);
229 if (rret != chunk_sizes[c]) {
230 warnx(
"READ ERROR!");
234 for (
int j = 0; j < chunk_sizes[c]; j++) {
235 if (read_buf[j] != write_buf[j]) {
236 warnx(
"COMPARISON ERROR: byte %d: %u != %u", j, (
unsigned int)read_buf[j], (
unsigned int)write_buf[j]);
237 align_read_ok =
false;
246 if (!align_read_ok) {
247 warnx(
"ABORTING FURTHER COMPARISON DUE TO ERROR");
253 warnx(
"align read result: %s\n", (align_read_ok) ?
"OK" :
"ERROR");
255 warnx(
"reading data unaligned..");
258 fd = open(PX4_STORAGEDIR
"/testfile", O_RDONLY);
260 bool unalign_read_ok =
true;
261 int unalign_read_err_count = 0;
263 memset(read_buf, 0,
sizeof(read_buf));
266 for (
unsigned i = 0; i < iterations; i++) {
267 int rret =
read(fd, read_buf + a, chunk_sizes[c]);
269 if (rret != chunk_sizes[c]) {
270 warnx(
"READ ERROR!");
274 for (
int j = 0; j < chunk_sizes[c]; j++) {
276 if ((read_buf + a)[j] != write_buf[j]) {
277 warnx(
"COMPARISON ERROR: byte %d, align shift: %d: %u != %u", j, a, (
unsigned int)read_buf[j + a],
278 (
unsigned int)write_buf[j]);
279 unalign_read_ok =
false;
280 unalign_read_err_count++;
282 if (unalign_read_err_count > 10) {
292 if (!unalign_read_ok) {
293 warnx(
"ABORTING FURTHER COMPARISON DUE TO ERROR");
299 ret = unlink(PX4_STORAGEDIR
"/testfile");
303 warnx(
"UNLINKING FILE FAILED");
312 d = opendir(PX4_STORAGEDIR);
316 while ((dir = readdir(d)) != NULL) {
322 warnx(
"directory listing ok (FS mounted and readable)");
326 warnx(
"FAILED LISTING MICROSD ROOT DIRECTORY");
High-resolution timer with callouts and timekeeping.
static void read(bootloader_app_shared_t *pshared)
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
struct __attribute__((__packed__)) reading_msg
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
static void write(bootloader_app_shared_t *pshared)
static int check_user_abort(int fd)
int test_file(int argc, char *argv[])
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
Performance measuring tools.