public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] nss: Enhance tst-reload1 coverage and logging
@ 2022-09-23 11:13 Florian Weimer
  2022-09-23 11:13 ` [PATCH 2/2] nss: Use shared prefix in IPv4 address in tst-reload1 Florian Weimer
  2022-09-23 13:33 ` [PATCH 1/2] nss: Enhance tst-reload1 coverage and logging Siddhesh Poyarekar
  0 siblings, 2 replies; 4+ messages in thread
From: Florian Weimer @ 2022-09-23 11:13 UTC (permalink / raw)
  To: libc-alpha

---
 nss/tst-reload1.c | 51 +++++++++++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 22 deletions(-)

diff --git a/nss/tst-reload1.c b/nss/tst-reload1.c
index fdc5bdd65b..9cc6115c96 100644
--- a/nss/tst-reload1.c
+++ b/nss/tst-reload1.c
@@ -121,7 +121,7 @@ must_be_tests (struct passwd *pt, struct hostent *ht)
       TEST_VERIFY (p != NULL);
       if (p != NULL)
 	{
-	  TEST_VERIFY (strcmp (p->pw_name, pt[i].pw_name) == 0);
+	  TEST_COMPARE_STRING (p->pw_name, pt[i].pw_name);
 	}
     }
 
@@ -132,8 +132,8 @@ must_be_tests (struct passwd *pt, struct hostent *ht)
       TEST_VERIFY (p != NULL);
       if (p != NULL)
 	{
-	  TEST_VERIFY (strcmp (p->pw_name, pt[i].pw_name) == 0);
-	  TEST_VERIFY (p->pw_uid == pt[i].pw_uid);
+	  TEST_COMPARE_STRING (p->pw_name, pt[i].pw_name);
+	  TEST_COMPARE (p->pw_uid, pt[i].pw_uid);
 	}
     }
   endpwent ();
@@ -144,10 +144,12 @@ must_be_tests (struct passwd *pt, struct hostent *ht)
       TEST_VERIFY (h != NULL);
       if (h != NULL)
 	{
-	  TEST_VERIFY (strcmp (h->h_name, ht[i].h_name) == 0);
+	  TEST_COMPARE_STRING (h->h_name, ht[i].h_name);
+	  TEST_COMPARE (h->h_addrtype, AF_INET);
 	  TEST_VERIFY (h->h_addr_list[0] != NULL);
-	  if (h->h_addr_list[0])
-	    TEST_VERIFY (strcmp (h->h_addr_list[0], ht[i].h_addr_list[0]) == 0);
+	  if (h->h_addr_list[0] != NULL)
+	    TEST_COMPARE_BLOB (h->h_addr_list[0], h->h_length,
+			       ht[i].h_addr_list[0], ht[i].h_length);
 	}
     }
 
@@ -158,14 +160,16 @@ must_be_tests (struct passwd *pt, struct hostent *ht)
       int herrno, res;
 
       res = gethostbyname2_r (ht[i].h_name, AF_INET,
-			    &r, buf, TESTBUFLEN, &rp, &herrno);
-      TEST_VERIFY (res == 0);
+			      &r, buf, TESTBUFLEN, &rp, &herrno);
+      TEST_COMPARE (res, 0);
       if (res == 0)
 	{
-	  TEST_VERIFY (strcmp (r.h_name, ht[i].h_name) == 0);
+	  TEST_COMPARE_STRING (r.h_name, ht[i].h_name);
+	  TEST_COMPARE (r.h_addrtype, AF_INET);
 	  TEST_VERIFY (r.h_addr_list[0] != NULL);
-	  if (r.h_addr_list[0])
-	    TEST_VERIFY (strcmp (r.h_addr_list[0], ht[i].h_addr_list[0]) == 0);
+	  if (r.h_addr_list[0] != NULL)
+	    TEST_COMPARE_BLOB (r.h_addr_list[0], r.h_length,
+			       ht[i].h_addr_list[0], ht[i].h_length);
 	}
     }
 
