bug-gnulib
[Top][All Lists]
Advanced

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

chown, lchown, fchownat tests: Avoid test failure on macOS 12


From: Bruno Haible
Subject: chown, lchown, fchownat tests: Avoid test failure on macOS 12
Date: Fri, 10 Feb 2023 14:00:45 +0100

On macOS 12.5, I see these 3 test failures:


FAIL: test-chown
================

../../gltests/test-chown.h:75: assertion 'st1.st_gid == getegid ()' failed
FAIL test-chown (exit status: 134)

FAIL: test-fchownat
===================

../../gltests/test-chown.h:75: assertion 'st1.st_gid == getegid ()' failed
FAIL test-fchownat (exit status: 134)

FAIL: test-lchown
=================

../../gltests/test-lchown.h:83: assertion 'st1.st_gid == getegid ()' failed
FAIL test-lchown (exit status: 134)


It is a particular situation, I guess, probably due to being logged in through
ssh: getgid() and getegid() both return (gid_t)(-1). But the st_gid of
freshly created files is reasonable.

This patch avoids the test failures. I could also make the entire test SKIPped,
but that would be exaggerated.


2023-02-10  Bruno Haible  <bruno@clisp.org>

        chown, lchown, fchownat tests: Avoid test failure on macOS 12.
        * tests/test-chown.h (test_chown): Skip some assertions if
        getgid() == (gid_t)-1.
        * tests/test-lchown.h (test_lchown): Likewise.

diff --git a/tests/test-chown.h b/tests/test-chown.h
index e8c3d49ff9..4c7b6eec33 100644
--- a/tests/test-chown.h
+++ b/tests/test-chown.h
@@ -72,7 +72,10 @@ test_chown (int (*func) (char const *, uid_t, gid_t), bool 
print)
   ASSERT (stat (BASE "dir/file", &st1) == 0);
   ASSERT (st1.st_uid != (uid_t) -1);
   ASSERT (st1.st_gid != (gid_t) -1);
-  ASSERT (st1.st_gid == getegid ());
+  /* On macOS 12, when logged in through ssh, getgid () and getegid () are both
+     == (gid_t) -1.  */
+  if (getgid () != (gid_t) -1)
+    ASSERT (st1.st_gid == getegid ());
 
   /* Sanity check of error cases.  */
   errno = 0;
@@ -132,7 +135,8 @@ test_chown (int (*func) (char const *, uid_t, gid_t), bool 
print)
   if (1 < gids_count)
     {
       ASSERT (gids[1] != st1.st_gid);
-      ASSERT (gids[1] != (gid_t) -1);
+      if (getgid () != (gid_t) -1)
+        ASSERT (gids[1] != (gid_t) -1);
       ASSERT (lstat (BASE "dir/link", &st2) == 0);
       ASSERT (st1.st_uid == st2.st_uid);
       ASSERT (st1.st_gid == st2.st_gid);
@@ -156,7 +160,8 @@ test_chown (int (*func) (char const *, uid_t, gid_t), bool 
print)
       ASSERT (func (BASE "dir/link2", -1, gids[1]) == 0);
       ASSERT (stat (BASE "dir/file", &st2) == 0);
       ASSERT (st1.st_uid == st2.st_uid);
-      ASSERT (gids[1] == st2.st_gid);
+      if (getgid () != (gid_t) -1)
+        ASSERT (gids[1] == st2.st_gid);
       ASSERT (lstat (BASE "dir/link", &st2) == 0);
       ASSERT (st1.st_uid == st2.st_uid);
       ASSERT (st1.st_gid == st2.st_gid);
diff --git a/tests/test-lchown.h b/tests/test-lchown.h
index 1e5dffef7f..1c68f4a1ba 100644
--- a/tests/test-lchown.h
+++ b/tests/test-lchown.h
@@ -80,7 +80,10 @@ test_lchown (int (*func) (char const *, uid_t, gid_t), bool 
print)
   ASSERT (stat (BASE "dir/file", &st1) == 0);
   ASSERT (st1.st_uid != (uid_t) -1);
   ASSERT (st1.st_gid != (gid_t) -1);
-  ASSERT (st1.st_gid == getegid ());
+  /* On macOS 12, when logged in through ssh, getgid () and getegid () are both
+     == (gid_t) -1.  */
+  if (getgid () != (gid_t) -1)
+    ASSERT (st1.st_gid == getegid ());
 
   /* Sanity check of error cases.  */
   errno = 0;
@@ -150,7 +153,8 @@ test_lchown (int (*func) (char const *, uid_t, gid_t), bool 
print)
   if (1 < gids_count)
     {
       ASSERT (gids[1] != st1.st_gid);
-      ASSERT (gids[1] != (gid_t) -1);
+      if (getgid () != (gid_t) -1)
+        ASSERT (gids[1] != (gid_t) -1);
       ASSERT (lstat (BASE "dir/link", &st2) == 0);
       ASSERT (st1.st_uid == st2.st_uid);
       ASSERT (st1.st_gid == st2.st_gid);
@@ -180,7 +184,8 @@ test_lchown (int (*func) (char const *, uid_t, gid_t), bool 
print)
       ASSERT (st1.st_gid == st2.st_gid);
       ASSERT (lstat (BASE "dir/link2", &st2) == 0);
       ASSERT (st1.st_uid == st2.st_uid);
-      ASSERT (gids[1] == st2.st_gid);
+      if (getgid () != (gid_t) -1)
+        ASSERT (gids[1] == st2.st_gid);
 
       /* Trailing slash follows through to directory.  */
       ASSERT (lstat (BASE "dir/link3", &st2) == 0);
@@ -196,7 +201,8 @@ test_lchown (int (*func) (char const *, uid_t, gid_t), bool 
print)
       ASSERT (st1.st_gid == st2.st_gid);
       ASSERT (lstat (BASE "dir/sub", &st2) == 0);
       ASSERT (st1.st_uid == st2.st_uid);
-      ASSERT (gids[1] == st2.st_gid);
+      if (getgid () != (gid_t) -1)
+        ASSERT (gids[1] == st2.st_gid);
     }
   else if (!CHOWN_CHANGE_TIME_BUG || HAVE_LCHMOD)
     {






reply via email to

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