From owner-p4-projects@FreeBSD.ORG Thu Jul 14 12:39:41 2005 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A70AD16A420; Thu, 14 Jul 2005 12:39:40 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 52EE616A41C for ; Thu, 14 Jul 2005 12:39:40 +0000 (GMT) (envelope-from soc-bushman@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0843043D48 for ; Thu, 14 Jul 2005 12:39:40 +0000 (GMT) (envelope-from soc-bushman@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j6ECdecK068456 for ; Thu, 14 Jul 2005 12:39:40 GMT (envelope-from soc-bushman@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j6ECddms068452 for perforce@freebsd.org; Thu, 14 Jul 2005 12:39:39 GMT (envelope-from soc-bushman@freebsd.org) Date: Thu, 14 Jul 2005 12:39:39 GMT Message-Id: <200507141239.j6ECddms068452@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to soc-bushman@freebsd.org using -f From: soc-bushman To: Perforce Change Reviews Cc: Subject: PERFORCE change 80147 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jul 2005 12:39:41 -0000 http://perforce.freebsd.org/chv.cgi?CH=80147 Change 80147 by soc-bushman@soc-bushman_stinger on 2005/07/14 12:39:36 rpc almost finished, most of tests for getserv* done Affected files ... .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getservent.c#11 edit .. //depot/projects/soc2005/nsswitch_cached/tests/Makefile#1 add .. //depot/projects/soc2005/nsswitch_cached/tests/common/test.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/getrpcent_test/Makefile#1 add .. //depot/projects/soc2005/nsswitch_cached/tests/getrpcent_test/getrpcent.c#1 add .. //depot/projects/soc2005/nsswitch_cached/tests/getrpcent_test/getrpcent.h#1 add .. //depot/projects/soc2005/nsswitch_cached/tests/getrpcent_test/getrpcent_test.c#1 add .. //depot/projects/soc2005/nsswitch_cached/tests/getservent_test/Makefile#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/getservent_test/getservent.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/getservent_test/getservent.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/getservent_test/getservent_test.c#2 edit Differences ... ==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getservent.c#11 (text+ko) ==== @@ -132,14 +132,14 @@ }; }; -static int wrap_getservbyname_r(struct key key, struct servent *serv, char *buffer, - size_t bufsize, struct servent **res); -static int wrap_getservbyport_r(struct key key, struct servent *serv, char *buffer, - size_t bufsize, struct servent **res); -static int wrap_getservent_r(struct key key, struct servent *serv, char *buffer, - size_t bufsize, struct servent **res); +static int wrap_getservbyname_r(struct key, struct servent *, char *, + size_t, struct servent **); +static int wrap_getservbyport_r(struct key, struct servent *, char *, + size_t, struct servent **); +static int wrap_getservent_r(struct key, struct servent *, char *, + size_t, struct servent **); static struct servent *getserv(int (*fn)(struct key, struct servent *, char *, - size_t, struct servent **), struct key key); + size_t, struct servent **), struct key); static int @@ -364,6 +364,7 @@ } } + rv = NS_NOTFOUND; switch (serv_mdata->how) { case nss_lt_name: if (strcmp(name, serv->s_name) == 0) @@ -432,8 +433,8 @@ default: break; }; + st->compat_mode_active = 0; - return (NS_UNAVAIL); } @@ -549,7 +550,6 @@ rv = yp_first(st->yp_domain, "services.byname", &st->yp_key, &st->yp_keylen, &resultbuf, &resultbuflen); if (rv) { - st->yp_stepping = 0; rv = NS_NOTFOUND; goto fin; } @@ -660,9 +660,9 @@ break; case ENDSERVENT: (void)nsdispatch(retval, compat_dtab, NSDB_SERVICES_COMPAT, "endservent", compat_src); - break; + break; default: - break; + break; } return (NS_UNAVAIL); @@ -699,7 +699,7 @@ } int -getservbyport_r(int port, const char *proto, struct servent *serv, char *buffer, +getservbyport_r)(int port, const char *proto, struct servent *serv, char *buffer, size_t bufsize, struct servent **result) { static const struct servent_mdata mdata = { nss_lt_id, 0 }; @@ -813,7 +813,7 @@ wrap_getservent_r(struct key key, struct servent *serv, char *buffer, size_t bufsize, struct servent **res) { - return (getservent_r(serv, buffer, bufsize, res)); + return getservent_r(serv, buffer, bufsize, res)); } static struct servent * @@ -853,6 +853,7 @@ } while (res == NULL && rv == ERANGE); if (rv != 0) errno = rv; + return (res); } @@ -861,8 +862,8 @@ { struct key key; - key.name=name; - key.proto=proto; + key.name = name; + key.proto = proto; return (getserv(wrap_getservbyname_r, key)); } @@ -872,8 +873,8 @@ { struct key key; - key.port=port; - key.proto=proto; + key.port = port; + key.proto = proto; return (getserv(wrap_getservbyport_r, key)); } @@ -882,9 +883,9 @@ getservent() { struct key key; - - key.proto=NULL; - key.port=0; + + key.proto =NULL; + key.port = 0; return (getserv(wrap_getservent_r, key)); } ==== //depot/projects/soc2005/nsswitch_cached/tests/common/test.c#2 (text+ko) ==== @@ -111,6 +111,9 @@ break; } __test_log1("<== %s\n\n", test->name); + + if (retval == T_FAILED) + break; } if (retval == T_PASSED) ==== //depot/projects/soc2005/nsswitch_cached/tests/getservent_test/Makefile#2 (text+ko) ==== @@ -4,8 +4,6 @@ PROGNAME=getservent_test MAN= -YP=1 - SRCS=getservent_test.c getservent.c WARNS?=2 CFLAGS+= -I${.CURDIR}/../../src/lib/libc -I${.CURDIR}/../../src/lib/libc/include ==== //depot/projects/soc2005/nsswitch_cached/tests/getservent_test/getservent.c#2 (text+ko) ==== @@ -134,14 +134,14 @@ }; }; -static int wrap_getservbyname_r(struct key key, struct servent *serv, char *buffer, - size_t bufsize, struct servent **res); -static int wrap_getservbyport_r(struct key key, struct servent *serv, char *buffer, - size_t bufsize, struct servent **res); -static int wrap_getservent_r(struct key key, struct servent *serv, char *buffer, - size_t bufsize, struct servent **res); +static int wrap_getservbyname_r(struct key, struct servent *, char *, + size_t, struct servent **); +static int wrap_getservbyport_r(struct key, struct servent *, char *, + size_t, struct servent **); +static int wrap_getservent_r(struct key, struct servent *, char *, + size_t, struct servent **); static struct servent *getserv(int (*fn)(struct key, struct servent *, char *, - size_t, struct servent **), struct key key); + size_t, struct servent **), struct key); static int @@ -366,6 +366,7 @@ } } + rv = NS_NOTFOUND; switch (serv_mdata->how) { case nss_lt_name: if (strcmp(name, serv->s_name) == 0) @@ -434,8 +435,8 @@ default: break; }; + st->compat_mode_active = 0; - return (NS_UNAVAIL); } @@ -551,7 +552,6 @@ rv = yp_first(st->yp_domain, "services.byname", &st->yp_key, &st->yp_keylen, &resultbuf, &resultbuflen); if (rv) { - st->yp_stepping = 0; rv = NS_NOTFOUND; goto fin; } @@ -662,9 +662,9 @@ break; case ENDSERVENT: (void)nsdispatch(retval, compat_dtab, NSDB_SERVICES_COMPAT, "endservent", compat_src); - break; + break; default: - break; + break; } return (NS_UNAVAIL); @@ -855,6 +855,7 @@ } while (res == NULL && rv == ERANGE); if (rv != 0) errno = rv; + return (res); } @@ -863,8 +864,8 @@ { struct key key; - key.name=name; - key.proto=proto; + key.name = name; + key.proto = proto; return (getserv(wrap_getservbyname_r, key)); } @@ -874,8 +875,8 @@ { struct key key; - key.port=port; - key.proto=proto; + key.port = port; + key.proto = proto; return (getserv(wrap_getservbyport_r, key)); } @@ -884,9 +885,9 @@ DECORATED(getservent)() { struct key key; - - key.proto=NULL; - key.port=0; + + key.proto =NULL; + key.port = 0; return (getserv(wrap_getservent_r, key)); } ==== //depot/projects/soc2005/nsswitch_cached/tests/getservent_test/getservent.h#2 (text+ko) ==== @@ -6,6 +6,8 @@ #include "../common/debug.h" #include +#define NSDB_SERVICES_COMPAT "services_compat" + int DECORATED(getservbyname_r)(const char *, const char *, struct servent *, char *, size_t, struct servent **); int DECORATED(getservbyport_r)(int, const char *, struct servent *, char *, ==== //depot/projects/soc2005/nsswitch_cached/tests/getservent_test/getservent_test.c#2 (text+ko) ==== @@ -8,6 +8,59 @@ #include #include +static struct servent * +clone_servent(struct servent *serv) +{ + struct servent *res; + char **cp; + int aliases_num; + + if (serv == NULL) + return (NULL); + + res = (struct servent *)malloc(sizeof(struct servent)); + assert(res != NULL); + memset(res, 0, sizeof(struct servent)); + + res->s_name = strdup(serv->s_name); + assert(res->s_name != NULL); + res->s_proto = strdup(serv->s_proto); + assert(res->s_proto != NULL); + res->s_port = serv->s_port; + + aliases_num = 0; + for (cp = serv->s_aliases; *cp; ++cp) + ++aliases_num; + + res->s_aliases = (char **)malloc((aliases_num+1) * (sizeof(char *))); + assert(res->s_aliases != NULL); + memset(res->s_aliases, 0, (aliases_num+1) * (sizeof(char *))); + + for (cp = serv->s_aliases; *cp; ++cp) { + res->s_aliases[cp - serv->s_aliases] = strdup(*cp); + assert(res->s_aliases[cp - serv->s_aliases] != NULL); + } + + return res; +} + +static void +free_servent(struct servent *serv) +{ + char **cp; + + if (serv == NULL) + return; + + free(serv->s_name); + free(serv->s_proto); + + for (cp = serv->s_aliases; *cp; ++cp) + free(*cp); + + free(serv); +} + static void result_info(int rv, struct servent *result) { @@ -138,6 +191,252 @@ return ((rv == 0) && (errno == 0)) ? T_PASSED : T_FAILED; } +struct servent * +trivial_getservbyname(const char *name, const char *proto) +{ + char **cp; + struct servent *result; + + DECORATED(setservent)(1); + while ( (result = DECORATED(getservent)()) != NULL) { + if (strcmp(result->s_name, name) == 0) + goto gotname; + + for (cp=result->s_aliases; *cp; ++cp) + if (strcmp(*cp, name) == 0) + goto gotname; + + continue; + +gotname: + if (strcmp(result->s_proto, proto) == 0) + break; + } + + DECORATED(endservent)(); + return (result); +} + +struct servent * +trivial_getservbyport(int port, const char *proto) +{ + struct servent *result; + + DECORATED(setservent)(1); + while ( (result = DECORATED(getservent)()) != NULL) { + if ((result->s_port == port) && (strcmp(result->s_proto, proto) == 0)) + break; + } + + DECORATED(endservent)(); + return (result); +} + +static enum __test_result +getservbyname_test2() +{ + struct servent *result_model; + struct servent *result1; + struct servent *result2; + + int rv; + char **cp; + + setservent(1); + while ( (result_model = getservent()) != NULL) { + __test_log2("trying name: %s, proto: %s\n", result_model->s_name, result_model->s_proto); + + result1 = clone_servent( DECORATED(getservbyname)(result_model->s_name, result_model->s_proto) ); + result2 = clone_servent( trivial_getservbyname(result_model->s_name, result_model->s_proto) ); + +// result_info(errno, result1); +// result_info(errno, result2); + + rv = result_compare(result1, result2); + free_servent(result1); + free_servent(result2); + if (rv != 0) + break; + + for (cp = result_model->s_aliases; *cp; ++cp) + { + __test_log2("trying name: %s, proto: %s\n", *cp, result_model->s_proto); + + result1 = clone_servent( DECORATED(getservbyname)(*cp, result_model->s_proto) ); + result2 = clone_servent( trivial_getservbyname(*cp, result_model->s_proto) ); + + rv = result_compare(result1, result2); + free_servent(result1); + free_servent(result2); + if (rv != 0) + break; + } + + if (rv != 0) + break; + } + + endservent(); + return ((rv == 0) && (errno == 0)) ? T_PASSED : T_FAILED; +} + +static enum __test_result +getservbyname_test3() +{ + struct servent *result_model; + struct servent *result1; + struct servent *result2; + + int counter; + int rv; + char **cp; + + counter = 0; + setservent(1); + while ( (result_model = getservent()) != NULL) { + switch (counter % 3) { + case 0: + break; + case 1: + result_model->s_name[0] = 'a'; + break; + case 2: + result_model->s_proto[0] = 'b'; + break; + } + __test_log2("trying name: %s, proto: %s\n", result_model->s_name, result_model->s_proto); + + result1 = clone_servent( DECORATED(getservbyname)(result_model->s_name, result_model->s_proto) ); + result2 = clone_servent( trivial_getservbyname(result_model->s_name, result_model->s_proto) ); + +// result_info(errno, result1); +// result_info(errno, result2); + + rv = result_compare(result1, result2); + free_servent(result1); + free_servent(result2); + if (rv != 0) + break; + + for (cp = result_model->s_aliases; *cp; ++cp) + { + __test_log2("trying name: %s, proto: %s\n", *cp, result_model->s_proto); + + result1 = clone_servent( DECORATED(getservbyname)(*cp, result_model->s_proto) ); + result2 = clone_servent( trivial_getservbyname(*cp, result_model->s_proto) ); + + rv = result_compare(result1, result2); + free_servent(result1); + free_servent(result2); + if (rv != 0) + break; + } + + if (rv != 0) + break; + + ++counter; + } + + endservent(); + return ((rv == 0) && (errno == 0)) ? T_PASSED : T_FAILED; +} + +static enum __test_result +getservbyport_test2() +{ + struct servent *result_model; + struct servent *result1; + struct servent *result2; + + int rv; + + setservent(1); + while ( (result_model = getservent()) != NULL) { + __test_log2("trying port: %d, proto: %s\n", result_model->s_port, result_model->s_proto); + + result1 = clone_servent( DECORATED(getservbyport)(result_model->s_port, result_model->s_proto) ); + result2 = clone_servent( trivial_getservbyport(result_model->s_port, result_model->s_proto) ); + + rv = result_compare(result1, result2); + free_servent(result1); + free_servent(result2); + if (rv != 0) + break; + } + + endservent(); + return ((rv == 0) && (errno == 0)) ? T_PASSED : T_FAILED; +} + +static enum __test_result +getservbyport_test3() +{ + struct servent *result_model; + struct servent *result1; + struct servent *result2; + + int counter; + int rv; + + counter = 0; + setservent(1); + while ( (result_model = getservent()) != NULL) { + switch (counter % 3) { + case 0: + break; + case 1: + result_model->s_port = ntohs(result_model->s_port); + break; + case 2: + result_model->s_proto[0] = 'b'; + break; + } + __test_log2("trying port: %d, proto: %s\n", result_model->s_port, result_model->s_proto); + + result1 = clone_servent( DECORATED(getservbyport)(result_model->s_port, result_model->s_proto) ); + result2 = clone_servent( trivial_getservbyport(result_model->s_port, result_model->s_proto) ); + + rv = result_compare(result1, result2); + free_servent(result1); + free_servent(result2); + if (rv != 0) + break; + + ++counter; + } + + endservent(); + return ((rv == 0) && (errno == 0)) ? T_PASSED : T_FAILED; +} + +static enum __test_result +servent_stress_test() +{ + const size_t bigsize = 65000; + + char *bigname; + char *bigproto; + + (void)DECORATED(getservbyname)("",""); + (void)DECORATED(getservbyport)(-1,""); + + bigname = (char *)malloc(bigsize); + assert(bigname != NULL); + memset(bigname, 'a', bigsize - 1); + bigname[bigsize - 1] = '\0'; + + bigproto = (char *)malloc(bigsize); + assert(bigproto != NULL); + memset(bigproto, 'b', bigsize - 1); + bigproto[bigsize - 1]='\0'; + + (void)DECORATED(getservbyname)(bigname, bigproto); + (void)DECORATED(getservbyport)(-1, bigproto); + + return T_PASSED; +} + int main(int argc, char *argv[]) { @@ -159,6 +458,26 @@ assert(tinfo != NULL); __register_test_info(tsystem, tinfo); + tinfo = __create_test_info("getservbyname_test2", getservbyname_test2, 1); + assert(tinfo != NULL); + __register_test_info(tsystem, tinfo); + + tinfo = __create_test_info("getservbyport_test2", getservbyport_test2, 1); + assert(tinfo != NULL); + __register_test_info(tsystem, tinfo); + + tinfo = __create_test_info("getservbyname_test3", getservbyname_test3, 1); + assert(tinfo != NULL); + __register_test_info(tsystem, tinfo); + + tinfo = __create_test_info("getservbyport_test3", getservbyport_test3, 1); + assert(tinfo != NULL); + __register_test_info(tsystem, tinfo); + + tinfo = __create_test_info("servent_stress_test", servent_stress_test, 1); + assert(tinfo != NULL); + __register_test_info(tsystem, tinfo); + __process_tests(tsystem, NULL, NULL); __destroy_test_system(tsystem); return 0;