9 #include "gmock/gmock.h" 10 #include "gtest/gtest.h" 22 TEST(SharedMemory, MemoryAndSemaphore) {
24 std::string memoryName =
"/shared-memory-test";
30 EXPECT_TRUE(sharedObject.
get());
34 EXPECT_FALSE(oldStaleSharedMemory.
createNew(memoryName,
false));
39 EXPECT_TRUE(sharedObject.
createNew(memoryName,
true));
43 EXPECT_FALSE(sharedObject.
createNew(memoryName,
false));
45 const u32 valueFromParent = 2;
46 const u32 valueFromChildSuccess = 3;
47 const u32 valueFromChildFailure = 4;
50 EXPECT_TRUE(0 == sharedObject.
get()->
value);
52 sharedObject.
get()->
value = valueFromParent;
60 childView.
attach(memoryName);
63 if (childView().
value == valueFromParent) {
64 childView().value = valueFromChildSuccess;
67 childView().value = valueFromChildFailure;
71 childView().semaphore.increment();
79 EXPECT_TRUE(valueFromChildSuccess == sharedObject.
get()->
value);
Shared memory utilities for connecting the simulator program to the robot program.
SharedMemorySemaphore semaphore
void attach(const std::string &name)
void init(unsigned int value)
bool createNew(const std::string &name, bool allowOverwrite=false)
TEST(SharedMemory, MemoryAndSemaphore)