33// /
44// / \author Pascal Boeschoten ([email protected] )55
6- // TODO: Update this for the socket lock
76#define BOOST_TEST_MODULE RORC_TestFileSharedObject
87#define BOOST_TEST_MAIN
98#define BOOST_TEST_DYN_LINK
1615#include < condition_variable>
1716#include < iostream>
1817#include < boost/test/unit_test.hpp>
19- #include < boost/filesystem.hpp>
2018#include < boost/exception/all.hpp>
21- #include " InterprocessLock.h"
19+ #include " ReadoutCard/ InterprocessLock.h"
2220
2321#include " ReadoutCard/Exception.h"
2422
2523namespace
2624{
2725
2826using namespace ::AliceO2::roc;
29- namespace b = boost;
30- namespace bip = boost::interprocess;
31- namespace bfs = boost::filesystem;
3227
3328struct TestObject {
3429 TestObject (const std::string& s, int i) : string(s), integer(i) {}
3530 std::string string;
3631 int integer;
3732};
3833
39- const std::string namedMutexName (" AliceO2_InterprocessMutex_Test" );
40- const bfs::path lockFilePath (" /tmp/AliceO2_InterprocessMutex_Test.lock" );
41-
42- void cleanupFiles ()
43- {
44- bip::named_mutex::remove (namedMutexName.c_str ());
45- bfs::remove (lockFilePath);
46- }
34+ const std::string lockName (" AliceO2_InterprocessMutex_Test" );
4735
4836#define CONSTRUCT_LOCK () \
49- Interprocess::Lock _test_lock { lockFilePath, namedMutexName }
37+ Interprocess::Lock _test_lock { lockName }
5038
5139void doLock ()
5240{
@@ -56,8 +44,6 @@ void doLock()
5644// Test the intraprocess locking
5745BOOST_AUTO_TEST_CASE (InterprocessMutexTestIntraprocess)
5846{
59- cleanupFiles ();
60-
6147 std::condition_variable conditionVariable;
6248 std::atomic<bool > childAcquired (false );
6349
@@ -68,7 +54,7 @@ BOOST_AUTO_TEST_CASE(InterprocessMutexTestIntraprocess)
6854 childAcquired = true ;
6955 conditionVariable.notify_all ();
7056 std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
71- } catch (const LockException & e) {
57+ } catch (const SocketLockException & e) {
7258 BOOST_FAIL (" Child failed to acquire FileSharedObject" );
7359 }
7460 });
@@ -80,7 +66,7 @@ BOOST_AUTO_TEST_CASE(InterprocessMutexTestIntraprocess)
8066 if (!status) {
8167 BOOST_FAIL (" Timed out or child failed to acquire lock" );
8268 }
83- BOOST_CHECK_THROW (doLock (), NamedMutexLockException );
69+ BOOST_CHECK_THROW (doLock (), SocketLockException );
8470
8571 // Wait on child thread
8672 future.get ();
@@ -93,8 +79,6 @@ BOOST_AUTO_TEST_CASE(InterprocessMutexTestIntraprocess)
9379// - The parent tries to acquire while the child has it -> it should fail
9480BOOST_AUTO_TEST_CASE (InterprocessMutexTestInterprocess)
9581{
96- cleanupFiles ();
97-
9882 pid_t pid = fork ();
9983
10084 if (pid == 0 ) {
@@ -103,7 +87,6 @@ BOOST_AUTO_TEST_CASE(InterprocessMutexTestInterprocess)
10387 CONSTRUCT_LOCK ();
10488 std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
10589 }
106- cleanupFiles ();
10790 exit (0 );
10891 } else if (pid > 0 ) {
10992 // Parent
0 commit comments