added a "test mode" for aos::Die and used it
ipc_stress_test was getting slowed down by disk I/O because of the
aos_fatal_error files getting written to /tmp and the stdout messages
that gtest doesn't capture were annoying, so I added a setting for
aos::Die to not do those things and used it in the ipc_stress_test
tests.
diff --git a/aos/common/die.cc b/aos/common/die.cc
index 467b81d..0ea7007 100644
--- a/aos/common/die.cc
+++ b/aos/common/die.cc
@@ -6,13 +6,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
-#ifdef __VXWORKS__
-#include <taskLib.h>
-// Have to re-declare it with __attribute__((noreturn)).
-extern "C" void abort() __attribute__((noreturn));
-#include <usrLib.h>
-#include <dbgLib.h>
-#endif
+#include <signal.h>
#include <string>
@@ -28,6 +22,7 @@
}
namespace {
+
// Calculates the filename to dump the message into.
const std::string GetFilename() {
#ifdef __VXWORKS__
@@ -50,6 +45,9 @@
}
#endif
}
+
+bool test_mode = false;
+
} // namespace
void VDie(const char *format, va_list args_in) {
@@ -60,31 +58,28 @@
fputs("aos fatal: ERROR!! details following\n", stderr);
va_copy(args1, args_in);
vfprintf(stderr, format, args1);
- fputs("aos fatal: ERROR!! see stderr for details\n", stdout);
+ if (!test_mode) {
+ fputs("aos fatal: ERROR!! see stderr for details\n", stdout);
- const std::string filename = GetFilename();
- if (!filename.empty()) {
- FILE *error_file = fopen(filename.c_str(), "w");
- if (error_file != NULL) {
- va_copy(args2, args_in);
- vfprintf(error_file, format, args2);
- fclose(error_file);
- } else {
- fprintf(stderr, "aos fatal: fopen('%s', \"w\") failed with %d (%s)\n",
- filename.c_str(), errno, strerror(errno));
+ const std::string filename = GetFilename();
+ if (!filename.empty()) {
+ FILE *error_file = fopen(filename.c_str(), "w");
+ if (error_file != NULL) {
+ va_copy(args2, args_in);
+ vfprintf(error_file, format, args2);
+ fclose(error_file);
+ } else {
+ fprintf(stderr, "aos fatal: fopen('%s', \"w\") failed with %d (%s)\n",
+ filename.c_str(), errno, strerror(errno));
+ }
}
}
-#ifdef __VXWORKS__
- printf("I am 0x%x suspending for debugging purposes.\n", taskIdSelf());
- printf("\t`tt 0x%x` will give you a stack trace.\n", taskIdSelf());
- fputs("\t`lkAddr` will reverse lookup a symbol for you.\n", stdout);
- fputs("\t`dbgHelp` and `help` have some useful commands in them.\n", stdout);
- taskSuspend(0);
- printf("You weren't supposed to resume 0x%x!!. Going to really die now.\n",
- taskIdSelf());
-#endif
abort();
}
+void SetDieTestMode(bool new_test_mode) {
+ test_mode = new_test_mode;
+}
+
} // namespace aos