Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Jul 2005 15:45:50 GMT
From:      soc-bushman <soc-bushman@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 80270 for review
Message-ID:  <200507151545.j6FFjoDo003345@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=80270

Change 80270 by soc-bushman@soc-bushman_stinger on 2005/07/15 15:45:26

	protocols test version finished, some syntax errors corrected

Affected files ...

.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getservent.c#12 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/getprotoent_test/Makefile#2 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/getprotoent_test/getproto.c#2 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/getprotoent_test/getprotoent.c#2 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/getprotoent_test/getprotoent.h#2 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/getprotoent_test/getprotoent_test.c#2 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/getprotoent_test/getprotoname.c#2 edit

Differences ...

==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getservent.c#12 (text+ko) ====

@@ -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 *

==== //depot/projects/soc2005/nsswitch_cached/tests/getprotoent_test/Makefile#2 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/tests/getprotoent_test/getproto.c#2 (text+ko) ====

@@ -37,7 +37,7 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD: src/lib/libc/net/getproto.c,v 1.4 2005/04/19 14:41:13 ume Exp $");
 
-#include <netdb.h>
+/*#include <netdb.h>
 #include "netdb_private.h"
 
 int
@@ -65,3 +65,4 @@
 		return (NULL);
 	return (&pd->proto);
 }
+*/

==== //depot/projects/soc2005/nsswitch_cached/tests/getprotoent_test/getprotoent.c#2 (text+ko) ====

@@ -37,18 +37,491 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD: src/lib/libc/net/getprotoent.c,v 1.5 2005/04/28 15:32:55 ume Exp $");
 
+#include "getprotoent.h"
+
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <errno.h>
 #include <netdb.h>
+#include <nsswitch.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "namespace.h"
+#include "nss_tls.h"
 #include "reentrant.h"
 #include "un-namespace.h"
