summaryrefslogtreecommitdiff
path: root/examples/Mem_Map
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1999-06-07 06:45:00 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1999-06-07 06:45:00 +0000
commit301f6de0c0719e95d4bdf766d1aae0a3debda263 (patch)
tree4c496c170b9af34f4e4261b5f011b94af3247e03 /examples/Mem_Map
parentf868ff49bd916a0de5d694eb9371c0db858e416f (diff)
downloadATCD-301f6de0c0719e95d4bdf766d1aae0a3debda263.tar.gz
.
Diffstat (limited to 'examples/Mem_Map')
-rw-r--r--examples/Mem_Map/IO-tests/IO_Test.cpp82
-rw-r--r--examples/Mem_Map/IO-tests/IO_Test.h49
-rw-r--r--examples/Mem_Map/IO-tests/test_io.cpp93
3 files changed, 160 insertions, 64 deletions
diff --git a/examples/Mem_Map/IO-tests/IO_Test.cpp b/examples/Mem_Map/IO-tests/IO_Test.cpp
index 2376b7b1ec6..aa981c439b1 100644
--- a/examples/Mem_Map/IO-tests/IO_Test.cpp
+++ b/examples/Mem_Map/IO-tests/IO_Test.cpp
@@ -6,7 +6,8 @@
ACE_RCSID(IO_tests, IO_Test, "$Id$")
-IO_Test::IO_Test (const char *name, ACE_Profile_Timer &tm)
+IO_Test::IO_Test (const char *name,
+ ACE_Profile_Timer &tm)
: name_ (name), tm_ (tm)
{
}
@@ -17,13 +18,16 @@ IO_Test::name (void)
return this->name_;
}
-Slow_Read_Write_Test::Slow_Read_Write_Test (char *name, ACE_Profile_Timer &tm)
+Slow_Read_Write_Test::Slow_Read_Write_Test (const char *name,
+ ACE_Profile_Timer &tm)
: IO_Test (name, tm)
{
}
int
-Slow_Read_Write_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp)
+Slow_Read_Write_Test::run_test (int iterations,
+ FILE *input_fp,
+ FILE *output_fp)
{
int ifd = fileno (input_fp);
int ofd = fileno (output_fp);
@@ -45,13 +49,16 @@ Slow_Read_Write_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp)
return 0;
}
-Stdio_Test::Stdio_Test (char *name, ACE_Profile_Timer &tm)
+Stdio_Test::Stdio_Test (const char *name,
+ ACE_Profile_Timer &tm)
: IO_Test (name, tm)
{
}
int
-Stdio_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp)
+Stdio_Test::run_test (int iterations,
+ FILE *input_fp,
+ FILE *output_fp)
{
this->tm_.start ();
@@ -69,13 +76,16 @@ Stdio_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp)
return 0;
}
-Block_Read_Write_Test::Block_Read_Write_Test (char *name, ACE_Profile_Timer &tm)
+Block_Read_Write_Test::Block_Read_Write_Test (const char *name,
+ ACE_Profile_Timer &tm)
: IO_Test (name, tm)
{
}
int
-Block_Read_Write_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp)
+Block_Read_Write_Test::run_test (int iterations,
+ FILE *input_fp,
+ FILE *output_fp)
{
int ifd = fileno (input_fp);
int ofd = fileno (output_fp);
@@ -87,7 +97,9 @@ Block_Read_Write_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp
char buf[BUFSIZ];
ssize_t n;
- while ((n = ACE_OS::read (ifd, buf, sizeof buf)) > 0)
+ while ((n = ACE_OS::read (ifd,
+ buf,
+ sizeof buf)) > 0)
::write (ofd, buf, n);
ACE_OS::lseek (ifd, 0, SEEK_SET);
@@ -98,13 +110,16 @@ Block_Read_Write_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp
return 0;
}
-Block_Fread_Fwrite_Test::Block_Fread_Fwrite_Test (char *name, ACE_Profile_Timer &tm)
+Block_Fread_Fwrite_Test::Block_Fread_Fwrite_Test (const char *name,
+ ACE_Profile_Timer &tm)
: IO_Test (name, tm)
{
}
int
-Block_Fread_Fwrite_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp)
+Block_Fread_Fwrite_Test::run_test (int iterations,
+ FILE *input_fp,
+ FILE *output_fp)
{
this->tm_.start ();
@@ -113,7 +128,10 @@ Block_Fread_Fwrite_Test::run_test (int iterations, FILE *input_fp, FILE *output_
char buf[BUFSIZ];
ssize_t n;
- while ((n = ACE_OS::fread (buf, 1, sizeof buf, input_fp)) != 0)
+ while ((n = ACE_OS::fread (buf,
+ 1,
+ sizeof buf,
+ input_fp)) != 0)
::fwrite (buf, n, 1, output_fp);
ACE_OS::rewind (input_fp);
@@ -124,50 +142,72 @@ Block_Fread_Fwrite_Test::run_test (int iterations, FILE *input_fp, FILE *output_
return 0;
}
-Mmap1_Test::Mmap1_Test (char *name, ACE_Profile_Timer &tm)
+Mmap1_Test::Mmap1_Test (const char *name,
+ ACE_Profile_Timer &tm)
: IO_Test (name, tm)
{
}
int
-Mmap1_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp)
+Mmap1_Test::run_test (int iterations,
+ FILE *input_fp,
+ FILE *output_fp)
{
ACE_Mem_Map map_input (fileno (input_fp));
void *src = map_input.addr ();
if (src == MAP_FAILED)
- ACE_ERROR_RETURN ((LM_ERROR, "%s", this->name ()), -1);
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%s",
+ this->name ()),
+ -1);
else
{
this->tm_.start ();
while (--iterations >= 0)
{
- if (ACE_OS::write (fileno (output_fp), src, map_input.size ()) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%s", this->name ()), -1);
- ACE_OS::lseek (fileno (output_fp), 0, SEEK_SET);
+ if (ACE_OS::write (fileno (output_fp),
+ src,
+ map_input.size ()) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%s",
+ this->name ()),
+ -1);
+ ACE_OS::lseek (fileno (output_fp),
+ 0,
+ SEEK_SET);
}
this->tm_.stop ();
}
if (map_input.unmap () == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%s", this->name ()), -1);
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%s",
+ this->name ()),
+ -1);
else
return 0;
}
-Mmap2_Test::Mmap2_Test (char *name, ACE_Profile_Timer &tm)
+Mmap2_Test::Mmap2_Test (const char *name,
+ ACE_Profile_Timer &tm)
: IO_Test (name, tm)
{
}
int
-Mmap2_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp)
+Mmap2_Test::run_test (int iterations,
+ FILE *input_fp,
+ FILE *output_fp)
{
ACE_Mem_Map map_input (fileno (input_fp));
int size = map_input.size ();
- ACE_Mem_Map map_output (fileno (output_fp), size, PROT_WRITE, MAP_SHARED);
+ ACE_Mem_Map map_output (fileno (output_fp),
+ size,
+ PROT_WRITE,
+ MAP_SHARED);
void *src = map_input.addr ();
void *dst = map_output.addr ();
diff --git a/examples/Mem_Map/IO-tests/IO_Test.h b/examples/Mem_Map/IO-tests/IO_Test.h
index 22dcf578d7f..38e73778edc 100644
--- a/examples/Mem_Map/IO-tests/IO_Test.h
+++ b/examples/Mem_Map/IO-tests/IO_Test.h
@@ -15,13 +15,16 @@ class IO_Test
{
public:
// Initialize the test name
- IO_Test (const char *name, ACE_Profile_Timer &tm);
+ IO_Test (const char *name,
+ ACE_Profile_Timer &tm);
// Return the name of the test
const char *name (void);
// Execute the IO test (note this is a pure virtual function...)
- virtual int run_test (int iterations, FILE *input_fp, FILE *output_fp) = 0;
+ virtual int run_test (int iterations,
+ FILE *input_fp,
+ FILE *output_fp) = 0;
protected:
// Name of the test
@@ -34,42 +37,60 @@ protected:
class Slow_Read_Write_Test : public IO_Test
{
public:
- Slow_Read_Write_Test (char *name, ACE_Profile_Timer &tm);
- virtual int run_test (int iterations, FILE *input_fp, FILE *output_fp);
+ Slow_Read_Write_Test (const char *name,
+ ACE_Profile_Timer &tm);
+ virtual int run_test (int iterations,
+ FILE *input_fp,
+ FILE *output_fp);
};
class Stdio_Test : public IO_Test
{
public:
- Stdio_Test (char *name, ACE_Profile_Timer &tm);
- virtual int run_test (int iterations, FILE *input_fp, FILE *output_fp);
+ Stdio_Test (const char *name,
+ ACE_Profile_Timer &tm);
+ virtual int run_test (int iterations,
+ FILE *input_fp,
+ FILE *output_fp);
};
class Block_Read_Write_Test : public IO_Test
{
public:
- Block_Read_Write_Test (char *name, ACE_Profile_Timer &tm);
- virtual int run_test (int iterations, FILE *input_fp, FILE *output_fp);
+ Block_Read_Write_Test (const char *name,
+ ACE_Profile_Timer &tm);
+ virtual int run_test (int iterations,
+ FILE *input_fp,
+ FILE *output_fp);
};
class Block_Fread_Fwrite_Test : public IO_Test
{
public:
- Block_Fread_Fwrite_Test (char *name, ACE_Profile_Timer &tm);
- virtual int run_test (int iterations, FILE *input_fp, FILE *output_fp);
+ Block_Fread_Fwrite_Test (const char *name,
+ ACE_Profile_Timer &tm);
+ virtual int run_test (int iterations,
+ FILE *input_fp,
+ FILE *output_fp);
};
class Mmap1_Test : public IO_Test
{
public:
- Mmap1_Test (char *name, ACE_Profile_Timer &tm);
- virtual int run_test (int iterations, FILE *input_fp, FILE *output_fp);
+ Mmap1_Test (const char *name,
+ ACE_Profile_Timer &tm);
+ virtual int run_test (int iterations,
+ FILE *input_fp,
+ FILE *output_fp);
};
class Mmap2_Test : public IO_Test
{
public:
- Mmap2_Test (char *name, ACE_Profile_Timer &tm);
- virtual int run_test (int iterations, FILE *input_fp, FILE *output_fp);
+ Mmap2_Test (const char *name,
+ ACE_Profile_Timer &tm);
+ virtual int run_test (int iterations,
+ FILE *input_fp,
+ FILE *output_fp);
};
diff --git a/examples/Mem_Map/IO-tests/test_io.cpp b/examples/Mem_Map/IO-tests/test_io.cpp
index 15c0b131e9d..3a6d2a0c015 100644
--- a/examples/Mem_Map/IO-tests/test_io.cpp
+++ b/examples/Mem_Map/IO-tests/test_io.cpp
@@ -14,10 +14,10 @@ ACE_RCSID(IO_tests, test_io, "$Id$")
static const char *program_name;
// Name of default input file.
-static char *input_filename = "/usr/dict/words";
+static const char *input_filename = "/usr/dict/words";
// Name of default output file.
-static char *output_filename = "/tmp/foo";
+static const char *output_filename = "/tmp/foo";
// Check if removing output file upon completion...
static int remove_output = 1;
@@ -85,21 +85,37 @@ static IO_Test *test_vector[100];
static int
run_tests (int iterations, FILE *input_fp, FILE *output_fp)
{
- // If HP/UX didn't suck so badly we could initialize in the global
- // scope...
int i = 0;
- ACE_NEW_RETURN (test_vector[i], Stdio_Test ("Stdio_Test", profile_timer), -1);
+ ACE_NEW_RETURN (test_vector[i],
+ Stdio_Test ("Stdio_Test",
+ profile_timer),
+ -1);
i++;
- ACE_NEW_RETURN (test_vector[i], Block_Fread_Fwrite_Test ("Block_Fread_Fwrite_Test", profile_timer), -1);
+ ACE_NEW_RETURN (test_vector[i],
+ Block_Fread_Fwrite_Test ("Block_Fread_Fwrite_Test",
+ profile_timer),
+ -1);
i++;
- ACE_NEW_RETURN (test_vector[i], Block_Read_Write_Test ("Block_Read_Write_Test", profile_timer), -1);
+ ACE_NEW_RETURN (test_vector[i],
+ Block_Read_Write_Test ("Block_Read_Write_Test",
+ profile_timer),
+ -1);
i++;
- ACE_NEW_RETURN (test_vector[i], Mmap1_Test ("Mmap1_Test", profile_timer), -1);
+ ACE_NEW_RETURN (test_vector[i],
+ Mmap1_Test ("Mmap1_Test",
+ profile_timer),
+ -1);
i++;
- ACE_NEW_RETURN (test_vector[i], Mmap2_Test ("Mmap2_Test", profile_timer), -1);
+ ACE_NEW_RETURN (test_vector[i],
+ Mmap2_Test ("Mmap2_Test",
+ profile_timer),
+ -1);
i++;
- ACE_NEW_RETURN (test_vector[i], Slow_Read_Write_Test ("Slow_Read_Write_Test", profile_timer), -1);
+ ACE_NEW_RETURN (test_vector[i],
+ Slow_Read_Write_Test ("Slow_Read_Write_Test",
+ profile_timer),
+ -1);
i++;
test_vector[i] = (IO_Test *) 0;
@@ -107,19 +123,26 @@ run_tests (int iterations, FILE *input_fp, FILE *output_fp)
for (i = 0; test_vector[i] != 0; i++)
{
if (ACE_OS::ftruncate (fileno (output_fp), 0) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%s\n", "ftruncate"), -1);
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%s\n",
+ "ftruncate"),
+ -1);
- ACE_DEBUG ((LM_DEBUG, "--------------------\n"
+ ACE_DEBUG ((LM_DEBUG,
+ "--------------------\n"
"starting %s for %d iterations(s):\n",
test_vector[i]->name (),
iterations));
- test_vector[i]->run_test (iterations, input_fp, output_fp);
+ test_vector[i]->run_test (iterations,
+ input_fp,
+ output_fp);
ACE_Profile_Timer::ACE_Elapsed_Time et;
profile_timer.elapsed_time (et);
- ACE_DEBUG ((LM_DEBUG, "wallclock time = %f, user time = %f, system time = %f\n",
+ ACE_DEBUG ((LM_DEBUG,
+ "wallclock time = %f, user time = %f, system time = %f\n",
et.real_time,
et.user_time,
et.system_time));
@@ -127,42 +150,54 @@ run_tests (int iterations, FILE *input_fp, FILE *output_fp)
delete test_vector[i];
}
- ACE_DEBUG ((LM_DEBUG, "--------------------\n"));
+ ACE_DEBUG ((LM_DEBUG,
+ "--------------------\n"));
return 0;
}
int
main (int argc, char *argv[])
{
-#if defined (ACE_WIN32)
- char delim = '\\';
-#else
- char delim = '/';
-#endif /* ACE_WIN32 */
- program_name = ACE::basename (argv[0], delim);
+ program_name = ACE::basename (argv[0],
+ ACE_DIRECTORY_SEPARATOR_CHAR);
parse_args (argc, argv);
ACE_Sig_Action sa ((ACE_SignalHandler) cleanup, SIGINT);
ACE_UNUSED_ARG (sa);
- FILE *input_fp = ACE_OS::fopen (input_filename, "r");
- FILE *output_fp = ACE_OS::fopen (output_filename, "w+");
+ FILE *input_fp =
+ ACE_OS::fopen (input_filename, "r");
+ FILE *output_fp =
+ ACE_OS::fopen (output_filename, "w+");
if (input_fp == 0)
- ACE_ERROR_RETURN ((LM_ERROR, "%s\n", "input_filename"), -1);
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%s\n",
+ "input_filename"),
+ -1);
if (output_fp == 0)
- ACE_ERROR_RETURN ((LM_ERROR, "%s\n", "output_filename"), -1);
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%s\n",
+ "output_filename"),
+ -1);
ACE_OS::unlink (output_filename);
- if (run_tests (iteration_count, input_fp, output_fp) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "run_tests"), -1);
+ if (run_tests (iteration_count,
+ input_fp,
+ output_fp) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "run_tests"),
+ -1);
if (ACE_OS::fclose (input_fp) == -1
|| ACE_OS::fclose (output_fp) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%s\n", "fclose"), -1);
-
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%s\n",
+ "fclose"),
+ -1);
cleanup ();
return 0;
}