libc/nss tests: Add regression tests for commit 55444c823e1f

PR:		252094
Sponsored by:	The FreeBSD Foundation
MFC after:	1 month
This commit is contained in:
Mark Johnston 2021-01-21 14:30:19 -05:00
parent 5619d49e07
commit 6e411d8b14
2 changed files with 93 additions and 19 deletions

View File

@ -42,11 +42,13 @@ __FBSDID("$FreeBSD$");
#include "testutil.h"
enum test_methods {
TEST_GETGRENT = 1,
TEST_GETGRNAM = 2,
TEST_GETGRGID = 4,
TEST_GETGRENT_2PASS = 8,
TEST_BUILD_SNAPSHOT = 16,
TEST_GETGRENT,
TEST_GETGRNAM,
TEST_GETGRGID,
TEST_GETGRENT_2PASS,
TEST_GETGRENT_INTERLEAVED_GETGRNAM,
TEST_GETGRENT_INTERLEAVED_GETGRGID,
TEST_BUILD_SNAPSHOT,
};
DECLARE_TEST_DATA(group)
@ -63,7 +65,8 @@ static void sdump_group(struct group *, char *, size_t);
static int group_read_snapshot_func(struct group *, char *);
static int group_check_ambiguity(struct group_test_data *, struct group *);
static int group_fill_test_data(struct group_test_data *);
static int group_fill_test_data(struct group_test_data *,
int (*cb)(struct group *, void *));
static int group_test_correctness(struct group *, void *);
static int group_test_getgrnam(struct group *, void *);
static int group_test_getgrgid(struct group *, void *);
@ -289,16 +292,20 @@ dump_group(struct group *result)
}
static int
group_fill_test_data(struct group_test_data *td)
group_fill_test_data(struct group_test_data *td,
int (*cb)(struct group *, void *))
{
struct group *grp;
setgroupent(1);
while ((grp = getgrent()) != NULL) {
if (group_test_correctness(grp, NULL) == 0)
if (group_test_correctness(grp, NULL) == 0) {
TEST_DATA_APPEND(group, td, grp);
else
if (cb != NULL && cb(grp, td) != 0)
return (-1);
} else {
return (-1);
}
}
endgrent();
@ -395,7 +402,7 @@ group_test_getgrent(struct group *grp, void *mdata __unused)
static int
run_tests(const char *snapshot_file, enum test_methods method)
{
struct group_test_data td, td_snap, td_2pass;
struct group_test_data td, td_snap, td_2pass, td_interleaved;
int rv;
TEST_DATA_INIT(group, &td, clone_group, free_group);
@ -422,7 +429,7 @@ run_tests(const char *snapshot_file, enum test_methods method)
}
}
rv = group_fill_test_data(&td);
rv = group_fill_test_data(&td, NULL);
if (rv == -1)
return (-1);
switch (method) {
@ -452,12 +459,28 @@ run_tests(const char *snapshot_file, enum test_methods method)
break;
case TEST_GETGRENT_2PASS:
TEST_DATA_INIT(group, &td_2pass, clone_group, free_group);
rv = group_fill_test_data(&td_2pass);
rv = group_fill_test_data(&td_2pass, NULL);
if (rv != -1)
rv = DO_2PASS_TEST(group, &td, &td_2pass,
compare_group, NULL);
TEST_DATA_DESTROY(group, &td_2pass);
break;
case TEST_GETGRENT_INTERLEAVED_GETGRNAM:
TEST_DATA_INIT(group, &td_interleaved, clone_group, free_group);
rv = group_fill_test_data(&td_interleaved, group_test_getgrnam);
if (rv != -1)
rv = DO_2PASS_TEST(group, &td, &td_interleaved,
compare_group, NULL);
TEST_DATA_DESTROY(group, &td_interleaved);
break;
case TEST_GETGRENT_INTERLEAVED_GETGRGID:
TEST_DATA_INIT(group, &td_interleaved, clone_group, free_group);
rv = group_fill_test_data(&td_interleaved, group_test_getgrgid);
if (rv != -1)
rv = DO_2PASS_TEST(group, &td, &td_interleaved,
compare_group, NULL);
TEST_DATA_DESTROY(group, &td_interleaved);
break;
case TEST_BUILD_SNAPSHOT:
if (snapshot_file != NULL)
rv = TEST_SNAPSHOT_FILE_WRITE(group, snapshot_file, &td,
@ -522,6 +545,18 @@ ATF_TC_BODY(getgrnam_with_snapshot, tc)
ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRNAM) == 0);
}
ATF_TC_WITHOUT_HEAD(getgrent_interleaved_getgrnam);
ATF_TC_BODY(getgrent_interleaved_getgrnam, tc)
{
ATF_REQUIRE(run_tests(NULL, TEST_GETGRENT_INTERLEAVED_GETGRNAM) == 0);
}
ATF_TC_WITHOUT_HEAD(getgrent_interleaved_getgrgid);
ATF_TC_BODY(getgrent_interleaved_getgrgid, tc)
{
ATF_REQUIRE(run_tests(NULL, TEST_GETGRENT_INTERLEAVED_GETGRGID) == 0);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, getgrent);
@ -531,6 +566,8 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, getgrgid_with_snapshot);
ATF_TP_ADD_TC(tp, getgrnam);
ATF_TP_ADD_TC(tp, getgrnam_with_snapshot);
ATF_TP_ADD_TC(tp, getgrent_interleaved_getgrnam);
ATF_TP_ADD_TC(tp, getgrent_interleaved_getgrgid);
return (atf_no_error());
}