-#include "netdb_private.h"
+//#include "netdb_private.h"
+
+/* nsswitch declarations */
+enum constants
+{
+	SETPROTOENT = 1,
+	ENDPROTOENT = 2,
+	PROTOENT_STORAGE_INITIAL	= 1 << 10, /* 1 KByte */
+	PROTOENT_STORAGE_MAX		= 1 << 20, /* 1 MByte */	
+};
+
+static const ns_src defaultsrc[] = {
+	{ NSSRC_FILES, NS_SUCCESS },
+	{ NULL, 0 }
+};
+
+/* files backend declarations */
+struct files_state
+{
+	FILE	*fp;
+	int	stayopen;
+};
+static	void	files_endstate(void *);
+NSS_TLS_HANDLING(files);
+
+static	int	files_protoent(void *, void *, va_list);
+static	int	files_setprotoent(void *, void *, va_list);
+
+/* get** wrappers for get**_r functions declarations */
+struct protoent_state {
+	struct protoent pe;
+	char		*buffer;
+	size_t	bufsize;
+};
+static	void	protoent_endstate(void *);
+NSS_TLS_HANDLING(protoent);
+
+union key {
+	const char *name;
+	int	proto;
+};
+
+static	int	wrap_getprotobyname_r(union key, struct protoent *, char *, 
+			size_t, struct protoent **);
+static	int	wrap_getprotobynumber_r(union key, struct protoent *, char *, 
+			size_t, struct protoent **);
+static	int	wrap_getprotoent_r(union key, struct protoent *, char *, 
+			size_t, struct protoent **);
+static	struct protoent *getpe(int (*fn)(union key, struct protoent *, char *, 
+			size_t, struct protoent **), union key);				
+
+static int
+protoent_unpack(char *p, struct protoent *pe, char **aliases,
+	size_t aliases_size, int *errnop)
+{
+	char *cp, **q, *endp;
+	long l;
+	
+	if (*p == '#')
+		return (-1);
+	cp = strpbrk(p, "#\n");
+	if (cp != NULL)
+		*cp = '\0';
+	pe->p_name = p;
+	cp = strpbrk(p, " \t");
+	if (cp == NULL)
+		return (-1);
+	*cp++ = '\0';
+	while (*cp == ' ' || *cp == '\t')
+		cp++;
+	p = strpbrk(cp, " \t");
+	if (p != NULL)
+		*p++ = '\0';
+	l = strtol(cp, &endp, 10);
+	if (endp == cp || *endp != '\0' || l < 0 || l > USHRT_MAX)
+		return -1;
+	pe->p_proto = l;
+	q = pe->p_aliases = aliases;
+	if (p != NULL) {
+		cp = p;
+		while (cp && *cp) {
+			if (*cp == ' ' || *cp == '\t') {
+				cp++;
+				continue;
+			}
+			if (q < &(aliases[aliases_size - 1]))
+				*q++ = cp;
+			else {
+				*errnop = ERANGE;
+				return -1;
+			}
+			cp = strpbrk(cp, " \t");
+			if (cp != NULL)
+				*cp++ = '\0';
+		}
+	}
+	*q = NULL;
+	return (0);	
+}
+			
+/* files backend implementation */
+static	void
+files_endstate(void *p)
+{
+	FILE * f;
+	
+	if (p == NULL)
+		return;
+	
+	f = ((struct files_state *)p)->fp;
+	if (f != NULL)
+		fclose(f);
+	
+	free(p);
+}
+
+static int
+files_protoent(void *retval, void *mdata, va_list ap)
+{
+	char		*name;
+	int		number;
+	struct protoent	*pe;
+	char		*buffer;
+	size_t	bufsize;
+	int		*errnop;
+	
+	char		*line;
+	size_t	linesize;
+	char		**aliases;
+	int		aliases_size;
+	char		**rp;
+	
+	struct files_state	*st;
+	int		rv;
+	int		stayopen;
+	enum nss_lookup_type	how;
+	
+	how = (enum nss_lookup_type)mdata;
+	switch (how)
+	{
+	case nss_lt_name:
+		name = va_arg(ap, char *);
+		break;
+	case nss_lt_id:
+		number = va_arg(ap, int);
+		break;
+	case nss_lt_all:
+		break;
+	default:
+		return (NS_NOTFOUND);
+	}
+		
+	pe = va_arg(ap, struct protoent *);
+	buffer = va_arg(ap, char *);
+	bufsize = va_arg(ap, size_t);
+	errnop = va_arg(ap, int *);
+	
+	*errnop = files_getstate(&st);
+	if (*errnop != 0)
+		return (NS_UNAVAIL);
+	
+	if (st->fp == NULL && (st->fp = fopen(_PATH_PROTOCOLS, "r")) == NULL) {
+		*errnop = errno;
+		return (NS_UNAVAIL);	
+	}
+	
+	if (how == nss_lt_all)
+		stayopen = 1;
+	else {
+		rewind(st->fp);
+		stayopen = st->stayopen;
+	}
+	
+	do {
+		if ((line = fgetln(st->fp, &linesize)) == NULL) {
+			*errnop = errno;
+			rv = NS_RETURN;
+			break;
+		}
+			
+		if (bufsize <= linesize + _ALIGNBYTES + sizeof(char *)) {
+			*errnop = ERANGE;
+			rv = NS_RETURN;
+			break;
+		}
+
+		aliases = (char **)_ALIGN(&buffer[linesize+1]);
+		aliases_size = (buffer + bufsize - (char *)aliases)/sizeof(char *);
+		if (aliases_size < 1) {
+			*errnop = ERANGE;
+			rv = NS_RETURN;
+			break;
+		}
+				
+		memcpy(buffer, line, linesize);
+		buffer[linesize] = '\0';
+
+		rv = protoent_unpack(buffer, pe, aliases, aliases_size, errnop);
+		if (rv != 0) {
+			if (*errnop == 0) {
+				rv = NS_NOTFOUND;
+				continue;
+			}
+			else {
+				rv = NS_RETURN;
+				break;
+			}
+		}
+		
+		switch (how)
+		{
+		case nss_lt_name:
+			if (strcmp(pe->p_name, name) == 0)
+				goto done;
+			for (rp = pe->p_aliases; *rp != NULL; rp++) {
+				if (strcmp(*rp, name) == 0)
+					goto done;
+			}
+			rv = NS_NOTFOUND;
+			continue;			
+done:
+			rv = NS_SUCCESS;
+			break;
+		case nss_lt_id:
+			rv = (pe->p_proto == number) ? NS_SUCCESS : NS_NOTFOUND;
+			break;
+		case nss_lt_all:
+			rv = NS_SUCCESS;
+			break;
+		}
+		
+	} while (!(rv & NS_TERMINATE));
+
+	if (!stayopen && st->fp!=NULL) {
+		fclose(st->fp);
+		st->fp = NULL;
+	}
+	
+	if ((rv == NS_SUCCESS) && (retval != NULL))
+		*((struct protoent **)retval) = pe;
+			
+	return (rv);
+}
+
+static int
+files_setprotoent(void *retval, void *mdata, va_list ap)
+{
+	struct files_state	*st;
+	int	rv;
+	int	f;
+	
+	rv = files_getstate(&st);
+	if (rv != 0)
+		return (NS_UNAVAIL);
+	
+	switch ((enum constants)mdata)
+	{
+	case SETPROTOENT:
+		f = va_arg(ap,int);
+		if (st->fp == NULL)
+			st->fp = fopen(_PATH_PROTOCOLS, "r");
+		else
+			rewind(st->fp);
+		st->stayopen |= f;
+		break;
+	case ENDPROTOENT:
+		if (st->fp != NULL) {
+			fclose(st->fp);
+			st->fp = NULL;
+		}		
+		st->stayopen = 0;		
+		break;
+	default:
+		break;	
+	}
+	
+	return (NS_UNAVAIL);
+}
+
+/* get**_r functions implementation */
+int
+DECORATED(getprotobyname_r)(const char *name, struct protoent *pe, char *buffer, 
+	size_t bufsize, struct protoent **result)
+{
+	static const ns_dtab dtab[] = {
+		{ NSSRC_FILES, files_protoent, (void *)nss_lt_name },
+		{ NULL, NULL, NULL }
+	};
+	
+	int	rv, ret_errno;
+
+	ret_errno = 0;
+	*result = NULL;
+	rv = nsdispatch(result, dtab, NSDB_PROTOCOLS, "getprotobyname_r", defaultsrc,
+	    name, pe, buffer, bufsize, &ret_errno);
+	
+	if (rv == NS_SUCCESS)
+		return (0);
+	else
+		return (ret_errno);	
+}
+
+int 
+DECORATED(getprotobynumber_r)(int number, struct protoent *pe, char *buffer, 
+	size_t bufsize, struct protoent **result)
+{
+	static const ns_dtab dtab[] = {
+		{ NSSRC_FILES, files_protoent, (void *)nss_lt_id },
+		{ NULL, NULL, NULL }
+	};
+	int	rv, ret_errno;
+
+	ret_errno = 0;
+	*result = NULL;
+	rv = nsdispatch(result, dtab, NSDB_PROTOCOLS, "getprotobynumber_r", defaultsrc,
+	    number, pe, buffer, bufsize, &ret_errno);
+	
+	if (rv == NS_SUCCESS)
+		return (0);
+	else
+		return (ret_errno);		
+}
+
+int
+DECORATED(getprotoent_r)(struct protoent *pe, char *buffer, size_t bufsize,
+	struct protoent **result)
+{
+	static const ns_dtab dtab[] = {
+		{ NSSRC_FILES, files_protoent, (void *)nss_lt_all },
+		{ NULL, NULL, NULL }
+	};
+	int	rv, ret_errno;
+
+	ret_errno = 0;
+	*result = NULL;
+	rv = nsdispatch(result, dtab, NSDB_PROTOCOLS, "getprotoent_r", defaultsrc,
+	    pe, buffer, bufsize, &ret_errno);
+
+	if (rv == NS_SUCCESS)
+		return (0);
+	else
+		return (ret_errno);		
+}
+
+void 
+DECORATED(setprotoent)(int stayopen)
+{
+	static const ns_dtab dtab[] = {
+		{ NSSRC_FILES, files_setprotoent, (void *)SETPROTOENT },
+		{ NULL, NULL, NULL }
+	};
+
+	(void)nsdispatch(NULL, dtab, NSDB_PROTOCOLS, "setprotoent", defaultsrc, stayopen);
+}
+
+void 
+DECORATED(endprotoent)()
+{
+	static const ns_dtab dtab[] = {
+		{ NSSRC_FILES, files_setprotoent, (void *)ENDPROTOENT },
+		{ NULL, NULL, NULL }
+	};
+
+	(void)nsdispatch(NULL, dtab, NSDB_PROTOCOLS, "endprotoent", defaultsrc);
+}
+
+/* get** wrappers for get**_r functions implementation */
+static 	void
+protoent_endstate(void *p)
+{
+	if (p == NULL)
+		return;
+
+	free(((struct protoent_state *)p)->buffer);	
+	free(p);
+}
+
+static	int
+wrap_getprotobyname_r(union key key, struct protoent *pe, char *buffer, size_t bufsize,
+    struct protoent **res)
+{
+	return (DECORATED(getprotobyname_r)(key.name, pe, buffer, bufsize, res));
+}
+
+static	int
+wrap_getprotobynumber_r(union key key, struct protoent *pe, char *buffer, size_t bufsize,
+    struct protoent **res)
+{
+	return (DECORATED(getprotobynumber_r)(key.proto, pe, buffer, bufsize, res));
+}
+
+static	int
+wrap_getprotoent_r(union key key, struct protoent *pe, char *buffer, size_t bufsize,
+    struct protoent **res)
+{
+	return (DECORATED(getprotoent_r)(pe, buffer, bufsize, res));
+}
+
+static struct protoent *
+getpe(int (*fn)(union key, struct protoent *, char *, size_t, struct protoent **),
+    union key key)
+{
+	int		 rv;
+	struct protoent	*res;
+	struct protoent_state * st;
+		
+	rv=protoent_getstate(&st);
+	if (rv != 0) {
+		errno = rv;
+		return NULL;
+	}
+
+	if (st->buffer == NULL) {
+		st->buffer = malloc(PROTOENT_STORAGE_INITIAL);
+		if (st->buffer == NULL)
+			return (NULL);
+		st->bufsize = PROTOENT_STORAGE_INITIAL;
+	}
+	do {
+		rv = fn(key, &st->pe, st->buffer, st->bufsize, &res);
+		if (res == NULL && rv == ERANGE) {
+			free(st->buffer);
+			if ((st->bufsize << 1) > PROTOENT_STORAGE_MAX) {
+				st->buffer = NULL;
+				errno = ERANGE;
+				return (NULL);
+			}
+			st->bufsize <<= 1;
+			st->buffer = malloc(st->bufsize);
+			if (st->buffer == NULL)
+				return (NULL);
+		}
+	} while (res == NULL && rv == ERANGE);
+	if (rv != 0)
+		errno = rv;
+	
+	return (res);
+}
+
+struct protoent *
+DECORATED(getprotobyname)(const char *name)
+{
+	union key key;
+
+	key.name = name;
+	
+	return (getpe(wrap_getprotobyname_r, key));
+}
+
+struct protoent *
+DECORATED(getprotobynumber)(int number)
+{
+	union key key;
+		
+	key.proto = number;
+	
+	return (getpe(wrap_getprotobynumber_r, key));
+}
+
+struct protoent *
+DECORATED(getprotoent)()
+{
+	union key key;
+	 
+	key.proto = 0;	/* not used */
+	
+	return (getpe(wrap_getprotoent_r, key));
+}
+
 
