Skip to content
Snippets Groups Projects
Commit 0dc8eeb1 authored by Beat Küng's avatar Beat Küng
Browse files

tests: avoid using exit()

parent 50cdb011
No related branches found
No related tags found
No related merge requests found
......@@ -69,7 +69,7 @@ static uint8_t get_value(uint32_t ofs)
return u.buf[ofs % 4];
}
static void test_corruption(const char *filename, uint32_t write_chunk, uint32_t write_size, uint16_t flags)
static int test_corruption(const char *filename, uint32_t write_chunk, uint32_t write_size, uint16_t flags)
{
printf("Testing on %s with write_chunk=%u write_size=%u\n",
filename, (unsigned)write_chunk, (unsigned)write_size);
......@@ -79,7 +79,7 @@ static void test_corruption(const char *filename, uint32_t write_chunk, uint32_t
if (fd == -1) {
perror(filename);
exit(1);
return 1;
}
// create a file of size write_size, in write_chunk blocks
......@@ -95,7 +95,7 @@ static void test_corruption(const char *filename, uint32_t write_chunk, uint32_t
if (write(fd, buffer, sizeof(buffer)) != (int)sizeof(buffer)) {
printf("write failed at offset %u\n", ofs);
exit(1);
return 1;
}
if (flags & FLAG_FSYNC) {
......@@ -118,7 +118,7 @@ static void test_corruption(const char *filename, uint32_t write_chunk, uint32_t
if (fd == -1) {
perror(filename);
exit(1);
return 1;
}
counter = 0;
......@@ -136,14 +136,14 @@ static void test_corruption(const char *filename, uint32_t write_chunk, uint32_t
if (read(fd, buffer, sizeof(buffer)) != (int)sizeof(buffer)) {
printf("read failed at offset %u\n", ofs);
close(fd);
return;
return 1;
}
for (uint16_t j = 0; j < write_chunk; j++) {
if (buffer[j] != get_value(ofs)) {
printf("corruption at ofs=%u got %u\n", ofs, buffer[j]);
close(fd);
return;
return 1;
}
ofs++;
......@@ -158,6 +158,7 @@ static void test_corruption(const char *filename, uint32_t write_chunk, uint32_t
close(fd);
unlink(filename);
printf("All OK\n");
return 0;
}
static void usage(void)
......@@ -221,7 +222,6 @@ int test_file2(int argc, char *argv[])
return 1;
}
test_corruption(filename, write_chunk, write_size, flags);
return 0;
return test_corruption(filename, write_chunk, write_size, flags);
}
......@@ -82,7 +82,7 @@ int test_uart_loopback(int argc, char *argv[])
}
printf("ERROR opening UART5, aborting..\n");
exit(uart5);
return 1;
}
uint8_t sample_stdout_fd[] = {'C', 'O', 'U', 'N', 'T', ' ', '#', '\n'};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment