PERFORCE change 100393 for review
Michael Bushkov
bushman at FreeBSD.org
Sat Jul 1 13:11:44 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=100393
Change 100393 by bushman at bushman_nss_ldap_cached on 2006/07/01 13:11:36
"services" database test finished
Affected files ...
.. //depot/projects/soc2006/nss_ldap_cached/src/tools/regression/lib/libc/nss/test-getserv.c#4 edit
.. //depot/projects/soc2006/nss_ldap_cached/src/tools/regression/lib/libc/nss/test-getserv.t#3 edit
.. //depot/projects/soc2006/nss_ldap_cached/src/tools/regression/lib/libc/nss/testutil.h#4 edit
Differences ...
==== //depot/projects/soc2006/nss_ldap_cached/src/tools/regression/lib/libc/nss/test-getserv.c#4 (text+ko) ====
@@ -51,7 +51,7 @@
static enum test_methods method = TEST_GETSERVENT;
DECLARE_TEST_DATA(servent)
-DECLARE_FILE_SNAPSHOT(servent)
+DECLARE_TEST_FILE_SNAPSHOT(servent)
DECLARE_1PASS_TEST(servent)
DECLARE_2PASS_TEST(servent)
@@ -63,10 +63,8 @@
static void sdump_servent(struct servent *, char *, size_t);
static int servent_read_snapshot_func(struct servent *, char *);
-static int check_servent_ambiguity_func(struct servent *, void *);
static int servent_check_ambiguity(struct servent_test_data *,
struct servent *);
-
static int servent_fill_test_data(struct servent_test_data *);
static int servent_test_correctness(struct servent *, void *);
static int servent_test_getservbyname(struct servent *, void *);
@@ -76,7 +74,7 @@
static void usage(void) __attribute__((__noreturn__));
IMPLEMENT_TEST_DATA(servent)
-IMPLEMENT_FILE_SNAPSHOT(servent)
+IMPLEMENT_TEST_FILE_SNAPSHOT(servent)
IMPLEMENT_1PASS_TEST(servent)
IMPLEMENT_2PASS_TEST(servent)
@@ -284,7 +282,7 @@
setservent(1);
while ((serv = getservent()) != NULL) {
- test_data_append(td, serv);
+ TEST_DATA_APPEND(servent, td, serv);
}
endservent();
@@ -321,16 +319,6 @@
return (-1);
}
-static int
-check_servent_ambiguity_func(struct servent *serv, void *mdata)
-{
-
- assert(serv != NULL);
- assert(mdata != NULL);
-
- return (!compare_servent(serv, (struct servent *)mdata, mdata));
-}
-
/* servent_check_ambiguity() is needed when one port+proto is associated with
* more than one service (these cases are usually marked as PROBLEM in
* /etc/services. This functions is needed also when one service+proto is
@@ -340,8 +328,8 @@
servent_check_ambiguity(struct servent_test_data *td, struct servent *serv)
{
- return (test_data_foreach(td, check_servent_ambiguity_func,
- (void *)serv) == 0 ? -1 : 0);
+ return (TEST_DATA_FIND(servent, td, serv, compare_servent,
+ NULL) != NULL ? 0 : -1);
}
static int
@@ -415,8 +403,8 @@
static int
servent_test_getservent(struct servent *serv, void *mdata)
{
- /* Only correctness should be checked when doing 1-pass test for
- * getservent(). Correctness is always checked in servent_1pass_test */
+ /* Only correctness can be checked when doing 1-pass test for
+ * getservent(). */
return (servent_test_correctness(serv, NULL));
}
@@ -424,7 +412,7 @@
usage(void)
{
(void)fprintf(stderr,
- "Usage: %s [-dnpe2]\n",
+ "Usage: %s [-dnpe2] [-s <file>]\n",
getprogname());
exit(1);
}
@@ -465,8 +453,8 @@
usage();
}
- test_data_init(&td, clone_servent, free_servent);
- test_data_init(&td_snap, clone_servent, free_servent);
+ TEST_DATA_INIT(servent, &td, clone_servent, free_servent);
+ TEST_DATA_INIT(servent, &td_snap, clone_servent, free_servent);
if (snapshot_file != NULL) {
if (access(snapshot_file, W_OK | R_OK) != 0) {
if (errno == ENOENT)
@@ -480,54 +468,55 @@
goto fin;
}
} else
- snapshot_read(snapshot_file, &td_snap,
- servent_read_snapshot_func);
+ TEST_SNAPSHOT_FILE_READ(servent, snapshot_file,
+ &td_snap, servent_read_snapshot_func);
}
servent_fill_test_data(&td);
switch (method) {
case TEST_GETSERVBYNAME:
if (snapshot_file == NULL)
- rv = servent_1pass_test(&td,
+ rv = DO_1PASS_TEST(servent, &td,
servent_test_getservbyname, (void *)&td);
else
- rv = servent_1pass_test(&td_snap,
+ rv = DO_1PASS_TEST(servent, &td_snap,
servent_test_getservbyname, (void *)&td_snap);
break;
case TEST_GETSERVBYPORT:
if (snapshot_file == NULL)
- rv = servent_1pass_test(&td,
+ rv = DO_1PASS_TEST(servent, &td,
servent_test_getservbyport, (void *)&td);
else
- rv = servent_1pass_test(&td_snap,
+ rv = DO_1PASS_TEST(servent, &td_snap,
servent_test_getservbyport, (void *)&td_snap);
break;
case TEST_GETSERVENT:
if (snapshot_file == NULL)
- rv = servent_1pass_test(&td, servent_test_getservent,
+ rv = DO_1PASS_TEST(servent, &td, servent_test_getservent,
(void *)&td);
else
- rv = servent_2pass_test(&td, &td_snap,
+ rv = DO_2PASS_TEST(servent, &td, &td_snap,
compare_servent, NULL);
break;
case TEST_GETSERVENT_2PASS:
- test_data_init(&td_2pass, clone_servent, free_servent);
+ TEST_DATA_INIT(servent, &td_2pass, clone_servent, free_servent);
servent_fill_test_data(&td_2pass);
- rv = servent_2pass_test(&td, &td_2pass,
+ rv = DO_2PASS_TEST(servent, &td, &td_2pass,
compare_servent, NULL);
- test_data_destroy(&td_2pass);
+ TEST_DATA_DESTROY(servent, &td_2pass);
break;
case TEST_BUILD_SNAPSHOT:
- rv = snapshot_write(snapshot_file, &td, sdump_servent);
+ rv = TEST_SNAPSHOT_FILE_WRITE(servent, snapshot_file, &td,
+ sdump_servent);
break;
default:
- rv = -1;
+ rv = 0;
break;
};
fin:
- test_data_destroy(&td_snap);
- test_data_destroy(&td);
+ TEST_DATA_DESTROY(servent, &td_snap);
+ TEST_DATA_DESTROY(servent, &td);
free(snapshot_file);
return (rv);
}
==== //depot/projects/soc2006/nss_ldap_cached/src/tools/regression/lib/libc/nss/test-getserv.t#3 (text+ko) ====
@@ -18,8 +18,12 @@
make $executable 2>&1 > /dev/null
-echo 1..4
+echo 1..8
do_test 1 'getservbyname()' '-n'
do_test 2 'getservbyport()' '-p'
do_test 3 'getservent()' '-e'
do_test 4 'getservent() 2-pass' '-2'
+do_test 5 'building snapshot, if needed' '-s snapshot'
+do_test 6 'getservbyname() snapshot' '-n -s snapshot'
+do_test 7 'getservbyport() snapshot' '-p -s snapshot'
+do_test 8 'getservent() snapshot' '-e -s snapshot'
==== //depot/projects/soc2006/nss_ldap_cached/src/tools/regression/lib/libc/nss/testutil.h#4 (text+ko) ====
@@ -41,22 +41,36 @@
STAILQ_HEAD(ent_head, ent##_entry) snapshot_data; \
}; \
\
-static void test_data_init(struct ent##_test_data *, \
+void __##ent##_test_data_init(struct ent##_test_data *, \
void (*)(struct ent *, struct ent const *), \
void (*freef)(struct ent *)); \
-static void test_data_destroy(struct ent##_test_data *); \
+void __##ent##_test_data_destroy(struct ent##_test_data *); \
\
-static void test_data_append(struct ent##_test_data *, struct ent *data);\
-static int test_data_foreach(struct ent##_test_data *, int (*)(struct ent *,\
+void __##ent##_test_data_append(struct ent##_test_data *, struct ent *data);\
+int __##ent##_test_data_foreach(struct ent##_test_data *, int (*)(struct ent *,\
void *), void *); \
-static int test_data_compare(struct ent##_test_data *, \
+int __##ent##_test_data_compare(struct ent##_test_data *, \
struct ent##_test_data *, int (*)(struct ent *, struct ent *, \
void *), void *); \
-static void test_data_clear(struct ent##_test_data *);
+struct ent *__##ent##_test_data_find(struct ent##_test_data *, struct ent *,\
+ int (*)(struct ent *, struct ent *, void *), void *); \
+void __##ent##_test_data_clear(struct ent##_test_data *);
+
+#define TEST_DATA_INIT(ent, td, clonef, freef)\
+ __##ent##_test_data_init(td, clonef, freef)
+#define TEST_DATA_DESTROY(ent, td) __##ent##_test_data_destroy(td)
+#define TEST_DATA_APPEND(ent, td, d) __##ent##_test_data_append(td, d)
+#define TEST_DATA_FOREACH(ent, td, f, mdata)\
+ __##ent##_test_data_foreach(td, f, mdata)
+#define TEST_DATA_COMPARE(ent, td1, td2, fcmp, mdata)\
+ __##ent##_test_data_compare(td1, td2, fcmp, mdata);
+#define TEST_DATA_FIND(ent, td, d, fcmp, mdata)\
+ __##ent##_test_data_find(td, d, fcmp, mdata)
+#define TEST_DATA_CLEAR(ent, td) __##ent##_test_data_clear(td)
#define IMPLEMENT_TEST_DATA(ent) \
-static void \
-test_data_init(struct ent##_test_data *td, \
+void \
+__##ent##_test_data_init(struct ent##_test_data *td, \
void (*clonef)(struct ent *, struct ent const *), \
void (*freef)(struct ent *)) \
{ \
@@ -70,14 +84,14 @@
STAILQ_INIT(&td->snapshot_data); \
} \
\
-static void \
-test_data_destroy(struct ent##_test_data *td) \
+void \
+__##ent##_test_data_destroy(struct ent##_test_data *td) \
{ \
- test_data_clear(td); \
+ __##ent##_test_data_clear(td); \
} \
\
-static void \
-test_data_append(struct ent##_test_data *td, struct ent *app_data) \
+void \
+__##ent##_test_data_append(struct ent##_test_data *td, struct ent *app_data) \
{ \
struct ent##_entry *e; \
\
@@ -92,8 +106,8 @@
STAILQ_INSERT_TAIL(&td->snapshot_data, e, entries); \
} \
\
-static int \
-test_data_foreach(struct ent##_test_data *td, \
+int \
+__##ent##_test_data_foreach(struct ent##_test_data *td, \
int (*forf)(struct ent *, void *), void *mdata) \
{ \
struct ent##_entry *e; \
@@ -112,8 +126,8 @@
return (rv); \
} \
\
-static int \
-test_data_compare(struct ent##_test_data *td1, struct ent##_test_data *td2,\
+int \
+__##ent##_test_data_compare(struct ent##_test_data *td1, struct ent##_test_data *td2,\
int (*cmp_func)(struct ent *, struct ent *, void *), void *mdata)\
{ \
struct ent##_entry *e1, *e2; \
@@ -143,8 +157,30 @@
return (rv); \
} \
\
-static void \
-test_data_clear(struct ent##_test_data *td) \
+struct ent * \
+__##ent##_test_data_find(struct ent##_test_data *td, struct ent *data, \
+ int (*cmp)(struct ent *, struct ent *, void *), void *mdata) \
+{ \
+ struct ent##_entry *e; \
+ struct ent *result; \
+ \
+ assert(td != NULL); \
+ assert(cmp != NULL); \
+ \
+ result = NULL; \
+ STAILQ_FOREACH(e, &td->snapshot_data, entries) { \
+ if (cmp(&e->data, data, mdata) == 0) { \
+ result = &e->data; \
+ break; \
+ } \
+ } \
+ \
+ return (result); \
+} \
+ \
+ \
+void \
+__##ent##_test_data_clear(struct ent##_test_data *td) \
{ \
struct ent##_entry *e; \
assert(td != NULL); \
@@ -159,27 +195,31 @@
}
\
-#define DECLARE_FILE_SNAPSHOT(ent) \
+#define DECLARE_TEST_FILE_SNAPSHOT(ent) \
struct ent##_snp_param { \
FILE *fp; \
void (*sdump_func)(struct ent *, char *, size_t); \
}; \
\
-static int snapshot_write_func(struct ent *, void *); \
-static int snapshot_write(char const *, struct ent##_test_data *, \
+int __##ent##_snapshot_write_func(struct ent *, void *); \
+int __##ent##_snapshot_write(char const *, struct ent##_test_data *, \
void (*)(struct ent *, char *, size_t)); \
-static int snapshot_read(char const *, struct ent##_test_data *, \
+int __##ent##_snapshot_read(char const *, struct ent##_test_data *, \
int (*)(struct ent *, char *));
+
+#define TEST_SNAPSHOT_FILE_WRITE(ent, fname, td, f)\
+ __##ent##_snapshot_write(fname, td, f)
+#define TEST_SNAPSHOT_FILE_READ(ent, fname, td, f)\
+ __##ent##_snapshot_read(fname, td, f)
-#define IMPLEMENT_FILE_SNAPSHOT(ent) \
-static int \
-snapshot_write_func(struct ent *data, void *mdata) \
+#define IMPLEMENT_TEST_FILE_SNAPSHOT(ent) \
+int \
+__##ent##_snapshot_write_func(struct ent *data, void *mdata) \
{ \
char buffer[1024]; \
struct ent##_snp_param *param; \
\
assert(data != NULL); \
- assert(mdata != NULL); \
\
param = (struct ent##_snp_param *)mdata; \
param->sdump_func(data, buffer, sizeof(buffer)); \
@@ -189,8 +229,8 @@
return (0); \
} \
\
-static int \
-snapshot_write(char const *fname, struct ent##_test_data *td, \
+int \
+__##ent##_snapshot_write(char const *fname, struct ent##_test_data *td, \
void (*sdump_func)(struct ent *, char *, size_t)) \
{ \
struct ent##_snp_param param; \
@@ -203,14 +243,14 @@
return (-1); \
\
param.sdump_func = sdump_func; \
- test_data_foreach(td, snapshot_write_func, ¶m); \
+ __##ent##_test_data_foreach(td, __##ent##_snapshot_write_func, ¶m); \
fclose(param.fp); \
\
return (0); \
} \
\
-static int \
-snapshot_read(char const *fname, struct ent##_test_data *td, \
+int \
+__##ent##_snapshot_read(char const *fname, struct ent##_test_data *td, \
int (*read_func)(struct ent *, char *)) \
{ \
char buffer[1024]; \
@@ -239,7 +279,7 @@
\
rv = read_func(&data, s); \
if (rv == 0) { \
- test_data_append(td, &data); \
+ __##ent##_test_data_append(td, &data); \
td->free_func(&data); \
} \
} \
@@ -251,36 +291,42 @@
}
#define DECLARE_1PASS_TEST(ent) \
-static int ent##_1pass_test(struct ent##_test_data *, \
+int __##ent##_1pass_test(struct ent##_test_data *, \
int (*)(struct servent *, void *), \
void *);
+
+#define DO_1PASS_TEST(ent, td, f, mdata)\
+ __##ent##_1pass_test(td, f, mdata)
#define IMPLEMENT_1PASS_TEST(ent) \
-static int \
-ent##_1pass_test(struct ent##_test_data *td, \
+int \
+__##ent##_1pass_test(struct ent##_test_data *td, \
int (*tf)(struct servent *, void *), \
void *mdata) \
{ \
int rv; \
- rv = test_data_foreach(td, tf, mdata); \
+ rv = __##ent##_test_data_foreach(td, tf, mdata); \
\
return (rv); \
}
#define DECLARE_2PASS_TEST(ent) \
-static int ent##_2pass_test(struct ent##_test_data *, \
+int __##ent##_2pass_test(struct ent##_test_data *, \
struct ent##_test_data *, \
int (*)(struct ent *, struct ent *, void *), void *);
+#define DO_2PASS_TEST(ent, td1, td2, f, mdata)\
+ __##ent##_2pass_test(td1, td2, f, mdata)
+
#define IMPLEMENT_2PASS_TEST(ent) \
-static int \
-ent##_2pass_test(struct ent##_test_data *td1, \
+int \
+__##ent##_2pass_test(struct ent##_test_data *td1, \
struct ent##_test_data *td2, \
int (*cmp_func)(struct ent *, struct ent *, void *), \
void *cmp_mdata) \
{ \
int rv; \
\
- rv = test_data_compare(td1, td2, cmp_func, cmp_mdata); \
+ rv = __##ent##_test_data_compare(td1, td2, cmp_func, cmp_mdata); \
return (rv); \
}
More information about the p4-projects
mailing list