-static struct protodata protodata;
+/*static struct protodata protodata;
 static thread_key_t protodata_key;
 static once_t protodata_init_once = ONCE_INITIALIZER;
 static int protodata_thr_keycreated = 0;
@@ -201,3 +674,4 @@
 		return (NULL);
 	return (&pd->proto);
 }
+*/

==== //depot/projects/soc2005/nsswitch_cached/tests/getprotoent_test/getprotoent.h#2 (text+ko) ====

@@ -1,0 +1,21 @@
+#ifndef __NSSWITCH_CACHED_GETPROTOENT_H__
+#define __NSSWITCH_CACHED_GETPROTOENT_H__
+
+#include "../common/test.h"
+#include "../common/debug.h"
+#include <netdb.h>
+
+int DECORATED(getprotobyname_r)(const char *, struct protoent *, char *, 
+	size_t, struct protoent **);
+int DECORATED(getprotobynumber_r)(int, struct protoent *, char *, 
+	size_t, struct protoent **);
+int DECORATED(getprotoent_r)(struct protoent *, char *, size_t,
+	struct protoent **);
+
+struct protoent *DECORATED(getprotobyname)(const char *);
+struct protoent *DECORATED(getprotobynumber)(int);
+struct protoent *DECORATED(getprotoent)();
+void DECORATED(setprotoent)(int);
+void DECORATED(endprotoent)();
+
+#endif

