summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorcoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-05-16 16:59:21 +0000
committercoryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-05-16 16:59:21 +0000
commitd8dedf08f42a78206fde7aa6802bd1434e16fc06 (patch)
treed78e2119997addece4b06d451b8f399cf4f7b5c8 /tests
parentd0ad5001fdf5b6c015afd3035d9ec3ca710b6753 (diff)
downloadATCD-d8dedf08f42a78206fde7aa6802bd1434e16fc06.tar.gz
ChangeLogTag:Tue May 16 09:53:19 2000 Carlos O'Ryan <coryan@uci.edu>
Diffstat (limited to 'tests')
-rw-r--r--tests/CDR_Array_Test.cpp256
-rw-r--r--tests/CDR_File_Test.cpp46
2 files changed, 181 insertions, 121 deletions
diff --git a/tests/CDR_Array_Test.cpp b/tests/CDR_Array_Test.cpp
index cca75e89607..1a3e3be7f1f 100644
--- a/tests/CDR_Array_Test.cpp
+++ b/tests/CDR_Array_Test.cpp
@@ -49,7 +49,7 @@
#error "Can't define USE_GETRUSAGE on this platform."
#endif
-ACE_RCSID(tests, CDR_Array_Test, "$Id$");
+ACE_RCSID(tests, CDR_Array_Test, "$Id$")
// 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
@@ -62,7 +62,7 @@ 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 = 5;
+static const int default_niter = 10;
//
// A simple cronometer in seconds, that encapsulates our time
@@ -144,6 +144,7 @@ public:
~CDR_Test ();
static void ttoh (const T& t, char* s);
+ static T checkval(int i);
private:
CDR_Test (const CDR_Test&);
@@ -163,7 +164,7 @@ zero (char* p, int k)
}
inline int
-max (int a, int b)
+mymax (int a, int b)
{
return (a >= b) ? a : b;
}
@@ -229,7 +230,7 @@ CDR_Test<T, H>::CDR_Test (int total, int niter, int use_array)
int dk;
for (dk = 0; dk < delta; dk++)
{
- int tdelta = t - max(sk, dk);
+ int tdelta = t - mymax(sk, dk);
CDR_Test<T, H>::do_test(tdelta, niter, 1,
srcbuf, dstbuf,
@@ -248,20 +249,29 @@ CDR_Test<T, H>::CDR_Test (int total, int niter, int use_array)
delete[] dstbuf;
}
-// Generate a ``interesting'' value for testing at pos `i'.
-#if 0
-// egcs-1.0.2 (egcs-2.90.27 980315) generates an internal compiler
-// error 9 with this.
-template<class T> inline T
-checkval<T> (int i)
+// Generate an ``interesting'' value for testing at pos >i<.
+template<class T, class H> T
+CDR_Test<T, H>::checkval (int i)
{
- const int cycle = 17;
- return T(i % cycle);
+ 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 = ACE_reinterpret_cast(unsigned char*, (&v));
+ unsigned int j;
+ for (j = 0; j < sizeof(T); j++)
+ {
+ s[j] = (unsigned char) ((j + i*sizeof(T)) % 256);
+ }
+
+ return v;
+ }
}
-#else
-const int cycle = 17;
-#define checkval(T,x) ((T) ((x) % cycle))
-#endif
static char digits[16] = {
'0', '1', '2', '3',
@@ -286,9 +296,9 @@ CDR_Test<T, H>::ttoh (const T& t, char* s)
ACE_reinterpret_cast(const unsigned char*, &t);
const unsigned char* q;
- for (q = p; q < p + sizeof(t); ++q)
+ for (q = p; q < p + sizeof(T); ++q)
{
- int k = ACE_static_cast(int, *q);
+ int k = *q;
*s++ = digits[ k >> 4 ];
*s++ = digits[ k & 15 ];
}
@@ -320,7 +330,7 @@ check_seal (char* pos)
// returns the alignment of ptr, wrt ACE_CDR::MAX_ALIGNMENT.
//
int
-tellalign (char* ptr)
+tellalign (const char* const ptr)
{
int align = ACE_CDR::MAX_ALIGNMENT;
while (ptr != ACE_ptr_align_binary(ptr, align))
@@ -344,7 +354,7 @@ CDR_Test<T, H>::do_test (int total, int niter, int use_array,
ACE_DEBUG((LM_DEBUG,
ACE_TEXT( "Starting Test for %s: %d elements " )
ACE_TEXT( "%susing arrays.\n" ),
- ACE_TEXT( H::name ),
+ ACE_TEXT( H::name ()),
total,
((use_array) ? ACE_TEXT( "" ) : ACE_TEXT( "not " ))));
@@ -368,12 +378,12 @@ CDR_Test<T, H>::do_test (int total, int niter, int use_array,
int i;
for (i = 0; i < total; i++)
{
- idata[i] = checkval(T, i);
+ idata[i] = CDR_Test<T, H>::checkval (i);
}
}
ACE_DEBUG((LM_DEBUG,
- ACE_TEXT( "Writing data...\n" )));
+ ACE_TEXT( "Writting data...\n" )));
char* toread = 0;
{
@@ -386,9 +396,10 @@ CDR_Test<T, H>::do_test (int total, int niter, int use_array,
int size = sizeof(T)*(dst_offset + total);
ACE_OutputCDR os (dstbuf, size);
+ // This is intrusive...
char* const end = os.begin ()->wr_ptr() + size;
- do_seal(end);
+ do_seal (end);
double secs = 0.0;
if (use_array)
@@ -409,7 +420,6 @@ CDR_Test<T, H>::do_test (int total, int niter, int use_array,
tellalign (os.begin ()->wr_ptr ())));
}
-
Crono crono;
crono.start ();
H::write_array (os, idata, total);
@@ -444,16 +454,16 @@ CDR_Test<T, H>::do_test (int total, int niter, int use_array,
if (n == niter - 1)
{
- toread = os.begin()->rd_ptr();
+ toread = os.begin ()->rd_ptr ();
}
}
totalsecs = totalsecs / niter;
ACE_DEBUG((LM_DEBUG,
- ACE_TEXT ("Writing to stream %d %s values: %f seconds.\n"),
+ ACE_TEXT ("Writting to stream %d %s values: %f seconds.\n"),
total,
- ACE_TEXT (H::name),
+ ACE_TEXT (H::name ()),
totalsecs));
}
@@ -478,9 +488,10 @@ CDR_Test<T, H>::do_test (int total, int niter, int use_array,
int size = (total + dst_offset)*sizeof(T);
ACE_InputCDR is (toread, size, opposite_byte_order);
- char* const end = is.rd_ptr() + size;
+ // This is intrusive...
+ char* const end = is.rd_ptr () + size;
- do_seal(end);
+ do_seal (end);
double secs = 0.0;
if (use_array)
@@ -504,7 +515,7 @@ CDR_Test<T, H>::do_test (int total, int niter, int use_array,
Crono crono;
crono.start ();
- H::read_array(is, idata, total);
+ H::read_array (is, idata, total);
crono.stop ();
secs = crono.read_seconds ();
}
@@ -525,7 +536,7 @@ CDR_Test<T, H>::do_test (int total, int niter, int use_array,
}
totalsecs += secs;
- if (!check_seal(end))
+ if (!check_seal (end))
{
ACE_ERROR((LM_ERROR,
ACE_TEXT( "Broken seal, aborting.\n" )));
@@ -539,7 +550,7 @@ CDR_Test<T, H>::do_test (int total, int niter, int use_array,
ACE_TEXT ("Reading from stream %d %s values")
ACE_TEXT (" (byte swapping): %f seconds.\n"),
total,
- ACE_TEXT (H::name),
+ ACE_TEXT (H::name ()),
totalsecs));
}
@@ -553,51 +564,24 @@ CDR_Test<T, H>::do_test (int total, int niter, int use_array,
int i;
for (i = 0; i < total; i++)
{
- T v;
+ T rv;
const char* src = ACE_reinterpret_cast(const char*, (idata + i));
- char* dst = ACE_reinterpret_cast(char*, (&v));
-
- // Easier than writing each H::swap...
- switch(sizeof(T))
- {
- case 1:
- *dst = *src;
- break;
-
- case 2:
- ACE_CDR::swap_2(src, dst);
- break;
+ char* dst = ACE_reinterpret_cast(char*, (&rv));
- case 4:
- ACE_CDR::swap_4(src, dst);
- break;
+ H::swap(src, dst);
- case 8:
- ACE_CDR::swap_8(src, dst);
- break;
-
- case 16:
- ACE_CDR::swap_16(src, dst);
- break;
-
- default:
- ACE_ERROR((LM_DEBUG,
- ACE_TEXT ("Unsupported size, aborting.\n")));
- ACE_OS::exit(1);
- }
-
-
- if (v != checkval(T, i))
+ T cv = CDR_Test<T, H>::checkval (i);
+ if (rv != cv)
{
- static char s1[32 + 1];
- static char s2[32 + 1];
- CDR_Test::ttoh (v, s1);
- CDR_Test::ttoh (checkval(T, i), s2);
+ 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, s1, s2));
+ i, rs, cs));
errors++;
if (errors == maxerrors)
{
@@ -620,7 +604,7 @@ CDR_Test<T, H>::do_test (int total, int niter, int use_array,
ACE_DEBUG((LM_DEBUG,
ACE_TEXT ("Data OK, Ending %s test.\n"),
- ACE_TEXT (H::name)));
+ ACE_TEXT (H::name ())));
}
template <class T, class N>
@@ -635,7 +619,14 @@ CDR_Test<T, N>::~CDR_Test ()
struct DoubleHelper
{
- static const char* name;
+ static const char* name ()
+ {
+ return "CDR::Double";
+ }
+ static const int integral ()
+ {
+ return 0;
+ }
static void read_array (ACE_InputCDR& is,
ACE_CDR::Double* x,
ACE_UINT32 n)
@@ -648,12 +639,22 @@ struct DoubleHelper
{
os.write_double_array (x, n);
}
+ static void swap (const char *src, char *dst)
+ {
+ ACE_CDR::swap_8 (src, dst);
+ }
};
-const char* DoubleHelper::name = "CDR::Double";
struct FloatHelper
{
- static const char* name;
+ static const char* name ()
+ {
+ return "CDR::Float";
+ }
+ static const int integral ()
+ {
+ return 0;
+ }
static void read_array (ACE_InputCDR& is,
ACE_CDR::Float* x,
ACE_UINT32 n)
@@ -666,12 +667,22 @@ struct FloatHelper
{
os.write_float_array (x, n);
}
+ static void swap (const char *src, char *dst)
+ {
+ ACE_CDR::swap_4 (src, dst);
+ }
};
-const char* FloatHelper::name = "CDR::Float";
struct ShortHelper
{
- static const char* name;
+ static const char* name ()
+ {
+ return "CDR::Short";
+ }
+ static const int integral ()
+ {
+ return 1;
+ }
static void read_array (ACE_InputCDR& is,
ACE_CDR::Short* x,
ACE_UINT32 n)
@@ -684,12 +695,22 @@ struct ShortHelper
{
os.write_short_array (x, n);
}
+ static void swap (const char *src, char *dst)
+ {
+ ACE_CDR::swap_2 (src, dst);
+ }
};
-const char* ShortHelper::name = "CDR::Short";
struct LongHelper
{
- static const char* name;
+ static const char* name ()
+ {
+ return "CDR::Long";
+ }
+ static const int integral ()
+ {
+ return 1;
+ }
static void read_array (ACE_InputCDR& is,
ACE_CDR::Long* x,
ACE_UINT32 n)
@@ -702,12 +723,22 @@ struct LongHelper
{
os.write_long_array (x, n);
}
+ static void swap (const char *src, char *dst)
+ {
+ ACE_CDR::swap_4 (src, dst);
+ }
};
-const char* LongHelper::name = "CDR::Long";
struct LongLongHelper
{
- static const char* name;
+ static const char* name ()
+ {
+ return "CDR::LongLong";
+ }
+ static const int integral ()
+ {
+ return 1;
+ }
static void read_array (ACE_InputCDR& is,
ACE_CDR::LongLong* x,
ACE_UINT32 n)
@@ -721,12 +752,22 @@ struct LongLongHelper
os.write_longlong_array (x, n);
}
+ static void swap (const char *src, char *dst)
+ {
+ ACE_CDR::swap_8 (src, dst);
+ }
};
-const char* LongLongHelper::name = "CDR::LongLong";
struct CharHelper
{
- static const char* name;
+ static const char* name ()
+ {
+ return "CDR::Char";
+ }
+ static const int integral ()
+ {
+ return 1;
+ }
static void read_array (ACE_InputCDR& is,
ACE_CDR::Char* x,
ACE_UINT32 n)
@@ -739,8 +780,11 @@ struct CharHelper
{
os.write_char_array (x, n);
}
+ static void swap (const char *src, char *dst)
+ {
+ *dst = *src;
+ }
};
-const char* CharHelper::name = "CDR::Char";
void usage (ACE_TCHAR* cmd)
{
@@ -758,12 +802,25 @@ void usage (ACE_TCHAR* cmd)
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 (" corresponding type tests will be performed.\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
main (int argc, ACE_TCHAR *argv[])
{
ACE_START_TEST (ACE_TEXT ("CDR_Array_Test"));
@@ -784,15 +841,15 @@ main (int argc, ACE_TCHAR *argv[])
int total = 0;
int niter = 0;
- struct { int c; int *v; } opts[] = {
- { 'd', &dtotal },
- { 'f', &ftotal },
- { 'q', &qtotal },
- { 'w', &wtotal },
- { 'h', &htotal },
- { 'c', &ctotal },
- { 't', &total },
- { 'n', &niter },
+ 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]);
@@ -806,7 +863,13 @@ main (int argc, ACE_TCHAR *argv[])
{
if (opts[i].c == opt)
{
- *(opts[i].v) = ACE_OS::atoi (get_opt.optarg);
+ int v = ACE_OS::atoi (get_opt.optarg);
+ if (!(opts[i].checkf) (v))
+ {
+ usage(argv[0]);
+ }
+
+ *(opts[i].v) = v;
got = 1;
break;
}
@@ -822,13 +885,6 @@ main (int argc, ACE_TCHAR *argv[])
{
total = default_total;
}
- else
- {
- if (total < 16)
- {
- usage(argv[0]);
- }
- }
if (niter == 0)
{
diff --git a/tests/CDR_File_Test.cpp b/tests/CDR_File_Test.cpp
index b0351ec2db6..bc25ad33717 100644
--- a/tests/CDR_File_Test.cpp
+++ b/tests/CDR_File_Test.cpp
@@ -47,9 +47,9 @@ public:
// Default constructor.
CDR_Test (ACE_CDR::Char o,
- ACE_CDR::Short s,
+ ACE_CDR::Short s,
ACE_CDR::Long w,
- ACE_CDR::LongLong lw,
+ ACE_CDR::LongLong lw,
ACE_CDR::Float f,
ACE_CDR::Double d);
// Constructor.
@@ -101,7 +101,7 @@ CDR_Test::CDR_Test (void)
}
CDR_Test::CDR_Test (ACE_CDR::Char o,
- ACE_CDR::Short s,
+ ACE_CDR::Short s,
ACE_CDR::Long w,
ACE_CDR::LongLong lw,
ACE_CDR::Float f,
@@ -185,7 +185,7 @@ run_test (int write_file,
ACE_CDR_BYTE_ORDER ? "little" : "big"));
n = file.send (output_mb->rd_ptr (),
- output_mb->length ());
+ output_mb->length ());
if (n != (size_t) output_mb->length())
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("send failed on %p\n"),
@@ -272,9 +272,9 @@ static void
usage(ACE_TCHAR* cmd)
{
ACE_ERROR ((LM_ERROR,
- ACE_TEXT ("Usage: %s ")
- ACE_TEXT ("[-f filename [-w|-r]]"),
- cmd));
+ ACE_TEXT ("Usage: %s ")
+ ACE_TEXT ("[-f filename [-w|-r]]"),
+ cmd));
ACE_OS::exit(1);
}
@@ -287,7 +287,7 @@ main (int argc, ACE_TCHAR *argv[])
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("This is ACE Version %u.%u.%u\n\n"),
- ACE::major_version (),
+ ACE::major_version(),
ACE::minor_version(),
ACE::beta_version()));
@@ -326,7 +326,11 @@ main (int argc, ACE_TCHAR *argv[])
}
// Create a temporary filename.
- ACE_FILE_Addr filename ((fn == 0) ? ACE_sap_any_cast (ACE_FILE_Addr &) : fn);
+ ACE_FILE_Addr filename(ACE_sap_any_cast (ACE_FILE_Addr &));
+ if (fn != 0)
+ {
+ filename.set (fn);
+ }
ACE_FILE_Connector connector;
ACE_FILE_IO file;
@@ -349,10 +353,10 @@ main (int argc, ACE_TCHAR *argv[])
// Unlink this file right away so that it is automatically removed
// when the process exits.
if (file.unlink () == -1)
- ACE_ERROR_RETURN ((LM_ERROR,
- ACE_TEXT ("unlink failed for %p\n"),
- filename.get_path_name ()),
- 1);
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("unlink failed for %p\n"),
+ filename.get_path_name ()),
+ 1);
}
// Unlink this file right away so that it is automatically removed
@@ -363,9 +367,9 @@ main (int argc, ACE_TCHAR *argv[])
filename.get_path_name ()),
1);
CDR_Test cdr_test ('a',
- 0x00ff,
+ 0x00ff,
0xaabbccdd,
- 0x01234567,
+ 0x01234567,
1.54321f,
1.12345);
@@ -373,18 +377,18 @@ main (int argc, ACE_TCHAR *argv[])
{
// write the file.
run_test (1,
- file,
- filename.get_path_name (),
- cdr_test);
+ file,
+ filename.get_path_name (),
+ cdr_test);
}
if (reading)
{
// read the file.
run_test (0,
- file,
- filename.get_path_name (),
- cdr_test);
+ file,
+ filename.get_path_name (),
+ cdr_test);
}
ACE_END_TEST;