ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
testPeriodicTrigger.cc
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#define BOOST_TEST_MODULE testPeriodicTrigger
4
5#include "Application.h"
6#include "PeriodicTrigger.h"
7#include "TestFacility.h"
8
9#include <boost/test/included/unit_test.hpp>
10
12
13 using namespace boost::unit_test_framework;
14 using namespace ChimeraTK;
15
16 // Just consume variables because the testfacility is too stupid to step without anything being written.
17 struct TestModule : public ApplicationModule {
19
20 ScalarPushInput<int> in{this, "in", "", ""};
21 void mainLoop() override { in.read(); }
22 };
23
25 TestApplication() : Application("myTestApp") {}
26 ~TestApplication() override { shutdown(); }
27
28 PeriodicTrigger p{this, "SomeTimer", "", 1000, {}, "/Config/timerPeriod", "../tickTock"};
29 TestModule m{this, "SomeModule", ""};
30 };
31
32 // This test is checking that the I/O variables are created as intended,
33 // and that the functionality in testable mode is working. It does not
34 // the real timing (and thus the only and main functionality of the PeriodicTrigger).
35 BOOST_AUTO_TEST_CASE(testIterface) {
36 BOOST_CHECK(true);
38 TestFacility test{app};
39 test.runApplication();
40
41 auto tick = test.getScalar<uint64_t>("/tickTock");
42 tick.readLatest();
43 BOOST_CHECK(tick.getVersionNumber() != VersionNumber{nullptr});
44 BOOST_CHECK_EQUAL(static_cast<uint64_t>(tick), 0);
45
46 // We can only check that the period variable exists and is writeable.
47 // There is no effect in testable mode. Actually, we cannot even write to it
48 // because it not read any more, and the test would faild with an unread queue.
49 BOOST_CHECK_NO_THROW((void)test.getScalar<uint32_t>("/Config/timerPeriod"));
50
51 auto oldVersion = tick.getVersionNumber();
52 // The test facilty does not recognise that the PeriodicTrigger send something. It expects some input from the CS.
53 app.p.sendTrigger();
54 test.writeScalar<int>("/SomeModule/in", 42);
55
56 test.stepApplication();
57 tick.read();
58
59 BOOST_CHECK(tick.getVersionNumber() > oldVersion);
60 BOOST_CHECK_EQUAL(static_cast<uint64_t>(tick), 1);
61 }
62
63} // namespace Tests::testPeriodicTrigger
void shutdown() override
This will remove the global pointer to the instance and allows creating another instance afterwards.
ApplicationModule()=default
Default constructor: Allows late initialisation of modules (e.g.
Convenience class for input scalar accessors with UpdateMode::push.
Helper class to facilitate tests of applications based on ApplicationCore.
InvalidityTracer application module.
Simple periodic trigger that fires a variable once per second.
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ctk::ScalarOutput< uint64_t > tick