ChimeraTK-DeviceAccess  03.18.00
testPcieErrorHandling.cpp
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 
4 #define BOOST_TEST_DYN_LINK
5 #define BOOST_TEST_MODULE PcieErrorHandling
6 #include <boost/test/unit_test.hpp>
7 using namespace boost::unit_test_framework;
8 
9 #include "BackendFactory.h"
10 #include "Device.h"
11 #include "DeviceBackend.h"
12 #include "DummyRegisterAccessor.h"
13 #include "Exception.h"
14 #include "MapFileParser.h"
15 #include "PcieBackend.h"
16 
17 #include <cstring>
18 
19 namespace ChimeraTK {
20  using namespace ChimeraTK;
21 }
22 
23 BOOST_AUTO_TEST_CASE(testPcieErrorHandling) {
24  std::string line;
25 
26  ChimeraTK::setDMapFilePath("pcie_device.dmap");
27  ChimeraTK::Device device("PCIE0");
28  auto reg = device.getScalarRegisterAccessor<uint32_t>("APP.0.WORD_FIRMWARE");
29 
30  BOOST_CHECK(!device.isFunctional());
31  device.open();
32 
33  BOOST_CHECK(device.isFunctional());
34  reg.read();
35  BOOST_CHECK(reg != 0);
36  BOOST_CHECK(device.isFunctional());
37 
38  std::cout << "Please now pull the hotplug handle or shut the board down via the MCH, then press ENTER...";
39  std::getline(std::cin, line);
40 
41  BOOST_CHECK(!device.isFunctional());
42  BOOST_CHECK_THROW(reg.read(), ChimeraTK::runtime_error);
43  BOOST_CHECK(!device.isFunctional());
44  BOOST_CHECK_THROW(device.open(), ChimeraTK::runtime_error);
45  BOOST_CHECK(!device.isFunctional());
46 
47  std::cout << "Please now push the hotplug handle back in or start the board via the MCH, then press ENTER...";
48  std::getline(std::cin, line);
49 
50  BOOST_CHECK(!device.isFunctional());
51  device.open();
52  BOOST_CHECK(device.isFunctional());
53 
54  BOOST_CHECK(device.isFunctional());
55  reg.read();
56  BOOST_CHECK(reg != 0);
57  BOOST_CHECK(device.isFunctional());
58 }
DeviceBackend.h
device
ctk::Device device
Definition: testExceptionDummyDevice.cc:18
MapFileParser.h
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(testPcieErrorHandling)
Definition: testPcieErrorHandling.cpp:23
PcieBackend.h
ChimeraTK::runtime_error
Exception thrown when a runtime error has occured.
Definition: Exception.h:18
Device.h
ChimeraTK::Device
Class allows to read/write registers from device.
Definition: Device.h:39
ChimeraTK::Device::open
void open(std::string const &aliasName)
Open a device by the given alias name from the DMAP file.
Definition: Device.cc:58
DummyRegisterAccessor.h
ChimeraTK::Device::getScalarRegisterAccessor
ScalarRegisterAccessor< UserType > getScalarRegisterAccessor(const RegisterPath &registerPathName, size_t wordOffsetInRegister=0, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a ScalarRegisterObject object for the given register.
Definition: Device.h:263
BackendFactory.h
Exception.h
ChimeraTK::setDMapFilePath
void setDMapFilePath(std::string dmapFilePath)
Set the location of the dmap file.
Definition: Utilities.cpp:327
ChimeraTK::Device::isFunctional
bool isFunctional() const
Return wether a device is working as intended, usually this means it is opened and does not have any ...
Definition: Device.cc:82
ChimeraTK
Definition: DummyBackend.h:16