Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TEC ApplicationModule
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MSK-SW
Infrastructure and Support
TEC
TEC ApplicationModule
Commits
6a01d8b0
Commit
6a01d8b0
authored
2 years ago
by
Jens Georg
Browse files
Options
Downloads
Patches
Plain Diff
Add test for heartbeat functionality
parent
3383574f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/executable_src/testHeartbeat.cc
+157
-0
157 additions, 0 deletions
tests/executable_src/testHeartbeat.cc
with
157 additions
and
0 deletions
tests/executable_src/testHeartbeat.cc
0 → 100644
+
157
−
0
View file @
6a01d8b0
// Define a name for the test module.
#define BOOST_TEST_MODULE testHeartbeat
// Only after defining the name include the unit test header.
#include
<boost/test/included/unit_test.hpp>
#include
<ChimeraTK/ApplicationCore/TestFacility.h>
#include
"Server.h"
#include
"TecDummy.h"
namespace
ctk
=
ChimeraTK
;
// Declare the server instance
struct
Fixture_t
{
Server
theServer
{
"tec_dummy"
};
ChimeraTK
::
TestFacility
testFacility
;
boost
::
shared_ptr
<
TecDummy
>
dummy
{
boost
::
dynamic_pointer_cast
<
TecDummy
>
(
ChimeraTK
::
BackendFactory
::
getInstance
().
createBackend
(
"ActualDevice"
))};
};
using
namespace
boost
::
unit_test_framework
;
BOOST_AUTO_TEST_SUITE
(
TecHeartbeatTestSuite
)
/**********************************************************************************************************************/
BOOST_FIXTURE_TEST_CASE
(
testHeartbeatEnableDisable
,
Fixture_t
)
{
std
::
cout
<<
"testHearbeatEnableDisable"
<<
std
::
endl
;
auto
heartbeatEnable
=
testFacility
.
getScalar
<
ctk
::
Boolean
>
(
"TecModule/enableHeartbeat"
);
auto
deviceType
=
testFacility
.
getScalar
<
int
>
(
"TecModule/mon_deviceType_rd"
);
testFacility
.
runApplication
();
// Set the device type, the module should not read that as neither heartbeat is on, nor explicit read request for
// the property and not added to periodic readout
int
setDeviceType
=
4711
;
dummy
->
set
(
TecFrame
::
TecParameter
::
DeviceType
,
setDeviceType
);
theServer
.
periodicRead
.
sendTrigger
();
testFacility
.
stepApplication
();
deviceType
.
readLatest
();
BOOST_CHECK_EQUAL
(
deviceType
,
0
);
// enable heartbeat, whe should get the value set above
heartbeatEnable
=
true
;
heartbeatEnable
.
write
();
theServer
.
periodicRead
.
sendTrigger
();
testFacility
.
stepApplication
();
deviceType
.
readLatest
();
BOOST_CHECK_EQUAL
(
setDeviceType
,
deviceType
);
// change value, should be updated in the module
setDeviceType
++
;
dummy
->
set
(
TecFrame
::
TecParameter
::
DeviceType
,
setDeviceType
);
theServer
.
periodicRead
.
sendTrigger
();
testFacility
.
stepApplication
();
deviceType
.
readLatest
();
BOOST_CHECK_EQUAL
(
setDeviceType
,
deviceType
);
// disable heartbeat, update value. Value in module should stay the same
heartbeatEnable
=
false
;
heartbeatEnable
.
write
();
setDeviceType
++
;
dummy
->
set
(
TecFrame
::
TecParameter
::
DeviceType
,
setDeviceType
);
theServer
.
periodicRead
.
sendTrigger
();
testFacility
.
stepApplication
();
deviceType
.
readLatest
();
BOOST_CHECK_EQUAL
(
setDeviceType
-
1
,
deviceType
);
}
/**********************************************************************************************************************/
BOOST_FIXTURE_TEST_CASE
(
testHearbeatOnPeriodicRead
,
Fixture_t
)
{
std
::
cout
<<
"testHearbeatOnPeriodicRead"
<<
std
::
endl
;
auto
heartbeatEnable
=
testFacility
.
getScalar
<
ctk
::
Boolean
>
(
"TecModule/enableHeartbeat"
);
auto
deviceType
=
testFacility
.
getScalar
<
int
>
(
"TecModule/mon_deviceType_rd"
);
int
setDeviceType
=
4811
;
dummy
->
set
(
TecFrame
::
TecParameter
::
DeviceType
,
setDeviceType
);
// Enable heartbeat, check that information from the heartbeat register is read
testFacility
.
runApplication
();
heartbeatEnable
=
true
;
heartbeatEnable
.
write
();
theServer
.
periodicRead
.
sendTrigger
();
testFacility
.
stepApplication
();
deviceType
.
readLatest
();
BOOST_CHECK_EQUAL
(
setDeviceType
,
deviceType
);
// Add a variable to the periodic read. The module should stop reading out the heartbeat register
testFacility
.
writeScalar
<
int
>
(
"TecModule/mon_serialNumber_enaPeriodicRead"
,
1
);
int
lastDeviceType
=
setDeviceType
;
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
dummy
->
set
(
TecFrame
::
TecParameter
::
DeviceType
,
++
setDeviceType
);
theServer
.
periodicRead
.
sendTrigger
();
testFacility
.
stepApplication
();
deviceType
.
readLatest
();
BOOST_CHECK_EQUAL
(
lastDeviceType
,
deviceType
);
}
// disable periodic variable. HB register should be updated again
testFacility
.
writeScalar
<
int
>
(
"TecModule/mon_serialNumber_enaPeriodicRead"
,
0
);
theServer
.
periodicRead
.
sendTrigger
();
testFacility
.
stepApplication
();
deviceType
.
readLatest
();
BOOST_CHECK_EQUAL
(
setDeviceType
,
deviceType
);
}
/**********************************************************************************************************************/
BOOST_FIXTURE_TEST_CASE
(
testHearbeatFailCausesModuleError
,
Fixture_t
)
{
std
::
cout
<<
"testHearbeatOnPeriodicRead"
<<
std
::
endl
;
auto
heartbeatEnable
=
testFacility
.
getScalar
<
ctk
::
Boolean
>
(
"TecModule/enableHeartbeat"
);
auto
deviceType
=
testFacility
.
getScalar
<
int
>
(
"TecModule/mon_deviceType_rd"
);
auto
errorMessage
=
testFacility
.
getScalar
<
std
::
string
>
(
"TecModule/errorMessage"
);
auto
errorStatus
=
testFacility
.
getScalar
<
int
>
(
"TecModule/errorStatus"
);
auto
errorReset
=
testFacility
.
getScalar
<
int
>
(
"TecModule/errorReset"
);
int
setDeviceType
=
4811
;
dummy
->
set
(
TecFrame
::
TecParameter
::
DeviceType
,
setDeviceType
);
// Enable heartbeat, check that information from the heartbeat register is read
testFacility
.
runApplication
();
heartbeatEnable
=
true
;
heartbeatEnable
.
write
();
theServer
.
periodicRead
.
sendTrigger
();
testFacility
.
stepApplication
();
deviceType
.
readLatest
();
BOOST_CHECK_EQUAL
(
setDeviceType
,
deviceType
);
dummy
->
simulateSerialTimeout
=
true
;
theServer
.
periodicRead
.
sendTrigger
();
testFacility
.
stepApplication
();
deviceType
.
readLatest
();
BOOST_CHECK
(
deviceType
.
dataValidity
()
==
ctk
::
DataValidity
::
faulty
);
BOOST_CHECK
(
errorMessage
.
readNonBlocking
());
BOOST_CHECK
(
errorStatus
.
readNonBlocking
());
BOOST_CHECK
(
std
::
string
(
errorMessage
)
!=
""
);
BOOST_CHECK
(
std
::
string
(
errorMessage
).
find
(
"mon_deviceType"
)
!=
std
::
string
::
npos
);
BOOST_CHECK
(
errorStatus
!=
0
);
BOOST_CHECK_EQUAL
(
setDeviceType
,
deviceType
);
}
/**********************************************************************************************************************/
BOOST_AUTO_TEST_SUITE_END
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment