Split out //aos/common:queue_testutils and rename stuff
It had three independent pieces of functionality, one of which had a
pretty bad name.
Change-Id: I4a6937692fa36e74f814b3be4d4c5bc751947088
diff --git a/aos/common/BUILD b/aos/common/BUILD
index 8e911de..9bcf811 100644
--- a/aos/common/BUILD
+++ b/aos/common/BUILD
@@ -17,24 +17,6 @@
)
cc_library(
- name = 'queue_testutils',
- srcs = [
- 'queue_testutils.cc',
- ],
- hdrs = [
- 'queue_testutils.h',
- ],
- deps = [
- ':once',
- ':queues',
- '//aos/testing:googletest',
- '//aos/common/logging:implementations',
- '//aos/linux_code/ipc_lib:shared_mem',
- ':mutex',
- ],
-)
-
-cc_library(
name = 'macros',
hdrs = [
'macros.h',
@@ -141,7 +123,7 @@
'//aos/testing:googletest',
':test_queue',
'//aos/common/logging',
- ':queue_testutils',
+ '//aos/testing:test_logging',
],
)
@@ -193,7 +175,7 @@
],
deps = [
'//aos/testing:googletest',
- ':queue_testutils',
+ '//aos/testing:test_shm',
':test_queue',
'//aos/common/util:thread',
':die',
@@ -271,18 +253,6 @@
)
cc_test(
- name = 'queue_testutils_test',
- srcs = [
- 'queue_testutils_test.cc',
- ],
- deps = [
- '//aos/testing:googletest',
- ':queue_testutils',
- '//aos/common/logging',
- ],
-)
-
-cc_test(
name = 'mutex_test',
srcs = [
'mutex_test.cc',
@@ -295,7 +265,7 @@
'//aos/common/util:death_test_log_implementation',
'//aos/common/util:thread',
'//aos/common:time',
- ':queue_testutils',
+ '//aos/testing:test_logging',
],
)
@@ -307,7 +277,7 @@
deps = [
'//aos/testing:googletest',
':event',
- ':queue_testutils',
+ '//aos/testing:test_logging',
':time',
],
)
@@ -334,12 +304,13 @@
],
deps = [
'//aos/testing:googletest',
+ '//aos/testing:prevent_exit',
':condition',
'//aos/common/util:thread',
':time',
':mutex',
'//aos/common/logging',
- ':queue_testutils',
+ '//aos/testing:test_shm',
'//aos/linux_code/ipc_lib:core_lib',
'//aos/linux_code/ipc_lib:aos_sync',
':die',
@@ -392,7 +363,7 @@
deps = [
':stl_mutex',
'//aos/testing:googletest',
- ':queue_testutils',
+ '//aos/testing:test_logging',
'//aos/common/util:thread',
':die',
],
diff --git a/aos/common/actions/BUILD b/aos/common/actions/BUILD
index de13464..9a86232 100644
--- a/aos/common/actions/BUILD
+++ b/aos/common/actions/BUILD
@@ -48,7 +48,7 @@
'//aos/testing:googletest',
':action_lib',
':test_action_queue',
- '//aos/common:queue_testutils',
+ '//aos/testing:test_shm',
'//aos/common/logging',
'//aos/common/logging:queue_logging',
'//aos/common:queues',
diff --git a/aos/common/actions/action_test.cc b/aos/common/actions/action_test.cc
index 1e94b32..21da2c7 100644
--- a/aos/common/actions/action_test.cc
+++ b/aos/common/actions/action_test.cc
@@ -4,13 +4,14 @@
#include <thread>
#include "gtest/gtest.h"
+
#include "aos/common/queue.h"
-#include "aos/common/queue_testutils.h"
#include "aos/common/actions/actor.h"
#include "aos/common/actions/actions.h"
#include "aos/common/actions/actions.q.h"
#include "aos/common/actions/test_action.q.h"
#include "aos/common/event.h"
+#include "aos/testing/test_shm.h"
using ::aos::time::Time;
@@ -98,8 +99,6 @@
class ActionTest : public ::testing::Test {
protected:
ActionTest() {
- // Flush the robot state queue so we can use clean shared memory for this.
- // test.
actions::test_action.goal.Clear();
actions::test_action.status.Clear();
actions::test_action2.goal.Clear();
@@ -114,7 +113,7 @@
}
// Bring up and down Core.
- ::aos::common::testing::GlobalCoreInstance my_core;
+ ::aos::testing::TestSharedMemory my_shm_;
::aos::common::actions::ActionQueue action_queue_;
};
diff --git a/aos/common/condition_test.cc b/aos/common/condition_test.cc
index 2310273..dbaa546 100644
--- a/aos/common/condition_test.cc
+++ b/aos/common/condition_test.cc
@@ -10,7 +10,7 @@
#include "aos/common/time.h"
#include "aos/common/mutex.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_shm.h"
#include "aos/common/type_traits.h"
#include "aos/linux_code/ipc_lib/core_lib.h"
#include "aos/common/logging/logging.h"
@@ -18,9 +18,9 @@
#include "aos/linux_code/ipc_lib/aos_sync.h"
#include "aos/common/die.h"
#include "aos/common/util/thread.h"
+#include "aos/testing/prevent_exit.h"
using ::aos::time::Time;
-using ::aos::common::testing::GlobalCoreInstance;
namespace aos {
namespace testing {
@@ -37,7 +37,7 @@
DISALLOW_COPY_AND_ASSIGN(ConditionTestCommon);
};
-// Some simple tests that don't rely on a GlobalCoreInstance to help with
+// Some simple tests that don't rely on a TestSharedMemory to help with
// debugging problems that cause tests using that to just completely lock up.
class SimpleConditionTest : public ConditionTestCommon {
public:
@@ -93,7 +93,7 @@
shared_->~Shared();
}
- GlobalCoreInstance my_core;
+ ::aos::testing::TestSharedMemory my_shm_;
Shared *const shared_;
@@ -136,7 +136,7 @@
child_ = fork();
if (child_ == 0) { // in child
- ::aos::common::testing::PreventExit();
+ ::aos::testing::PreventExit();
Run();
exit(EXIT_SUCCESS);
} else { // in parent
diff --git a/aos/common/controls/BUILD b/aos/common/controls/BUILD
index 08cbd36..5bb31fb 100644
--- a/aos/common/controls/BUILD
+++ b/aos/common/controls/BUILD
@@ -28,7 +28,7 @@
'//aos/common:time',
'//aos/common/messages:robot_state',
'//aos/testing:googletest',
- '//aos/common:queue_testutils',
+ '//aos/testing:test_shm',
],
)
diff --git a/aos/common/controls/control_loop_test.h b/aos/common/controls/control_loop_test.h
index 4fd13a3..30115b8 100644
--- a/aos/common/controls/control_loop_test.h
+++ b/aos/common/controls/control_loop_test.h
@@ -3,7 +3,7 @@
#include "gtest/gtest.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_shm.h"
#include "aos/common/time.h"
namespace aos {
@@ -52,7 +52,7 @@
::aos::time::Time last_ds_time_ = ::aos::time::Time::InSeconds(0);
::aos::time::Time current_time_ = ::aos::time::Time::InSeconds(0);
- ::aos::common::testing::GlobalCoreInstance my_core;
+ ::aos::testing::TestSharedMemory my_shm_;
};
} // namespace testing
diff --git a/aos/common/event_test.cc b/aos/common/event_test.cc
index 7331309..91af403 100644
--- a/aos/common/event_test.cc
+++ b/aos/common/event_test.cc
@@ -4,7 +4,7 @@
#include "gtest/gtest.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_logging.h"
#include "aos/common/time.h"
namespace aos {
@@ -16,7 +16,7 @@
protected:
void SetUp() override {
- ::aos::common::testing::EnableTestLogging();
+ ::aos::testing::EnableTestLogging();
}
};
diff --git a/aos/common/mutex_test.cc b/aos/common/mutex_test.cc
index 6614d5c..af80bd1 100644
--- a/aos/common/mutex_test.cc
+++ b/aos/common/mutex_test.cc
@@ -13,7 +13,7 @@
#include "aos/common/util/death_test_log_implementation.h"
#include "aos/common/util/thread.h"
#include "aos/common/time.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_logging.h"
#include "aos/linux_code/ipc_lib/core_lib.h"
namespace aos {
@@ -25,7 +25,7 @@
protected:
void SetUp() override {
- ::aos::common::testing::EnableTestLogging();
+ ::aos::testing::EnableTestLogging();
SetDieTestMode(true);
}
};
diff --git a/aos/common/network/BUILD b/aos/common/network/BUILD
index fd9a831..19335ba 100644
--- a/aos/common/network/BUILD
+++ b/aos/common/network/BUILD
@@ -44,7 +44,6 @@
deps = [
':team_number',
'//aos/testing:googletest',
- '//aos/common:queue_testutils',
],
)
diff --git a/aos/common/queue_test.cc b/aos/common/queue_test.cc
index 310301d..dc8c62c 100644
--- a/aos/common/queue_test.cc
+++ b/aos/common/queue_test.cc
@@ -3,10 +3,11 @@
#include <memory>
#include "gtest/gtest.h"
+
#include "aos/common/test_queue.q.h"
-#include "aos/common/queue_testutils.h"
#include "aos/common/util/thread.h"
#include "aos/common/die.h"
+#include "aos/testing/test_shm.h"
using ::aos::time::Time;
@@ -20,7 +21,7 @@
SetDieTestMode(true);
}
- GlobalCoreInstance my_core;
+ ::aos::testing::TestSharedMemory my_shm_;
// 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
// is no longer valid.
@@ -210,17 +211,19 @@
class GroupTest : public ::testing::Test {
protected:
- GlobalCoreInstance my_core;
- // Create a new instance of the test group so that it invalidates the queue
- // that it points to. Otherwise, we will have a pointer to shared memory that
- // is no longer valid.
- TwoQueues my_test_queuegroup;
-
GroupTest()
: my_test_queuegroup(".aos.common.testing.test_queuegroup",
0x20561114,
".aos.common.testing.test_queuegroup.first",
".aos.common.testing.test_queuegroup.second") {}
+
+ // Create a new instance of the test group so that it invalidates the queue
+ // that it points to. Otherwise, we will have a pointer to shared memory that
+ // is no longer valid.
+ TwoQueues my_test_queuegroup;
+
+ private:
+ ::aos::testing::TestSharedMemory my_shm_;
};
// Tests that the hash gets preserved.
diff --git a/aos/common/queue_testutils.h b/aos/common/queue_testutils.h
deleted file mode 100644
index fb0ffcd..0000000
--- a/aos/common/queue_testutils.h
+++ /dev/null
@@ -1,52 +0,0 @@
-#ifndef AOS_COMMON_QUEUE_TESTUTILS_H_
-#define AOS_COMMON_QUEUE_TESTUTILS_H_
-
-#include "aos/linux_code/ipc_lib/shared_mem.h"
-
-// This file has some general helper functions for dealing with testing things
-// that use shared memory etc.
-
-namespace aos {
-namespace common {
-namespace testing {
-
-// Manages creating and cleaning up "shared memory" which works within this
-// process and any that it fork(2)s.
-class GlobalCoreInstance {
- public:
- // Calls EnableTestLogging().
- GlobalCoreInstance();
- ~GlobalCoreInstance();
-
- private:
- struct aos_core global_core_data_;
-};
-
-// Enables the logging framework for use during a gtest test.
-// It will print out all WARNING and above messages all of the time. It will
-// also print out all log messages when a test fails.
-// This function only needs to be called once in each process (after gtest is
-// initialized), however it can be called more than that.
-void EnableTestLogging();
-
-// Registers an exit handler (using atexit(3)) which will call _exit(2).
-// Intended to be called in a freshly fork(2)ed process where it will run before
-// any other exit handlers that were already registered and prevent them from
-// being run.
-void PreventExit();
-
-// Redirect the messages enabled by EnableTestLogging() function to a file.
-// By default the messages are printed to standard output.
-void SetLogFileName(const char* filename);
-
-// Force the messages to be printed as they are handled by the logging
-// framework. This can be useful for tests that hang where no messages would
-// otherwise be printed. This is also useful for tests that do pass, but where
-// we want to use graphing tools to verify what's happening.
-void ForcePrintLogsDuringTests();
-
-} // namespace testing
-} // namespace common
-} // namespace aos
-
-#endif // AOS_COMMON_QUEUE_TESTUTILS_H_
diff --git a/aos/common/queue_types_test.cc b/aos/common/queue_types_test.cc
index b8b5e47..bbadf34 100644
--- a/aos/common/queue_types_test.cc
+++ b/aos/common/queue_types_test.cc
@@ -10,7 +10,7 @@
#include "aos/common/byteorder.h"
#include "aos/common/queue_primitives.h"
#include "aos/common/logging/logging.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_logging.h"
using ::aos::common::testing::Structure;
using ::aos::common::testing::MessageWithStructure;
@@ -30,7 +30,7 @@
class QueueTypesTest : public ::testing::Test {
public:
QueueTypesTest() {
- ::aos::common::testing::EnableTestLogging();
+ ::aos::testing::EnableTestLogging();
}
::testing::AssertionResult Equal(const MessageType &l, const MessageType &r) {
diff --git a/aos/common/stl_mutex_test.cc b/aos/common/stl_mutex_test.cc
index 7d84416..236f506 100644
--- a/aos/common/stl_mutex_test.cc
+++ b/aos/common/stl_mutex_test.cc
@@ -2,7 +2,7 @@
#include "gtest/gtest.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_logging.h"
#include "aos/common/util/thread.h"
#include "aos/common/die.h"
@@ -12,7 +12,7 @@
class StlMutexDeathTest : public ::testing::Test {
protected:
void SetUp() override {
- ::aos::common::testing::EnableTestLogging();
+ ::aos::testing::EnableTestLogging();
SetDieTestMode(true);
}
};
diff --git a/aos/common/util/BUILD b/aos/common/util/BUILD
index 35d8e87..cbaf8ba 100644
--- a/aos/common/util/BUILD
+++ b/aos/common/util/BUILD
@@ -61,7 +61,6 @@
deps = [
'//aos/common/logging',
'//aos/common:time',
- '//aos/common:queue_testutils',
],
)
@@ -211,5 +210,6 @@
deps = [
':phased_loop',
'//aos/testing:googletest',
+ '//aos/testing:test_logging',
],
)
diff --git a/aos/common/util/phased_loop_test.cc b/aos/common/util/phased_loop_test.cc
index 5846f25..1641a92 100644
--- a/aos/common/util/phased_loop_test.cc
+++ b/aos/common/util/phased_loop_test.cc
@@ -2,7 +2,7 @@
#include "gtest/gtest.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_logging.h"
namespace aos {
namespace time {
@@ -11,7 +11,7 @@
class PhasedLoopTest : public ::testing::Test {
protected:
PhasedLoopTest() {
- ::aos::common::testing::EnableTestLogging();
+ ::aos::testing::EnableTestLogging();
}
};
diff --git a/aos/linux_code/ipc_lib/BUILD b/aos/linux_code/ipc_lib/BUILD
index 8f26882..444c2bb 100644
--- a/aos/linux_code/ipc_lib/BUILD
+++ b/aos/linux_code/ipc_lib/BUILD
@@ -84,10 +84,11 @@
],
deps = [
'//aos/testing:googletest',
+ '//aos/testing:prevent_exit',
':queue',
'//aos/common/logging',
':core_lib',
- '//aos/common:queue_testutils',
+ '//aos/testing:test_shm',
'//aos/common:time',
'//aos/common:die',
'//aos/common/util:thread',
@@ -106,7 +107,7 @@
deps = [
'//aos/testing:googletest',
'//aos/common:time',
- '//aos/common:queue_testutils',
+ '//aos/testing:test_shm',
'//aos/common:mutex',
':core_lib',
'//aos/common:die',
diff --git a/aos/linux_code/ipc_lib/ipc_stress_test.cc b/aos/linux_code/ipc_lib/ipc_stress_test.cc
index 880d226..2ca4628 100644
--- a/aos/linux_code/ipc_lib/ipc_stress_test.cc
+++ b/aos/linux_code/ipc_lib/ipc_stress_test.cc
@@ -9,7 +9,6 @@
#include <string>
#include "aos/common/time.h"
-#include "aos/common/queue_testutils.h"
#include "aos/common/type_traits.h"
#include "aos/common/mutex.h"
#include "aos/linux_code/ipc_lib/core_lib.h"
@@ -17,6 +16,7 @@
#include "aos/common/libc/dirname.h"
#include "aos/common/libc/aos_strsignal.h"
#include "aos/common/logging/logging.h"
+#include "aos/testing/test_shm.h"
// This runs all of the IPC-related tests in a bunch of parallel processes for a
// while and makes sure that they don't fail. It also captures the stdout and
@@ -210,7 +210,7 @@
return EXIT_FAILURE;
}
- ::aos::common::testing::GlobalCoreInstance global_core;
+ ::aos::testing::TestSharedMemory my_shm_;
Shared *shared = static_cast<Shared *>(shm_malloc(sizeof(Shared)));
new (shared) Shared(time::Time::Now() + kTestTime);
diff --git a/aos/linux_code/ipc_lib/raw_queue_test.cc b/aos/linux_code/ipc_lib/raw_queue_test.cc
index adb84b9..ec07a0b 100644
--- a/aos/linux_code/ipc_lib/raw_queue_test.cc
+++ b/aos/linux_code/ipc_lib/raw_queue_test.cc
@@ -12,18 +12,18 @@
#include "aos/linux_code/ipc_lib/core_lib.h"
#include "aos/common/type_traits.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_shm.h"
#include "aos/common/time.h"
#include "aos/common/logging/logging.h"
#include "aos/common/die.h"
#include "aos/common/util/thread.h"
#include "aos/common/util/options.h"
#include "aos/common/util/death_test_log_implementation.h"
+#include "aos/testing/prevent_exit.h"
using ::testing::AssertionResult;
using ::testing::AssertionSuccess;
using ::testing::AssertionFailure;
-using ::aos::common::testing::GlobalCoreInstance;
namespace aos {
namespace testing {
@@ -178,7 +178,7 @@
kForkSleep.sec(), kForkSleep.nsec());
time::SleepFor(kForkSleep);
}
- ::aos::common::testing::PreventExit();
+ ::aos::testing::PreventExit();
function(arg);
CHECK_NE(-1, futex_set(done));
exit(EXIT_SUCCESS);
@@ -319,7 +319,7 @@
}
private:
- GlobalCoreInstance my_core;
+ ::aos::testing::TestSharedMemory my_shm_;
};
char *RawQueueTest::fatal_failure;
diff --git a/aos/testing/BUILD b/aos/testing/BUILD
index 2365bd8..8656d23 100644
--- a/aos/testing/BUILD
+++ b/aos/testing/BUILD
@@ -7,4 +7,68 @@
deps = [
'//third_party/googletest',
],
+ testonly = True,
+)
+
+cc_library(
+ name = 'test_logging',
+ visibility = ['//visibility:public'],
+ srcs = [
+ 'test_logging.cc',
+ ],
+ hdrs = [
+ 'test_logging.h',
+ ],
+ deps = [
+ ':googletest',
+ '//aos/common/logging:implementations',
+ '//aos/common:once',
+ '//aos/common:mutex',
+ ],
+ testonly = True,
+)
+
+cc_test(
+ name = 'test_logging_test',
+ srcs = [
+ 'test_logging_test.cc',
+ ],
+ deps = [
+ ':googletest',
+ ':test_logging',
+ '//aos/common/logging',
+ ],
+)
+
+cc_library(
+ name = 'prevent_exit',
+ visibility = ['//visibility:public'],
+ srcs = [
+ 'prevent_exit.cc',
+ ],
+ hdrs = [
+ 'prevent_exit.h',
+ ],
+ deps = [
+ '//aos/common/logging',
+ ],
+ testonly = True,
+)
+
+cc_library(
+ name = 'test_shm',
+ visibility = ['//visibility:public'],
+ srcs = [
+ 'test_shm.cc',
+ ],
+ hdrs = [
+ 'test_shm.h',
+ ],
+ deps = [
+ '//aos/common:queues',
+ '//aos/linux_code/ipc_lib:shared_mem',
+ '//aos/common/logging',
+ ':test_logging',
+ ],
+ testonly = True,
)
diff --git a/aos/testing/gtest_main.cc b/aos/testing/gtest_main.cc
index db403bb..ef63293 100644
--- a/aos/testing/gtest_main.cc
+++ b/aos/testing/gtest_main.cc
@@ -4,15 +4,13 @@
#include "gtest/gtest.h"
namespace aos {
-namespace common {
namespace testing {
-// Actually declared/defined in aos/common/queue_testutils.
+// Actually declared/defined in //aos/testing:test_logging.
void SetLogFileName(const char* filename) __attribute__((weak));
void ForcePrintLogsDuringTests() __attribute__((weak));
} // namespace testing
-} // namespace common
} // namespace aos
GTEST_API_ int main(int argc, char **argv) {
@@ -47,14 +45,14 @@
break;
case 'p':
- if (::aos::common::testing::ForcePrintLogsDuringTests) {
- ::aos::common::testing::ForcePrintLogsDuringTests();
+ if (::aos::testing::ForcePrintLogsDuringTests) {
+ ::aos::testing::ForcePrintLogsDuringTests();
}
break;
case 'o':
- if (::aos::common::testing::SetLogFileName) {
- ::aos::common::testing::SetLogFileName(optarg);
+ if (::aos::testing::SetLogFileName) {
+ ::aos::testing::SetLogFileName(optarg);
}
break;
diff --git a/aos/testing/prevent_exit.cc b/aos/testing/prevent_exit.cc
new file mode 100644
index 0000000..93d7c58
--- /dev/null
+++ b/aos/testing/prevent_exit.cc
@@ -0,0 +1,23 @@
+#include "aos/testing/prevent_exit.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "aos/common/logging/logging.h"
+
+namespace aos {
+namespace testing {
+namespace {
+
+void TerminateExitHandler() {
+ _exit(EXIT_SUCCESS);
+}
+
+} // namespace
+
+void PreventExit() {
+ CHECK_EQ(atexit(TerminateExitHandler), 0);
+}
+
+} // namespace testing
+} // namespace aos
diff --git a/aos/testing/prevent_exit.h b/aos/testing/prevent_exit.h
new file mode 100644
index 0000000..ee39fdb
--- /dev/null
+++ b/aos/testing/prevent_exit.h
@@ -0,0 +1,16 @@
+#ifndef AOS_TESTING_PREVENT_EXIT_H_
+#define AOS_TESTING_PREVENT_EXIT_H_
+
+namespace aos {
+namespace testing {
+
+// Registers an exit handler (using atexit(3)) which will call _exit(2).
+// Intended to be called in a freshly fork(2)ed process where it will run before
+// any other exit handlers that were already registered and prevent them from
+// being run.
+void PreventExit();
+
+} // namespace testing
+} // namespace aos
+
+#endif // AOS_TESTING_PREVENT_EXIT_H_
diff --git a/aos/common/queue_testutils.cc b/aos/testing/test_logging.cc
similarity index 78%
rename from aos/common/queue_testutils.cc
rename to aos/testing/test_logging.cc
index 5843e67..cdbec94 100644
--- a/aos/common/queue_testutils.cc
+++ b/aos/testing/test_logging.cc
@@ -1,13 +1,11 @@
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_logging.h"
-#include <string.h>
-#include <sys/mman.h>
-#include <unistd.h>
-#include <stdlib.h>
+#include <stdio.h>
+
+#include <vector>
#include "gtest/gtest.h"
-#include "aos/common/queue.h"
#include "aos/common/logging/implementations.h"
#include "aos/common/once.h"
#include "aos/common/mutex.h"
@@ -15,7 +13,6 @@
using ::aos::logging::LogMessage;
namespace aos {
-namespace common {
namespace testing {
namespace {
@@ -123,47 +120,17 @@
::testing::UnitTest::GetInstance()->listeners().Append(
new MyTestEventListener());
- return NULL;
+ return nullptr;
}
Once<void> enable_test_logging_once(DoEnableTestLogging);
-const size_t kCoreSize = 0x100000;
-
-void TerminateExitHandler() {
- _exit(EXIT_SUCCESS);
-}
-
} // namespace
-GlobalCoreInstance::GlobalCoreInstance() {
- global_core = &global_core_data_;
- global_core->owner = true;
- // Use mmap(2) manually instead of through malloc(3) so that we can pass
- // MAP_SHARED which allows forked processes to communicate using the
- // "shared" memory.
- void *memory = mmap(NULL, kCoreSize, PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_ANONYMOUS, -1, 0);
- CHECK_NE(memory, MAP_FAILED);
-
- aos_core_use_address_as_shared_mem(memory, kCoreSize);
-
- EnableTestLogging();
-}
-
-GlobalCoreInstance::~GlobalCoreInstance() {
- PCHECK(munmap(global_core->mem_struct, kCoreSize));
- global_core = NULL;
-}
-
void EnableTestLogging() {
enable_test_logging_once.Get();
}
-void PreventExit() {
- CHECK_EQ(atexit(TerminateExitHandler), 0);
-}
-
void SetLogFileName(const char* filename) {
TestLogImplementation::GetInstance()->SetOutputFile(filename);
}
@@ -173,5 +140,4 @@
}
} // namespace testing
-} // namespace common
} // namespace aos
diff --git a/aos/testing/test_logging.h b/aos/testing/test_logging.h
new file mode 100644
index 0000000..a4d835a
--- /dev/null
+++ b/aos/testing/test_logging.h
@@ -0,0 +1,27 @@
+#ifndef AOS_TESTING_TEST_LOGGING_H_
+#define AOS_TESTING_TEST_LOGGING_H_
+
+namespace aos {
+namespace testing {
+
+// Enables the logging framework for use during a gtest test.
+// It will print out all WARNING and above messages all of the time. It will
+// also print out all log messages when a test fails.
+// This function only needs to be called once in each process (after gtest is
+// initialized), however it can be called more than that.
+void EnableTestLogging();
+
+// Redirect the messages enabled by EnableTestLogging() function to a file.
+// By default the messages are printed to standard output.
+void SetLogFileName(const char* filename);
+
+// Force the messages to be printed as they are handled by the logging
+// framework. This can be useful for tests that hang where no messages would
+// otherwise be printed. This is also useful for tests that do pass, but where
+// we want to use graphing tools to verify what's happening.
+void ForcePrintLogsDuringTests();
+
+} // namespace testing
+} // namespace aos
+
+#endif // AOS_TESTING_TEST_LOGGING_H_
diff --git a/aos/common/queue_testutils_test.cc b/aos/testing/test_logging_test.cc
similarity index 85%
rename from aos/common/queue_testutils_test.cc
rename to aos/testing/test_logging_test.cc
index 2defe74..369f94d 100644
--- a/aos/common/queue_testutils_test.cc
+++ b/aos/testing/test_logging_test.cc
@@ -1,4 +1,4 @@
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_logging.h"
#include <thread>
@@ -7,7 +7,6 @@
#include "aos/common/logging/logging.h"
namespace aos {
-namespace common {
namespace testing {
// Tests logging from multiple threads.
@@ -27,5 +26,4 @@
}
} // namespace testing
-} // namespace common
} // namespace aos
diff --git a/aos/testing/test_shm.cc b/aos/testing/test_shm.cc
new file mode 100644
index 0000000..92c3924
--- /dev/null
+++ b/aos/testing/test_shm.cc
@@ -0,0 +1,38 @@
+#include "aos/testing/test_shm.h"
+
+#include <sys/mman.h>
+
+#include "aos/common/queue.h"
+#include "aos/common/logging/logging.h"
+#include "aos/testing/test_logging.h"
+
+namespace aos {
+namespace testing {
+namespace {
+
+const size_t kCoreSize = 0x100000;
+
+} // namespace
+
+TestSharedMemory::TestSharedMemory() {
+ global_core = &global_core_data_;
+ global_core->owner = true;
+ // Use mmap(2) manually instead of through malloc(3) so that we can pass
+ // MAP_SHARED which allows forked processes to communicate using the
+ // "shared" memory.
+ void *memory = mmap(NULL, kCoreSize, PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+ CHECK_NE(memory, MAP_FAILED);
+
+ aos_core_use_address_as_shared_mem(memory, kCoreSize);
+
+ ::aos::testing::EnableTestLogging();
+}
+
+TestSharedMemory::~TestSharedMemory() {
+ PCHECK(munmap(global_core->mem_struct, kCoreSize));
+ global_core = NULL;
+}
+
+} // namespace testing
+} // namespace aos
diff --git a/aos/testing/test_shm.h b/aos/testing/test_shm.h
new file mode 100644
index 0000000..dcb6906
--- /dev/null
+++ b/aos/testing/test_shm.h
@@ -0,0 +1,24 @@
+#ifndef AOS_TESTING_TEST_SHM_H_
+#define AOS_TESTING_TEST_SHM_H_
+
+#include "aos/linux_code/ipc_lib/shared_mem.h"
+
+namespace aos {
+namespace testing {
+
+// Manages creating and cleaning up "shared memory" which works within this
+// process and any that it fork(2)s.
+class TestSharedMemory {
+ public:
+ // Calls EnableTestLogging().
+ TestSharedMemory();
+ ~TestSharedMemory();
+
+ private:
+ struct aos_core global_core_data_;
+};
+
+} // namespace testing
+} // namespace aos
+
+#endif // AOS_TESTING_TEST_SHM_H_
diff --git a/frc971/control_loops/voltage_cap/BUILD b/frc971/control_loops/voltage_cap/BUILD
index ed2181c..8c2df46 100644
--- a/frc971/control_loops/voltage_cap/BUILD
+++ b/frc971/control_loops/voltage_cap/BUILD
@@ -18,6 +18,6 @@
deps = [
':voltage_cap',
'//aos/testing:googletest',
- '//aos/common:queue_testutils',
+ '//aos/testing:test_shm',
],
)
diff --git a/frc971/control_loops/voltage_cap/voltage_cap_test.cc b/frc971/control_loops/voltage_cap/voltage_cap_test.cc
index f508b25..4bee640 100644
--- a/frc971/control_loops/voltage_cap/voltage_cap_test.cc
+++ b/frc971/control_loops/voltage_cap/voltage_cap_test.cc
@@ -3,8 +3,9 @@
#include "frc971/control_loops/voltage_cap/voltage_cap.h"
#include "gtest/gtest.h"
+
#include "aos/common/queue.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_shm.h"
using ::aos::time::Time;
@@ -15,7 +16,7 @@
class VoltageTest : public ::testing::Test {
protected:
// Bring up and down Core.
- ::aos::common::testing::GlobalCoreInstance my_core;
+ ::aos::testing::TestSharedMemory my_shm_;
};
// Tests that voltage inputs return the same if inside the box.
diff --git a/frc971/zeroing/BUILD b/frc971/zeroing/BUILD
index 67cb091..8a8d82c 100644
--- a/frc971/zeroing/BUILD
+++ b/frc971/zeroing/BUILD
@@ -30,7 +30,7 @@
],
deps = [
'//aos/testing:googletest',
- '//aos/common:queue_testutils',
+ '//aos/testing:test_shm',
':zeroing',
'//aos/common/util:thread',
'//aos/common:die',
diff --git a/frc971/zeroing/zeroing_test.cc b/frc971/zeroing/zeroing_test.cc
index 4a82e04..b4c9813 100644
--- a/frc971/zeroing/zeroing_test.cc
+++ b/frc971/zeroing/zeroing_test.cc
@@ -7,7 +7,7 @@
#include "gtest/gtest.h"
#include "frc971/zeroing/zeroing.h"
#include "frc971/control_loops/control_loops.q.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_shm.h"
#include "aos/common/util/thread.h"
#include "aos/common/die.h"
#include "frc971/control_loops/position_sensor_sim.h"
@@ -34,7 +34,7 @@
estimator->UpdateEstimate(sensor_values_);
}
- aos::common::testing::GlobalCoreInstance my_core;
+ ::aos::testing::TestSharedMemory my_shm_;
};
TEST_F(ZeroingTest, TestMovingAverageFilter) {
diff --git a/y2014/control_loops/drivetrain/drivetrain_lib_test.cc b/y2014/control_loops/drivetrain/drivetrain_lib_test.cc
index 9fdfbd8..0769f45 100644
--- a/y2014/control_loops/drivetrain/drivetrain_lib_test.cc
+++ b/y2014/control_loops/drivetrain/drivetrain_lib_test.cc
@@ -4,7 +4,6 @@
#include "gtest/gtest.h"
#include "aos/common/network/team_number.h"
-#include "aos/common/queue_testutils.h"
#include "aos/common/controls/polytope.h"
#include "aos/common/controls/control_loop_test.h"
diff --git a/y2014_bot3/control_loops/drivetrain/drivetrain_lib_test.cc b/y2014_bot3/control_loops/drivetrain/drivetrain_lib_test.cc
index 2c04831..270828f 100644
--- a/y2014_bot3/control_loops/drivetrain/drivetrain_lib_test.cc
+++ b/y2014_bot3/control_loops/drivetrain/drivetrain_lib_test.cc
@@ -4,7 +4,6 @@
#include "gtest/gtest.h"
#include "aos/common/network/team_number.h"
-#include "aos/common/queue_testutils.h"
#include "aos/common/controls/polytope.h"
#include "aos/common/controls/control_loop_test.h"
diff --git a/y2015/actors/BUILD b/y2015/actors/BUILD
index e561440..06ab08a 100644
--- a/y2015/actors/BUILD
+++ b/y2015/actors/BUILD
@@ -130,7 +130,7 @@
],
deps = [
'//aos/testing:googletest',
- '//aos/common:queue_testutils',
+ '//aos/testing:test_shm',
'//aos/common/logging:queue_logging',
'//aos/common:queues',
'//aos/common:time',
@@ -431,7 +431,7 @@
],
deps = [
'//aos/testing:googletest',
- '//aos/common:queue_testutils',
+ '//aos/testing:test_shm',
'//aos/common/logging:queue_logging',
'//aos/common:queues',
'//aos/common:time',
diff --git a/y2015/actors/score_actor_test.cc b/y2015/actors/score_actor_test.cc
index 4791f09..f859875 100644
--- a/y2015/actors/score_actor_test.cc
+++ b/y2015/actors/score_actor_test.cc
@@ -4,7 +4,7 @@
#include "gtest/gtest.h"
#include "aos/common/queue.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_shm.h"
#include "aos/common/actions/actor.h"
#include "y2015/actors/score_action.q.h"
#include "y2015/actors/score_actor.h"
@@ -34,7 +34,7 @@
}
// Bring up and down Core.
- ::aos::common::testing::GlobalCoreInstance my_core;
+ ::aos::testing::TestSharedMemory my_shm_;
};
// Tests that cancel stops not only the score action, but also the underlying
diff --git a/y2015/actors/stack_actor_test.cc b/y2015/actors/stack_actor_test.cc
index e1b1856..35b3604 100644
--- a/y2015/actors/stack_actor_test.cc
+++ b/y2015/actors/stack_actor_test.cc
@@ -4,7 +4,7 @@
#include "gtest/gtest.h"
#include "aos/common/queue.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_shm.h"
#include "aos/common/actions/actor.h"
#include "y2015/actors/stack_action.q.h"
#include "y2015/actors/stack_actor.h"
@@ -36,7 +36,7 @@
}
// Bring up and down Core.
- ::aos::common::testing::GlobalCoreInstance my_core;
+ ::aos::testing::TestSharedMemory my_shm_;
};
// Tests that cancel stops not only the stack action, but the underlying profile
diff --git a/y2015/control_loops/drivetrain/drivetrain_lib_test.cc b/y2015/control_loops/drivetrain/drivetrain_lib_test.cc
index d3869aa..8585fda 100644
--- a/y2015/control_loops/drivetrain/drivetrain_lib_test.cc
+++ b/y2015/control_loops/drivetrain/drivetrain_lib_test.cc
@@ -4,7 +4,6 @@
#include "gtest/gtest.h"
#include "aos/common/network/team_number.h"
-#include "aos/common/queue_testutils.h"
#include "aos/common/controls/polytope.h"
#include "aos/common/controls/control_loop_test.h"
diff --git a/y2015/util/BUILD b/y2015/util/BUILD
index 481ed7e..71c7adb 100644
--- a/y2015/util/BUILD
+++ b/y2015/util/BUILD
@@ -19,7 +19,7 @@
],
deps = [
'//aos/testing:googletest',
- '//aos/common:queue_testutils',
+ '//aos/testing:test_logging',
'//aos/common/logging',
'//frc971/control_loops:team_number_test_environment',
':kinematics',
diff --git a/y2015/util/kinematics_test.cc b/y2015/util/kinematics_test.cc
index be1645e..acf3699 100644
--- a/y2015/util/kinematics_test.cc
+++ b/y2015/util/kinematics_test.cc
@@ -3,7 +3,7 @@
#include "gtest/gtest.h"
#include "aos/common/logging/logging.h"
-#include "aos/common/queue_testutils.h"
+#include "aos/testing/test_logging.h"
#include "y2015/util/kinematics.h"
#include "frc971/control_loops/team_number_test_environment.h"
@@ -25,7 +25,7 @@
upper_angle_limit_(M_PI / 2.0) {}
void SetUp() {
- ::aos::common::testing::EnableTestLogging();
+ ::aos::testing::EnableTestLogging();
kinematics_ = ElevatorArmKinematics(arm_length_, upper_height_limit_, lower_height_limit_,
upper_angle_limit_, lower_angle_limit_);
}
diff --git a/y2015_bot3/control_loops/drivetrain/drivetrain_lib_test.cc b/y2015_bot3/control_loops/drivetrain/drivetrain_lib_test.cc
index 8848535..4e66302 100644
--- a/y2015_bot3/control_loops/drivetrain/drivetrain_lib_test.cc
+++ b/y2015_bot3/control_loops/drivetrain/drivetrain_lib_test.cc
@@ -4,7 +4,6 @@
#include "gtest/gtest.h"
#include "aos/common/network/team_number.h"
-#include "aos/common/queue_testutils.h"
#include "aos/common/controls/polytope.h"
#include "aos/common/controls/control_loop_test.h"