11/*
2- * $PostgreSQL: pgsql/src/tools/fsync/test_fsync.c,v 1.24 2009/08/10 18:19:06 momjian Exp $
2+ * $PostgreSQL: pgsql/src/tools/fsync/test_fsync.c,v 1.25 2009/09/21 20:20:56 momjian Exp $
33 *
44 *
55 *test_fsync.c
@@ -149,8 +149,12 @@ main(int argc, char *argv[])
149149die ("Cannot open output file." );
150150gettimeofday (& start_t ,NULL );
151151for (i = 0 ;i < loops ;i ++ )
152+ {
152153if (write (tmpfile ,buf ,WRITE_SIZE )!= WRITE_SIZE )
153154die ("write failed" );
155+ if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
156+ die ("seek failed" );
157+ }
154158gettimeofday (& elapse_t ,NULL );
155159close (tmpfile );
156160printf ("\tone 16k o_sync write " );
@@ -167,6 +171,8 @@ main(int argc, char *argv[])
167171die ("write failed" );
168172if (write (tmpfile ,buf ,WRITE_SIZE /2 )!= WRITE_SIZE /2 )
169173die ("write failed" );
174+ if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
175+ die ("seek failed" );
170176}
171177gettimeofday (& elapse_t ,NULL );
172178close (tmpfile );
@@ -188,8 +194,12 @@ main(int argc, char *argv[])
188194die ("Cannot open output file." );
189195gettimeofday (& start_t ,NULL );
190196for (i = 0 ;i < loops ;i ++ )
197+ {
191198if (write (tmpfile ,buf ,WRITE_SIZE /2 )!= WRITE_SIZE /2 )
192199die ("write failed" );
200+ if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
201+ die ("seek failed" );
202+ }
193203gettimeofday (& elapse_t ,NULL );
194204close (tmpfile );
195205printf ("\topen o_dsync, write " );
@@ -205,8 +215,12 @@ main(int argc, char *argv[])
205215die ("Cannot open output file." );
206216gettimeofday (& start_t ,NULL );
207217for (i = 0 ;i < loops ;i ++ )
218+ {
208219if (write (tmpfile ,buf ,WRITE_SIZE /2 )!= WRITE_SIZE /2 )
209220die ("write failed" );
221+ if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
222+ die ("seek failed" );
223+ }
210224gettimeofday (& elapse_t ,NULL );
211225close (tmpfile );
212226printf ("\topen o_sync, write " );
@@ -226,6 +240,8 @@ main(int argc, char *argv[])
226240if (write (tmpfile ,buf ,WRITE_SIZE /2 )!= WRITE_SIZE /2 )
227241die ("write failed" );
228242fdatasync (tmpfile );
243+ if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
244+ die ("seek failed" );
229245}
230246gettimeofday (& elapse_t ,NULL );
231247close (tmpfile );
@@ -246,6 +262,8 @@ main(int argc, char *argv[])
246262die ("write failed" );
247263if (fsync (tmpfile )!= 0 )
248264die ("fsync failed" );
265+ if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
266+ die ("seek failed" );
249267}
250268gettimeofday (& elapse_t ,NULL );
251269close (tmpfile );
@@ -269,6 +287,8 @@ main(int argc, char *argv[])
269287die ("write failed" );
270288if (write (tmpfile ,buf ,WRITE_SIZE /2 )!= WRITE_SIZE /2 )
271289die ("write failed" );
290+ if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
291+ die ("seek failed" );
272292}
273293gettimeofday (& elapse_t ,NULL );
274294close (tmpfile );
@@ -290,6 +310,8 @@ main(int argc, char *argv[])
290310die ("write failed" );
291311if (write (tmpfile ,buf ,WRITE_SIZE /2 )!= WRITE_SIZE /2 )
292312die ("write failed" );
313+ if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
314+ die ("seek failed" );
293315}
294316gettimeofday (& elapse_t ,NULL );
295317close (tmpfile );
@@ -310,6 +332,8 @@ main(int argc, char *argv[])
310332if (write (tmpfile ,buf ,WRITE_SIZE /2 )!= WRITE_SIZE /2 )
311333die ("write failed" );
312334fdatasync (tmpfile );
335+ if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
336+ die ("seek failed" );
313337}
314338gettimeofday (& elapse_t ,NULL );
315339close (tmpfile );
@@ -332,6 +356,8 @@ main(int argc, char *argv[])
332356die ("write failed" );
333357if (fsync (tmpfile )!= 0 )
334358die ("fsync failed" );
359+ if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
360+ die ("seek failed" );
335361}
336362gettimeofday (& elapse_t ,NULL );
337363close (tmpfile );