ChimeraTK-DeviceAccess
03.25.00
Loading...
Searching...
No Matches
sharedDummyHelpers.h
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2
// SPDX-License-Identifier: LGPL-3.0-or-later
3
#pragma once
4
5
#include <sys/file.h>
6
7
#include <boost/interprocess/managed_shared_memory.hpp>
8
9
#include <iostream>
10
#include <string>
11
#include <utility>
12
13
enum class
MirrorRequestType
:
int
{
from
= 1,
to
,
stop
};
14
15
bool
shm_exists
(std::string shmName) {
16
bool
result;
17
18
try
{
19
boost::interprocess::managed_shared_memory shm{boost::interprocess::open_only, shmName.c_str()};
20
result = shm.check_sanity();
21
}
22
catch
(
const
std::exception& ex) {
23
result =
false
;
24
}
25
return
result;
26
}
27
28
// Use a file lock on dmap-file to ensure we are not running
29
// concurrent tests in parallel using the same shared dummies.
30
//
31
// Note: flock() creates an advisory lock only, plain file access is not
32
// prevented. The lock is automatically released when the process terminates!
33
struct
TestLocker
{
34
TestLocker
(
const
char
* dmapFile) {
35
// open dmap file for locking
36
fd
= open(dmapFile, O_RDONLY);
37
if
(
fd
== -1) {
38
std::cout <<
"Cannot open file '"
<< dmapFile <<
"' for locking."
<< std::endl;
39
exit(1);
40
}
41
42
// obtain lock
43
int
res = flock(
fd
, LOCK_EX);
44
if
(res == -1) {
45
std::cout <<
"Cannot acquire lock on file '"
<< dmapFile <<
"'."
<< std::endl;
46
exit(1);
47
}
48
}
49
50
int
fd
;
51
};
MirrorRequestType
MirrorRequestType
Definition
sharedDummyHelpers.h:13
MirrorRequestType::to
@ to
MirrorRequestType::from
@ from
MirrorRequestType::stop
@ stop
shm_exists
bool shm_exists(std::string shmName)
Definition
sharedDummyHelpers.h:15
TestLocker
Definition
testPcieBackend.cpp:52
TestLocker::fd
int fd
Definition
sharedDummyHelpers.h:50
TestLocker::TestLocker
TestLocker(const char *dmapFile)
Definition
sharedDummyHelpers.h:34
sources
ChimeraTK-DeviceAccess
tests
include
sharedDummyHelpers.h
Generated by
1.9.8