From 5febb0abc1a3613d7fc6207795b5ea0b174dc789 Mon Sep 17 00:00:00 2001
From: Jan Timm <jan.horst.karl.timm@desy.de>
Date: Tue, 21 Jan 2020 13:53:49 +0100
Subject: [PATCH] 	DeviceModule

		writeAfterOpen writes constants to devices
		remove writeAfterOpen in recovery loop
			that should be in writeRecoveryOpen
		extend testProcessVariableRecovery for constants
---
 src/DeviceModule.cc                              |  3 ---
 .../testProcessVariableRecovery.cc               | 16 +++++++++++++++-
 tests/test5.map                                  |  1 +
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/DeviceModule.cc b/src/DeviceModule.cc
index 3fa2ca8f..3973cf07 100644
--- a/src/DeviceModule.cc
+++ b/src/DeviceModule.cc
@@ -367,9 +367,6 @@ namespace ChimeraTK {
           for(auto& initHandler : initialisationHandlers) {
             initHandler(this);
           }
-          for(auto& te : writeAfterOpen) {
-            te->write();
-          }
           { // scope for the lock guard
             boost::unique_lock<boost::shared_mutex> uniqueLock(recoverySharedMutex);
             for(auto& te : writeRecoveryOpen) {
diff --git a/tests/executables_src/testProcessVariableRecovery.cc b/tests/executables_src/testProcessVariableRecovery.cc
index 666cdf9e..4478e6a7 100644
--- a/tests/executables_src/testProcessVariableRecovery.cc
+++ b/tests/executables_src/testProcessVariableRecovery.cc
@@ -11,6 +11,7 @@
 #include "check_timeout.h"
 #include "ApplicationModule.h"
 #include "ArrayAccessor.h"
+#include "ConfigReader.h"
 
 #include <regex>
 
@@ -125,26 +126,33 @@ BOOST_AUTO_TEST_CASE(testWriteToReadOnly) {
 BOOST_AUTO_TEST_CASE(testProcessVariableRecovery) {
   std::cout << "testProcessVariableRecovery" << std::endl;
   TestApplication app;
+
+
   app.findTag(".*").connectTo(app.cs); // creates /TEST/TO_DEV_SCALAR1 and /TEST/TO/DEV/ARRAY1
   // devices are not automatically connected (yet)
   app.dev.connectTo(app.cs,
       app.cs("deviceTrigger", typeid(int),
           1)); // In TEST it connects to TO_DEV_SCALAR1 and TO_DEV_ARRAY1, and creates TO_DEV_SCALAR2, FROM_DEV1, FROM_DEV2, TO_DEV_AREA2, FROM_DEV_AREA1 and FROM_DEV_AREA2
 
+  // make a constant and connect to the device
+  auto constante = ctk::VariableNetworkNode::makeConstant(1,44252,1);
+  constante >> app.dev["CONSTANT"]("VAR32");
+
   ctk::TestFacility test(false);
   // initial value for the direct CS->DEV register
   test.writeScalar("/TEST/TO_DEV_SCALAR2", 42);
   std::vector<int32_t> array = {99, 99, 99, 99};
   test.writeArray("/TEST/TO_DEV_ARRAY2", array);
 
+  app.dumpConnections();
   app.run();
-  //app.dumpConnections();
 
   ctk::Device dummy;
   dummy.open(deviceCDD);
   //Check that the initial values are there.
   //auto reg2 = dummy.getScalarRegisterAccessor<int32_t>("/TEST/TO_DEV_SCALAR2");
   //CHECK_EQUAL_TIMEOUT([=]()mutable{reg2.readLatest(); return int32_t(reg2);},0,3000);
+  CHECK_EQUAL_TIMEOUT(dummy.read<int32_t>("/CONSTANT/VAR32"), 44252, 3000);
   CHECK_EQUAL_TIMEOUT(dummy.read<int32_t>("/TEST/TO_DEV_SCALAR2"), 42, 3000);
   CHECK_EQUAL_TIMEOUT(dummy.read<int32_t>("/TEST/TO_DEV_ARRAY2", 1, 0)[0], 99, 3000);
   CHECK_EQUAL_TIMEOUT(dummy.read<int32_t>("/TEST/TO_DEV_ARRAY2", 1, 1)[0], 99, 3000);
@@ -169,12 +177,14 @@ BOOST_AUTO_TEST_CASE(testProcessVariableRecovery) {
   dummyBackend->throwExceptionOpen = true;
 
   //Set dummy registers to 0.
+  dummy.write<int32_t>("/CONSTANT/VAR32", 0);
   dummy.write<int32_t>("/TEST/TO_DEV_SCALAR1", 0);
   dummy.write<int32_t>("/TEST/TO_DEV_SCALAR2", 0);
   array = {0, 0, 0, 0};
   dummy.write("/TEST/TO_DEV_ARRAY1", array);
   dummy.write("/TEST/TO_DEV_ARRAY2", array);
 
+  CHECK_EQUAL_TIMEOUT(dummy.read<int32_t>("/CONSTANT/VAR32"), 0, 3000);
   dummyBackend->throwExceptionWrite = true;
   dummyBackend->throwExceptionRead = true;
 
@@ -198,4 +208,8 @@ BOOST_AUTO_TEST_CASE(testProcessVariableRecovery) {
 
   BOOST_CHECK_EQUAL(dummy.read<int32_t>("/TEST/TO_DEV_SCALAR1"), 100);
   BOOST_CHECK((dummy.read<int32_t>("/TEST/TO_DEV_ARRAY1", 0) == std::vector<int32_t>{100, 100, 100, 100}));
+
+  // check if the constant is written back after recovery
+  CHECK_EQUAL_TIMEOUT(dummy.read<int32_t>("/CONSTANT/VAR32"), 44252, 3000);
+
 }
diff --git a/tests/test5.map b/tests/test5.map
index 5edd121c..1d903662 100644
--- a/tests/test5.map
+++ b/tests/test5.map
@@ -10,3 +10,4 @@ TEST.FROM_DEV_ARRAY1     0x00000004    0x0000002C    0x00000010 0 32 0 1 RO
 TEST.FROM_DEV_SCALAR2    0x00000001    0x0000003C    0x00000004 0 32 0 1 RO
 TEST.FROM_DEV_ARRAY2     0x00000004    0x00000040    0x00000010 0 32 0 1 RO
 
+CONSTANT.VAR32           0x00000001    0x00000050    0x00000004
-- 
GitLab