@@ -175,10 +179,11 @@ must_be_tests (struct passwd *pt, struct hostent *ht)
       TEST_VERIFY (h != NULL);
       if (h != NULL)
 	{
-	  TEST_VERIFY (strcmp (h->h_name, ht[i].h_name) == 0);
+	  TEST_COMPARE_STRING (h->h_name, ht[i].h_name);
 	  TEST_VERIFY (h->h_addr_list[0] != NULL);
-	  if (h->h_addr_list[0])
-	    TEST_VERIFY (strcmp (h->h_addr_list[0], ht[i].h_addr_list[0]) == 0);
+	  if (h->h_addr_list[0] != NULL)
+	    TEST_COMPARE_BLOB (h->h_addr_list[0], h->h_length,
+			       ht[i].h_addr_list[0], ht[i].h_length);
 	}
     }
 
@@ -198,17 +203,19 @@ must_be_tests (struct passwd *pt, struct hostent *ht)
 
       ap = NULL;
       res = getaddrinfo (ht[i].h_name, NULL, &hint, &ap);
-      TEST_VERIFY (res == 0);
+      TEST_COMPARE (res, 0);
       TEST_VERIFY (ap != NULL);
       if (res == 0 && ap != NULL)
 	{
 	  j = 0; /* which address in the list */
 	  while (ap)
 	    {
+	      TEST_COMPARE (ap->ai_family, AF_INET);
+
 	      struct sockaddr_in *in = (struct sockaddr_in *)ap->ai_addr;
 	      unsigned char *up = (unsigned char *)&in->sin_addr;
 
-	      TEST_VERIFY (memcmp (up, ht[i].h_addr_list[j], 4) == 0);
+	      TEST_COMPARE_BLOB (up, 4, ht[i].h_addr_list[j], 4);
 
 	      ap = ap->ai_next;
 	      ++j;
@@ -233,7 +240,7 @@ must_be_tests (struct passwd *pt, struct hostent *ht)
 			 host_buf, sizeof(host_buf),
 			 NULL, 0, NI_NOFQDN);
 
-      TEST_VERIFY (res == 0);
+      TEST_COMPARE (res, 0);
       if (res == 0)
 	TEST_VERIFY (strcmp (ht[i].h_name, host_buf) == 0);
       else
@@ -285,8 +292,8 @@ test_cross_switch_consistency (void)
       TEST_VERIFY (p != NULL);
       if (p != NULL)
 	{
-	  TEST_VERIFY (strcmp (p->pw_name, pwd_table_1[i].pw_name) == 0);
-	  TEST_VERIFY (p->pw_uid == pwd_table_1[i].pw_uid);
+	  TEST_COMPARE_STRING (p->pw_name, pwd_table_1[i].pw_name);
+	  TEST_COMPARE (p->pw_uid, pwd_table_1[i].pw_uid);
 	}
 
       /* After the first lookup, switch to conf2 and verify */
@@ -296,7 +303,7 @@ test_cross_switch_consistency (void)
 	  xrename ("/etc/nsswitch.conf2", "/etc/nsswitch.conf");
 
 	  p = getpwnam (pwd_table_2[0].pw_name);
-	  TEST_VERIFY (p->pw_uid == pwd_table_2[0].pw_uid);
+	  TEST_COMPARE (p->pw_uid, pwd_table_2[0].pw_uid);
 	}
 
       /* But the original loop should still be on conf1.  */
@@ -311,8 +318,8 @@ test_cross_switch_consistency (void)
       TEST_VERIFY (p != NULL);
       if (p != NULL)
 	{
-	  TEST_VERIFY (strcmp (p->pw_name, pwd_table_2[i].pw_name) == 0);
-	  TEST_VERIFY (p->pw_uid == pwd_table_2[i].pw_uid);
+	  TEST_COMPARE_STRING (p->pw_name, pwd_table_2[i].pw_name);
+	  TEST_COMPARE (p->pw_uid, pwd_table_2[i].pw_uid);
 	}
     }
   endpwent ();

base-commit: 774d43f27dbc730ee4b8b37bce4d5b3d5c0b74b6
-- 
2.37.3



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] nss: Use shared prefix in IPv4 address in tst-reload1
  2022-09-23 11:13 [PATCH 1/2] nss: Enhance tst-reload1 coverage and logging Florian Weimer
