Mercurial > hg > octave-shane > gnulib-hg
annotate tests/test-fsync.c @ 17632:86af85d364e1 default tip
unistd: port readlink to Mac OS X 10.3.9
* lib/unistd.in.h (_GL_INCLUDING_UNISTD_H): New macro, to work
around self-include problem in Mac OS X 10.3.9 when combined with
readlink module. Problem reported by Klaus Zietler in
<http://bugs.gnu.org/16825>.
author | Paul Eggert <eggert@penguin.cs.ucla.edu> |
---|---|
date | Tue, 25 Feb 2014 11:16:27 -0800 |
parents | 344018b6e5d7 |
children |
rev | line source |
---|---|
10565 | 1 /* Test of fsync() function. |
17587 | 2 Copyright (C) 2008-2014 Free Software Foundation, Inc. |
10565 | 3 |
4 This program is free software: you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
12520
e84eea643139
tests: fix license on several tests
Eric Blake <ebb9@byu.net>
parents:
12496
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
10565 | 7 (at your option) any later version. |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
16 | |
17 #include <config.h> | |
10814
ce4af5bb9f57
Avoid test failure on Haiku.
Bruno Haible <bruno@clisp.org>
parents:
10565
diff
changeset
|
18 |
12487
8ba9831d54bf
Include header file being tested immediately after config.h.
Bruno Haible <bruno@clisp.org>
parents:
12197
diff
changeset
|
19 #include <unistd.h> |
8ba9831d54bf
Include header file being tested immediately after config.h.
Bruno Haible <bruno@clisp.org>
parents:
12197
diff
changeset
|
20 |
12489 | 21 #include "signature.h" |
22 SIGNATURE_CHECK (fsync, int, (int)); | |
23 | |
10814
ce4af5bb9f57
Avoid test failure on Haiku.
Bruno Haible <bruno@clisp.org>
parents:
10565
diff
changeset
|
24 #include <errno.h> |
10565 | 25 #include <fcntl.h> |
26 | |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12489
diff
changeset
|
27 #include "macros.h" |
10565 | 28 |
29 int | |
12197
e45d9bb2233e
tests: avoid several compiler warnings
Eric Blake <ebb9@byu.net>
parents:
10814
diff
changeset
|
30 main (void) |
10565 | 31 { |
32 int fd; | |
33 const char *file = "test-fsync.txt"; | |
34 | |
15632
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
35 /* Assuming stdin and stdout are ttys, fsync is allowed to fail, but |
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
36 may succeed as an extension. */ |
15631
76e03c88266c
Enhance fsync, fdatasync tests.
Bruno Haible <bruno@clisp.org>
parents:
15621
diff
changeset
|
37 for (fd = 0; fd < 2; fd++) |
76e03c88266c
Enhance fsync, fdatasync tests.
Bruno Haible <bruno@clisp.org>
parents:
15621
diff
changeset
|
38 if (fsync (fd) != 0) |
76e03c88266c
Enhance fsync, fdatasync tests.
Bruno Haible <bruno@clisp.org>
parents:
15621
diff
changeset
|
39 { |
76e03c88266c
Enhance fsync, fdatasync tests.
Bruno Haible <bruno@clisp.org>
parents:
15621
diff
changeset
|
40 ASSERT (errno == EINVAL /* POSIX */ |
16935
498a2211d839
Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
41 || errno == ENOTSUP /* seen on Mac OS X 10.5 */ |
15631
76e03c88266c
Enhance fsync, fdatasync tests.
Bruno Haible <bruno@clisp.org>
parents:
15621
diff
changeset
|
42 || errno == EBADF /* seen on AIX 7.1 */ |
15729
d4ef28dc56e2
fsync tests: Avoid a test failure on mingw.
Bruno Haible <bruno@clisp.org>
parents:
15689
diff
changeset
|
43 || errno == EIO /* seen on mingw */ |
15631
76e03c88266c
Enhance fsync, fdatasync tests.
Bruno Haible <bruno@clisp.org>
parents:
15621
diff
changeset
|
44 ); |
76e03c88266c
Enhance fsync, fdatasync tests.
Bruno Haible <bruno@clisp.org>
parents:
15621
diff
changeset
|
45 } |
76e03c88266c
Enhance fsync, fdatasync tests.
Bruno Haible <bruno@clisp.org>
parents:
15621
diff
changeset
|
46 |
15632
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
47 /* fsync must fail on invalid fd. */ |
15689 | 48 { |
49 errno = 0; | |
50 ASSERT (fsync (-1) == -1); | |
51 ASSERT (errno == EBADF); | |
52 } | |
53 { | |
17295
3a09cc104f4c
tests: don't assume fd 99 is closed
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
54 close (99); |
15689 | 55 errno = 0; |
56 ASSERT (fsync (99) == -1); | |
57 ASSERT (errno == EBADF); | |
58 } | |
15631
76e03c88266c
Enhance fsync, fdatasync tests.
Bruno Haible <bruno@clisp.org>
parents:
15621
diff
changeset
|
59 |
10565 | 60 fd = open (file, O_WRONLY|O_CREAT|O_TRUNC, 0644); |
61 ASSERT (0 <= fd); | |
62 ASSERT (write (fd, "hello", 5) == 5); | |
63 ASSERT (fsync (fd) == 0); | |
64 ASSERT (close (fd) == 0); | |
15632
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
65 |
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
66 /* For a read-only regular file input file descriptor, fsync should |
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
67 succeed (since at least atime changes can be synchronized). */ |
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
68 fd = open (file, O_RDONLY); |
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
69 ASSERT (0 <= fd); |
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
70 { |
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
71 char buf[1]; |
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
72 ASSERT (read (fd, buf, sizeof buf) == sizeof buf); |
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
73 } |
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
74 ASSERT (fsync (fd) == 0); |
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
75 ASSERT (close (fd) == 0); |
c96b3b10e579
test-fsync: yet another enhancement
Eric Blake <eblake@redhat.com>
parents:
15631
diff
changeset
|
76 |
10565 | 77 ASSERT (unlink (file) == 0); |
78 | |
79 return 0; | |
80 } |