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
|
// NOLINTBEGIN(*)
#include "cxx_common.h"
#undef SUITE_NAME
#define SUITE_NAME AsynReconnectionTestSuite
class AsynReconnectionTestSuite : public CxxTest::TestSuite
{
protected:
DeviceProxy *device1;
string device1_name;
string device1_instance_name;
public:
SUITE_NAME() :
device1_instance_name{"test"} // TODO pass via cl
{
//
// Arguments check -------------------------------------------------
//
// locally defined (test suite scope) mandatory parameters
// localparam = CxxTest::TangoPrinter::get_param_loc("localparam","description of what localparam is");
// predefined mandatory parameters
device1_name = CxxTest::TangoPrinter::get_param("device1");
// predefined optional parameters
// CxxTest::TangoPrinter::get_param_opt("loop"); // loop parameter is then managed by the CXX framework itself
// always add this line, otherwise arguments will not be parsed correctly
CxxTest::TangoPrinter::validate_args();
//
// Initialization --------------------------------------------------
//
try
{
device1 = new DeviceProxy(device1_name);
device1->ping();
}
catch(CORBA::Exception &e)
{
Except::print_exception(e);
exit(-1);
}
}
virtual ~SUITE_NAME()
{
//
// Clean up --------------------------------------------------------
//
// clean up in case test suite terminates before Server_Killed is restored to defaults
if(CxxTest::TangoPrinter::is_restore_set("Server_Killed"))
{
try
{
CxxTest::TangoPrinter::start_server(device1_instance_name);
}
catch(const std::runtime_error &ex)
{
std::cerr << "start_server failed: \"" << ex.what() << "\"\n";
}
}
// delete dynamically allocated objects
delete device1;
}
static SUITE_NAME *createSuite()
{
return new SUITE_NAME();
}
static void destroySuite(SUITE_NAME *suite)
{
delete suite;
}
//
// Tests -------------------------------------------------------
//
// Test TestNormalWriteAttributeAsync
void test_TestNormalWriteAttributeAsynch()
{
try
{
// Write one attribute
long id = 0;
DeviceAttribute send;
send.set_name("attr_asyn_write");
DevLong lg = 222;
TS_ASSERT_THROWS_NOTHING(send << lg);
TS_ASSERT_THROWS_NOTHING(id = device1->write_attribute_asynch(send));
bool finish = false;
long nb_not_arrived = 0;
while(finish == false)
{
try
{
device1->write_attribute_reply(id);
finish = true;
}
catch(AsynReplyNotArrived &)
{
finish = false;
TEST_LOG << "Attribute not yet written" << endl;
nb_not_arrived++;
}
if(finish == false)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
TS_ASSERT(nb_not_arrived >= 1);
TEST_LOG << " Asynchronous write_attribute in polling mode --> OK" << endl;
}
catch(const Tango::DevFailed &e)
{
Tango::Except::print_exception(e);
exit(-1);
}
catch(CORBA::Exception &ex)
{
Except::print_exception(ex);
exit(-1);
}
}
// Test TestWriteAttributeAsynchAfterReconnection
void test_TestWriteAttributeAsynchAfterReconnection()
{
TS_ASSERT_THROWS_NOTHING(CxxTest::TangoPrinter::kill_server());
CxxTest::TangoPrinter::restore_set("Server_Killed");
std::this_thread::sleep_for(std::chrono::seconds(1));
TS_ASSERT_THROWS_NOTHING(CxxTest::TangoPrinter::start_server(device1_instance_name));
std::this_thread::sleep_for(std::chrono::seconds(1));
CxxTest::TangoPrinter::restore_unset("Server_Killed");
try
{
// Write one attribute
long id = 0;
DeviceAttribute send;
send.set_name("attr_asyn_write");
DevLong lg = 444;
TS_ASSERT_THROWS_NOTHING(send << lg);
TS_ASSERT_THROWS_NOTHING(id = device1->write_attribute_asynch(send));
bool finish = false;
long nb_not_arrived = 0;
while(finish == false)
{
try
{
device1->write_attribute_reply(id);
finish = true;
}
catch(AsynReplyNotArrived &)
{
finish = false;
TEST_LOG << "Attribute not yet written" << endl;
nb_not_arrived++;
}
if(finish == false)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
TS_ASSERT(nb_not_arrived >= 1);
// Read the attribute
long read_id;
DeviceAttribute *received = nullptr;
read_id = device1->read_attribute_asynch("attr_asyn_write");
finish = false;
nb_not_arrived = 0;
while(finish == false)
{
try
{
received = device1->read_attribute_reply(read_id);
Tango::DevLong val;
*received >> val;
TEST_LOG << "attr_asyn_write attribute value = " << val << endl;
TS_ASSERT_EQUALS(val, 444);
finish = true;
}
catch(AsynReplyNotArrived &)
{
finish = false;
TEST_LOG << "Attribute not yet read" << endl;
nb_not_arrived++;
}
if(finish == false)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
delete received;
TS_ASSERT(nb_not_arrived >= 1);
TEST_LOG << " Asynchronous read_attribute in polling mode --> OK" << endl;
TEST_LOG << " Asynchronous write_attribute in polling mode after reconnection--> OK" << endl;
}
catch(const Tango::DevFailed &e)
{
Tango::Except::print_exception(e);
exit(-1);
}
catch(CORBA::Exception &ex)
{
Except::print_exception(ex);
exit(-1);
}
}
};
// NOLINTEND(*)
|