Skip to content

Commit

Permalink
test: use unique names for global shm segments
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoessbauer committed Jan 15, 2020
1 parent 05578ff commit 15f0bc7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 1 addition & 3 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,5 @@ if(BUILD_TESTING)
add_executable(common_test ${TEST_SOURCES})
target_link_libraries(common_test PRIVATE gtest gtest_main "drace-common")
# SHMDriver requires serial execution
gtest_discover_tests(common_test
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
PROPERTIES RUN_SERIAL ON)
gtest_discover_tests(common_test WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
endif()
25 changes: 20 additions & 5 deletions common/test/ShmDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,27 @@
* SPDX-License-Identifier: MIT
*/

#include <random>
#include <string>
#include "gtest/gtest.h"

#include "ipc/SyncSHMDriver.h"

/**
* \note use unique names for SHM segments as tests
* might run in parallel
*/

/**
* \brief Return the name with a unique suffix
*/
std::string getUniqueName(const std::string & name){
return name + std::to_string(std::random_device()());
}

TEST(SyncShmDriver, InitFinalize) {
ipc::SyncSHMDriver<true, false> sender("test-shm", true);
ipc::SyncSHMDriver<true, false> receiver("test-shm", true);
std::string shmseg(getUniqueName("test-shm-if"));
ipc::SyncSHMDriver<true, false> sender(shmseg.c_str(), true);
ipc::SyncSHMDriver<true, false> receiver(shmseg.c_str(), true);

sender.id(ipc::SMDataID::CONNECT);
sender.commit();
Expand All @@ -36,9 +50,10 @@ TEST(SyncShmDriver, Emplace) {
int a = 10;
bool b = false;
};
std::string shmseg(getUniqueName("test-shm-emplace"));

ipc::SyncSHMDriver<true, false> sender("test-shm", true);
ipc::SyncSHMDriver<true, false> receiver("test-shm", true);
ipc::SyncSHMDriver<true, false> sender(shmseg.c_str(), true);
ipc::SyncSHMDriver<true, false> receiver(shmseg.c_str(), true);

sender.emplace<test_t>(ipc::SMDataID::SYMBOL);
sender.commit();
Expand Down

0 comments on commit 15f0bc7

Please sign in to comment.