mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-30 18:06:39 +08:00
tests: avoid using exit()
This commit is contained in:
@@ -69,7 +69,7 @@ static uint8_t get_value(uint32_t ofs)
|
|||||||
return u.buf[ofs % 4];
|
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",
|
printf("Testing on %s with write_chunk=%u write_size=%u\n",
|
||||||
filename, (unsigned)write_chunk, (unsigned)write_size);
|
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) {
|
if (fd == -1) {
|
||||||
perror(filename);
|
perror(filename);
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a file of size write_size, in write_chunk blocks
|
// 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)) {
|
if (write(fd, buffer, sizeof(buffer)) != (int)sizeof(buffer)) {
|
||||||
printf("write failed at offset %u\n", ofs);
|
printf("write failed at offset %u\n", ofs);
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & FLAG_FSYNC) {
|
if (flags & FLAG_FSYNC) {
|
||||||
@@ -118,7 +118,7 @@ static void test_corruption(const char *filename, uint32_t write_chunk, uint32_t
|
|||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
perror(filename);
|
perror(filename);
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
counter = 0;
|
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)) {
|
if (read(fd, buffer, sizeof(buffer)) != (int)sizeof(buffer)) {
|
||||||
printf("read failed at offset %u\n", ofs);
|
printf("read failed at offset %u\n", ofs);
|
||||||
close(fd);
|
close(fd);
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint16_t j = 0; j < write_chunk; j++) {
|
for (uint16_t j = 0; j < write_chunk; j++) {
|
||||||
if (buffer[j] != get_value(ofs)) {
|
if (buffer[j] != get_value(ofs)) {
|
||||||
printf("corruption at ofs=%u got %u\n", ofs, buffer[j]);
|
printf("corruption at ofs=%u got %u\n", ofs, buffer[j]);
|
||||||
close(fd);
|
close(fd);
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ofs++;
|
ofs++;
|
||||||
@@ -158,6 +158,7 @@ static void test_corruption(const char *filename, uint32_t write_chunk, uint32_t
|
|||||||
close(fd);
|
close(fd);
|
||||||
unlink(filename);
|
unlink(filename);
|
||||||
printf("All OK\n");
|
printf("All OK\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usage(void)
|
static void usage(void)
|
||||||
@@ -221,7 +222,6 @@ int test_file2(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
test_corruption(filename, write_chunk, write_size, flags);
|
return test_corruption(filename, write_chunk, write_size, flags);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ int test_uart_loopback(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("ERROR opening UART5, aborting..\n");
|
printf("ERROR opening UART5, aborting..\n");
|
||||||
exit(uart5);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t sample_stdout_fd[] = {'C', 'O', 'U', 'N', 'T', ' ', '#', '\n'};
|
uint8_t sample_stdout_fd[] = {'C', 'O', 'U', 'N', 'T', ' ', '#', '\n'};
|
||||||
|
|||||||
Reference in New Issue
Block a user