From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Subject: Fix some test failures on Android ≥ 11
Date: Tue, 10 Jan 2023 17:37:34 +0100 [thread overview]
Message-ID: <4980298.ezd0NqBDhE@nimes> (raw)
On Android 11, I'm seeing these test failures from a testdir:
FAIL: test-fclose
=================
fdsan: attempted to close file descriptor 3, expected to be unowned, actually owned by FILE* 0xa70c2ecc
Aborted
FAIL test-fclose (exit status: 134)
FAIL: test-fdopen
=================
fdsan: failed to exchange ownership of file descriptor: fd 1 is owned by FILE* 0xb4841a0c, was expected to be unowned
Aborted
FAIL test-fdopen (exit status: 134)
FAIL: test-fflush
=================
fdsan: attempted to close file descriptor 3, expected to be unowned, actually owned by FILE* 0xab8014dc
Aborted
FAIL test-fflush (exit status: 134)
FAIL: test-fgetc
================
fdsan: attempted to close file descriptor 3, expected to be unowned, actually owned by FILE* 0xab20531c
Aborted
FAIL test-fgetc (exit status: 134)
FAIL: test-fputc
================
fdsan: attempted to close file descriptor 3, expected to be unowned, actually owned by FILE* 0xabe0299c
Aborted
FAIL test-fputc (exit status: 134)
FAIL: test-fread
================
fdsan: attempted to close file descriptor 3, expected to be unowned, actually owned by FILE* 0xb2c8001c
Aborted
FAIL test-fread (exit status: 134)
FAIL: test-fseeko4.sh
=====================
fdsan: attempted to close file descriptor 3, expected to be unowned, actually owned by FILE* 0xb31c5d7c
Aborted
FAIL test-fseeko4.sh (exit status: 1)
FAIL: test-ftello4.sh
=====================
fdsan: attempted to close file descriptor 3, expected to be unowned, actually owned by FILE* 0xb4fc246c
Aborted
FAIL test-ftello4.sh (exit status: 1)
FAIL: test-fwrite
=================
fdsan: attempted to close file descriptor 3, expected to be unowned, actually owned by FILE* 0xa6d067dc
Aborted
FAIL test-fwrite (exit status: 134)
These test failures are all triggered by the file-descriptor sanitizer
<https://android.googlesource.com/platform/bionic/+/master/docs/fdsan.md>
<https://developer.android.com/about/versions/11/behavior-changes-all>
This patch avoids the failures.
2023-01-10 Bruno Haible <bruno@clisp.org>
Fix some test failures on Android ≥ 11.
* tests/test-fclose.c (main): On Android, avoid triggering the
file-descriptor sanitizer (fdsan).
* tests/test-fdopen.c (main): Likewise.
* tests/test-fflush.c (main): Likewise.
* tests/test-fgetc.c (main): Likewise.
* tests/test-fputc.c (main): Likewise.
* tests/test-fread.c (main): Likewise.
* tests/test-fseeko4.c (main): Likewise.
* tests/test-ftello4.c (main): Likewise.
* tests/test-fwrite.c (main): Likewise.
diff --git a/tests/test-fclose.c b/tests/test-fclose.c
index 5eda8fa672..5df500634e 100644
--- a/tests/test-fclose.c
+++ b/tests/test-fclose.c
@@ -75,6 +75,7 @@ main (int argc, char **argv)
/* Test that fclose() sets errno if someone else closes the stream
fd behind the back of stdio. */
+ #if !defined __ANDROID__ /* fdsan */
{
FILE *fp = fdopen (fd, "w+");
ASSERT (fp != NULL);
@@ -83,6 +84,7 @@ main (int argc, char **argv)
ASSERT (fclose (fp) == EOF);
ASSERT (errno == EBADF);
}
+ #endif
/* Test that fclose() sets errno if the stream was constructed with
an invalid file descriptor. */
diff --git a/tests/test-fdopen.c b/tests/test-fdopen.c
index 113bde0c83..cf28f8e7e5 100644
--- a/tests/test-fdopen.c
+++ b/tests/test-fdopen.c
@@ -33,9 +33,14 @@ main (void)
failure, since the behavior is not well-defined on invalid file
descriptors, so try fdopen 1000 times and if that's not enough to
fail due to EMFILE, so be it. */
+ #if defined __ANDROID__ /* fdsan */
+ #define COUNT 1
+ #else
+ #define COUNT 1000
+ #endif
int i;
- for (i = 0; i < 1000; i++)
+ for (i = 0; i < COUNT; i++)
{
errno = 0;
if (! fdopen (STDOUT_FILENO, "w"))
diff --git a/tests/test-fflush.c b/tests/test-fflush.c
index c996b18c25..f43d9788eb 100644
--- a/tests/test-fflush.c
+++ b/tests/test-fflush.c
@@ -148,6 +148,7 @@ main (void)
/* Test that fflush() sets errno if someone else closes the stream
fd behind the back of stdio. */
+ #if !defined __ANDROID__ /* fdsan */
{
FILE *fp = fopen ("test-fflush.txt", "w");
ASSERT (fp != NULL);
@@ -158,6 +159,7 @@ main (void)
ASSERT (errno == EBADF);
fclose (fp);
}
+ #endif
/* Test that fflush() sets errno if the stream was constructed with
an invalid file descriptor. */
diff --git a/tests/test-fgetc.c b/tests/test-fgetc.c
index 59ab4098d4..c8c65f58aa 100644
--- a/tests/test-fgetc.c
+++ b/tests/test-fgetc.c
@@ -54,6 +54,7 @@ main (int argc, char **argv)
/* Test that fgetc() sets errno if someone else closes the stream
fd behind the back of stdio. */
+ #if !defined __ANDROID__ /* fdsan */
{
FILE *fp = fopen (filename, "r");
ASSERT (fp != NULL);
@@ -64,6 +65,7 @@ main (int argc, char **argv)
ASSERT (ferror (fp));
fclose (fp);
}
+ #endif
/* Test that fgetc() sets errno if the stream was constructed with
an invalid file descriptor. */
diff --git a/tests/test-fputc.c b/tests/test-fputc.c
index 2f0f1a33a9..3a9e7c38ac 100644
--- a/tests/test-fputc.c
+++ b/tests/test-fputc.c
@@ -45,6 +45,7 @@ main (int argc, char **argv)
/* Test that fputc() on an unbuffered stream sets errno if someone else
closes the stream fd behind the back of stdio. */
+ #if !defined __ANDROID__ /* fdsan */
{
FILE *fp = fopen (filename, "w");
ASSERT (fp != NULL);
@@ -56,6 +57,7 @@ main (int argc, char **argv)
ASSERT (ferror (fp));
fclose (fp);
}
+ #endif
/* Test that fputc() on an unbuffered stream sets errno if the stream
was constructed with an invalid file descriptor. */
diff --git a/tests/test-fread.c b/tests/test-fread.c
index 54e9d631ae..d6d16ec3d9 100644
--- a/tests/test-fread.c
+++ b/tests/test-fread.c
@@ -54,6 +54,7 @@ main (int argc, char **argv)
/* Test that fread() sets errno if someone else closes the stream
fd behind the back of stdio. */
+ #if !defined __ANDROID__ /* fdsan */
{
FILE *fp = fopen (filename, "r");
char buf[5];
@@ -65,6 +66,7 @@ main (int argc, char **argv)
ASSERT (ferror (fp));
fclose (fp);
}
+ #endif
/* Test that fread() sets errno if the stream was constructed with
an invalid file descriptor. */
diff --git a/tests/test-fseeko4.c b/tests/test-fseeko4.c
index f509702b3e..ad90a2c990 100644
--- a/tests/test-fseeko4.c
+++ b/tests/test-fseeko4.c
@@ -33,6 +33,7 @@ main (int argc, char **argv)
{
FILE *fp = fopen (filename, "r");
ASSERT (fp != NULL);
+ #if !defined __ANDROID__ /* fdsan */
setvbuf (fp, NULL, _IONBF, 0);
ASSERT (ftell (fp) == 0);
ASSERT (fseeko (fp, 0, SEEK_END) == 0);
@@ -41,6 +42,7 @@ main (int argc, char **argv)
errno = 0;
ASSERT (fseeko (fp, 0, SEEK_SET) == -1);
ASSERT (errno == EBADF);
+ #endif
fclose (fp);
}
diff --git a/tests/test-ftello4.c b/tests/test-ftello4.c
index b1ff8268f6..590c17b678 100644
--- a/tests/test-ftello4.c
+++ b/tests/test-ftello4.c
@@ -33,11 +33,13 @@ main (int argc, char **argv)
{
FILE *fp = fopen (filename, "r");
ASSERT (fp != NULL);
+ #if !defined __ANDROID__ /* fdsan */
setvbuf (fp, NULL, _IONBF, 0);
ASSERT (close (fileno (fp)) == 0);
errno = 0;
ASSERT (ftello (fp) == (off_t)-1);
ASSERT (errno == EBADF);
+ #endif
fclose (fp);
}
diff --git a/tests/test-fwrite.c b/tests/test-fwrite.c
index 07f8b73e03..503e849b47 100644
--- a/tests/test-fwrite.c
+++ b/tests/test-fwrite.c
@@ -45,6 +45,7 @@ main (int argc, char **argv)
/* Test that fwrite() on an unbuffered stream sets errno if someone else
closes the stream fd behind the back of stdio. */
+ #if !defined __ANDROID__ /* fdsan */
{
FILE *fp = fopen (filename, "w");
char buf[5] = "world";
@@ -57,6 +58,7 @@ main (int argc, char **argv)
ASSERT (ferror (fp));
fclose (fp);
}
+ #endif
/* Test that fwrite() on an unbuffered stream sets errno if the stream
was constructed with an invalid file descriptor. */
reply other threads:[~2023-01-10 16:38 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4980298.ezd0NqBDhE@nimes \
--to=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).