1 #include "ace/OS_NS_string.h"
2 #include "ace/OS_NS_unistd.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/Mem_Map.h"
5 #include "ace/Log_Msg.h"
8 #if !defined(ACE_WIN32)
11 IO_Test::IO_Test (const char *name
,
12 ACE_Profile_Timer
&tm
)
13 : name_ (name
), tm_ (tm
)
27 Slow_Read_Write_Test::Slow_Read_Write_Test (const char *name
,
28 ACE_Profile_Timer
&tm
)
34 Slow_Read_Write_Test::run_test (int iterations
,
38 ACE_HANDLE ifd
= ACE_OS::fileno (input_fp
);
39 ACE_HANDLE ofd
= ACE_OS::fileno (output_fp
);
43 while (--iterations
>= 0)
47 while (ACE_OS::read (ifd
, &c
, sizeof c
) > 0)
48 ACE_OS::write (ofd
, &c
, sizeof c
);
50 ACE_OS::lseek (ifd
, 0, SEEK_SET
);
51 ACE_OS::lseek (ofd
, 0, SEEK_SET
);
58 Stdio_Test::Stdio_Test (const char *name
,
59 ACE_Profile_Timer
&tm
)
65 Stdio_Test::run_test (int iterations
,
71 while (--iterations
>= 0)
75 while ((c
= ACE_OS::getc (input_fp
)) != EOF
)
76 ACE_OS::putc (c
, output_fp
);
78 ACE_OS::rewind (input_fp
);
79 ACE_OS::rewind (output_fp
);
85 Block_Read_Write_Test::Block_Read_Write_Test (const char *name
,
86 ACE_Profile_Timer
&tm
)
92 Block_Read_Write_Test::run_test (int iterations
,
96 ACE_HANDLE ifd
= ACE_OS::fileno (input_fp
);
97 ACE_HANDLE ofd
= ACE_OS::fileno (output_fp
);
101 while (--iterations
>= 0)
106 while ((n
= ACE_OS::read (ifd
,
109 ACE_OS::write (ofd
, buf
, n
);
111 ACE_OS::lseek (ifd
, 0, SEEK_SET
);
112 ACE_OS::lseek (ofd
, 0, SEEK_SET
);
119 Block_Fread_Fwrite_Test::Block_Fread_Fwrite_Test (const char *name
,
120 ACE_Profile_Timer
&tm
)
126 Block_Fread_Fwrite_Test::run_test (int iterations
,
132 while (--iterations
>= 0)
137 while ((n
= ACE_OS::fread (buf
,
141 ACE_OS::fwrite (buf
, n
, 1, output_fp
);
143 ACE_OS::rewind (input_fp
);
144 ACE_OS::rewind (output_fp
);
151 Mmap1_Test::Mmap1_Test (const char *name
,
152 ACE_Profile_Timer
&tm
)
158 Mmap1_Test::run_test (int iterations
,
162 ACE_Mem_Map
map_input (ACE_OS::fileno (input_fp
));
163 void *src
= map_input
.addr ();
165 if (src
== MAP_FAILED
)
166 ACE_ERROR_RETURN ((LM_ERROR
, ACE_TEXT ("%C"), this->name ()), -1);
171 while (--iterations
>= 0)
173 if (ACE_OS::write (ACE_OS::fileno (output_fp
),
175 map_input
.size ()) == -1)
176 ACE_ERROR_RETURN ((LM_ERROR
,
180 ACE_OS::lseek (ACE_OS::fileno (output_fp
),
188 if (map_input
.unmap () == -1)
189 ACE_ERROR_RETURN ((LM_ERROR
,
197 Mmap2_Test::Mmap2_Test (const char *name
,
198 ACE_Profile_Timer
&tm
)
204 Mmap2_Test::run_test (int iterations
,
208 ACE_Mem_Map
map_input (ACE_OS::fileno (input_fp
));
209 int size
= map_input
.size ();
210 ACE_Mem_Map
map_output (ACE_OS::fileno (output_fp
),
214 void *src
= map_input
.addr ();
215 void *dst
= map_output
.addr ();
217 if (src
== MAP_FAILED
|| dst
== MAP_FAILED
)
223 while (--iterations
>= 0)
224 ACE_OS::memcpy (dst
, src
, size
);
229 if (map_input
.unmap () == -1
230 || map_output
.unmap () == -1)