==== //depot/projects/soc2005/nsswitch_cached/tests/getprotoent_test/getprotoent_test.c#2 (text+ko) ====

@@ -1,6 +1,6 @@
 #include "../common/test.h"
 #include "../common/debug.h"
-#include "getrpcent.h"
+#include "getprotoent.h"
 #include <arpa/inet.h>
 #include <netdb.h>
 #include <errno.h>
@@ -9,8 +9,402 @@
 #include <stdlib.h>
 #include <string.h>
 
+static struct protoent *
+clone_protoent(struct protoent *proto)
+{
+	struct protoent *res;
+	char **cp;
+	int aliases_num;
+	
+	if (proto == NULL)
+		return (NULL);
+	
+	res = (struct protoent *)malloc(sizeof(struct protoent));
+	assert(res != NULL);
+	memset(res, 0, sizeof(struct protoent));
+		
+	res->p_name = strdup(proto->p_name);
+	assert(res->p_name != NULL);
+	res->p_proto = proto->p_proto;
+	
+	aliases_num = 0;
+	for (cp = proto->p_aliases; *cp; ++cp)
+		++aliases_num;
+	
+	res->p_aliases = (char **)malloc((aliases_num+1) * (sizeof(char *)));
+	assert(res->p_aliases != NULL);
+	memset(res->p_aliases, 0, (aliases_num+1) * (sizeof(char *)));
+	
+	for (cp = proto->p_aliases; *cp; ++cp) {
+		res->p_aliases[cp - proto->p_aliases] = strdup(*cp);
+		assert(res->p_aliases[cp - proto->p_aliases] != NULL);
+	}
+	
+	return res;
+}
+
+static void 
+free_protoent(struct protoent *proto)
+{
+	char **cp;
+	
+	if (proto == NULL)
+		return;
+	
+	free(proto->p_name);
+	
+	for (cp = proto->p_aliases; *cp; ++cp)
+		free(*cp);
+	
+	free(proto);
+}
+
+static void 
+result_info(int rv, struct protoent *result)
+{
+	if (rv == 0) {
+		if (result == NULL)
+			__test_log2("success: entry was not found\n");
+		else {
+			__test_log2("success: entry was found\n");
+			__test_log2("name: %s\n", result->p_name);
+			__test_log2("proto: %d\n", htons(result->p_proto));
+
+			if (*(result->p_aliases)!='\0') {                               
+				char ** cp;
+				
+				__test_log2("aliases:\n");
+				for (cp=result->p_aliases; *cp; ++cp)
+					__test_log2("\t\t%s\n",*cp);
+			} else
+				__test_log2("\tno aliases\n");
+		}
+	} else
+		__test_log2("failure: code=%d, details='%s'",rv,strerror(rv));
+}
+
+static  int 
+result_compare(struct protoent *proto1, struct protoent *proto2)
+{
+	char **c1, **c2;
+        
+	if (proto1 == proto2)
+		return 0;
+        
+	if ((proto1 == NULL) || (proto2 == NULL))
+		return -1;
+        
+	if ( (strcmp(proto1->p_name,proto2->p_name)!=0) ||
+		(proto1->p_proto != proto2->p_proto))
+			return -1;
+        
+	c1=proto1->p_aliases;
+	c2=proto2->p_aliases;
+	for (;*c1 && *c2; ++c1, ++c2)
+		if (strcmp(*c1,*c2)!=0)
+			return -1;
+                
+	if ((*c1!='\0') || (*c2!='\0'))
+		return -1;
+        
+	return 0;
+}
+
+static enum __test_result
+getprotoent_test1()
+{
+	struct protoent *result1;
+	struct protoent *result2;
+                
+	int rv;
+    
+	rv = 0;    
+	DECORATED(setprotoent)(1);
+	setprotoent(1);
+	do
+	{
+		//TRACE_OFF();
+		result1 = DECORATED(getprotoent)();
+		result2 = getprotoent();
+
+		rv = result_compare(result1, result2);
+
+		result_info(0, result1);
+		result_info(0, result2);
+		//TRACE_ON();           
+	} while (((result1 != NULL) || (result2 != NULL) )&& (rv == 0));
+
+	return (rv == 0) ? T_PASSED : T_FAILED;
+}
+
+struct protoent *
+trivial_getprotobyname(const char *name)
+{
+	char **cp;
+	struct protoent *result;
+	
+	DECORATED(setprotoent)(1);
+	while ( (result = DECORATED(getprotoent)()) != NULL) {
+		if (strcmp(result->p_name, name) == 0)
+			goto fin;
+		
+		for (cp=result->p_aliases; *cp; ++cp)
+			if (strcmp(*cp, name) == 0)
+				goto fin;
+	}
+	
+fin:
+	DECORATED(endprotoent)();	
+	return (result);
+}
+
+struct protoent *
+trivial_getprotobynumber(int number)
+{
+	struct protoent *result;
+	
+	DECORATED(setprotoent)(1);
+	while ( (result = DECORATED(getprotoent)()) != NULL) {
+		if (result->p_proto == number)
+			break;
+	}
+	
+	DECORATED(endprotoent)();	
+	return (result);
+}
+
+static enum __test_result
+getprotobyname_test1()
+{		
+	struct protoent *result_model;
+	struct protoent *result1;
+	struct protoent *result2;
+		
+	int rv;
+	char **cp;
+		
+	setprotoent(1);
+	while ( (result_model = getprotoent()) != NULL) {
+		__test_log2("trying name: %s\n", result_model->p_name);
+		
+		result1 = clone_protoent( DECORATED(getprotobyname)(result_model->p_name) );
+		result2 = clone_protoent( trivial_getprotobyname(result_model->p_name) );
+
+		rv = result_compare(result1, result2);
+		result_info(0, result1);
+		result_info(0, result2);
+		free_protoent(result1);
+		free_protoent(result2);		
+		if (rv != 0)
+			break;
+		
+		for (cp = result_model->p_aliases; *cp; ++cp)
+		{
+			__test_log2("trying name: %s\n", *cp);
+			
+			result1 = clone_protoent( DECORATED(getprotobyname)(*cp) );
+			result2 = clone_protoent( trivial_getprotobyname(*cp) );
+			
+			rv = result_compare(result1, result2);			
+			free_protoent(result1);
+			free_protoent(result2);
+			if (rv != 0)
+				break;
+		}
+		
+		if (rv != 0)
+			break;
+	}
+
+	endprotoent();	
+	return (rv == 0) ? T_PASSED : T_FAILED;		
+}
+
+static enum __test_result
+getprotobynumber_test1()
+{
+	struct protoent *result_model;
+	struct protoent *result1;
+	struct protoent *result2;
+		
+	int rv;
+		
+	setprotoent(1);
+	while ( (result_model = getprotoent()) != NULL) {
+		__test_log2("trying number: %d\n", result_model->p_proto);
+		
+		result1 = clone_protoent( DECORATED(getprotobynumber)(result_model->p_proto) );
+		result2 = clone_protoent( trivial_getprotobynumber(result_model->p_proto) );
+		
+		rv = result_compare(result1, result2);
+		free_protoent(result1);
+		free_protoent(result2);
+		if (rv != 0)
+			break;
+	}
+
+	endprotoent();	
+	return (rv == 0) ? T_PASSED : T_FAILED;		
+}
+
+static enum __test_result
+getprotobyname_test2()
+{		
+	struct protoent *result_model;
+	struct protoent *result1;
+	struct protoent *result2;
+		
+	int counter;
+	int rv;
+	char **cp;
+		
+	counter = 0;
+	setprotoent(1);
+	while ( (result_model = getprotoent()) != NULL) {
+		switch (counter % 2)
+		{
+		case 0:
+			break;
+		case 1:
+			result_model->p_name[0]='a';
+			break;
+		};
+		
+		__test_log2("trying name: %s\n", result_model->p_name);
+				
+		result1 = clone_protoent( DECORATED(getprotobyname)(result_model->p_name) );
+		result2 = clone_protoent( trivial_getprotobyname(result_model->p_name) );
+
+		rv = result_compare(result1, result2);
+		free_protoent(result1);
+		free_protoent(result2);		
+		if (rv != 0)
+			break;
+		
+		for (cp = result_model->p_aliases; *cp; ++cp)
+		{
+			switch (counter % 2)
+			{
+			case 0:
+				break;
+			case 1:
+				(*cp)[0]='a';
+				break;
+			};
+			__test_log2("trying name: %s\n", *cp);	
+
+			result1 = clone_protoent( DECORATED(getprotobyname)(*cp) );
+			result2 = clone_protoent( trivial_getprotobyname(*cp) );
+			
+			rv = result_compare(result1, result2);			
+			free_protoent(result1);
+			free_protoent(result2);
+			if (rv != 0)
+				break;
+		}
+		
+		if (rv != 0)
+			break;
+		
+		++counter;
+	}
+
+	endprotoent();	
+	return (rv == 0) ? T_PASSED : T_FAILED;		
+}
+
+static enum __test_result
+getprotobynumber_test2()
+{
+	struct protoent *result_model;
+	struct protoent *result1;
+	struct protoent *result2;
+
+	int counter;	
+	int rv;
+		
+	counter = 0;
+	setprotoent(1);
+	while ( (result_model = getprotoent()) != NULL) {
+		switch (counter % 2)
+		{
+		case 0:
+			break;
+		case 1:
+			result_model->p_proto = htonl(result_model->p_proto);
+			break;
+		}
+		__test_log2("trying number: %d\n", result_model->p_proto);
+				
+		result1 = clone_protoent( DECORATED(getprotobynumber)(result_model->p_proto) );
+		result2 = clone_protoent( trivial_getprotobynumber(result_model->p_proto) );
+		
+		rv = result_compare(result1, result2);
+		free_protoent(result1);
+		free_protoent(result2);
+		if (rv != 0)
+			break;
+		
+		++counter;
+	}
+
+	endprotoent();	
+	return (rv == 0) ? T_PASSED : T_FAILED;		
+}
+
+static enum __test_result
+protoent_stress_test()
+{	
+	const size_t bigsize = 65000;	
+	char *bigname;
+	
+	(void)DECORATED(getprotobyname)("");
+	(void)DECORATED(getprotobynumber)(-1);
+	
+	bigname = (char *)malloc(bigsize);
+	assert(bigname != NULL);
+	memset(bigname, 'a', bigsize - 1);
+	bigname[bigsize - 1] = '\0';
+	
+	(void)DECORATED(getprotobyname)(bigname);
+	
+	return (T_PASSED);
+}
+
 int 
 main(int argc, char *argv[])
