1 // Test program for different methods of copying files.
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/OS_NS_unistd.h"
6 #include "ace/Profile_Timer.h"
7 #include "ace/Get_Opt.h"
8 #include "ace/Signal.h"
9 #include "ace/Log_Msg.h"
12 #if !defined(ACE_WIN32)
15 static const ACE_TCHAR
*program_name
;
17 // Name of default input file.
18 static const ACE_TCHAR
*input_filename
= ACE_TEXT ("/usr/dict/words");
20 // Name of default output file.
21 static const ACE_TCHAR
*output_filename
= ACE_TEXT ("/tmp/foo");
23 // Check if removing output file upon completion...
24 static int remove_output
= 1;
26 // Count of the number of iterations to run the tests.
27 static int iteration_count
= 100;
29 // Profiler used to keep track of file I/O time.
30 static ACE_Profile_Timer profile_timer
;
32 // Explain usage and exit.
35 print_usage_and_die ()
37 ACE_OS::fprintf (stderr
, "usage: %s"
38 " [-i input_file] [-o output_file] [-n iteration_count] [-r]\n",
39 ACE_TEXT_ALWAYS_CHAR (program_name
));
43 // Clean up the output file on exit from a signal.
49 ACE_OS::unlink (output_filename
);
53 // Parse the command-line arguments and set options.
56 parse_args (int argc
, ACE_TCHAR
*argv
[])
58 ACE_Get_Opt
get_opt (argc
, argv
, ACE_TEXT ("i:n:o:r"));
60 for (int c
; ((c
= get_opt ()) != -1); )
64 input_filename
= get_opt
.opt_arg ();
67 iteration_count
= ACE_OS::atoi (get_opt
.opt_arg ());
70 output_filename
= get_opt
.opt_arg ();
76 print_usage_and_die ();
81 // Vector of pointers to derived classes that inherit from IO_Test
84 static IO_Test
*test_vector
[100];
87 run_tests (int iterations
, FILE *input_fp
, FILE *output_fp
)
91 ACE_NEW_RETURN (test_vector
[i
],
92 Stdio_Test ("Stdio_Test",
96 ACE_NEW_RETURN (test_vector
[i
],
97 Block_Fread_Fwrite_Test ("Block_Fread_Fwrite_Test",
101 ACE_NEW_RETURN (test_vector
[i
],
102 Block_Read_Write_Test ("Block_Read_Write_Test",
106 ACE_NEW_RETURN (test_vector
[i
],
107 Mmap1_Test ("Mmap1_Test",
111 ACE_NEW_RETURN (test_vector
[i
],
112 Mmap2_Test ("Mmap2_Test",
116 ACE_NEW_RETURN (test_vector
[i
],
117 Slow_Read_Write_Test ("Slow_Read_Write_Test",
122 test_vector
[i
] = (IO_Test
*) 0;
124 for (i
= 0; test_vector
[i
] != 0; i
++)
126 ACE_HANDLE hfile
= fileno (output_fp
);
127 if (ACE_OS::ftruncate (hfile
, 0) == -1)
128 ACE_ERROR_RETURN ((LM_ERROR
,
130 ACE_TEXT ("ftruncate")),
133 ACE_DEBUG ((LM_DEBUG
,
134 ACE_TEXT ("--------------------\n")
135 ACE_TEXT ("starting %C for %d iterations(s):\n"),
136 test_vector
[i
]->name (),
139 test_vector
[i
]->run_test (iterations
,
143 ACE_Profile_Timer::ACE_Elapsed_Time et
;
144 profile_timer
.elapsed_time (et
);
146 ACE_DEBUG ((LM_DEBUG
,
147 ACE_TEXT ("wallclock time = %f, user time = %f, system time = %f\n"),
152 delete test_vector
[i
];
155 ACE_DEBUG ((LM_DEBUG
,
156 ACE_TEXT ("--------------------\n")));
161 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
163 program_name
= ACE::basename (argv
[0],
164 ACE_DIRECTORY_SEPARATOR_CHAR
);
165 parse_args (argc
, argv
);
167 ACE_Sig_Action
sa ((ACE_SignalHandler
) cleanup
, SIGINT
);
171 ACE_OS::fopen (input_filename
, ACE_TEXT ("r"));
173 ACE_OS::fopen (output_filename
, ACE_TEXT ("w+"));
176 ACE_ERROR_RETURN ((LM_ERROR
,
182 ACE_ERROR_RETURN ((LM_ERROR
,
187 ACE_OS::unlink (output_filename
);
189 if (run_tests (iteration_count
,
192 ACE_ERROR_RETURN ((LM_ERROR
, ACE_TEXT ("%p\n"), ACE_TEXT ("run_tests")),
195 if (ACE_OS::fclose (input_fp
) == -1
196 || ACE_OS::fclose (output_fp
) == -1)
197 ACE_ERROR_RETURN ((LM_ERROR
, ACE_TEXT ("%p\n"), ACE_TEXT ("fclose")),
203 int ACE_TMAIN (int, ACE_TCHAR
*[]) {
204 // not supported on win32