10 #include <boost/bind/bind.hpp>
11 #include <boost/date_time/posix_time/posix_time.hpp>
12 #include <boost/function.hpp>
13 #include <boost/lambda/lambda.hpp>
14 #include <boost/make_shared.hpp>
19 using namespace boost::unit_test_framework;
22 #define TEST_MAPPING_FILE "testDummyRegisterAccessors.map"
23 #define INVALID_MAPPING_FILE "invalidSequences.map"
30 :
DummyBackend(mapFileName), someRegister(this,
"APP0",
"SOME_REGISTER"),
31 someMuxedRegister(this,
"APP0",
"DAQ0_ADCA") {}
43 :
DummyBackend(mapFileName), invalidRegister(this,
"INVALID",
"NO_WORDS") {}
56 void testExceptions();
59 void testRegisterAccessor();
62 void testMuxedRegisterAccessor();
65 boost::shared_ptr<TestableDummyBackend>
device;
83 framework::master_test_suite().p_name.value =
"DummyRegister test suite";
91 std::cout <<
"testExceptions" << std::endl;
98 std::cout <<
"testRegisterAccessor" << std::endl;
104 BOOST_CHECK(
device->someRegister.getNumberOfElements() == 10);
108 BOOST_CHECK(
device->_barContents[1][0] == 3);
111 device->_barContents[1][0] = 5;
112 device->_barContents[1][3] = 77;
113 BOOST_CHECK(
device->someRegister[0] == 5);
114 BOOST_CHECK(
device->someRegister[3] == 77);
117 device->someRegister[0] = 666;
118 device->someRegister[9] = 999;
119 BOOST_CHECK(
device->_barContents[1][0] == 666);
120 BOOST_CHECK(
device->_barContents[1][9] == 999);
121 device->someRegister[1] = 111;
122 device->someRegister[2] = 222;
123 device->someRegister[3] = 333;
124 device->someRegister[4] = 444;
125 BOOST_CHECK(
device->_barContents[1][1] == 111);
126 BOOST_CHECK(
device->_barContents[1][2] == 222);
127 BOOST_CHECK(
device->_barContents[1][3] == 333);
128 BOOST_CHECK(
device->_barContents[1][4] == 444);
131 BOOST_CHECK(
device->someRegister[1]++ == 111);
132 BOOST_CHECK(
device->someRegister[2]-- == 222);
133 BOOST_CHECK(++
device->someRegister[3] == 334);
134 BOOST_CHECK(--
device->someRegister[4] == 443);
135 BOOST_CHECK(
device->_barContents[1][1] == 112);
136 BOOST_CHECK(
device->_barContents[1][2] == 221);
137 BOOST_CHECK(
device->_barContents[1][3] == 334);
138 BOOST_CHECK(
device->_barContents[1][4] == 443);
146 std::cout <<
"testMuxedRegisterAccessor" << std::endl;
152 BOOST_CHECK(
device->someMuxedRegister.getNumberOfElements() == 4096);
153 BOOST_CHECK(
device->someMuxedRegister.getNumberOfSequences() == 16);
157 static const int areaIndexOffset = 1000 / 4;
180 } __attribute__((packed)) cooked;
184 int pitch =
sizeof(mixedReg.raw);
187 mixedReg.cooked.r0 = 42;
188 mixedReg.cooked.r1 = 120;
189 mixedReg.cooked.r2 = 222;
190 mixedReg.cooked.r3 = -110;
191 mixedReg.cooked.r4 = 1;
192 mixedReg.cooked.r5 = 33;
193 mixedReg.cooked.r6 = 6;
194 mixedReg.cooked.r7 = 7;
195 mixedReg.cooked.r8 = 8;
196 mixedReg.cooked.r9 = 9;
197 mixedReg.cooked.r10 = 10;
198 mixedReg.cooked.r11 = 11;
199 mixedReg.cooked.r12 = 12;
200 mixedReg.cooked.r13 = 13;
201 mixedReg.cooked.r14 = 14;
202 mixedReg.cooked.r15 = 15;
203 for(
int i = 0; i < 13; i++)
device->_barContents[0xD][areaIndexOffset + i] = mixedReg.raw[i];
206 BOOST_CHECK((
int)((
char*)&(mixedReg.cooked.r5) - (
char*)&(mixedReg.cooked.r0)) == 10);
207 BOOST_CHECK((
int)((
char*)&(mixedReg.cooked.r10) - (
char*)&(mixedReg.cooked.r0)) == 28);
208 BOOST_CHECK((
int)((
char*)&(mixedReg.cooked.r15) - (
char*)&(mixedReg.cooked.r0)) == pitch - 4);
209 BOOST_CHECK(
device->_barContents[0xD][areaIndexOffset + 0] == 42);
210 BOOST_CHECK(
device->_barContents[0xD][areaIndexOffset + 1] == 120 + 0x10000 * 222);
211 BOOST_CHECK(
device->_barContents[0xD][areaIndexOffset + 9] == 12);
212 BOOST_CHECK(
device->_barContents[0xD][areaIndexOffset + 12] == 15);
214 mixedReg.cooked.r0 = 1;
215 mixedReg.cooked.r1 = 11;
216 mixedReg.cooked.r2 = 22;
217 mixedReg.cooked.r3 = 33;
218 mixedReg.cooked.r4 = 0;
219 mixedReg.cooked.r5 = 55;
220 mixedReg.cooked.r6 = 66;
221 mixedReg.cooked.r7 = 77;
222 mixedReg.cooked.r8 = 88;
223 mixedReg.cooked.r9 = 99;
224 mixedReg.cooked.r10 = 100;
225 mixedReg.cooked.r11 = 111;
226 mixedReg.cooked.r12 = 222;
227 mixedReg.cooked.r13 = 333;
228 mixedReg.cooked.r14 = 444;
229 mixedReg.cooked.r15 = 555;
230 for(
int i = 0; i < 13; i++)
device->_barContents[0xD][areaIndexOffset + pitch / 4 + i] = mixedReg.raw[i];
233 BOOST_CHECK(
device->_barContents[0xD][areaIndexOffset + pitch / 4 + 0] == 1);
234 BOOST_CHECK(
device->_barContents[0xD][areaIndexOffset + pitch / 4 + 1] == 11 + 0x10000 * 22);
235 BOOST_CHECK(
device->_barContents[0xD][areaIndexOffset + pitch / 4 + 9] == 222);
236 BOOST_CHECK(
device->_barContents[0xD][areaIndexOffset + pitch / 4 + 12] == 555);
239 for(
int i = 2; i < 4096; i++) {
240 mixedReg.cooked.r0 = i + 0;
241 mixedReg.cooked.r1 = i + 1;
242 mixedReg.cooked.r2 = i + 2;
243 mixedReg.cooked.r3 = i + 3;
244 mixedReg.cooked.r4 = i + 4;
245 mixedReg.cooked.r5 = i + 5;
246 mixedReg.cooked.r6 = i + 6;
247 mixedReg.cooked.r7 = i + 7;
248 mixedReg.cooked.r8 = i + 8;
249 mixedReg.cooked.r9 = i + 9;
250 mixedReg.cooked.r10 = i + 10;
251 mixedReg.cooked.r11 = i + 11;
252 mixedReg.cooked.r12 = i + 12;
253 mixedReg.cooked.r13 = i + 13;
254 mixedReg.cooked.r14 = i + 14;
255 mixedReg.cooked.r15 = i + 15;
256 for(
int k = 0; k < 13; k++)
device->_barContents[0xD][areaIndexOffset + i * (pitch / 4) + k] = mixedReg.raw[k];
260 BOOST_CHECK(
device->someMuxedRegister[0][0] == 42);
261 BOOST_CHECK(
device->someMuxedRegister[1][0] == 120);
262 BOOST_CHECK(
device->someMuxedRegister[2][0] == 222);
263 BOOST_CHECK(
device->someMuxedRegister[3][0] == -110);
264 BOOST_CHECK(
device->someMuxedRegister[4][0] == 1);
265 BOOST_CHECK(
device->someMuxedRegister[5][0] == 33);
266 BOOST_CHECK(
device->someMuxedRegister[6][0] == 6);
267 BOOST_CHECK(
device->someMuxedRegister[7][0] == 7);
268 BOOST_CHECK(
device->someMuxedRegister[8][0] == 8);
269 BOOST_CHECK(
device->someMuxedRegister[9][0] == 9);
270 BOOST_CHECK(
device->someMuxedRegister[10][0] == 10);
271 BOOST_CHECK(
device->someMuxedRegister[11][0] == 11);
272 BOOST_CHECK(
device->someMuxedRegister[12][0] == 12);
273 BOOST_CHECK(
device->someMuxedRegister[13][0] == 13);
274 BOOST_CHECK(
device->someMuxedRegister[14][0] == 14);
275 BOOST_CHECK(
device->someMuxedRegister[15][0] == 15);
277 BOOST_CHECK(
device->someMuxedRegister[0][1] == 1);
278 BOOST_CHECK(
device->someMuxedRegister[1][1] == 11);
279 BOOST_CHECK(
device->someMuxedRegister[2][1] == 22);
280 BOOST_CHECK(
device->someMuxedRegister[3][1] == 33);
281 BOOST_CHECK(
device->someMuxedRegister[4][1] == 0);
282 BOOST_CHECK(
device->someMuxedRegister[5][1] == 55);
283 BOOST_CHECK(
device->someMuxedRegister[6][1] == 66);
284 BOOST_CHECK(
device->someMuxedRegister[7][1] == 77);
285 BOOST_CHECK(
device->someMuxedRegister[8][1] == 88);
286 BOOST_CHECK(
device->someMuxedRegister[9][1] == 99);
287 BOOST_CHECK(
device->someMuxedRegister[10][1] == 100);
288 BOOST_CHECK(
device->someMuxedRegister[11][1] == 111);
289 BOOST_CHECK(
device->someMuxedRegister[12][1] == 222);
290 BOOST_CHECK(
device->someMuxedRegister[13][1] == 333);
291 BOOST_CHECK(
device->someMuxedRegister[14][1] == 444);
292 BOOST_CHECK(
device->someMuxedRegister[15][1] == 555);
294 for(
int i = 2; i < 65536 / 16; i++) {
295 for(
int k = 0; k < 16; k++) {
296 int expectedValue = i + k;
297 void* ptr = (
void*)&expectedValue;
298 if(k == 1 || k == 2 || k == 6) {
299 expectedValue = *(
reinterpret_cast<int16_t*
>(ptr));
302 expectedValue = *(
reinterpret_cast<int8_t*
>(ptr));
305 expectedValue = expectedValue & 0x1;
308 expectedValue = expectedValue & 0xFFFFFF;
310 std::stringstream message;
311 message <<
"someMuxedRegister[" << k <<
"][" << i <<
"] == " <<
device->someMuxedRegister[k][i] <<
" but "
312 << expectedValue <<
" expected.";
313 BOOST_CHECK_MESSAGE(
device->someMuxedRegister[k][i] == expectedValue, message.str());
318 device->someMuxedRegister[0][0] = 666;
319 device->someMuxedRegister[1][0] = 999;
320 device->someMuxedRegister[2][0] = 222;
321 device->someMuxedRegister[3][0] = -111;
322 device->someMuxedRegister[4][0] = 0;
323 device->someMuxedRegister[5][0] = 555;
324 device->someMuxedRegister[6][0] = 666;
325 device->someMuxedRegister[7][0] = 777;
326 device->someMuxedRegister[8][0] = 888;
327 device->someMuxedRegister[9][0] = 999;
328 device->someMuxedRegister[10][0] = 1111;
329 device->someMuxedRegister[11][0] = 2222;
330 device->someMuxedRegister[12][0] = 3333;
331 device->someMuxedRegister[13][0] = 4444;
332 device->someMuxedRegister[14][0] = 5555;
333 device->someMuxedRegister[15][0] = 6666;
335 for(
int i = 1; i < 65536 / 16; i++) {
336 for(
int k = 0; k < 16; k++) {
337 device->someMuxedRegister[k][i] = 10 * k + i;
341 for(
int k = 0; k < 13; k++) mixedReg.raw[k] =
device->_barContents[0xD][areaIndexOffset + k];
342 BOOST_CHECK(mixedReg.cooked.r0 == 666);
343 BOOST_CHECK(mixedReg.cooked.r1 == 999);
344 BOOST_CHECK(mixedReg.cooked.r2 == 222);
345 BOOST_CHECK(mixedReg.cooked.r3 == -111);
346 BOOST_CHECK(mixedReg.cooked.r4 == 0);
347 BOOST_CHECK(mixedReg.cooked.r5 == 555);
348 BOOST_CHECK(mixedReg.cooked.r6 == 666);
349 BOOST_CHECK(mixedReg.cooked.r7 == 777);
350 BOOST_CHECK(mixedReg.cooked.r8 == 888);
351 BOOST_CHECK(mixedReg.cooked.r9 == 999);
352 BOOST_CHECK(mixedReg.cooked.r10 == 1111);
353 BOOST_CHECK(mixedReg.cooked.r11 == 2222);
354 BOOST_CHECK(mixedReg.cooked.r12 == 3333);
355 BOOST_CHECK(mixedReg.cooked.r13 == 4444);
356 BOOST_CHECK(mixedReg.cooked.r14 == 5555);
357 BOOST_CHECK(mixedReg.cooked.r15 == 6666);
359 for(
int i = 1; i < 65536 / 16; i++) {
360 for(
int k = 0; k < 13; k++) mixedReg.raw[k] =
device->_barContents[0xD][areaIndexOffset + i * (pitch / 4) + k];
361 BOOST_CHECK(mixedReg.cooked.r0 == 10 * 0 + i);
362 BOOST_CHECK(mixedReg.cooked.r1 == std::min(10 * 1 + i, 32767));
363 BOOST_CHECK(mixedReg.cooked.r2 == std::min(10 * 2 + i, 32767));
364 BOOST_CHECK(mixedReg.cooked.r3 == std::min(10 * 3 + i, 127));
365 BOOST_CHECK(mixedReg.cooked.r4 == std::min(10 * 4 + i, 1));
366 BOOST_CHECK(mixedReg.cooked.r5 == 10 * 5 + i);
367 BOOST_CHECK(mixedReg.cooked.r6 == std::min(10 * 6 + i, 32767));
368 BOOST_CHECK(mixedReg.cooked.r7 == 10 * 7 + i);
369 BOOST_CHECK(mixedReg.cooked.r8 == 10 * 8 + i);
370 BOOST_CHECK(mixedReg.cooked.r9 == 10 * 9 + i);
371 BOOST_CHECK(mixedReg.cooked.r10 == 10 * 10 + i);
372 BOOST_CHECK(mixedReg.cooked.r11 == 10 * 11 + i);
373 BOOST_CHECK(mixedReg.cooked.r12 == 10 * 12 + i);
374 BOOST_CHECK(mixedReg.cooked.r13 == 10 * 13 + i);
375 BOOST_CHECK(mixedReg.cooked.r14 == 10 * 14 + i);
376 BOOST_CHECK(mixedReg.cooked.r15 == (
unsigned int)(10 * 15 + i));