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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
|
//=============================================================================
/**
* @file CDR_Array_Test.cpp
*
* $Id: CDR_Array_Test.cpp 93638 2011-03-24 13:16:05Z johnnyw $
*
* Checks ACE_OutputCDR::write_XX_array.
* Checks ACE_InputCDR::read_XX_array.
* Checks operator<< and operator>> for CDR Streams in
* each of the basic CDR types.
* Gives a measure of the speed of the ACE CDR streams wrt those
* operations.
*
*
* @author Cristian Ferretti <cristian_ferretti@yahoo.com>
*/
//=============================================================================
// For measuring time, choose your method:
// Define:
//
// * USE_GETRUSAGE for using ACE_OS::getrusage.
// Ticks only when process is running.
//
// * USE_CLOCK for using clock(2).
// You're on your own, no ACE_OS:: support.
// Ticks only when process is running.
//
// * None of the above for using ACE_High_Res_Timer.
// Ticks independent of running state of process.
// #define USE_CLOCK
// #define USE_GETRUSAGE
#if defined(USE_CLOCK)
#include <time.h>
#endif
#include "test_config.h"
#include "ace/OS_Memory.h"
#include "ace/OS_NS_stdlib.h"
#include "ace/Get_Opt.h"
#include "ace/CDR_Stream.h"
#include "ace/High_Res_Timer.h"
#include "ace/ACE.h"
#if defined(USE_GETRUSAGE) && !defined(ACE_HAS_GETRUSAGE)
#error "Can't define USE_GETRUSAGE on this platform."
#endif
// Default number of elements for check buffer, for each tested CDR type.
// Be aware that time will be affected by the buffer fitting/not fitting
// in the cache (ie, if default_total*sizeof(T) bytes fit in the cache).
// Also, you want that your time measuring method has a resolution
// compatible with this buffer size, if not you will end up measuring 0.
// You can change this value with -t option.
static const int default_total = 32*1024;
// Repeat this many times for each tested CDR type.
// We then take the average time that took for each type and report that.
// You can change this value with -n option.
static const int default_niter = 10;
//
// A simple cronometer in seconds, that encapsulates our time
// measuring method.
//
class Crono {
public:
Crono() {}
~Crono() {}
void start ()
{
#if defined(USE_CLOCK)
start_ = clock ();
#elif defined(USE_GETRUSAGE)
ACE_OS::getrusage (RUSAGE_SELF, &start_);
#else
timer.start ();
#endif
}
void stop ()
{
#if defined(USE_CLOCK)
end_ = clock ();
#elif defined(USE_GETRUSAGE)
ACE_OS::getrusage (RUSAGE_SELF, &end_);
#else
timer.stop ();
#endif
}
double read_seconds ()
{
#if defined(USE_CLOCK)
return (end_ - start_) / (double) CLOCKS_PER_SEC;
#elif defined(USE_GETRUSAGE)
timeval diff;
diff.tv_sec = end_.ru_utime.tv_sec - start_.ru_utime.tv_sec;
diff.tv_usec = end_.ru_utime.tv_usec - start_.ru_utime.tv_usec;
while (diff.tv_usec < 0)
{
--diff.tv_sec;
diff.tv_usec += ACE_ONE_SECOND_IN_USECS;
}
return diff.tv_sec + diff.tv_usec / double(ACE_ONE_SECOND_IN_USECS);
#else
ACE_Time_Value tv;
timer.elapsed_time(tv);
return tv.usec () / 1000000.0;
#endif
}
private:
#if defined(USE_CLOCK)
clock_t start_;
clock_t end_;
#elif defined(USE_GETRUSAGE)
ACE_Rusage start_;
ACE_Rusage end_;
#else
ACE_High_Res_Timer timer;
#endif
};
//
// Our test, performed in the constructor.
// T is one of the CDR types.
// H is a helper class (described later).
//
// All this stuff is in a class and not in template functions
// to avoid having to deal with potential template function
// instantiations problems.
//
template<class T, class H> class CDR_Test
{
public:
CDR_Test (int total, int niter, int use_array);
static void do_test (int total, int niter, int use_array,
char* srcbuf, char* dstbuf,
int src_offset = 0, int dst_offset = 0);
~CDR_Test ();
static void ttoh (const T& t, char* s);
static T checkval(int i);
private:
CDR_Test (const CDR_Test<T, H>&);
CDR_Test<T, H>& operator= (const CDR_Test<T, H>&);
};
static ACE_UINT32 seal = 0xdeadbeef;
void
zero (char* p, size_t k)
{
char* end = p + k;
while (p < end)
{
*p++ = '\0';
}
}
inline int
mymax (int a, int b)
{
return (a >= b) ? a : b;
}
void
memabort ()
{
ACE_ERROR((LM_ERROR,
ACE_TEXT ("new failed, aborting\n")));
ACE_OS::exit (1);
}
template<class T, class H>
CDR_Test<T, H>::CDR_Test (int total, int niter, int use_array)
{
if (total <= 0)
{
return ;
}
char* srcbuf;
char* dstbuf;
{
const size_t stotal =
(total + 10) * H::size () + sizeof(ACE_UINT32) + ACE_CDR::MAX_ALIGNMENT;
ACE_NEW(srcbuf, char[stotal]);
if (srcbuf == 0)
{
memabort ();
}
zero(srcbuf, stotal);
ACE_NEW(dstbuf, char[stotal]);
if (dstbuf == 0)
{
memabort ();
}
zero(dstbuf, stotal);
}
if (use_array)
{
// We want to test all the possible loop unrolling deltas.
int t;
for (t = total - 3; t <= total; t++)
{
int delta;
if (sizeof(long) <= H::size ())
{
delta = 1;
}
else
{
delta = (int) (sizeof(long) / H::size ());
}
// We want to test all the posible source/destination buffer
// alignment combinations.
int sk;
for (sk = 0; sk < delta; sk++)
{
int dk;
for (dk = 0; dk < delta; dk++)
{
int tdelta = t - mymax(sk, dk);
CDR_Test<T, H>::do_test(tdelta, niter, 1,
srcbuf, dstbuf,
sk, dk);
}
}
}
}
else
{
do_test(total, niter, use_array, srcbuf, dstbuf);
}
delete[] srcbuf;
delete[] dstbuf;
}
// Generate an ``interesting'' value for testing at pos >i<.
template<class T, class H> T
CDR_Test<T, H>::checkval (int i)
{
if (!H::integral ())
{
// If T is not an integral type, we don't want to risk
// getting an invalid bit pattern for a T value.
return T(i);
}
else
{
T v;
unsigned char* s = reinterpret_cast<unsigned char*> ((&v));
unsigned int j;
for (j = 0; j < H::size (); j++)
{
s[j] = (unsigned char) ((j + i * H::size ()) % 256);
}
return v;
}
}
//
// Returns in s an hex representation of T's memory.
// (differences in byte order will be noticed in s).
//
// If T = int,
// t = 0xaabbccdd,
// => s = "aabbccdd" for big endian machines,
// s = "ddccbbaa" for little endian machines.
//
template<class T, class H> void
CDR_Test<T, H>::ttoh (const T& t, char* s)
{
const unsigned char *const p =
reinterpret_cast<const unsigned char*> (&t);
static char digits[16] = {
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'a', 'b',
'c', 'd', 'e', 'f'
};
const unsigned char* q;
for (q = p; q < p + H::size (); ++q)
{
int k = *q;
*s++ = digits[ k >> 4 ];
*s++ = digits[ k & 15 ];
}
*s = 0;
}
void
do_seal (char* pos)
{
char* ps = reinterpret_cast<char*> (&seal);
pos[0] = ps[0];
pos[1] = ps[1];
pos[2] = ps[2];
pos[3] = ps[3];
}
int
check_seal (char* pos)
{
char* ps = reinterpret_cast<char*> (&seal);
return (pos[0] == ps[0]
&& pos[1] == ps[1]
&& pos[2] == ps[2]
&& pos[3] == ps[3]);
}
//
// returns the alignment of ptr, wrt ACE_CDR::MAX_ALIGNMENT.
//
int
tellalign (const char* const ptr)
{
int align = ACE_CDR::MAX_ALIGNMENT;
while (ptr != ACE_ptr_align_binary(ptr, align))
{
align = align >> 1;
}
return align;
}
template<class T, class H> void
CDR_Test<T, H>::do_test (int total, int niter, int use_array,
char* srcbuf, char* dstbuf,
int src_offset, int dst_offset)
{
if (!use_array)
{
dst_offset = src_offset = 0;
}
ACE_DEBUG((LM_DEBUG,
ACE_TEXT( "Starting Test for %s: %d elements " )
ACE_TEXT( "%susing arrays.\n" ),
H::name (),
total,
((use_array) ? ACE_TEXT( "" ) : ACE_TEXT( "not " ))));
if (!use_array && (total % 4) != 0)
{
int lasttotal = total;
total -= (total % 4);
ACE_DEBUG((LM_DEBUG,
ACE_TEXT( "Rounding from %d to %d elements.\n" ),
lasttotal,
total));
}
char* src = ACE_ptr_align_binary(srcbuf, H::size ());
T* idata = reinterpret_cast<T*> (src);
idata += src_offset;
src = reinterpret_cast<char*> (idata);
{
int i;
for (i = 0; i < total; i++)
{
idata[i] = CDR_Test<T, H>::checkval (i);
}
}
ACE_DEBUG((LM_DEBUG,
ACE_TEXT( "Writing data...\n" )));
char* toread = 0;
{
ACE_TEST_ASSERT(use_array || total % 4 == 0);
double totalsecs = 0.0;
int n;
for (n = 0; n < niter; n++)
{
size_t size = H::size () * (dst_offset + total) +
ACE_CDR::MAX_ALIGNMENT;
ACE_OutputCDR os (dstbuf, size);
// This is intrusive...
char* const end = os.begin ()->wr_ptr() + size;
do_seal (end);
double secs = 0.0;
if (use_array)
{
{
int i;
for (i = 0; i < dst_offset; i++)
{
os << T(0);
}
}
if (n == 0)
{
ACE_DEBUG((LM_DEBUG,
ACE_TEXT ("* src align = %d, dst align = %d\n"),
tellalign (src),
tellalign (os.begin ()->wr_ptr ())));
}
Crono crono;
crono.start ();
H::write_array (os, idata, total);
crono.stop ();
secs = crono.read_seconds ();
}
else
{
int i = 0;
for (; i < dst_offset; i++)
{
os << T(0);
}
i = 0;
Crono crono;
crono.start();
while (i < total)
{
os << idata[i++];
os << idata[i++];
os << idata[i++];
os << idata[i++];
// static char rs[32 + 1];
// CDR_Test<T,H>::ttoh (idata[i], rs);
// ACE_DEBUG ((LM_DEBUG, "Write idata[%d] = %s\n", i, rs));
// os << idata[i];
// i++;
}
crono.stop ();
secs = crono.read_seconds ();
}
if (!check_seal(end))
{
ACE_ERROR((LM_ERROR,
ACE_TEXT( "Broken seal, aborting.\n" )));
ACE_OS::exit(1);
}
totalsecs += secs;
if (n == niter - 1)
{
toread = os.begin ()->rd_ptr ();
}
}
totalsecs = totalsecs / niter;
ACE_DEBUG((LM_DEBUG,
ACE_TEXT ("Writing to stream %d %s values: %f seconds.\n"),
total,
H::name (),
totalsecs));
}
{
int i;
for (i = 0; i < total; i++)
{
idata[i] = 0;
}
}
ACE_DEBUG((LM_DEBUG,
ACE_TEXT( "Reading them back in opposing byte order...\n" )));
const int opposite_byte_order = 1 - ACE_CDR_BYTE_ORDER;
{
double totalsecs = 0.0;
int n;
for (n = 0; n < niter; n++)
{
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("====== Read iteration %d\n"), n));
size_t size = (total + dst_offset) * H::size ();
ACE_InputCDR is (toread, size, opposite_byte_order);
// This is intrusive...
char* const end = is.rd_ptr () + size;
do_seal (end);
double secs = 0.0;
if (use_array)
{
{
int i;
for (i = 0; i < dst_offset; i++)
{
T v;
is >> v;
}
}
if (n == 0)
{
ACE_DEBUG((LM_DEBUG,
ACE_TEXT ("* src align = %d, dst align = %d\n"),
tellalign (is.rd_ptr ()),
tellalign (src)));
}
Crono crono;
crono.start ();
H::read_array (is, idata, total);
crono.stop ();
secs = crono.read_seconds ();
// Testing for good bit value. Try reading atleast 10
// times the size of total. It should fail with good bit
// set to 0.
H::read_array (is, idata, 10 * total);
if (is.good_bit () != 0)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Test for good bit failed in %s Array_test\n"),
H::name ()));
}
}
else
{
int i = 0;
Crono crono;
crono.start ();
while (i < total)
{
#if 0
T v;
is >> v;
static char rs[32 + 1];
CDR_Test<T,H>::ttoh (v, rs);
ACE_DEBUG ((LM_DEBUG, "Read idata[%d] = %s\n", i, rs));
idata[i] = v;
i++;
#else
is >> idata[i++];
is >> idata[i++];
is >> idata[i++];
is >> idata[i++];
#endif /* 0 */
}
crono.stop ();
secs = crono.read_seconds ();
}
totalsecs += secs;
if (!check_seal (end))
{
ACE_ERROR((LM_ERROR,
ACE_TEXT( "Broken seal, aborting.\n" )));
ACE_OS::exit(1);
}
}
totalsecs = totalsecs / niter;
ACE_DEBUG((LM_DEBUG,
ACE_TEXT ("Reading from stream %d %s values")
ACE_TEXT (" (byte swapping): %f seconds.\n"),
total,
H::name (),
totalsecs));
}
ACE_DEBUG((LM_DEBUG,
ACE_TEXT ("Now checking data...\n") ));
int errors = 0;
const int maxerrors = 6;
{
int i;
for (i = 0; i < total; i++)
{
T rv;
const char* src = reinterpret_cast<const char*> ((idata + i));
char* dst = reinterpret_cast<char*> ((&rv));
H::swap(src, dst);
// Due to a "feature" of the gcc 4.1.1 optimizer, we need to do
// something with the src pointer so that it doesn't optimize it
// away. Calling tellalign() is benign, but the optimizer
// doesn't know/care. -- Chad Elliott 1/10/2007
tellalign (src);
T cv = CDR_Test<T, H>::checkval (i);
if (!ACE::is_equal (rv, cv))
{
static char rs[32 + 1];
static char cs[32 + 1];
CDR_Test<T, H>::ttoh (rv, rs);
CDR_Test<T, H>::ttoh (cv, cs);
ACE_ERROR((LM_ERROR,
ACE_TEXT ( "Wrong value at pos %d:" )
ACE_TEXT ( " '%s' should be '%s'.\n" ),
i, rs, cs));
errors++;
if (errors == maxerrors)
{
ACE_ERROR((LM_ERROR,
ACE_TEXT ( "%d errors found, ")
ACE_TEXT ( "interrupting check.\n" ),
errors));
break;
}
}
}
}
if (errors != 0)
{
ACE_ERROR((LM_ERROR,
ACE_TEXT (" assertion failed: Inconsistencies found (%d), ")
ACE_TEXT ("aborting.\n"), errors));
ACE_OS::exit(1);
}
ACE_DEBUG((LM_DEBUG,
ACE_TEXT ("Data OK, test %s completed.\n"),
H::name ()));
}
template <class T, class N>
CDR_Test<T, N>::~CDR_Test ()
{
}
//
// Helper Clases for the second template parameter of CDR_Test.
// One for each tested CDR type.
//
struct DoubleHelper
{
static const ACE_TCHAR* name ()
{
return ACE_TEXT ("CDR::Double");
}
static int integral ()
{
return 0;
}
static void read_array (ACE_InputCDR& is,
ACE_CDR::Double* x,
ACE_UINT32 n)
{
is.read_double_array (x, n);
}
static void write_array (ACE_OutputCDR& os,
ACE_CDR::Double* x,
ACE_UINT32 n)
{
os.write_double_array (x, n);
}
static void swap (const char *src, char *dst)
{
ACE_CDR::swap_8 (src, dst);
}
static size_t size ()
{
return sizeof(ACE_CDR::Double);
}
};
struct FloatHelper
{
static const ACE_TCHAR* name ()
{
return ACE_TEXT ("CDR::Float");
}
static int integral ()
{
return 0;
}
static void read_array (ACE_InputCDR& is,
ACE_CDR::Float* x,
ACE_UINT32 n)
{
is.read_float_array (x, n);
}
static void write_array (ACE_OutputCDR& os,
ACE_CDR::Float* x,
ACE_UINT32 n)
{
os.write_float_array (x, n);
}
static void swap (const char *src, char *dst)
{
ACE_CDR::swap_4 (src, dst);
}
static size_t size ()
{
return sizeof(ACE_CDR::Float);
}
};
struct ShortHelper
{
static const ACE_TCHAR* name ()
{
return ACE_TEXT ("CDR::Short");
}
static int integral ()
{
return 1;
}
static void read_array (ACE_InputCDR& is,
ACE_CDR::Short* x,
ACE_UINT32 n)
{
is.read_short_array (x, n);
}
static void write_array (ACE_OutputCDR& os,
ACE_CDR::Short* x,
ACE_UINT32 n)
{
os.write_short_array (x, n);
}
static void swap (const char *src, char *dst)
{
ACE_CDR::swap_2 (src, dst);
}
static size_t size ()
{
return sizeof(ACE_CDR::Short);
}
};
struct LongHelper
{
static const ACE_TCHAR* name ()
{
return ACE_TEXT ("CDR::Long");
}
static int integral ()
{
return 1;
}
static void read_array (ACE_InputCDR& is,
ACE_CDR::Long* x,
ACE_UINT32 n)
{
is.read_long_array (x, n);
}
static void write_array (ACE_OutputCDR& os,
ACE_CDR::Long* x,
ACE_UINT32 n)
{
os.write_long_array (x, n);
}
static void swap (const char *src, char *dst)
{
ACE_CDR::swap_4 (src, dst);
}
static size_t size ()
{
return sizeof(ACE_CDR::Long);
}
};
#if !defined (ACE_LACKS_LONGLONG_T)
struct LongLongHelper
{
static const ACE_TCHAR* name ()
{
return ACE_TEXT ("CDR::LongLong");
}
static int integral ()
{
return 1;
}
static void read_array (ACE_InputCDR& is,
ACE_CDR::LongLong* x,
ACE_UINT32 n)
{
is.read_longlong_array (x, n);
}
static void write_array (ACE_OutputCDR& os,
ACE_CDR::LongLong* x,
ACE_UINT32 n)
{
os.write_longlong_array (x, n);
}
static void swap (const char *src, char *dst)
{
ACE_CDR::swap_8 (src, dst);
}
static size_t size ()
{
return sizeof(ACE_CDR::LongLong);
}
};
#endif /* ! ACE_LACKS_LONGLONG_T */
struct CharHelper
{
static const ACE_TCHAR* name ()
{
return ACE_TEXT ("CDR::Char");
}
static int integral ()
{
return 1;
}
static void read_array (ACE_InputCDR& is,
ACE_CDR::Char* x,
ACE_UINT32 n)
{
is.read_char_array (x, n);
}
static void write_array (ACE_OutputCDR& os,
ACE_CDR::Char* x,
ACE_UINT32 n)
{
os.write_char_array (x, n);
}
static void swap (const char *src, char *dst)
{
*dst = *src;
}
static size_t size ()
{
return sizeof(ACE_CDR::Char);
}
};
void usage (const ACE_TCHAR* cmd)
{
ACE_ERROR((LM_ERROR,
ACE_TEXT ("Usage: %s ")
ACE_TEXT ("[-n n] " )
ACE_TEXT ("[[-d n|-f n|-q n|-w n|-h n|-c n|-t n] | [-t n]]\n")
ACE_TEXT (" -n n: average time for n iterations.\n")
ACE_TEXT (" -d n: n double precision floating point\n")
ACE_TEXT (" -f n: n single precision floating point\n")
ACE_TEXT (" -q n: n quadwords (int64).\n")
ACE_TEXT (" -w n: n words (int32).\n")
ACE_TEXT (" -h n: n halfwords (int16).\n")
ACE_TEXT (" -c n: n chars.\n")
ACE_TEXT (" -t n: n iterations for every type.\n")
ACE_TEXT (" n must be >= 16 for dfqwhct.\n")
ACE_TEXT (" If you provide one of dfqwhc, then only the\n")
ACE_TEXT (" test for the corresponding type ")
ACE_TEXT ("will be performed.\n"),
cmd));
ACE_OS::exit(1);
}
int
validtotal (int n)
{
return n >= 16;
}
int
validiters (int n)
{
return n > 0;
}
int
run_main (int argc, ACE_TCHAR *argv[])
{
ACE_START_TEST (ACE_TEXT ("CDR_Array_Test"));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("This is ACE Version %u.%u.%u\n\n"),
ACE::major_version (),
ACE::minor_version(),
ACE::beta_version()));
ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("d:f:q:w:h:c:t:n:"));
int dtotal = 0;
int ftotal = 0;
int qtotal = 0;
int wtotal = 0;
int htotal = 0;
int ctotal = 0;
int total = 0;
int niter = 0;
struct { int c; int *v; int (*checkf)(int); } opts[] = {
{ 'd', &dtotal, validtotal },
{ 'f', &ftotal, validtotal },
{ 'q', &qtotal, validtotal },
{ 'w', &wtotal, validtotal },
{ 'h', &htotal, validtotal },
{ 'c', &ctotal, validtotal },
{ 't', &total, validtotal },
{ 'n', &niter, validiters },
};
int n = sizeof(opts)/sizeof(opts[0]);
int opt;
while ((opt = get_opt ()) != EOF)
{
int got = 0;
int i;
for (i = 0; i < n; i++)
{
if (opts[i].c == opt)
{
int v = ACE_OS::atoi (get_opt.opt_arg ());
if (!(opts[i].checkf) (v))
{
usage(ACE_TEXT("CDR_Array_Test"));
}
*(opts[i].v) = v;
got = 1;
break;
}
}
if (!got)
{
usage(ACE_TEXT("CDR_Array_Test"));
}
}
if (total == 0)
{
total = default_total;
}
if (niter == 0)
{
niter = default_niter;
}
if (dtotal == 0
&& ftotal == 0
&& qtotal == 0
&& wtotal == 0
&& htotal == 0
&& ctotal == 0)
{
dtotal = ftotal = qtotal = wtotal = htotal = ctotal = total;
}
int use_array;
for (use_array = 0; use_array < 2; use_array++)
{
{
CDR_Test<ACE_CDR::Double, DoubleHelper>
test (dtotal, niter, use_array);
}
{
CDR_Test<ACE_CDR::Float, FloatHelper>
test (ftotal, niter, use_array);
}
#if !defined (ACE_LACKS_LONGLONG_T)
{
CDR_Test<ACE_CDR::LongLong, LongLongHelper>
test (qtotal, niter, use_array);
}
#endif /* ! ACE_LACKS_LONGLONG_T */
{
CDR_Test<ACE_CDR::Long, LongHelper>
test (wtotal, niter, use_array);
}
{
CDR_Test<ACE_CDR::Short, ShortHelper>
test (htotal, niter, use_array);
}
{
CDR_Test<ACE_CDR::Char, CharHelper>
test (ctotal, niter, use_array);
}
}
ACE_END_TEST;
return 0;
}
|