bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Implementation of fsync for Windows


From: Jim Meyering
Subject: Re: [PATCH] Implementation of fsync for Windows
Date: Wed, 01 Oct 2008 18:06:31 +0200

"Richard W.M. Jones" <address@hidden> wrote:
> This patch implements fsync for Windows.
>
> I tested it using MinGW cross-compiler from a Fedora host, and wine
> instead of Windows:
>
>   ./gnulib-tool --create-testdir --dir=/tmp/testdir fsync
>
>   [Verify it configures & builds normally on Linux, then ...]
>
>   [Create a test program, test.c (attached).  Edit Makefile.am to
>   compile the test program and link against libgnu.]
>
>   autoreconf
>   ./configure --host=i686-pc-mingw32
>   make
>   WINEDEBUG=+relay wine ./test.exe
>
>   [Grep through the debugging output for calls to FlushFileBuffers]
>
> I would like to add a test, but I couldn't work out how programs in
> the tests/ subdirectory get run and what their environment is, which
> is fairly crucial for this sort of system call.

Hi Rich,

To make gnulib-tool's --with-tests option work, you can add
this to your change set:

>From ac7caea063e546b0c99cf7a11947837ea7490b90 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 1 Oct 2008 17:52:17 +0200
Subject: [PATCH] add fsync tests

---
 modules/fsync-tests |   10 ++++++++++
 tests/test-fsync.c  |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 0 deletions(-)
 create mode 100644 modules/fsync-tests
 create mode 100644 tests/test-fsync.c

diff --git a/modules/fsync-tests b/modules/fsync-tests
new file mode 100644
index 0000000..c407dc2
--- /dev/null
+++ b/modules/fsync-tests
@@ -0,0 +1,10 @@
+Files:
+tests/test-fsync.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-fsync
+check_PROGRAMS += test-fsync
diff --git a/tests/test-fsync.c b/tests/test-fsync.c
new file mode 100644
index 0000000..d0479d2
--- /dev/null
+++ b/tests/test-fsync.c
@@ -0,0 +1,34 @@
+/* Test fsync. */
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#define ASSERT(expr) \
+  do                                                                         \
+    {                                                                        \
+      if (!(expr))                                                           \
+        {                                                                    \
+          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+          fflush (stderr);                                                   \
+          abort ();                                                          \
+        }                                                                    \
+    }                                                                        \
+  while (0)
+
+int
+main ()
+{
+  int fd;
+  const char *file = "test-fsync.txt";
+
+  ASSERT (fsync (0) != 0);
+  fd = open (file, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+  ASSERT (0 <= fd);
+  ASSERT (write (fd, "hello", 5) == 5);
+  ASSERT (fsync (fd) == 0);
+  ASSERT (close (fd) == 0);
+  ASSERT (unlink (file) == 0);
+
+  return 0;
+}
--
1.6.0.2.307.gc427




reply via email to

[Prev in Thread] Current Thread [Next in Thread]