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/atom_code/ipc_lib/ipc_lib.gyp b/aos/atom_code/ipc_lib/ipc_lib.gyp
index 617b203..af9d779 100644
--- a/aos/atom_code/ipc_lib/ipc_lib.gyp
+++ b/aos/atom_code/ipc_lib/ipc_lib.gyp
@@ -61,6 +61,7 @@
'core_lib',
'<(AOS)/common/common.gyp:queue_testutils',
'<(AOS)/common/common.gyp:time',
+ '<(AOS)/common/common.gyp:die',
],
},
{
diff --git a/aos/atom_code/ipc_lib/queue_test.cc b/aos/atom_code/ipc_lib/queue_test.cc
index 9e5f3ae..dda40af 100644
--- a/aos/atom_code/ipc_lib/queue_test.cc
+++ b/aos/atom_code/ipc_lib/queue_test.cc
@@ -15,6 +15,7 @@
#include "aos/common/queue_testutils.h"
#include "aos/common/time.h"
#include "aos/common/logging/logging.h"
+#include "aos/common/die.h"
using ::testing::AssertionResult;
using ::testing::AssertionSuccess;
@@ -136,6 +137,9 @@
void SetUp() override {
::testing::Test::SetUp();
+
+ SetDieTestMode(true);
+
fatal_failure = static_cast<char *>(shm_malloc(sizeof(fatal_failure)));
static bool registered = false;
if (!registered) {
diff --git a/aos/common/common.gyp b/aos/common/common.gyp
index f3b4e69..f73f1f6 100644
--- a/aos/common/common.gyp
+++ b/aos/common/common.gyp
@@ -156,6 +156,7 @@
'queue_testutils',
'queue_test_queue',
'<(AOS)/common/util/util.gyp:thread',
+ 'die',
],
},
{
@@ -272,6 +273,7 @@
'<(EXTERNALS):gtest',
'mutex',
'<(AOS)/build/aos.gyp:logging',
+ 'die',
],
},
{
@@ -289,6 +291,7 @@
'<(AOS)/build/aos.gyp:logging',
'queue_testutils',
'<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:core_lib',
+ 'die',
],
},
{
diff --git a/aos/common/condition_test.cc b/aos/common/condition_test.cc
index fca2820..7e74918 100644
--- a/aos/common/condition_test.cc
+++ b/aos/common/condition_test.cc
@@ -13,6 +13,7 @@
#include "aos/atom_code/ipc_lib/core_lib.h"
#include "aos/common/logging/logging.h"
#include "aos/common/macros.h"
+#include "aos/common/die.h"
using ::aos::time::Time;
using ::aos::common::testing::GlobalCoreInstance;
@@ -43,6 +44,11 @@
time::SleepFor(::Time::InSeconds(0.008));
}
+ protected:
+ void SetUp() override {
+ SetDieTestMode(true);
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(ConditionTest);
};
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
diff --git a/aos/common/die.h b/aos/common/die.h
index 28519a8..d973b42 100644
--- a/aos/common/die.h
+++ b/aos/common/die.h
@@ -15,6 +15,11 @@
__attribute__((noreturn))
__attribute__((format(gnu_printf, 1, 0)));
+// Turns on (or off) "test mode", where (V)Die doesn't write out files and
+// doesn't print to stdout.
+// Test mode defaults to false.
+void SetDieTestMode(bool test_mode);
+
} // namespace aos
#endif // AOS_COMMON_DIE_H_
diff --git a/aos/common/mutex_test.cpp b/aos/common/mutex_test.cpp
index 652cd9e..10f4e0b 100644
--- a/aos/common/mutex_test.cpp
+++ b/aos/common/mutex_test.cpp
@@ -10,6 +10,7 @@
#include "gtest/gtest.h"
#include "aos/atom_code/ipc_lib/aos_sync.h"
+#include "aos/common/die.h"
namespace aos {
namespace testing {
@@ -17,6 +18,11 @@
class MutexTest : public ::testing::Test {
public:
Mutex test_mutex;
+
+ protected:
+ void SetUp() override {
+ SetDieTestMode(true);
+ }
};
typedef MutexTest MutexDeathTest;
diff --git a/aos/common/queue_test.cc b/aos/common/queue_test.cc
index 32d1d23..ebb0bba 100644
--- a/aos/common/queue_test.cc
+++ b/aos/common/queue_test.cc
@@ -6,6 +6,7 @@
#include "aos/common/test_queue.q.h"
#include "aos/common/queue_testutils.h"
#include "aos/common/util/thread.h"
+#include "aos/common/die.h"
using ::aos::time::Time;
@@ -15,6 +16,10 @@
class QueueTest : public ::testing::Test {
protected:
+ void SetUp() override {
+ SetDieTestMode(true);
+ }
+
GlobalCoreInstance my_core;
// Create a new instance of the test queue so that it invalidates the queue
// that it points to. Otherwise, we will have a pointer to shared memory that