diff options
Diffstat (limited to 'examples/Mem_Map/IO-tests')
-rw-r--r-- | examples/Mem_Map/IO-tests/IO_Test.cpp | 189 | ||||
-rw-r--r-- | examples/Mem_Map/IO-tests/IO_Test.h | 71 | ||||
-rw-r--r-- | examples/Mem_Map/IO-tests/Makefile | 66 | ||||
-rw-r--r-- | examples/Mem_Map/IO-tests/test_io.cpp | 166 |
4 files changed, 0 insertions, 492 deletions
diff --git a/examples/Mem_Map/IO-tests/IO_Test.cpp b/examples/Mem_Map/IO-tests/IO_Test.cpp deleted file mode 100644 index 12dde886e25..00000000000 --- a/examples/Mem_Map/IO-tests/IO_Test.cpp +++ /dev/null @@ -1,189 +0,0 @@ -// $Id$ - -#include "ace/OS.h" -#include "ace/Mem_Map.h" -#include "IO_Test.h" - -IO_Test::IO_Test (const char *name, ACE_Profile_Timer &tm) - : name_ (name), tm_ (tm) -{ -} - -const char * -IO_Test::name (void) -{ - return this->name_; -} - -Slow_Read_Write_Test::Slow_Read_Write_Test (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) -{ - int ifd = fileno (input_fp); - int ofd = fileno (output_fp); - - this->tm_.start (); - - while (--iterations >= 0) - { - char c; - - while (ACE_OS::read (ifd, &c, sizeof c) > 0) - ::write (ofd, &c, sizeof c); - - ACE_OS::lseek (ifd, 0, SEEK_SET); - ACE_OS::lseek (ofd, 0, SEEK_SET); - } - - this->tm_.stop (); - return 0; -} - -Stdio_Test::Stdio_Test (char *name, ACE_Profile_Timer &tm) - : IO_Test (name, tm) -{ -} - -int -Stdio_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp) -{ - this->tm_.start (); - - while (--iterations >= 0) - { - int c; - - while ((c = getc (input_fp)) != EOF) - putc (c, output_fp); - - ACE_OS::rewind (input_fp); - ACE_OS::rewind (output_fp); - } - this->tm_.stop (); - return 0; -} - -Block_Read_Write_Test::Block_Read_Write_Test (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) -{ - int ifd = fileno (input_fp); - int ofd = fileno (output_fp); - - this->tm_.start (); - - while (--iterations >= 0) - { - char buf[BUFSIZ]; - ssize_t n; - - while ((n = ACE_OS::read (ifd, buf, sizeof buf)) > 0) - ::write (ofd, buf, n); - - ACE_OS::lseek (ifd, 0, SEEK_SET); - ACE_OS::lseek (ofd, 0, SEEK_SET); - } - - this->tm_.stop (); - return 0; -} - -Block_Fread_Fwrite_Test::Block_Fread_Fwrite_Test (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) -{ - this->tm_.start (); - - while (--iterations >= 0) - { - char buf[BUFSIZ]; - ssize_t n; - - while ((n = ACE_OS::fread (buf, 1, sizeof buf, input_fp)) != 0) - ::fwrite (buf, n, 1, output_fp); - - ACE_OS::rewind (input_fp); - ACE_OS::rewind (output_fp); - } - - this->tm_.stop (); - return 0; -} - -Mmap1_Test::Mmap1_Test (char *name, ACE_Profile_Timer &tm) - : IO_Test (name, tm) -{ -} - -int -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); - 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); - } - - this->tm_.stop (); - } - - if (map_input.unmap () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%s", this->name ()), -1); - else - return 0; -} - -Mmap2_Test::Mmap2_Test (char *name, ACE_Profile_Timer &tm) - : IO_Test (name, tm) -{ -} - -int -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); - void *src = map_input.addr (); - void *dst = map_output.addr (); - - if (src == MAP_FAILED || dst == MAP_FAILED) - return -1; - else - { - this->tm_.start (); - - while (--iterations >= 0) - ACE_OS::memcpy (dst, src, size); - - this->tm_.stop (); - } - - if (map_input.unmap () == -1 - || map_output.unmap () == -1) - return -1; - else - return 0; -} diff --git a/examples/Mem_Map/IO-tests/IO_Test.h b/examples/Mem_Map/IO-tests/IO_Test.h deleted file mode 100644 index 659a85eec15..00000000000 --- a/examples/Mem_Map/IO-tests/IO_Test.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -/* Class hierarchy for the File I/O tests. */ - -#include "ace/Profile_Timer.h" - -/* Base class for all the File I/O tests. */ - -class IO_Test -{ -public: - // Initialize the test name - 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; - -protected: - // Name of the test - const char *name_; - - // Reference to a timer - ACE_Profile_Timer &tm_; -}; - -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); -}; - -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); -}; - -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); -}; - -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); -}; - -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); -}; - -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); -}; - diff --git a/examples/Mem_Map/IO-tests/Makefile b/examples/Mem_Map/IO-tests/Makefile deleted file mode 100644 index 8397a4b679c..00000000000 --- a/examples/Mem_Map/IO-tests/Makefile +++ /dev/null @@ -1,66 +0,0 @@ -#---------------------------------------------------------------------------- -# -# $Id$ -# -# Makefile for Mem_Map IO tests -#---------------------------------------------------------------------------- - -#---------------------------------------------------------------------------- -# Local macros -#---------------------------------------------------------------------------- - -BIN = test_io - -FILES = IO_Test - -SRC = $(addsuffix .cpp,$(FILES)) -OBJ = $(addsuffix .o,$(FILES)) - -BUILD = $(VBIN) - -#---------------------------------------------------------------------------- -# Include macros and targets -#---------------------------------------------------------------------------- - -include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU -include $(ACE_ROOT)/include/makeinclude/macros.GNU -include $(ACE_ROOT)/include/makeinclude/rules.common.GNU -include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU -include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU -include $(ACE_ROOT)/include/makeinclude/rules.local.GNU - -#---------------------------------------------------------------------------- -# Local targets -#---------------------------------------------------------------------------- - -#---------------------------------------------------------------------------- -# Dependencies -#---------------------------------------------------------------------------- - -# DO NOT DELETE THIS LINE -- g++dep uses it. -# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. - -.obj/IO_Test.o .obj/IO_Test.so .shobj/IO_Test.o .shobj/IO_Test.so: IO_Test.cpp \ - $(ACE_ROOT)/ace/OS.h \ - $(ACE_ROOT)/ace/inc_user_config.h \ - $(ACE_ROOT)/ace/config.h \ - $(ACE_ROOT)/ace/streams.h \ - $(ACE_ROOT)/ace/Basic_Types.h \ - $(ACE_ROOT)/ace/Basic_Types.i \ - $(ACE_ROOT)/ace/OS.i \ - $(ACE_ROOT)/ace/Trace.h \ - $(ACE_ROOT)/ace/Log_Msg.h \ - $(ACE_ROOT)/ace/Log_Record.h \ - $(ACE_ROOT)/ace/ACE.h \ - $(ACE_ROOT)/ace/ACE.i \ - $(ACE_ROOT)/ace/Log_Priority.h \ - $(ACE_ROOT)/ace/Log_Record.i \ - $(ACE_ROOT)/ace/Mem_Map.h \ - $(ACE_ROOT)/ace/Mem_Map.i IO_Test.h \ - $(ACE_ROOT)/ace/Profile_Timer.h \ - $(ACE_ROOT)/ace/Time_Value.h \ - $(ACE_ROOT)/ace/High_Res_Timer.h \ - $(ACE_ROOT)/ace/High_Res_Timer.i \ - $(ACE_ROOT)/ace/Profile_Timer.i - -# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/examples/Mem_Map/IO-tests/test_io.cpp b/examples/Mem_Map/IO-tests/test_io.cpp deleted file mode 100644 index c12a8a654d6..00000000000 --- a/examples/Mem_Map/IO-tests/test_io.cpp +++ /dev/null @@ -1,166 +0,0 @@ -// $Id$ - -// Test program for different methods of copying files. - -#include "ace/OS.h" -#include "ace/Profile_Timer.h" -#include "ace/Get_Opt.h" -#include "ace/Signal.h" -#include "IO_Test.h" - -// Name of program. -static const char *program_name; - -// Name of default input file. -static char *input_filename = "/usr/dict/words"; - -// Name of default output file. -static char *output_filename = "/tmp/foo"; - -// Check if removing output file upon completion... -static int remove_output = 1; - -// Count of the number of iterations to run the tests. -static int iteration_count = 100; - -// Profiler used to keep track of file I/O time. -static ACE_Profile_Timer profile_timer; - -// Explain usage and exit. - -static void -print_usage_and_die (void) -{ - ACE_OS::fprintf (stderr, "usage: %s" - " [-i input_file] [-o output_file] [-n iteration_count] [-r]\n", - program_name); - ACE_OS::exit (1); -} - -// Clean up the output file on exit from a signal. - -extern "C" void -cleanup (int = 0) -{ - if (remove_output) - ACE_OS::unlink (output_filename); - ACE_OS::exit (0); -} - -// Parse the command-line arguments and set options. - -static void -parse_args (int argc, char *argv[]) -{ - ACE_Get_Opt get_opt (argc, argv, "i:n:o:r"); - - for (int c; ((c = get_opt ()) != -1); ) - switch (c) - { - case 'i': - input_filename = get_opt.optarg; - break; - case 'n': - iteration_count = ACE_OS::atoi (get_opt.optarg); - break; - case 'o': - output_filename = get_opt.optarg; - break; - case 'r': - remove_output = 0; - break; - default: - print_usage_and_die (); - break; - } -} - -// Vector of pointers to derived classes that inherit from IO_Test -// base class. - -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); - i++; - 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); - i++; - 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); - i++; - ACE_NEW_RETURN (test_vector[i], Slow_Read_Write_Test ("Slow_Read_Write_Test", profile_timer), -1); - i++; - - test_vector[i] = (IO_Test *) 0; - - 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_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); - - 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", - et.real_time, - et.user_time, - et.system_time)); - - delete test_vector[i]; - } - - 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); - 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+"); - - if (input_fp == 0) - 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_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 (ACE_OS::fclose (input_fp) == -1 - || ACE_OS::fclose (output_fp) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%s\n", "fclose"), -1); - - cleanup (); - return 0; -} |