View File

@ -41,6 +41,8 @@ __FBSDID("$FreeBSD$");
enum test_methods {
TEST_GETPWENT,
TEST_GETPWENT_INTERLEAVED_GETPWNAM,
TEST_GETPWENT_INTERLEAVED_GETPWUID,
TEST_GETPWNAM,
TEST_GETPWUID,
TEST_GETPWENT_2PASS,
@ -64,7 +66,8 @@ static void dump_passwd(struct passwd *);
static int passwd_read_snapshot_func(struct passwd *, char *);
static int passwd_check_ambiguity(struct passwd_test_data *, struct passwd *);
static int passwd_fill_test_data(struct passwd_test_data *);
static int passwd_fill_test_data(struct passwd_test_data *,
int (*cb)(struct passwd *, void *));
static int passwd_test_correctness(struct passwd *, void *);
static int passwd_test_getpwnam(struct passwd *, void *);
static int passwd_test_getpwuid(struct passwd *, void *);
@ -236,16 +239,20 @@ passwd_read_snapshot_func(struct passwd *pwd, char *line)
}
static int
passwd_fill_test_data(struct passwd_test_data *td)
passwd_fill_test_data(struct passwd_test_data *td,
int (*cb)(struct passwd *, void *))
{
struct passwd *pwd;
setpassent(1);
while ((pwd = getpwent()) != NULL) {
if (passwd_test_correctness(pwd, NULL) == 0)
if (passwd_test_correctness(pwd, NULL) == 0) {
TEST_DATA_APPEND(passwd, td, pwd);
else
if (cb != NULL && cb(pwd, td) != 0)
return (-1);
} else {
return (-1);
}
}
endpwent();
@ -376,7 +383,7 @@ passwd_test_getpwent(struct passwd *pwd, void *mdata __unused)
static int
run_tests(const char *snapshot_file, enum test_methods method)
{
struct passwd_test_data td, td_snap, td_2pass;
struct passwd_test_data td, td_snap, td_2pass, td_interleaved;
int rv;
TEST_DATA_INIT(passwd, &td, clone_passwd, free_passwd);
@ -402,7 +409,7 @@ run_tests(const char *snapshot_file, enum test_methods method)
}
}
rv = passwd_fill_test_data(&td);
rv = passwd_fill_test_data(&td, NULL);
if (rv == -1)
return (-1);
@ -433,12 +440,28 @@ run_tests(const char *snapshot_file, enum test_methods method)
break;
case TEST_GETPWENT_2PASS:
TEST_DATA_INIT(passwd, &td_2pass, clone_passwd, free_passwd);
rv = passwd_fill_test_data(&td_2pass);
rv = passwd_fill_test_data(&td_2pass, NULL);
if (rv != -1)
rv = DO_2PASS_TEST(passwd, &td, &td_2pass,
compare_passwd, NULL);
TEST_DATA_DESTROY(passwd, &td_2pass);
break;
case TEST_GETPWENT_INTERLEAVED_GETPWNAM:
TEST_DATA_INIT(passwd, &td_interleaved, clone_passwd, free_passwd);
rv = passwd_fill_test_data(&td_interleaved, passwd_test_getpwnam);
if (rv != -1)
rv = DO_2PASS_TEST(passwd, &td, &td_interleaved,
compare_passwd, NULL);
TEST_DATA_DESTROY(passwd, &td_interleaved);
break;
case TEST_GETPWENT_INTERLEAVED_GETPWUID:
TEST_DATA_INIT(passwd, &td_interleaved, clone_passwd, free_passwd);
rv = passwd_fill_test_data(&td_interleaved, passwd_test_getpwuid);
if (rv != -1)
rv = DO_2PASS_TEST(passwd, &td, &td_interleaved,
compare_passwd, NULL);
TEST_DATA_DESTROY(passwd, &td_interleaved);
break;
case TEST_BUILD_SNAPSHOT:
if (snapshot_file != NULL)
rv = TEST_SNAPSHOT_FILE_WRITE(passwd, snapshot_file,
@ -503,6 +526,18 @@ ATF_TC_BODY(getpwuid_with_snapshot, tc)
ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWUID) == 0);
}
ATF_TC_WITHOUT_HEAD(getpwent_interleaved_getpwnam);
ATF_TC_BODY(getpwent_interleaved_getpwnam, tc)
{
ATF_REQUIRE(run_tests(NULL, TEST_GETPWENT_INTERLEAVED_GETPWNAM) == 0);
}
ATF_TC_WITHOUT_HEAD(getpwent_interleaved_getpwuid);
ATF_TC_BODY(getpwent_interleaved_getpwuid, tc)
{
ATF_REQUIRE(run_tests(NULL, TEST_GETPWENT_INTERLEAVED_GETPWUID) == 0);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, getpwent);
@ -512,6 +547,8 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, getpwnam_with_snapshot);
ATF_TP_ADD_TC(tp, getpwuid);
ATF_TP_ADD_TC(tp, getpwuid_with_snapshot);
ATF_TP_ADD_TC(tp, getpwent_interleaved_getpwnam);
ATF_TP_ADD_TC(tp, getpwent_interleaved_getpwuid);
return (atf_no_error());
}