@ 2022-09-23 11:13 ` Florian Weimer
  2022-09-23 13:34   ` Siddhesh Poyarekar
  2022-09-23 13:33 ` [PATCH 1/2] nss: Enhance tst-reload1 coverage and logging Siddhesh Poyarekar
  1 sibling, 1 reply; 4+ messages in thread
From: Florian Weimer @ 2022-09-23 11:13 UTC (permalink / raw)
  To: libc-alpha

Otherwise, sorting based on the longest-matching prefix in
getaddrinfo can reorder the addresses in ways the test does not
expect, depending on the IPv4 address of the host.
---
 nss/tst-reload1.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/nss/tst-reload1.c b/nss/tst-reload1.c
index 9cc6115c96..c9db197d55 100644
--- a/nss/tst-reload1.c
+++ b/nss/tst-reload1.c
@@ -43,12 +43,12 @@ static struct passwd pwd_table_1[] = {
 
 static const char *hostaddr_5[] =
   {
-   "ABCD", "abcd", "1234", NULL
+   "ABCd", "ABCD", "ABC4", NULL
   };
 
 static const char *hostaddr_15[] =
   {
-   "4321", "ghij", NULL
+   "4321", "4322", NULL
   };
 
 static const char *hostaddr_25[] =
@@ -86,12 +86,12 @@ static const char *hostaddr_6[] =
 
 static const char *hostaddr_16[] =
   {
-   "7890", "a1b2", NULL
+   "7890", "7891", NULL
   };
 
 static const char *hostaddr_26[] =
   {
-   "qwer", "tyui", NULL
+   "qwer", "qweR", NULL
   };
 
 static struct hostent host_table_2[] = {
-- 
2.37.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] nss: Enhance tst-reload1 coverage and logging
  2022-09-23 11:13 [PATCH 1/2] nss: Enhance tst-reload1 coverage and logging Florian Weimer
  2022-09-23 11:13 ` [PATCH 2/2] nss: Use shared prefix in IPv4 address in tst-reload1 Florian Weimer
