grp: testgrp should exit unsupported properly.

Message ID 1492030877-22569-1-git-send-email-wainersm@gmail.com
State New
Headers show

Commit Message

Wainer dos Santos Moschetta April 12, 2017, 9:01 p.m.
grp/testgrp should properly exit unsupported if getpweuid() returns
NULL and it does not set errno since it indicates that tests are
executed by a passwordless user.

Also refactor to use the support test driver.

Checked on x86_64-linux-gnu.

2017-04-13  Wainer dos Santos Moschetta  <wainersm@gmail.com>

	* grp/testgrp.c: Import support/test-driver.
	(do_test): New, replace main().
	(do_test): exit unsupported if getpwuid() returns NULL
	and it does not set errno.
---
 grp/testgrp.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

Comments

Florian Weimer April 20, 2017, 11:56 a.m. | #1
On 04/12/2017 11:01 PM, Wainer dos Santos Moschetta wrote:
> grp/testgrp should properly exit unsupported if getpweuid() returns
> NULL and it does not set errno since it indicates that tests are
> executed by a passwordless user.

Shouldn't this be a regular FAIL?  We should assume that the user 
running the testsuite has a name.

Thanks,
Florian
Florian Weimer April 20, 2017, 1:39 p.m. | #2
On 04/20/2017 03:26 PM, Wainer dos Santos Moschetta wrote:
> On 20-04-2017 08:56, Florian Weimer wrote:
>> On 04/12/2017 11:01 PM, Wainer dos Santos Moschetta wrote:
>>> grp/testgrp should properly exit unsupported if getpweuid() returns
>>> NULL and it does not set errno since it indicates that tests are
>>> executed by a passwordless user.
>>
>> Shouldn't this be a regular FAIL?  We should assume that the user 
>> running the testsuite has a name.
> 
> Is there a consensus about FAIL vs UNSUPPORTED?
> 
> In https://sourceware.org/glibc/wiki/Testing/Testsuite you read:
> "EXIT_UNSUPPORTEDfrom<support/test-driver.h>is a magic exit status (77) 
> which indicates that the test is not supported on this particular system 
> (perhaps due to lack of hardware or kernel support detected at run time).".
> 
> But I tend to think a test should exit unsupported if the environment 
> doesn't provide all requirements to execute the it properly.
> 
> Giving a bit of context: I ran glibc's testsuite in an VM provided by a 
> cloud provider, which access is granted through SSH keys. Other tests 
> also exit FAIL due lack of user's password.

In your case, it's an environment issue.  But I think what you are 
proposing reduces the scope of the test itself, which is why I think 
this change is not appropriate.

Thanks,
Florian

Patch

diff --git a/grp/testgrp.c b/grp/testgrp.c
index 892cfaa..38f6088 100644
--- a/grp/testgrp.c
+++ b/grp/testgrp.c
@@ -1,12 +1,14 @@ 
+#include <errno.h>
 #include <grp.h>
 #include <pwd.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <support/test-driver.h>
 
 int
-main (int argc, char *argv[])
+do_test (void)
 {
   uid_t me;
   struct passwd *my_passwd;
@@ -14,9 +16,21 @@  main (int argc, char *argv[])
   char **members;
 
   me = getuid ();
+  errno = 0;
   my_passwd = getpwuid (me);
   if (my_passwd == NULL)
-    printf ("Cannot find user entry for UID %d\n", me);
+    {
+      if (errno == 0)
+        {
+          printf ("Cannot find user entry for UID %d\n", me);
+          return EXIT_UNSUPPORTED;
+        }
+      else
+        {
+          printf ("FAIL: getpwuid() exited with error: %m\n");
+          return EXIT_FAILURE;
+        }
+    }
   else
     {
       printf ("My login name is %s.\n", my_passwd->pw_name);
@@ -39,3 +53,5 @@  main (int argc, char *argv[])
 
   return my_passwd && my_group ? EXIT_SUCCESS : EXIT_FAILURE;
 }
+
+#include <support/test-driver.c>