Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ApplicationCore
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
ChimeraTK Mirror
ApplicationCore
Commits
ba52b1ac
Commit
ba52b1ac
authored
2 years ago
by
Jens Georg
Committed by
Martin Christoph Hierholzer
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix testDeviceInitialisationHandler
parent
7a5f7810
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/executables_src/testDeviceInitialisationHandler.cc
+31
-24
31 additions, 24 deletions
tests/executables_src/testDeviceInitialisationHandler.cc
with
31 additions
and
24 deletions
tests/executables_src/testDeviceInitialisationHandler.cc
+
31
−
24
View file @
ba52b1ac
// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
// SPDX-License-Identifier: LGPL-3.0-or-later
//#include <future>
#define BOOST_TEST_MODULE testDeviceInitialisationHandler
//#include <boost/mpl/list.hpp>
#include
"Application.h"
#include
"DeviceModule.h"
#include
<boost/test/included/unit_test.hpp>
//#include "ScalarAccessor.h"
#include
"check_timeout.h"
#include
"DeviceModule.h"
#include
"TestFacility.h"
#include
"Utilities.h"
#include
<ChimeraTK/Device.h>
#include
<ChimeraTK/ExceptionDummyBackend.h>
#include
<stdlib.h>
#include
<boost/test/included/unit_test.hpp>
#include
<cstdlib>
using
namespace
boost
::
unit_test_framework
;
namespace
ctk
=
ChimeraTK
;
...
...
@@ -49,9 +47,8 @@ void initialiseReg3(ChimeraTK::Device&) {
/* dummy application */
struct
TestApplication
:
public
ctk
::
Application
{
TestApplication
()
:
Application
(
"testSuite"
)
{}
~
TestApplication
()
{
shutdown
();
}
~
TestApplication
()
override
{
shutdown
();
}
void
defineConnections
()
{}
// the setup is done in the tests
ctk
::
DeviceModule
dev
{
this
,
deviceCDD
,
""
,
&
initialiseReg1
};
};
...
...
@@ -65,10 +62,8 @@ BOOST_AUTO_TEST_CASE(testBasicInitialisation) {
var2
=
0
;
var3
=
0
;
// app.dev.connectTo(app.cs);
ctk
::
TestFacility
test
{
app
};
test
.
runApplication
();
// app.dumpConnections();
ctk
::
Device
dummy
;
dummy
.
open
(
deviceCDD
);
...
...
@@ -115,12 +110,11 @@ BOOST_AUTO_TEST_CASE(testMultipleInitialisationHandlers) {
app
.
dev
.
addInitialisationHandler
(
&
initialiseReg2
);
app
.
dev
.
addInitialisationHandler
(
&
initialiseReg3
);
// app.dev.connectTo(app.cs);
ctk
::
TestFacility
test
{
app
};
test
.
runApplication
();
// app.dumpConnections();
auto
deviceStatus
=
test
.
getScalar
<
int32_t
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
deviceCDD
/
"status"
);
auto
deviceStatus
=
test
.
getScalar
<
int32_t
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
ctk
::
Utilities
::
stripName
(
deviceCDD
,
false
)
/
"status"
);
// *********************************************************
// REQUIRED TEST 4: Handlers are executed in the right order
...
...
@@ -179,8 +173,11 @@ BOOST_AUTO_TEST_CASE(testInitialisationException) {
app
.
run
();
// app.dumpConnections();
CHECK_EQUAL_TIMEOUT
(
test
.
readScalar
<
int32_t
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
deviceCDD
/
"status"
),
1
,
30000
);
CHECK_EQUAL_TIMEOUT
(
test
.
readScalar
<
std
::
string
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
deviceCDD
/
"status_message"
),
CHECK_EQUAL_TIMEOUT
(
test
.
readScalar
<
int32_t
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
ctk
::
Utilities
::
stripName
(
deviceCDD
,
false
)
/
"status"
),
1
,
30000
);
CHECK_EQUAL_TIMEOUT
(
test
.
readScalar
<
std
::
string
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
ctk
::
Utilities
::
stripName
(
deviceCDD
,
false
)
/
"status_message"
),
exceptionMessage
,
10000
);
// Check that the execution of init handlers was stopped after the exception:
...
...
@@ -194,12 +191,15 @@ BOOST_AUTO_TEST_CASE(testInitialisationException) {
// recover the error
throwInInitialisation
=
false
;
// wait until the device is reported to be OK again (chec
h
with timeout),
// wait until the device is reported to be OK again (chec
k
with timeout),
// then check the initialisation (again, no extra timeout needed because of the logic:
// success is only reported after successful init).
CHECK_EQUAL_TIMEOUT
(
test
.
readScalar
<
int32_t
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
deviceCDD
/
"status"
),
0
,
10000
);
CHECK_EQUAL_TIMEOUT
(
test
.
readScalar
<
std
::
string
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
deviceCDD
/
"status_message"
),
""
,
10000
);
test
.
readScalar
<
int32_t
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
ctk
::
Utilities
::
stripName
(
deviceCDD
,
false
)
/
"status"
),
0
,
10000
);
CHECK_EQUAL_TIMEOUT
(
test
.
readScalar
<
std
::
string
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
ctk
::
Utilities
::
stripName
(
deviceCDD
,
false
)
/
"status_message"
),
""
,
10000
);
// initialisation should be correct now
BOOST_CHECK_EQUAL
(
var1
,
42
);
...
...
@@ -222,21 +222,28 @@ BOOST_AUTO_TEST_CASE(testInitialisationException) {
reg4_cs
=
20
;
reg4_cs
.
write
();
CHECK_EQUAL_TIMEOUT
(
test
.
readScalar
<
int32_t
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
deviceCDD
/
"status"
),
1
,
10000
);
CHECK_EQUAL_TIMEOUT
(
test
.
readScalar
<
int32_t
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
ctk
::
Utilities
::
stripName
(
deviceCDD
,
false
)
/
"status"
),
1
,
10000
);
// First we see the message from the failing write
BOOST_CHECK
(
test
.
readScalar
<
std
::
string
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
deviceCDD
/
"status_message"
)
!=
""
);
BOOST_CHECK
(
test
.
readScalar
<
std
::
string
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
ctk
::
Utilities
::
stripName
(
deviceCDD
,
false
)
/
"status_message"
)
!=
""
);
dummyBackend
->
throwExceptionWrite
=
false
;
// Afterwards we see a message from the failing initialisation (which we can now distinguish from the original write
// exception because write does not throw any more)
CHECK_EQUAL_TIMEOUT
(
test
.
readScalar
<
std
::
string
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
deviceCDD
/
"status_message"
),
CHECK_EQUAL_TIMEOUT
(
test
.
readScalar
<
std
::
string
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
ctk
::
Utilities
::
stripName
(
deviceCDD
,
false
)
/
"status_message"
),
exceptionMessage
,
10000
);
// Now fix the initialisation error and check that the device comes up.
throwInInitialisation
=
false
;
// Wait until the device is OK again
CHECK_EQUAL_TIMEOUT
(
test
.
readScalar
<
int32_t
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
deviceCDD
/
"status"
),
0
,
10000
);
CHECK_EQUAL_TIMEOUT
(
test
.
readScalar
<
std
::
string
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
deviceCDD
/
"status_message"
),
""
,
10000
);
test
.
readScalar
<
int32_t
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
ctk
::
Utilities
::
stripName
(
deviceCDD
,
false
)
/
"status"
),
0
,
10000
);
CHECK_EQUAL_TIMEOUT
(
test
.
readScalar
<
std
::
string
>
(
ctk
::
RegisterPath
(
"/Devices"
)
/
ctk
::
Utilities
::
stripName
(
deviceCDD
,
false
)
/
"status_message"
),
""
,
10000
);
// Finally check that the 20 arrives on the device
CHECK_EQUAL_TIMEOUT
(
dummy
.
read
<
int32_t
>
(
"/REG4"
),
20
,
10000
);
}
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