[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fseek/ftell tests on platforms with bad ungetc
From: |
Eric Blake |
Subject: |
fseek/ftell tests on platforms with bad ungetc |
Date: |
Wed, 25 Feb 2009 16:03:50 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Would someone with access to a system that has previously been failing the
ftell/fseek tests (older glibc, HPUX, and perhaps other old platforms) please
check this patch? The expected results is that test-fseek.sh now passes, and
test-fseek2.sh skips (likewise for fseeko, ftell, ftello).
You can also get it from:
git pull git://repo.or.cz/gnulib/ericb.git master
From: Eric Blake <address@hidden>
Date: Wed, 25 Feb 2009 07:42:31 -0700
Subject: [PATCH] tests: skip fseek/ftell tests if ungetc is broken
* m4/ungetc.m4: New file.
* modules/fseek-tests: Split test, so ungetc dependency is
separate from rest of test.
* modules/fseeko-tests: Likewise.
* modules/ftell-tests: Likewise.
* modules/ftello-tests: Likewise.
* tests/test-fseek.c (main): Isolate ungetc dependency.
* tests/test-fseeko.c (main): Likewise.
* tests/test-ftell.c (main): Likewise.
* tests/test-ftello.c (main): Likewise.
* tests/test-fseek2.sh: New file.
* tests/test-fseeko2.sh: Likewise.
* tests/test-ftell2.sh: Likewise.
* tests/test-ftello2.sh: Likewise.
---
ChangeLog | 20 +++++++++++++++++++-
m4/ungetc.m4 | 33 +++++++++++++++++++++++++++++++++
modules/fseek-tests | 5 ++++-
modules/fseeko-tests | 5 ++++-
modules/ftell-tests | 5 ++++-
modules/ftello-tests | 5 ++++-
tests/test-fseek.c | 19 ++++++++++++++++---
tests/test-fseek2.sh | 3 +++
tests/test-fseeko.c | 19 ++++++++++++++++---
tests/test-fseeko2.sh | 3 +++
tests/test-ftell.c | 31 +++++++++++++++++++++----------
tests/test-ftell2.sh | 3 +++
tests/test-ftello.c | 35 +++++++++++++++++++++++------------
tests/test-ftello2.sh | 3 +++
14 files changed, 156 insertions(+), 33 deletions(-)
create mode 100644 m4/ungetc.m4
create mode 100755 tests/test-fseek2.sh
create mode 100755 tests/test-fseeko2.sh
create mode 100755 tests/test-ftell2.sh
create mode 100755 tests/test-ftello2.sh
diff --git a/ChangeLog b/ChangeLog
index 3c3521a..bfb04fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2009-02-25 Eric Blake <address@hidden>
+
+ tests: skip fseek/ftell tests if ungetc is broken
+ * m4/ungetc.m4: New file.
+ * modules/fseek-tests: Split test, so ungetc dependency is
+ separate from rest of test.
+ * modules/fseeko-tests: Likewise.
+ * modules/ftell-tests: Likewise.
+ * modules/ftello-tests: Likewise.
+ * tests/test-fseek.c (main): Isolate ungetc dependency.
+ * tests/test-fseeko.c (main): Likewise.
+ * tests/test-ftell.c (main): Likewise.
+ * tests/test-ftello.c (main): Likewise.
+ * tests/test-fseek2.sh: New file.
+ * tests/test-fseeko2.sh: Likewise.
+ * tests/test-ftell2.sh: Likewise.
+ * tests/test-ftello2.sh: Likewise.
+
2009-02-25 Gary V. Vaughan <address@hidden>
strtod: avoid C99 decl-after-statement
diff --git a/m4/ungetc.m4 b/m4/ungetc.m4
new file mode 100644
index 0000000..67a8607
--- /dev/null
+++ b/m4/ungetc.m4
@@ -0,0 +1,33 @@
+# ungetc.m4 serial 1
+dnl Copyright (C) 2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN_ONCE([gl_FUNC_UNGETC_WORKS],
+[
+ AC_REQUIRE([AC_PROG_CC])
+
+ AC_CACHE_CHECK([whether ungetc works on arbitrary bytes],
+ [gl_cv_func_ungetc_works],
+ [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+#include <stdio.h>
+ ]], [FILE *f; long l;
+ if (!(f = fopen ("conftest.tmp", "w+"))) return 1;
+ if (fputs ("abc", f) < 0) return 2;
+ rewind (f);
+ if (fgetc (f) != 'a') return 3;
+ if (fgetc (f) != 'b') return 4;
+ if (ungetc ('d', f) != 'd') return 5;
+ if (fseek (f, 0, SEEK_CUR) != 0) return 6;
+ if (ftell (f) != 1) return 7;
+ if (fgetc (f) != 'b') return 8;
+ fclose (f); remove ("conftest.tmp");])],
+ [gl_cv_func_ungetc_works=yes], [gl_cv_func_ungetc_works=no],
+ [gl_cv_func_ungetc_works='guessing no'])
+ ])
+ if test "$gl_cv_func_ungetc_works" != yes; then
+ AC_DEFINE([FUNC_UNGETC_BROKEN], [1],
+ [Define to 1 if ungetc is broken when used on arbitrary bytes.])
+ fi
+])
diff --git a/modules/fseek-tests b/modules/fseek-tests
index a1c97fe..7f10d48 100644
--- a/modules/fseek-tests
+++ b/modules/fseek-tests
@@ -1,12 +1,15 @@
Files:
tests/test-fseek.c
tests/test-fseek.sh
+tests/test-fseek2.sh
+m4/ungetc.m4
Depends-on:
configure.ac:
+gl_FUNC_UNGETC_WORKS
Makefile.am:
-TESTS += test-fseek.sh
+TESTS += test-fseek.sh test-fseek2.sh
TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'
check_PROGRAMS += test-fseek
diff --git a/modules/fseeko-tests b/modules/fseeko-tests
index 8e077ec..b01ed58 100644
--- a/modules/fseeko-tests
+++ b/modules/fseeko-tests
@@ -1,12 +1,15 @@
Files:
tests/test-fseeko.c
tests/test-fseeko.sh
+tests/test-fseeko2.sh
+m4/ungetc.m4
Depends-on:
configure.ac:
+gl_FUNC_UNGETC_WORKS
Makefile.am:
-TESTS += test-fseeko.sh
+TESTS += test-fseeko.sh test-fseeko2.sh
TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'
check_PROGRAMS += test-fseeko
diff --git a/modules/ftell-tests b/modules/ftell-tests
index ad82ded..ce5f479 100644
--- a/modules/ftell-tests
+++ b/modules/ftell-tests
@@ -1,13 +1,16 @@
Files:
tests/test-ftell.c
tests/test-ftell.sh
+tests/test-ftell2.sh
+m4/ungetc.m4
Depends-on:
binary-io
configure.ac:
+gl_FUNC_UNGETC_WORKS
Makefile.am:
-TESTS += test-ftell.sh
+TESTS += test-ftell.sh test-ftell2.sh
TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'
check_PROGRAMS += test-ftell
diff --git a/modules/ftello-tests b/modules/ftello-tests
index 48179bc..cc7f46e 100644
--- a/modules/ftello-tests
+++ b/modules/ftello-tests
@@ -1,13 +1,16 @@
Files:
tests/test-ftello.c
tests/test-ftello.sh
+tests/test-ftello2.sh
+m4/ungetc.m4
Depends-on:
binary-io
configure.ac:
+gl_FUNC_UNGETC_WORKS
Makefile.am:
-TESTS += test-ftello.sh
+TESTS += test-ftello.sh test-ftello2.sh
TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'
check_PROGRAMS += test-ftello
diff --git a/tests/test-fseek.c b/tests/test-fseek.c
index 24cf3b8..6ba3788 100644
--- a/tests/test-fseek.c
+++ b/tests/test-fseek.c
@@ -1,5 +1,5 @@
/* Test of fseek() function.
- Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -33,6 +33,10 @@
} \
while (0)
+#ifndef FUNC_UNGETC_BROKEN
+# define FUNC_UNGETC_BROKEN 0
+#endif
+
int
main (int argc, char **argv)
{
@@ -47,10 +51,19 @@ main (int argc, char **argv)
ASSERT (ch == '#');
ASSERT (ungetc (ch, stdin) == ch);
ASSERT (fseek (stdin, 2, SEEK_SET) == 0);
- /* Test that fseek discards random ungetc data. */
ch = fgetc (stdin);
ASSERT (ch == '/');
- ASSERT (ungetc (ch ^ 0xff, stdin) == (ch ^ 0xff));
+ if (2 < argc)
+ {
+ if (FUNC_UNGETC_BROKEN)
+ {
+ fputs ("Skipping test: ungetc cannot handle arbitrary bytes\n",
+ stderr);
+ return 77;
+ }
+ /* Test that fseek discards random ungetc data. */
+ ASSERT (ungetc (ch ^ 0xff, stdin) == (ch ^ 0xff));
+ }
ASSERT (fseek (stdin, 0, SEEK_END) == 0);
ASSERT (fgetc (stdin) == EOF);
/* Test that fseek resets end-of-file marker. */
diff --git a/tests/test-fseek2.sh b/tests/test-fseek2.sh
new file mode 100755
index 0000000..a4c9cb7
--- /dev/null
+++ b/tests/test-fseek2.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec ./test-fseek${EXEEXT} 1 2 < "$srcdir/test-fseek2.sh"
diff --git a/tests/test-fseeko.c b/tests/test-fseeko.c
index 3a1383b..9c284da 100644
--- a/tests/test-fseeko.c
+++ b/tests/test-fseeko.c
@@ -1,5 +1,5 @@
/* Test of fseeko() function.
- Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -33,6 +33,10 @@
} \
while (0)
+#ifndef FUNC_UNGETC_BROKEN
+# define FUNC_UNGETC_BROKEN 0
+#endif
+
int
main (int argc, char **argv)
{
@@ -50,10 +54,19 @@ main (int argc, char **argv)
ASSERT (ch == '#');
ASSERT (ungetc (ch, stdin) == ch);
ASSERT (fseeko (stdin, 2, SEEK_SET) == 0);
- /* Test that fseek discards random ungetc data. */
ch = fgetc (stdin);
ASSERT (ch == '/');
- ASSERT (ungetc (ch ^ 0xff, stdin) == (ch ^ 0xff));
+ if (2 < argc)
+ {
+ if (FUNC_UNGETC_BROKEN)
+ {
+ fputs ("Skipping test: ungetc cannot handle arbitrary bytes\n",
+ stderr);
+ return 77;
+ }
+ /* Test that fseek discards random ungetc data. */
+ ASSERT (ungetc (ch ^ 0xff, stdin) == (ch ^ 0xff));
+ }
ASSERT (fseeko (stdin, 0, SEEK_END) == 0);
ASSERT (fgetc (stdin) == EOF);
/* Test that fseek resets end-of-file marker. */
diff --git a/tests/test-fseeko2.sh b/tests/test-fseeko2.sh
new file mode 100755
index 0000000..6e1130c
--- /dev/null
+++ b/tests/test-fseeko2.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec ./test-fseeko${EXEEXT} 1 2 < "$srcdir/test-fseeko2.sh"
diff --git a/tests/test-ftell.c b/tests/test-ftell.c
index 092be19..845d944 100644
--- a/tests/test-ftell.c
+++ b/tests/test-ftell.c
@@ -1,5 +1,5 @@
/* Test of ftell() function.
- Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -35,6 +35,10 @@
} \
while (0)
+#ifndef FUNC_UNGETC_BROKEN
+# define FUNC_UNGETC_BROKEN 0
+#endif
+
int
main (int argc, char **argv)
{
@@ -80,15 +84,22 @@ main (int argc, char **argv)
ASSERT (ch == '@');
ASSERT (ftell (stdin) == 3);
-#if !defined __hpux /* HP-UX 11 has a known bug here */
- /* Test ftell after ungetc without read. */
- ASSERT (fseek (stdin, 0, SEEK_CUR) == 0);
- ASSERT (ftell (stdin) == 3);
-#endif
-
- ch = ungetc ('~', stdin);
- ASSERT (ch == '~');
- ASSERT (ftell (stdin) == 2);
+ if (2 < argc)
+ {
+ if (FUNC_UNGETC_BROKEN)
+ {
+ fputs ("Skipping test: ungetc cannot handle arbitrary bytes\n",
+ stderr);
+ return 77;
+ }
+ /* Test ftell after ungetc without read. */
+ ASSERT (fseek (stdin, 0, SEEK_CUR) == 0);
+ ASSERT (ftell (stdin) == 3);
+
+ ch = ungetc ('~', stdin);
+ ASSERT (ch == '~');
+ ASSERT (ftell (stdin) == 2);
+ }
/* Test ftell beyond end of file. */
ASSERT (fseek (stdin, 0, SEEK_END) == 0);
diff --git a/tests/test-ftell2.sh b/tests/test-ftell2.sh
new file mode 100755
index 0000000..3b645b8
--- /dev/null
+++ b/tests/test-ftell2.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec ./test-ftell${EXEEXT} 1 2 < "$srcdir/test-ftell2.sh"
diff --git a/tests/test-ftello.c b/tests/test-ftello.c
index 87f4966..621ceda 100644
--- a/tests/test-ftello.c
+++ b/tests/test-ftello.c
@@ -1,5 +1,5 @@
/* Test of ftello() function.
- Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -35,6 +35,10 @@
} \
while (0)
+#ifndef FUNC_UNGETC_BROKEN
+# define FUNC_UNGETC_BROKEN 0
+#endif
+
int
main (int argc, char **argv)
{
@@ -88,17 +92,24 @@ main (int argc, char **argv)
ASSERT (ftell (stdin) == 3);
ASSERT (ftello (stdin) == 3);
-#if !defined __hpux /* HP-UX 11 has a known bug here */
- /* Test ftell after ungetc without read. */
- ASSERT (fseek (stdin, 0, SEEK_CUR) == 0);
- ASSERT (ftell (stdin) == 3);
- ASSERT (ftello (stdin) == 3);
-#endif
-
- ch = ungetc ('~', stdin);
- ASSERT (ch == '~');
- ASSERT (ftell (stdin) == 2);
- ASSERT (ftello (stdin) == 2);
+ if (2 < argc)
+ {
+ if (FUNC_UNGETC_BROKEN)
+ {
+ fputs ("Skipping test: ungetc cannot handle arbitrary bytes\n",
+ stderr);
+ return 77;
+ }
+ /* Test ftell after ungetc without read. */
+ ASSERT (fseek (stdin, 0, SEEK_CUR) == 0);
+ ASSERT (ftell (stdin) == 3);
+ ASSERT (ftello (stdin) == 3);
+
+ ch = ungetc ('~', stdin);
+ ASSERT (ch == '~');
+ ASSERT (ftell (stdin) == 2);
+ ASSERT (ftello (stdin) == 2);
+ }
/* Test ftell beyond end of file. */
ASSERT (fseek (stdin, 0, SEEK_END) == 0);
diff --git a/tests/test-ftello2.sh b/tests/test-ftello2.sh
new file mode 100755
index 0000000..ba750b0
--- /dev/null
+++ b/tests/test-ftello2.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec ./test-ftello${EXEEXT} 1 2 < "$srcdir/test-ftello2.sh"
--
1.6.1.2