From ca1894b350b44643498d9dcefd7e8f3ef0a7ca4f Mon Sep 17 00:00:00 2001 From: Josh Henderson Date: Sun, 29 Aug 2021 03:54:25 -0400 Subject: [PATCH] AP_gtest: enable testing for exit conditions, SITL unit tests --- tests/AP_gtest.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/AP_gtest.h b/tests/AP_gtest.h index 2ed1e61ad3..b1284e751a 100644 --- a/tests/AP_gtest.h +++ b/tests/AP_gtest.h @@ -5,6 +5,7 @@ #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #include +#include #define AP_GTEST_PRINTATBLE_PARAM_MEMBER(class_name_, printable_member_) \ @@ -14,6 +15,27 @@ return os << param.printable_member_; \ } +/* +* Override the WEAK version of AP_HAL_SITL/system.cpp panic() instead of staying in an infinite loop +* This is used by the gtest suite to test for an exit signal caused by a test statement and continue testing +* Printing to stderr is required for gtest matching +*/ +#define AP_GTEST_PANIC() \ +void AP_HAL::panic(const char *errormsg, ...) \ +{ \ + va_list ap; \ + auto outputs = {stdout, stderr}; \ + for( auto output : outputs) { \ + fflush(stdout); \ + fprintf(output, "PANIC: "); \ + va_start(ap, errormsg); \ + vfprintf(output, errormsg, ap); \ + va_end(ap); \ + fprintf(output, "\n"); \ + } \ + abort(); \ +} + #define AP_GTEST_MAIN() \ int main(int argc, char *argv[]) \ { \