-{	
-	return (0);
+{
+	struct test_system *tsystem;
+	struct test_info	*tinfo;
+	
+	tsystem = __init_test_system("getproto* nsswitch testing");
+	assert(tsystem != NULL);
+	
+	tinfo = __create_test_info("getprotoent_test1", getprotoent_test1, 0);
+	assert(tinfo != NULL);
+	__register_test_info(tsystem, tinfo);
+
+	tinfo = __create_test_info("getprotobyname_test1", getprotobyname_test1, 1);
+	assert(tinfo != NULL);
+	__register_test_info(tsystem, tinfo);
+	
+	tinfo = __create_test_info("getprotobynumber_test1", getprotobynumber_test1, 1);
+	assert(tinfo != NULL);
+	__register_test_info(tsystem, tinfo);
+		
+	tinfo = __create_test_info("getprotobyname_test2", getprotobyname_test2, 1);
+	assert(tinfo != NULL);
+	__register_test_info(tsystem, tinfo);
+	
+	tinfo = __create_test_info("getprotobynumber_test2", getprotobynumber_test2, 1);
+	assert(tinfo != NULL);
+	__register_test_info(tsystem, tinfo);
+
+	tinfo = __create_test_info("protoent_stress_test", protoent_stress_test, 1);
+	assert(tinfo != NULL);
+	__register_test_info(tsystem, tinfo);
+		
+	__process_tests(tsystem, NULL, NULL);
+	__destroy_test_system(tsystem);
+	return 0;
 }


>>> TRUNCATED FOR MAIL (1000 lines) <<<



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200507151545.j6FFjoDo003345>