ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
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>
7using namespace boost::unit_test_framework;
8
9#include "BackendFactory.h"
10#include "Device.h"
11#include "DeviceBackend.h"
13#include "Exception.h"
14#include "MapFileParser.h"
15#include "PcieBackend.h"
16
17#include <cstring>
18
19namespace ChimeraTK {
20 using namespace ChimeraTK;
21}
22
23BOOST_AUTO_TEST_CASE(testPcieErrorHandling) {
24 std::string line;
25
26 ChimeraTK::setDMapFilePath("pcie_device.dmap");
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}
Class allows to read/write registers from device.
Definition Device.h:39
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:266
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
void open(std::string const &aliasName)
Open a device by the given alias name from the DMAP file.
Definition Device.cc:58
Exception thrown when a runtime error has occured.
Definition Exception.h:18
void setDMapFilePath(std::string dmapFilePath)
Set the location of the dmap file.
ctk::Device device
BOOST_AUTO_TEST_CASE(testPcieErrorHandling)