@ 2022-09-23 13:33 ` Siddhesh Poyarekar
  1 sibling, 0 replies; 4+ messages in thread
From: Siddhesh Poyarekar @ 2022-09-23 13:33 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha



On 2022-09-23 07:13, Florian Weimer via Libc-alpha wrote:
> ---
>   nss/tst-reload1.c | 51 +++++++++++++++++++++++++++--------------------
>   1 file changed, 29 insertions(+), 22 deletions(-)

LGTM.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

> 
> diff --git a/nss/tst-reload1.c b/nss/tst-reload1.c
> index fdc5bdd65b..9cc6115c96 100644
> --- a/nss/tst-reload1.c
> +++ b/nss/tst-reload1.c
> @@ -121,7 +121,7 @@ must_be_tests (struct passwd *pt, struct hostent *ht)
>         TEST_VERIFY (p != NULL);
>         if (p != NULL)
>   	{
> -	  TEST_VERIFY (strcmp (p->pw_name, pt[i].pw_name) == 0);
> +	  TEST_COMPARE_STRING (p->pw_name, pt[i].pw_name);
>   	}
>       }
>   
> @@ -132,8 +132,8 @@ must_be_tests (struct passwd *pt, struct hostent *ht)
>         TEST_VERIFY (p != NULL);
>         if (p != NULL)
>   	{
> -	  TEST_VERIFY (strcmp (p->pw_name, pt[i].pw_name) == 0);
> -	  TEST_VERIFY (p->pw_uid == pt[i].pw_uid);
> +	  TEST_COMPARE_STRING (p->pw_name, pt[i].pw_name);
> +	  TEST_COMPARE (p->pw_uid, pt[i].pw_uid);
>   	}
>       }
>     endpwent ();
> @@ -144,10 +144,12 @@ must_be_tests (struct passwd *pt, struct hostent *ht)
>         TEST_VERIFY (h != NULL);
>         if (h != NULL)
>   	{
> -	  TEST_VERIFY (strcmp (h->h_name, ht[i].h_name) == 0);
> +	  TEST_COMPARE_STRING (h->h_name, ht[i].h_name);
> +	  TEST_COMPARE (h->h_addrtype, AF_INET);
>   	  TEST_VERIFY (h->h_addr_list[0] != NULL);
> -	  if (h->h_addr_list[0])
> -	    TEST_VERIFY (strcmp (h->h_addr_list[0], ht[i].h_addr_list[0]) == 0);
> +	  if (h->h_addr_list[0] != NULL)
> +	    TEST_COMPARE_BLOB (h->h_addr_list[0], h->h_length,
> +			       ht[i].h_addr_list[0], ht[i].h_length);
>   	}
>       }
>   
> @@ -158,14 +160,16 @@ must_be_tests (struct passwd *pt, struct hostent *ht)
>         int herrno, res;
>   
>         res = gethostbyname2_r (ht[i].h_name, AF_INET,
> -			    &r, buf, TESTBUFLEN, &rp, &herrno);
> -      TEST_VERIFY (res == 0);
> +			      &r, buf, TESTBUFLEN, &rp, &herrno);
> +      TEST_COMPARE (res, 0);
>         if (res == 0)
>   	{
> -	  TEST_VERIFY (strcmp (r.h_name, ht[i].h_name) == 0);
> +	  TEST_COMPARE_STRING (r.h_name, ht[i].h_name);
> +	  TEST_COMPARE (r.h_addrtype, AF_INET);
>   	  TEST_VERIFY (r.h_addr_list[0] != NULL);
> -	  if (r.h_addr_list[0])
> -	    TEST_VERIFY (strcmp (r.h_addr_list[0], ht[i].h_addr_list[0]) == 0);
> +	  if (r.h_addr_list[0] != NULL)
> +	    TEST_COMPARE_BLOB (r.h_addr_list[0], r.h_length,
> +			       ht[i].h_addr_list[0], ht[i].h_length);
>   	}
>       }
>   
> @@ -175,10 +179,11 @@ must_be_tests (struct passwd *pt, struct hostent *ht)
>         TEST_VERIFY (h != NULL);
>         if (h != NULL)
>   	{
> -	  TEST_VERIFY (strcmp (h->h_name, ht[i].h_name) == 0);
> +	  TEST_COMPARE_STRING (h->h_name, ht[i].h_name);
>   	  TEST_VERIFY (h->h_addr_list[0] != NULL);
> -	  if (h->h_addr_list[0])
> -	    TEST_VERIFY (strcmp (h->h_addr_list[0], ht[i].h_addr_list[0]) == 0);
> +	  if (h->h_addr_list[0] != NULL)
> +	    TEST_COMPARE_BLOB (h->h_addr_list[0], h->h_length,
> +			       ht[i].h_addr_list[0], ht[i].h_length);
>   	}
>       }
>   
> @@ -198,17 +203,19 @@ must_be_tests (struct passwd *pt, struct hostent *ht)
>   
>         ap = NULL;
>         res = getaddrinfo (ht[i].h_name, NULL, &hint, &ap);
> -      TEST_VERIFY (res == 0);
> +      TEST_COMPARE (res, 0);
>         TEST_VERIFY (ap != NULL);
>         if (res == 0 && ap != NULL)
>   	{
>   	  j = 0; /* which address in the list */
>   	  while (ap)
>   	    {
> +	      TEST_COMPARE (ap->ai_family, AF_INET);
> +
>   	      struct sockaddr_in *in = (struct sockaddr_in *)ap->ai_addr;
>   	      unsigned char *up = (unsigned char *)&in->sin_addr;
>   
> -	      TEST_VERIFY (memcmp (up, ht[i].h_addr_list[j], 4) == 0);
> +	      TEST_COMPARE_BLOB (up, 4, ht[i].h_addr_list[j], 4);
>   
>   	      ap = ap->ai_next;
>   	      ++j;
> @@ -233,7 +240,7 @@ must_be_tests (struct passwd *pt, struct hostent *ht)
>   			 host_buf, sizeof(host_buf),
>   			 NULL, 0, NI_NOFQDN);
>   
> -      TEST_VERIFY (res == 0);
> +      TEST_COMPARE (res, 0);
>         if (res == 0)
>   	TEST_VERIFY (strcmp (ht[i].h_name, host_buf) == 0);
>         else
> @@ -285,8 +292,8 @@ test_cross_switch_consistency (void)
>         TEST_VERIFY (p != NULL);
>         if (p != NULL)
>   	{
> -	  TEST_VERIFY (strcmp (p->pw_name, pwd_table_1[i].pw_name) == 0);
> -	  TEST_VERIFY (p->pw_uid == pwd_table_1[i].pw_uid);
> +	  TEST_COMPARE_STRING (p->pw_name, pwd_table_1[i].pw_name);
> +	  TEST_COMPARE (p->pw_uid, pwd_table_1[i].pw_uid);
>   	}
>   
>         /* After the first lookup, switch to conf2 and verify */
> @@ -296,7 +303,7 @@ test_cross_switch_consistency (void)
>   	  xrename ("/etc/nsswitch.conf2", "/etc/nsswitch.conf");
>   
>   	  p = getpwnam (pwd_table_2[0].pw_name);
> -	  TEST_VERIFY (p->pw_uid == pwd_table_2[0].pw_uid);
> +	  TEST_COMPARE (p->pw_uid, pwd_table_2[0].pw_uid);
>   	}
>   
>         /* But the original loop should still be on conf1.  */
> @@ -311,8 +318,8 @@ test_cross_switch_consistency (void)
>         TEST_VERIFY (p != NULL);
>         if (p != NULL)
>   	{
> -	  TEST_VERIFY (strcmp (p->pw_name, pwd_table_2[i].pw_name) == 0);
> -	  TEST_VERIFY (p->pw_uid == pwd_table_2[i].pw_uid);
> +	  TEST_COMPARE_STRING (p->pw_name, pwd_table_2[i].pw_name);
> +	  TEST_COMPARE (p->pw_uid, pwd_table_2[i].pw_uid);
>   	}
>       }
>     endpwent ();
> 
> base-commit: 774d43f27dbc730ee4b8b37bce4d5b3d5c0b74b6

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] nss: Use shared prefix in IPv4 address in tst-reload1
  2022-09-23 11:13 ` [PATCH 2/2] nss: Use shared prefix in IPv4 address in tst-reload1 Florian Weimer
@ 2022-09-23 13:34   ` Siddhesh Poyarekar
  0 siblings, 0 replies; 4+ messages in thread
From: Siddhesh Poyarekar @ 2022-09-23 13:34 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha



On 2022-09-23 07:13, Florian Weimer via Libc-alpha wrote:
> Otherwise, sorting based on the longest-matching prefix in
> getaddrinfo can reorder the addresses in ways the test does not
> expect, depending on the IPv4 address of the host.
> ---

LGTM.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

>   nss/tst-reload1.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/nss/tst-reload1.c b/nss/tst-reload1.c
> index 9cc6115c96..c9db197d55 100644
> --- a/nss/tst-reload1.c
> +++ b/nss/tst-reload1.c
> @@ -43,12 +43,12 @@ static struct passwd pwd_table_1[] = {
>   
>   static const char *hostaddr_5[] =
>     {
> -   "ABCD", "abcd", "1234", NULL
> +   "ABCd", "ABCD", "ABC4", NULL
>     };
>   
>   static const char *hostaddr_15[] =
>     {
> -   "4321", "ghij", NULL
> +   "4321", "4322", NULL
>     };
>   
>   static const char *hostaddr_25[] =
> @@ -86,12 +86,12 @@ static const char *hostaddr_6[] =
>   
>   static const char *hostaddr_16[] =
>     {
> -   "7890", "a1b2", NULL
> +   "7890", "7891", NULL
>     };
>   
>   static const char *hostaddr_26[] =
>     {
> -   "qwer", "tyui", NULL
> +   "qwer", "qweR", NULL
>     };
>   
>   static struct hostent host_table_2[] = {

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-23 13:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-23 11:13 [PATCH 1/2] nss: Enhance tst-reload1 coverage and logging Florian Weimer
2022-09-23 11:13 ` [PATCH 2/2] nss: Use shared prefix in IPv4 address in tst-reload1 Florian Weimer
2022-09-23 13:34   ` Siddhesh Poyarekar
2022-09-23 13:33 ` [PATCH 1/2] nss: Enhance tst-reload1 coverage and logging Siddhesh Poyarekar

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).