1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
// NOLINTBEGIN(*)
// BUG Report:
// a change of the attribute configuration setting to "Not specified"
// is lost if a DevRestart or ServerRestart is done.
// This test checks this feature for: sys/tg_test/1/double_scalar
// The setting is also lost for events.per_event.period even if a DevRestart is not done.
//
// All data are inquired, so this tests works without using the event mechanism.
//
// This program has a exit code of:
// 0 if test is passed
// >0 if test is not passed
// tango version: 7.1 cvs head (15.10.2009)
//
// contact: georg.kasper@frm2.tum.de
#include "old_common.h"
const char *const notset = "Not specified";
// redundancy problem with:
// min_alarm, alarms.min_alarm, max_alarm and alarms.max_alarm in Tango::AttributeInfoEx
// if pedantic_test is false: Tango::AttributeInfoEx::mXX_alarm is not checked
// but Tango::AttributeInfoEx::alarms.mXX_alarm
const bool pedantic_test = false;
void setValues(Tango::AttributeInfoEx &ai, const bool doReset);
int compare(Tango::AttributeInfoEx &ai_act, Tango::AttributeInfoEx &ai_expected);
void reset_to_default(Tango::AttributeInfoEx &, string &);
int main(int argc, char **argv)
{
if(argc != 2)
{
TEST_LOG << "usage: att_conf <device>" << endl;
exit(-1);
}
int res = 0;
int rc = 0;
// string dnUrl = "tango://taco24:10000/sys/tg_test/1";
string dnUrl = argv[1];
string devnm = argv[1];
string an = "Double_attr";
Tango::DeviceProxy *dev = NULL;
Tango::DeviceProxy *adm_dev = NULL;
Tango::AttributeInfoListEx ail;
Tango::AttributeInfoEx ai_orig;
Tango::AttributeInfoEx ai_act;
Tango::AttributeInfoEx ai_expected;
Tango::DeviceData ddOut;
Tango::DeviceData ddIn;
try
{
dev = new Tango::DeviceProxy(dnUrl);
adm_dev = new Tango::DeviceProxy(dev->adm_name().c_str());
// TEST_LOG << "connected to: " << dev->dev_name() << "\t";
// TEST_LOG << "with adm_device: " << dev->adm_name() << endl;
// TEST_LOG << "connected to: " << adm_dev->dev_name() << endl;
ai_orig = dev->attribute_query(an);
// test 1: change to numerical/string values:
// TEST_LOG << endl << "test 1: change to numerical/string values" << endl;
ai_expected = ai_orig;
setValues(ai_expected, false);
ail.clear();
ail.push_back(ai_expected);
dev->set_attribute_config(ail);
std::this_thread::sleep_for(std::chrono::seconds(1));
ai_act = dev->attribute_query(an);
res = compare(ai_act, ai_expected);
if(res != 0)
{
rc = 1;
// TEST_LOG << "test 1: FAILED, set and control numerical changes." << endl;
ail.clear();
ail.push_back(ai_orig);
dev->set_attribute_config(ail);
exit(-1);
}
else
{
TEST_LOG << " Set and control numerical changes --> OK" << endl;
}
// test 2: change to: Not specified
// TEST_LOG << endl << "test 2: change to Not specified" << endl;
ai_expected = ai_orig;
setValues(ai_expected, true);
ail.clear();
ail.push_back(ai_expected);
dev->set_attribute_config(ail);
std::this_thread::sleep_for(std::chrono::seconds(1));
ai_act = dev->attribute_query(an);
reset_to_default(ai_expected, an);
res = compare(ai_act, ai_expected);
if(res != 0)
{
rc = rc * 10 + 1;
// TEST_LOG << "test 2: FAILED, set all to '" << notset << "' control changes" << endl;
ail.clear();
ail.push_back(ai_orig);
dev->set_attribute_config(ail);
exit(-1);
}
else
{
TEST_LOG << " Set all to 'not specified' --> OK" << endl;
}
// test 3: device restart, change to numerical/string values
// TEST_LOG << endl << "test 3: change to numerical/string values with device restart" << endl;
ai_expected = ai_orig;
setValues(ai_expected, false);
ail.clear();
ail.push_back(ai_expected);
dev->set_attribute_config(ail);
// TEST_LOG << " make a DevRestart" << endl;
ddIn << devnm;
adm_dev->set_timeout_millis(6000);
ddOut = adm_dev->command_inout("DevRestart", ddIn);
std::this_thread::sleep_for(std::chrono::seconds(5));
ai_act = dev->attribute_query(an);
res = compare(ai_act, ai_expected);
if(res != 0)
{
rc = rc * 10 + 1;
// TEST_LOG << "test 3: FAILED, set all to numerical/string values and control changes after a
// DevRestart" << endl;
ail.clear();
ail.push_back(ai_orig);
dev->set_attribute_config(ail);
exit(-1);
}
else
{
TEST_LOG << " Set all to numerical/string values and control changes after a DevRestart --> OK" << endl;
}
// test 4: device restart, change to 'Not specified'
// TEST_LOG << endl << "test 4: change to 'Not specified' with device restart" << endl;
ai_expected = ai_orig;
setValues(ai_expected, true);
ail.clear();
ail.push_back(ai_expected);
dev->set_attribute_config(ail);
// TEST_LOG << " make a DevRestart" << endl;
ddIn << devnm;
ddOut = adm_dev->command_inout("DevRestart", ddIn);
std::this_thread::sleep_for(std::chrono::seconds(5));
ai_act = dev->attribute_query(an);
reset_to_default(ai_expected, an);
res = compare(ai_act, ai_expected);
if(res != 0)
{
rc = rc * 10 + 1;
// TEST_LOG << "test 4: FAILED, set all to '" << notset << "' control changes after a DevRestart"
// << endl;
}
else
{
TEST_LOG << " Set all to 'Not specified' + control changes after a DevRestart --> OK" << endl;
}
// restore original setting:
ail.clear();
ail.push_back(ai_orig);
dev->set_attribute_config(ail);
}
catch(Tango::DevFailed &ex)
{
rc = 9999;
Tango::Except::print_exception(ex);
exit(-1);
}
delete adm_dev;
delete dev;
return rc;
}
void setValues(Tango::AttributeInfoEx &ai, const bool doReset)
{
ai.description = doReset ? notset : "description";
ai.label = doReset ? notset : "label";
ai.unit = doReset ? notset : "unit";
ai.standard_unit = doReset ? notset : "11";
ai.display_unit = doReset ? notset : "22";
ai.format = doReset ? notset : "myformat";
ai.min_value = doReset ? notset : "33";
ai.max_value = doReset ? notset : "44";
ai.min_alarm = doReset ? notset : "55"; // i have a problem with this: redundancy alarms.min_alarm
ai.max_alarm = doReset ? notset : "66"; // i have a problem with this: redundancy alarms.max_alarm
ai.alarms.min_alarm = doReset ? notset : "77";
ai.alarms.max_alarm = doReset ? notset : "88";
ai.alarms.min_warning = doReset ? notset : "99";
ai.alarms.max_warning = doReset ? notset : "111";
ai.alarms.delta_t = doReset ? notset : "222";
ai.alarms.delta_val = doReset ? notset : "333";
ai.events.ch_event.abs_change = doReset ? notset : "444";
ai.events.ch_event.rel_change = doReset ? notset : "555";
ai.events.per_event.period = doReset ? notset : "6666";
ai.events.arch_event.archive_rel_change = doReset ? notset : "777";
ai.events.arch_event.archive_abs_change = doReset ? notset : "888";
ai.events.arch_event.archive_period = doReset ? notset : "9999";
}
int compare(Tango::AttributeInfoEx &ai_act, Tango::AttributeInfoEx &ai_expected)
{
int rc = 0;
#define CMP(x) \
if((ai_act.x != ai_expected.x)) \
{ \
rc = 1; \
TEST_LOG << #x << ":\tBUG got: " << ai_act.x << "\texpected: " << ai_expected.x << endl; \
}
CMP(description);
CMP(label);
CMP(unit);
CMP(standard_unit);
CMP(display_unit);
CMP(format);
CMP(min_value);
CMP(max_value);
if(::pedantic_test)
{
CMP(min_alarm);
}
if(::pedantic_test)
{
CMP(max_alarm);
}
CMP(alarms.min_alarm);
CMP(alarms.max_alarm);
CMP(alarms.min_warning);
CMP(alarms.max_warning);
CMP(alarms.delta_t);
CMP(alarms.delta_val);
CMP(events.ch_event.abs_change);
CMP(events.ch_event.rel_change);
CMP(events.per_event.period);
CMP(events.arch_event.archive_rel_change);
CMP(events.arch_event.archive_abs_change);
CMP(events.arch_event.archive_period);
return rc;
}
void reset_to_default(Tango::AttributeInfoEx &ai, string &att_name)
{
ai.description = "No description";
ai.label = att_name.c_str();
ai.unit = "";
ai.standard_unit = "No standard unit";
ai.display_unit = "No display unit";
ai.format = "%6.2f";
ai.events.per_event.period = "1000";
}
// eof
// NOLINTEND(*)
|