diff options
author | DJ Delorie <dj@delorie.com> | 2017-07-17 15:50:43 -0400 |
---|---|---|
committer | DJ Delorie <dj@delorie.com> | 2017-07-17 15:52:44 -0400 |
commit | ae5c498d93d049d9574d3f8f18e62cac64cbdf5c (patch) | |
tree | 986e51e120bd42c02fe2ee5a4b04ca13951600e3 /nss/tst-nss-test1.c | |
parent | 48145e1c7dabaeab7ad8346d14f910cdeb6bc910 (diff) | |
download | glibc-ae5c498d93d049d9574d3f8f18e62cac64cbdf5c.zip glibc-ae5c498d93d049d9574d3f8f18e62cac64cbdf5c.tar.gz glibc-ae5c498d93d049d9574d3f8f18e62cac64cbdf5c.tar.bz2 |
Extend NSS test suite
* nss/nss_test.h: New.
* nss/nss_test1.h: Rewrite to use test-provided data. Add group
tests. Parameterize to allow multiple instances.
* nss/nss_test2.h: New. Second instance.
* nss/nss_test.ver: New.
* nss/nss_test1.c: Update to use new framework.
* nss/nss_test2.c: New.
* nss/nss_test3.c: New.
* nss/nss_test4.c: New.
* nss/nss_test5.c: New.
* nss/Makefile: Build new tests.
* shlib-versions: Add libnss_test2.
Diffstat (limited to 'nss/tst-nss-test1.c')
-rw-r--r-- | nss/tst-nss-test1.c | 76 |
1 files changed, 64 insertions, 12 deletions
diff --git a/nss/tst-nss-test1.c b/nss/tst-nss-test1.c index c5750e0..ff13272 100644 --- a/nss/tst-nss-test1.c +++ b/nss/tst-nss-test1.c @@ -1,9 +1,49 @@ +/* Basic test of passwd database handling. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + #include <nss.h> #include <pwd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "nss_test.h" + +static int hook_called = 0; + +/* Note: the values chosen here are arbitrary; they need only be + unique within the table. However, they do need to match the + "pwdids" array further down. */ +static struct passwd pwd_table[] = { + PWD (100), + PWD (30), + PWD (200), + PWD (60), + PWD (20000), + PWD_LAST () + }; + +void +_nss_test1_init_hook(test_tables *t) +{ + hook_called = 1; + t->pwd_table = pwd_table; +} static int do_test (void) @@ -12,20 +52,26 @@ do_test (void) __nss_configure_lookup ("passwd", "test1"); + /* This must match the pwd_table above. */ static const unsigned int pwdids[] = { 100, 30, 200, 60, 20000 }; #define npwdids (sizeof (pwdids) / sizeof (pwdids[0])) + setpwent (); const unsigned int *np = pwdids; for (struct passwd *p = getpwent (); p != NULL; ++np, p = getpwent ()) - if (p->pw_uid != *np || strncmp (p->pw_name, "name", 4) != 0 - || atol (p->pw_name + 4) != *np) - { - printf ("passwd entry %td wrong (%s, %u)\n", - np - pwdids, p->pw_name, p->pw_uid); - retval = 1; - break; - } + { + retval += compare_passwds (np-pwdids, p, & pwd_table[np-pwdids]); + + if (p->pw_uid != *np || strncmp (p->pw_name, "name", 4) != 0 + || atol (p->pw_name + 4) != *np) + { + printf ("FAIL: passwd entry %td wrong (%s, %u)\n", + np - pwdids, p->pw_name, p->pw_uid); + retval = 1; + break; + } + } endpwent (); @@ -37,14 +83,14 @@ do_test (void) struct passwd *p = getpwnam (buf); if (p == NULL || p->pw_uid != pwdids[i] || strcmp (buf, p->pw_name) != 0) { - printf ("passwd entry \"%s\" wrong\n", buf); + printf ("FAIL: passwd entry \"%s\" wrong\n", buf); retval = 1; } p = getpwuid (pwdids[i]); if (p == NULL || p->pw_uid != pwdids[i] || strcmp (buf, p->pw_name) != 0) { - printf ("passwd entry %u wrong\n", pwdids[i]); + printf ("FAIL: passwd entry %u wrong\n", pwdids[i]); retval = 1; } @@ -53,18 +99,24 @@ do_test (void) p = getpwnam (buf); if (p != NULL) { - printf ("passwd entry \"%s\" wrong\n", buf); + printf ("FAIL: passwd entry \"%s\" wrong\n", buf); retval = 1; } p = getpwuid (pwdids[i] + 1); if (p != NULL) { - printf ("passwd entry %u wrong\n", pwdids[i] + 1); + printf ("FAIL: passwd entry %u wrong\n", pwdids[i] + 1); retval = 1; } } + if (!hook_called) + { + retval = 1; + printf("FAIL: init hook never called\n"); + } + return retval; } |