Skip to content
Snippets Groups Projects
Commit eeb93582 authored by Dietrich Rothe's avatar Dietrich Rothe
Browse files

improve test as requested by Martin; update xml validation script

parent 868cfbe2
No related branches found
No related tags found
No related merge requests found
......@@ -85,10 +85,11 @@ in a property tag (or any tag for a special property, see Secion \ref special_pr
- `macro_pulse_number_source`: Name of process variable which contains the macro pusle number which should be attached
to the properties.
- `persist`: Controls behaviour of DOOCS persistency files. This is only important for writable arrays with more than MAX_CONF_LENGTH entries
(usually 20). Possible values are `true` (the default) - always save the array,
`false` - do not save the array,
(usually 20). Possible values are `true` (the default) - always save the array, where
long arrays are saved in separate files below `hist/` while short arrays go into the server config file;
`false` - do not save the array;
`auto` - default DOOCS behaviour, only arrays with up to 20 entries are saved, in server config file.
Long arrays are saved in separate files below `hist/` instead of the server config file.
\subsection zeromq ZeroMQ publication
......
......@@ -24,10 +24,10 @@ namespace ChimeraTK {
PersistConfig(std::string txt) {
transform(txt.begin(), txt.end(), txt.begin(), ::tolower);
if(txt == "false" or txt == "0") {
if(txt == "false" or txt =="off" or txt == "0") {
val = OFF;
}
else if(txt == "true" or txt == "1") {
else if(txt == "true" or txt == "on" or txt == "1") {
val = ON;
}
else if(txt == "auto") {
......
......@@ -2,15 +2,17 @@
<device_server xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://github.com/ChimeraTK/ControlSystemAdapter-DoocsAdapter"
xsi:schemaLocation="https://github.com/ChimeraTK/ControlSystemAdapter-DoocsAdapter ../xmlschema/doocs_variable_tree.xsd">
<!-- global default -->
<persist>false</persist>
<persist>auto</persist>
<location name="INT">
<!--default for this location -->
<persist>true</persist>
<D_array source="TO_DEVICE_ARRAY" type="int" />
<D_array source="FROM_DEVICE_ARRAY" name="MY_RENAMED_INTARRAY" type="int" />
<D_array source="FROM_DEVICE_ARRAY" type="int" />
</location>
<location name="DOUBLE">
<!--default for this location -->
<persist>false</persist>
<D_array source="TO_DEVICE_ARRAY" type="double" >
<persist>true</persist>
</D_array>
......
......@@ -35,7 +35,8 @@ void vectorFromFile(std::vector<T>& vec, const char* fname) {
const int alen = 40;
// slightly modified GlobalFixture from serverBasedTestTools.h
// slightly modified GlobalFixture from serverBasedTestTools.h:
// use longer arrays in ReferenceTestApplication, cleanup persistency files at startup
struct GlobalFixture {
GlobalFixture() {
cleanupFiles();
......@@ -75,7 +76,7 @@ CTK_BOOST_GLOBAL_FIXTURE(GlobalFixture)
// the array must have testStartValue+i at index i.
template<class T>
static bool testArrayContent1(std::vector<T>& array, std::string const& propertyName, T testStartValue, T delta) {
static bool testArrayContent(std::vector<T>& array, std::string const& propertyName, T testStartValue, T delta) {
bool isOK = true;
T currentTestValue = testStartValue;
size_t index = 0;
......@@ -93,20 +94,20 @@ static bool testArrayContent1(std::vector<T>& array, std::string const& property
return isOK;
}
template<class T>
static bool testArrayContent(std::string const& propertyName, T testStartValue, T delta) {
static bool testArrayContentFromProperty(std::string const& propertyName, T testStartValue, T delta) {
auto array = DoocsServerTestHelper::doocsGetArray<T>(propertyName);
return testArrayContent1(array, propertyName, testStartValue, delta);
return testArrayContent(array, propertyName, testStartValue, delta);
}
/// Using prepared persistence file, start server, check restored values, change values, trigger persisting, compare file with expectation
BOOST_AUTO_TEST_CASE(testArrayWrite) {
GlobalFixture::referenceTestApplication.runMainLoopOnce();
std::string const& propertyAddress = "//INT/MY_RENAMED_INTARRAY";
std::string const& propertyAddress = "//INT/FROM_DEVICE_ARRAY";
checkDataType(propertyAddress, DATA_A_INT);
CHECK_WITH_TIMEOUT(testArrayContent<float>("//INT/MY_RENAMED_INTARRAY", 100, 1) == true);
CHECK_WITH_TIMEOUT(testArrayContent<float>("//DOUBLE/FROM_DEVICE_ARRAY", 200.1, 1) == true);
CHECK_WITH_TIMEOUT(testArrayContentFromProperty<float>("//INT/FROM_DEVICE_ARRAY", 100, 1) == true);
CHECK_WITH_TIMEOUT(testArrayContentFromProperty<float>("//DOUBLE/FROM_DEVICE_ARRAY", 200.1, 1) == true);
std::vector<int> vint(alen);
std::vector<double> vdouble(alen);
......@@ -122,19 +123,28 @@ BOOST_AUTO_TEST_CASE(testArrayWrite) {
// check changed values
usleep(100000);
CHECK_WITH_TIMEOUT(testArrayContent<float>("//INT/MY_RENAMED_INTARRAY", 150, 1) == true);
CHECK_WITH_TIMEOUT(testArrayContent<float>("//DOUBLE/FROM_DEVICE_ARRAY", 250.3, 1) == true);
CHECK_WITH_TIMEOUT(testArrayContentFromProperty<float>("//INT/FROM_DEVICE_ARRAY", 150, 1) == true);
CHECK_WITH_TIMEOUT(testArrayContentFromProperty<float>("//DOUBLE/FROM_DEVICE_ARRAY", 250.3, 1) == true);
// trigger array storing
DoocsServerTestHelper::doocsSet<bool>("//ARRAY_PERSISTENCE_TEST._SVR/SVR.SAVE", true);
// wait till disk file written
usleep(500000);
// check persisted file against known values
std::vector<int> vint2(alen);
std::vector<double> vdouble2(alen);
vectorFromFile(vint2, "hist/INT-TO_DEVICE_ARRAY.intarray");
vectorFromFile(vdouble2, "hist/DOUBLE-TO_DEVICE_ARRAY.doublearray");
CHECK_WITH_TIMEOUT(testArrayContent1<int>(vint2, "//INT/MY_RENAMED_INTARRAY", 150, 1) == true);
CHECK_WITH_TIMEOUT(testArrayContent1<double>(vdouble2, "//DOUBLE/FROM_DEVICE_ARRAY", 250.3, 1) == true);
// check persisted file against known values. Try several times, reading from disk.
bool intArrayRestored = false;
bool doubleArrayRestored = false;
for(int count = 0; count < 100; ++count) {
usleep(100000);
std::vector<int> vint2(alen);
std::vector<double> vdouble2(alen);
vectorFromFile(vint2, "hist/INT-TO_DEVICE_ARRAY.intarray");
vectorFromFile(vdouble2, "hist/DOUBLE-TO_DEVICE_ARRAY.doublearray");
intArrayRestored = testArrayContent<int>(vint2, "//INT/TO_DEVICE_ARRAY from file", 150, 1);
doubleArrayRestored = testArrayContent<double>(vdouble2, "//DOUBLE/TO_DEVICE_ARRAY from file", 250.3, 1);
if(intArrayRestored && doubleArrayRestored) {
std::cout << "arrays recovered after read tries: " << count+1 << std::endl;
break;
}
}
BOOST_CHECK(intArrayRestored);
BOOST_CHECK(doubleArrayRestored);
}
#!/bin/bash
for f in *.xml variableTreeXml/*.xml; do
[[ $f = *codeIsNotInt.xml ]] && continue
xmllint --noout --schema ../xmlschema/doocs_variable_tree.xsd $f
done
......@@ -148,7 +148,11 @@
<xs:simpleType name="PersistDataType">
<xs:restriction base="xs:string">
<xs:enumeration value="false"/>
<xs:enumeration value="off"/>
<xs:enumeration value="0"/>
<xs:enumeration value="true"/>
<xs:enumeration value="on"/>
<xs:enumeration value="1"/>
<xs:enumeration value="auto"/>
</xs:restriction>
</xs:simpleType>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment