4 #define BOOST_TEST_DYN_LINK
5 #define BOOST_TEST_MODULE GenericMuxedInterruptDistributorTest
10 #include <boost/test/unit_test.hpp>
16 using namespace boost::unit_test_framework;
20 auto currentTime = startTime;
21 while(currentTime < startTime + std::chrono::milliseconds(msTimeout)) {
22 std::this_thread::sleep_for(std::chrono::milliseconds(10));
31 BOOST_AUTO_TEST_SUITE(INTCHandlerTestSuite)
33 static constexpr std::string_view testCdd{
"(WriteMonitoring:xdma/slot5?map=irq_test.mapp)"};
42 acknowledged[
"ISR"] = 0;
43 acknowledged[
"IAR"] = 0;
44 acknowledged[
"ICR"] = 0;
47 [&] { acknowledged[
"ISR"] |=
static_cast<uint32_t
>(getRawAccessor(
"TEST0",
"ISR")); });
49 [&] { acknowledged[
"IAR"] |=
static_cast<uint32_t
>(getRawAccessor(
"TEST1",
"IAR")); });
51 [&] { acknowledged[
"ICR"] |=
static_cast<uint32_t
>(getRawAccessor(
"TEST2",
"ICR")); });
53 [&] { acknowledged[
"ISR"] |=
static_cast<uint32_t
>(getRawAccessor(
"TEST5",
"ISR")); });
55 [&] { sie |=
static_cast<uint32_t
>(getRawAccessor(
"TEST5",
"SIE")); });
59 [[maybe_unused]] std::string address, std::map<std::string, std::string> parameters) {
60 if(parameters[
"map"].empty()) {
90 TestFixture(uint32_t interrupt,
bool activateAsyncFirst) : _interrupt(interrupt) {
91 dummyBackend = boost::dynamic_pointer_cast<WriteMonitoringBackend>(
device.
getBackend());
94 if(activateAsyncFirst) {
100 "!" +
std::to_string(interrupt) +
":4", {ChimeraTK::AccessMode::wait_for_new_data}));
105 if(activateAsyncFirst) {
129 BOOST_CHECK_MESSAGE(
false,
"Creating register \"" + testRegister +
"\" did not throw as expected!");
132 std::cout <<
"Caught expected exception for " << boost::unit_test::framework::current_test_case().p_name
133 <<
". Print for manual check of message: " << e.
what() << std::endl;
149 BOOST_TEST(0x0 == ier);
150 BOOST_TEST(dummyBackend->acknowledged[
"ISR"] == 0);
155 BOOST_TEST(0x10 == ier);
156 BOOST_TEST(dummyBackend->acknowledged[
"ISR"] == 0x10);
157 dummyBackend->acknowledged[
"ISR"] = 0;
161 BOOST_TEST(ier == 0x30);
162 BOOST_TEST(dummyBackend->acknowledged[
"ISR"] == 0x20);
170 BOOST_TEST(ier == 0x20);
177 BOOST_TEST(ier == 0x0);
186 BOOST_TEST(0x10 == ier);
187 BOOST_TEST(dummyBackend->acknowledged[
"ISR"] == 0x10);
208 auto dummyInterruptTrigger =
210 dummyInterruptTrigger.
write();
221 device.
read<int32_t>(
"TEST3/MER/DUMMY_READABLE") == 0x3);
224 BOOST_TEST(
device.
read<uint32_t>(
"TEST3/IER") == (1U << 0));
232 BOOST_TEST(
device.
read<int32_t>(
"TEST3/SUB1/MER") == 0x3);
233 BOOST_TEST(
device.
read<uint32_t>(
"TEST3/SUB1/IER") == (1U << 3));
237 AcknowledgeTest(uint32_t interrupt, std::string ackReg) : TestFixture(interrupt, true), ackRegister(ackReg) {}
244 BOOST_TEST(dummyBackend->acknowledged[ackRegister] == 0x10);
248 isr.setAndWrite(0x11);
250 dummyBackend->acknowledged[ackRegister] = 0;
252 dummyInterrupt.write();
256 BOOST_TEST(dummyBackend->acknowledged[ackRegister] == 0x10);
258 dummyBackend->acknowledged[ackRegister] = 0;
260 "!" +
std::to_string(_interrupt) +
":5", {ChimeraTK::AccessMode::wait_for_new_data}));
261 BOOST_TEST(dummyBackend->acknowledged[ackRegister] == 0x20);
266 isr.setAndWrite(0x11);
268 dummyBackend->acknowledged[ackRegister] = 0;
269 dummyInterrupt.write();
273 BOOST_TEST(dummyBackend->acknowledged[ackRegister] == 0x10);
274 if(ackRegister !=
"ISR") {
275 BOOST_TEST(isr.readAndGet() == 0x11);
279 isr.setAndWrite(0x21);
281 dummyBackend->acknowledged[ackRegister] = 0;
282 dummyInterrupt.write();
284 BOOST_CHECK(!accInterrupt.readNonBlocking());
286 BOOST_TEST(dummyBackend->acknowledged[ackRegister] == 0x20);
287 if(ackRegister !=
"ISR") {
288 BOOST_TEST(isr.readAndGet() == 0x21);
292 isr.setAndWrite(0x31);
294 dummyBackend->acknowledged[ackRegister] = 0;
295 dummyInterrupt.write();
299 BOOST_TEST(dummyBackend->acknowledged[ackRegister] == 0x30);
300 if(ackRegister !=
"ISR") {
301 BOOST_TEST(isr.readAndGet() == 0x31);
337 : TestFixture(interrupt, enableFirst), isEnabled(enableFirst) {
378 device.
open(
"(dummy:xdma/slot5?map=irq_test.mapp)");
382 imr.setAndWrite(0x7F);
387 BOOST_CHECK_MESSAGE(
false,
"IMR not detected as invalid option.");
390 std::cout <<
"Caught expected exeption. Print for manual check of message: " << e.
what() << std::endl;
397 BOOST_TEST(imr.readAndGet() == 0x6F);
414 BOOST_TEST(sie.readAndGet() == 0x0);
415 BOOST_TEST(cie.readAndGet() == 0x0);
416 BOOST_TEST(dummyBackend->acknowledged[
"ISR"] == 0x0);
417 BOOST_TEST(isr.readAndGet() == 0x0);
423 BOOST_TEST(sie.readAndGet() == 0x10);
424 BOOST_TEST(isr.readAndGet() == 0x10);
425 BOOST_TEST(dummyBackend->acknowledged[
"ISR"] == 0x10);
426 BOOST_TEST(cie.readAndGet() == 0x0);
431 BOOST_TEST(cie.readAndGet() == 0x10);
441 BOOST_TEST(sie.readAndGet() == 0x10);
442 BOOST_TEST(dummyBackend->acknowledged[
"ISR"] == 0x10);
443 dummyBackend->acknowledged[
"ISR"] = 0x0;
447 BOOST_CHECK_MESSAGE((sie == 0x20) ||
449 "SIE is " +
std::to_string(sie) +
", but should be 0x20 or 0x30");
450 BOOST_TEST(dummyBackend->acknowledged[
"ISR"] == 0x20);
457 BOOST_TEST(cie.readAndGet() == 0x10);
466 BOOST_TEST(cie.readAndGet() == 0x20);
469 BOOST_TEST(cie.readAndGet() == 0x30);
477 BOOST_TEST(dummyBackend->sie == 0x0);
478 BOOST_TEST(dummyBackend->acknowledged[
"ISR"] == 0x0);
483 BOOST_TEST(dummyBackend->sie == 0x30);
484 BOOST_TEST(dummyBackend->acknowledged[
"ISR"] == 0x30);
706 BOOST_AUTO_TEST_SUITE_END()