ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
testRebotBackendCreation.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 testRebotBackendCreation
6#include <boost/test/unit_test.hpp>
7using namespace boost::unit_test_framework;
8
9#include "BackendFactory.h"
10#include "Device.h"
11#include "DMapFileParser.h"
12#include "NumericAddress.h"
13#include "RebotBackend.h"
14#include "Utilities.h"
15
16namespace ChimeraTK {
17 using namespace ChimeraTK;
18}
19
21
22BOOST_AUTO_TEST_SUITE(RebotDeviceTestSuite)
23
24BOOST_AUTO_TEST_CASE(testFactoryForRebotDeviceCreation) {
25 // set dmap file path
26 auto dmapPathBackup = ChimeraTK::getDMapFilePath();
27 std::string dmapPath{"./dummies.dmap"};
28 if(framework::master_test_suite().argc > 1) {
29 dmapPath = framework::master_test_suite().argv[1];
30 }
32 std::string port{"5001"};
33 if(framework::master_test_suite().argc > 2) {
34 port = framework::master_test_suite().argv[2];
35 }
36
37 // There are four situations where the map-file information is coming from
38 // 1. From the dmap file (old way, third column in dmap file)
39 // 2. From the URI (new, recommended, not supported by dmap parser at the
40 // moment)
41 // 3. No map file at all (not supported by the dmap parser at the moment)
42 // 4. Both dmap file and URI contain the information (prints a warning and
43 // takes the one from the dmap file)
44
45 // 1. The original way with map file as third column in the dmap file
46 ChimeraTK::Device rebotDevice;
47 rebotDevice.open("mskrebot");
48 checkWriteReadFromRegister(rebotDevice);
49
50 ChimeraTK::Device rebotDevice2;
51 // create another mskrebot
52 rebotDevice2.open("mskrebot");
53 checkWriteReadFromRegister(rebotDevice2);
54
55 rebotDevice.write<double>("BOARD/WORD_USER", 48);
56 rebotDevice.close(); // we have to close this because
57
58 // 2. Creating without map file in the dmap only works by putting an sdm on
59 // creation because we have to bypass the dmap file parser which at the time
60 // of writing this requires a map file as third column
61 ChimeraTK::Device secondDevice;
62 secondDevice.open("(rebot?ip=localhost&port=" + port + "&map=mtcadummy_rebot.map)");
63 BOOST_CHECK(secondDevice.read<double>("BOARD/WORD_USER") == 48);
64 secondDevice.close();
65
66 // 3. We don't have a map file, so we have to use numerical addressing
67 ChimeraTK::Device thirdDevice;
68 thirdDevice.open("(rebot?ip=localhost&port=" + port + ")");
69 BOOST_CHECK(thirdDevice.read<int32_t>(ChimeraTK::numeric_address::BAR() / 0 / 0xC) == 48 << 3); // The user register
70 // is on bar 0,
71 // address 0xC. We
72 // have no fixed point
73 // data conversion but
74 // 3 fractional bits.
75 thirdDevice.close();
76
77 // 4. This should print a warning. We can't check that, so we just check that
78 // it does work like the other two options.
79 ChimeraTK::Device fourthDevice;
80 fourthDevice.open("REBOT_DOUBLEMAP");
81 BOOST_CHECK(fourthDevice.read<double>("BOARD/WORD_USER") == 48);
82
83 // reset dmap path to what was at the start of these tests
84 ChimeraTK::setDMapFilePath(dmapPathBackup);
85}
86
87BOOST_AUTO_TEST_SUITE_END()
88
90 std::vector<int32_t> dataToWrite({2, 3, 100, 20});
91
92 // 0xDEADBEEF is a word preset by the dummy firmware in the WORD_COMPILATION
93 // register (addr 0x04). reading and verifying this register means the read
94 // api of device acces works for the rebot device.
95 BOOST_CHECK_EQUAL(rebotDevice.read<uint32_t>("BOARD/WORD_COMPILATION"), 0xDEADBEEF);
96
97 // ADC.WORLD_CLK_MUX is a 4 word/element register, this test would verify
98 // write to the device through the api works. (THe read command has been
99 // established to work by the read of the preset word).
100 rebotDevice.write("ADC/WORD_CLK_MUX", dataToWrite);
101 BOOST_CHECK(rebotDevice.read<int>("ADC/WORD_CLK_MUX", 4) == dataToWrite);
102
103 // test read from offset 2 on a multi word/element register.
104 auto acc1 = rebotDevice.getScalarRegisterAccessor<int32_t>("ADC/WORD_CLK_MUX", 2);
105 acc1.read();
106 BOOST_CHECK_EQUAL(dataToWrite[2], static_cast<int32_t>(acc1));
107
108 // test write one element at offset position 2 on a multiword register.
109 acc1 = dataToWrite[0];
110 acc1.write();
111 acc1 = 0;
112 acc1.read();
113 BOOST_CHECK_EQUAL(dataToWrite[0], static_cast<int32_t>(acc1));
114
115 // test writing a continuous block from offset 1 in a multiword register.
116 auto acc2 = rebotDevice.getOneDRegisterAccessor<int32_t>("ADC/WORD_CLK_MUX", 2, 1);
117 acc2 = std::vector<int32_t>({676, 9987});
118 acc2.write();
119 acc2 = std::vector<int32_t>({0, 0});
120 acc2.read();
121 BOOST_CHECK_EQUAL(acc2[0], 676);
122 BOOST_CHECK_EQUAL(acc2[1], 9987);
123
124 // write to larger area
125 auto testArea = rebotDevice.getOneDRegisterAccessor<int32_t>("ADC/TEST_AREA"); // testArea is 1024 words long
126 for(int i = 0; i < 10; ++i) {
127 testArea[i] = i;
128 }
129 testArea.write();
130 testArea.read();
131 for(int i = 0; i < 10; ++i) {
132 BOOST_CHECK_EQUAL(testArea[i], i);
133 }
134}
Class allows to read/write registers from device.
Definition Device.h:39
void close()
Close the device.
Definition Device.cc:66
UserType read(const RegisterPath &registerPathName, const AccessModeFlags &flags=AccessModeFlags({})) const
Inefficient convenience function to read a single-word register without obtaining an accessor.
Definition Device.h:296
void open(std::string const &aliasName)
Open a device by the given alias name from the DMAP file.
Definition Device.cc:58
void write(const RegisterPath &registerPathName, UserType value, const AccessModeFlags &flags=AccessModeFlags({}))
Inefficient convenience function to write a single-word register without obtaining an accessor.
Definition Device.h:317
RegisterPath BAR()
The numeric_address::BAR() function can be used to directly access registers by numeric addresses,...
std::string getDMapFilePath()
Returns the dmap file name which the library currently uses for looking up device(alias) names.
void setDMapFilePath(std::string dmapFilePath)
Set the location of the dmap file.
void checkWriteReadFromRegister(ChimeraTK::Device &rebotDevice)
BOOST_AUTO_TEST_CASE(testFactoryForRebotDeviceCreation)