Fix error handling in x52test

x52test used to assume that a positive return code indicated a signal
was received and a negative return code indicated an error in libx52.
However, libx52 was changed a while back to return only a positive error
code of type `libx52_error_code`.

This commit changes that assumption, so that:

* The first check is always against `LIBX52_SUCCESS`, to ensure that any
  change in the enumeration won't break the rest of the code.
* Tests terminated by a signal return the negated value of the signal,
  i.e. -15 is SIGTERM and -2 is SIGINT.
* Tests that fail within libx52 return a standard `libx52_error_code`.
* Error printing uses `libx52_strerror`.

Addresses #19.
debian-packaging
nirenjan 2020-05-18 14:53:47 -07:00
parent 16b4ad693b
commit be1f7e0d5a
2 changed files with 8 additions and 8 deletions

View File

@ -80,7 +80,7 @@ void print_banner(const char *message)
static void signal_handler(int sig)
{
test_exit = sig;
test_exit = -sig;
}
#define TESTS \
@ -139,12 +139,12 @@ static int run_tests(int test_set)
#undef X
} while (0);
if (rc > 0) {
fprintf(stderr, "Received %s signal, quitting...\n", strsignal(rc));
} else if (rc < 0) {
fprintf(stderr, "Got error %s\n", strerror(-rc));
} else {
if (rc == LIBX52_SUCCESS) {
puts("All tests completed successfully");
} else if (rc > 0) {
fprintf(stderr, "Got error %s\n", libx52_strerror(rc));
} else {
fprintf(stderr, "Received %s signal, quitting...\n", strsignal(-rc));
}
if (rc >= 0) test_cleanup();

View File

@ -21,13 +21,13 @@ extern bool nodelay;
int rc; \
rc = ( libx52_set_ ## tst (dev, __VA_ARGS__) ); \
if (rc) { \
fprintf(stderr, "\n%s(%s) failed with %d\n", #tst, #__VA_ARGS__, rc); \
fprintf(stderr, "\n%s(%s) failed with %d(%s)\n", #tst, #__VA_ARGS__, rc, libx52_strerror(rc)); \
return rc; \
} \
if (test_exit) return test_exit; \
rc = libx52_update(dev); \
if (rc) { \
fprintf(stderr, "\nupdate failed with %d\n", rc); \
fprintf(stderr, "\nupdate failed with %d(%s)\n", rc, libx52_strerror(rc)); \
return rc; \
} \
if (test_exit) return test_exit; \