1168754Sbushman/*-
2168754Sbushman * Copyright (c) 2006 Michael Bushkov <bushman@freebsd.org>
3251867Seadler * All rights reserved.
4168754Sbushman *
5168754Sbushman * Redistribution and use in source and binary forms, with or without
6168754Sbushman * modification, are permitted provided that the following conditions
7168754Sbushman * are met:
8168754Sbushman * 1. Redistributions of source code must retain the above copyright
9168754Sbushman *    notice, this list of conditions and the following disclaimer.
10168754Sbushman * 2. Redistributions in binary form must reproduce the above copyright
11168754Sbushman *    notice, this list of conditions and the following disclaimer in the
12168754Sbushman *    documentation and/or other materials provided with the distribution.
13168754Sbushman *
14168754Sbushman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15168754Sbushman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16168754Sbushman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17168754Sbushman * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18168754Sbushman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19168754Sbushman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20168754Sbushman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21168754Sbushman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22168754Sbushman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23168754Sbushman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24168754Sbushman * SUCH DAMAGE.
25168754Sbushman *
26168754Sbushman */
27168754Sbushman
28168754Sbushman#include <sys/cdefs.h>
29168754Sbushman__FBSDID("$FreeBSD: stable/10/lib/libc/tests/nss/getproto_test.c 319298 2017-05-31 08:30:37Z ngie $");
30168754Sbushman
31168754Sbushman#include <arpa/inet.h>
32168754Sbushman#include <assert.h>
33168754Sbushman#include <errno.h>
34168754Sbushman#include <netdb.h>
35168754Sbushman#include <stdio.h>
36168754Sbushman#include <stdlib.h>
37168754Sbushman#include <string.h>
38168754Sbushman#include <stringlist.h>
39168754Sbushman#include <unistd.h>
40292323Sngie
41292323Sngie#include <atf-c.h>
42292323Sngie
43168754Sbushman#include "testutil.h"
44168754Sbushman
45168754Sbushmanenum test_methods {
46168754Sbushman	TEST_GETPROTOENT,
47168754Sbushman	TEST_GETPROTOBYNAME,
48168754Sbushman	TEST_GETPROTOBYNUMBER,
49168754Sbushman	TEST_GETPROTOENT_2PASS,
50168754Sbushman	TEST_BUILD_SNAPSHOT
51168754Sbushman};
52168754Sbushman
53168754SbushmanDECLARE_TEST_DATA(protoent)
54168754SbushmanDECLARE_TEST_FILE_SNAPSHOT(protoent)
55168754SbushmanDECLARE_1PASS_TEST(protoent)
56168754SbushmanDECLARE_2PASS_TEST(protoent)
57168754Sbushman
58168754Sbushmanstatic void clone_protoent(struct protoent *, struct protoent const *);
59168754Sbushmanstatic int compare_protoent(struct protoent *, struct protoent *, void *);
60168754Sbushmanstatic void dump_protoent(struct protoent *);
61168754Sbushmanstatic void free_protoent(struct protoent *);
62168754Sbushman
63168754Sbushmanstatic void sdump_protoent(struct protoent *, char *, size_t);
64168754Sbushmanstatic int protoent_read_snapshot_func(struct protoent *, char *);
65168754Sbushman
66291363Sngiestatic int protoent_check_ambiguity(struct protoent_test_data *,
67168754Sbushman	struct protoent *);
68168754Sbushmanstatic int protoent_fill_test_data(struct protoent_test_data *);
69168754Sbushmanstatic int protoent_test_correctness(struct protoent *, void *);
70168754Sbushmanstatic int protoent_test_getprotobyname(struct protoent *, void *);
71168754Sbushmanstatic int protoent_test_getprotobynumber(struct protoent *, void *);
72168754Sbushmanstatic int protoent_test_getprotoent(struct protoent *, void *);
73291363Sngie
74168754SbushmanIMPLEMENT_TEST_DATA(protoent)
75168754SbushmanIMPLEMENT_TEST_FILE_SNAPSHOT(protoent)
76168754SbushmanIMPLEMENT_1PASS_TEST(protoent)
77168754SbushmanIMPLEMENT_2PASS_TEST(protoent)
78168754Sbushman
79168754Sbushmanstatic void
80168754Sbushmanclone_protoent(struct protoent *dest, struct protoent const *src)
81168754Sbushman{
82168754Sbushman	assert(dest != NULL);
83168754Sbushman	assert(src != NULL);
84291363Sngie
85168754Sbushman	char **cp;
86168754Sbushman	int aliases_num;
87291363Sngie
88168754Sbushman	memset(dest, 0, sizeof(struct protoent));
89291363Sngie
90168754Sbushman	if (src->p_name != NULL) {
91168754Sbushman		dest->p_name = strdup(src->p_name);
92168754Sbushman		assert(dest->p_name != NULL);
93168754Sbushman	}
94291363Sngie
95168754Sbushman	dest->p_proto = src->p_proto;
96291363Sngie
97168754Sbushman	if (src->p_aliases != NULL) {
98168754Sbushman		aliases_num = 0;
99168754Sbushman		for (cp = src->p_aliases; *cp; ++cp)
100168754Sbushman			++aliases_num;
101291363Sngie
102319298Sngie		dest->p_aliases = calloc(aliases_num + 1, sizeof(char *));
103168754Sbushman		assert(dest->p_aliases != NULL);
104291363Sngie
105168754Sbushman		for (cp = src->p_aliases; *cp; ++cp) {
106168754Sbushman			dest->p_aliases[cp - src->p_aliases] = strdup(*cp);
107168754Sbushman			assert(dest->p_aliases[cp - src->p_aliases] != NULL);
108168754Sbushman		}
109168754Sbushman	}
110168754Sbushman}
111168754Sbushman
112291363Sngiestatic void
113168754Sbushmanfree_protoent(struct protoent *pe)
114168754Sbushman{
115168754Sbushman	char **cp;
116291363Sngie
117168754Sbushman	assert(pe != NULL);
118291363Sngie
119168754Sbushman	free(pe->p_name);
120291363Sngie
121168754Sbushman	for (cp = pe->p_aliases; *cp; ++cp)
122168754Sbushman		free(*cp);
123168754Sbushman	free(pe->p_aliases);
124168754Sbushman}
125168754Sbushman
126291363Sngiestatic  int
127168754Sbushmancompare_protoent(struct protoent *pe1, struct protoent *pe2, void *mdata)
128168754Sbushman{
129168754Sbushman	char **c1, **c2;
130291363Sngie
131168754Sbushman	if (pe1 == pe2)
132168754Sbushman		return 0;
133291363Sngie
134168754Sbushman	if ((pe1 == NULL) || (pe2 == NULL))
135168754Sbushman		goto errfin;
136291363Sngie
137168754Sbushman	if ((strcmp(pe1->p_name, pe2->p_name) != 0) ||
138168754Sbushman		(pe1->p_proto != pe2->p_proto))
139168754Sbushman			goto errfin;
140291363Sngie
141168754Sbushman	c1 = pe1->p_aliases;
142168754Sbushman	c2 = pe2->p_aliases;
143291363Sngie
144168754Sbushman	if ((pe1->p_aliases == NULL) || (pe2->p_aliases == NULL))
145168754Sbushman		goto errfin;
146291363Sngie
147168754Sbushman	for (;*c1 && *c2; ++c1, ++c2)
148168754Sbushman		if (strcmp(*c1, *c2) != 0)
149168754Sbushman			goto errfin;
150291363Sngie
151168754Sbushman	if ((*c1 != '\0') || (*c2 != '\0'))
152168754Sbushman		goto errfin;
153291363Sngie
154168754Sbushman	return 0;
155291363Sngie
156168754Sbushmanerrfin:
157292323Sngie	if (mdata == NULL) {
158168754Sbushman		printf("following structures are not equal:\n");
159168754Sbushman		dump_protoent(pe1);
160168754Sbushman		dump_protoent(pe2);
161168754Sbushman	}
162168754Sbushman
163168754Sbushman	return (-1);
164168754Sbushman}
165168754Sbushman
166168754Sbushmanstatic void
167168754Sbushmansdump_protoent(struct protoent *pe, char *buffer, size_t buflen)
168168754Sbushman{
169168754Sbushman	char **cp;
170168754Sbushman	int written;
171291363Sngie
172168754Sbushman	written = snprintf(buffer, buflen, "%s %d",
173291363Sngie		pe->p_name, pe->p_proto);
174168754Sbushman	buffer += written;
175319298Sngie	if (written > (int)buflen)
176168754Sbushman		return;
177168754Sbushman	buflen -= written;
178291363Sngie
179168754Sbushman	if (pe->p_aliases != NULL) {
180168754Sbushman		if (*(pe->p_aliases) != '\0') {
181168754Sbushman			for (cp = pe->p_aliases; *cp; ++cp) {
182319298Sngie				written = snprintf(buffer, buflen, " %s", *cp);
183168754Sbushman				buffer += written;
184319298Sngie				if (written > (int)buflen)
185168754Sbushman					return;
186168754Sbushman				buflen -= written;
187291363Sngie
188168754Sbushman				if (buflen == 0)
189291363Sngie					return;
190168754Sbushman			}
191168754Sbushman		} else
192168754Sbushman			snprintf(buffer, buflen, " noaliases");
193168754Sbushman	} else
194168754Sbushman		snprintf(buffer, buflen, " (null)");
195168754Sbushman}
196168754Sbushman
197168754Sbushmanstatic int
198168754Sbushmanprotoent_read_snapshot_func(struct protoent *pe, char *line)
199168754Sbushman{
200168754Sbushman	StringList *sl;
201168754Sbushman	char *s, *ps, *ts;
202168754Sbushman	int i;
203168754Sbushman
204292323Sngie	printf("1 line read from snapshot:\n%s\n", line);
205291363Sngie
206168754Sbushman	i = 0;
207168754Sbushman	sl = NULL;
208168754Sbushman	ps = line;
209168754Sbushman	memset(pe, 0, sizeof(struct protoent));
210168754Sbushman	while ( (s = strsep(&ps, " ")) != NULL) {
211168754Sbushman		switch (i) {
212168754Sbushman			case 0:
213168754Sbushman				pe->p_name = strdup(s);
214168754Sbushman				assert(pe->p_name != NULL);
215168754Sbushman			break;
216168754Sbushman
217168754Sbushman			case 1:
218168754Sbushman				pe->p_proto = (int)strtol(s, &ts, 10);
219168754Sbushman				if (*ts != '\0') {
220168754Sbushman					free(pe->p_name);
221168754Sbushman					return (-1);
222168754Sbushman				}
223168754Sbushman			break;
224168754Sbushman
225168754Sbushman			default:
226168754Sbushman				if (sl == NULL) {
227168754Sbushman					if (strcmp(s, "(null)") == 0)
228168754Sbushman						return (0);
229291363Sngie
230168754Sbushman					sl = sl_init();
231168754Sbushman					assert(sl != NULL);
232291363Sngie
233168754Sbushman					if (strcmp(s, "noaliases") != 0) {
234168754Sbushman						ts = strdup(s);
235168754Sbushman						assert(ts != NULL);
236168754Sbushman						sl_add(sl, ts);
237168754Sbushman					}
238168754Sbushman				} else {
239168754Sbushman					ts = strdup(s);
240168754Sbushman					assert(ts != NULL);
241168754Sbushman					sl_add(sl, ts);
242168754Sbushman				}
243291363Sngie			break;
244292323Sngie		}
245168754Sbushman		++i;
246168754Sbushman	}
247168754Sbushman
248168754Sbushman	if (i < 3) {
249168754Sbushman		free(pe->p_name);
250168754Sbushman		memset(pe, 0, sizeof(struct protoent));
251168754Sbushman		return (-1);
252168754Sbushman	}
253291363Sngie
254168754Sbushman	sl_add(sl, NULL);
255168754Sbushman	pe->p_aliases = sl->sl_str;
256168754Sbushman
257168754Sbushman	/* NOTE: is it a dirty hack or not? */
258291363Sngie	free(sl);
259168754Sbushman	return (0);
260168754Sbushman}
261168754Sbushman
262291363Sngiestatic void
263168754Sbushmandump_protoent(struct protoent *result)
264168754Sbushman{
265168754Sbushman	if (result != NULL) {
266168754Sbushman		char buffer[1024];
267168754Sbushman		sdump_protoent(result, buffer, sizeof(buffer));
268168754Sbushman		printf("%s\n", buffer);
269168754Sbushman	} else
270168754Sbushman		printf("(null)\n");
271168754Sbushman}
272168754Sbushman
273168754Sbushmanstatic int
274168754Sbushmanprotoent_fill_test_data(struct protoent_test_data *td)
275168754Sbushman{
276168754Sbushman	struct protoent *pe;
277291363Sngie
278168754Sbushman	setprotoent(1);
279168754Sbushman	while ((pe = getprotoent()) != NULL) {
280168754Sbushman		if (protoent_test_correctness(pe, NULL) == 0)
281168754Sbushman			TEST_DATA_APPEND(protoent, td, pe);
282168754Sbushman		else
283168754Sbushman			return (-1);
284168754Sbushman	}
285168754Sbushman	endprotoent();
286291363Sngie
287168754Sbushman	return (0);
288168754Sbushman}
289168754Sbushman
290168754Sbushmanstatic int
291319298Sngieprotoent_test_correctness(struct protoent *pe, void *mdata __unused)
292168754Sbushman{
293292323Sngie	printf("testing correctness with the following data:\n");
294292323Sngie	dump_protoent(pe);
295291363Sngie
296168754Sbushman	if (pe == NULL)
297168754Sbushman		goto errfin;
298291363Sngie
299168754Sbushman	if (pe->p_name == NULL)
300168754Sbushman		goto errfin;
301291363Sngie
302168754Sbushman	if (pe->p_proto < 0)
303168754Sbushman		goto errfin;
304291363Sngie
305168754Sbushman	if (pe->p_aliases == NULL)
306168754Sbushman		goto errfin;
307291363Sngie
308292323Sngie	printf("correct\n");
309291363Sngie
310291363Sngie	return (0);
311168754Sbushmanerrfin:
312292323Sngie	printf("incorrect\n");
313291363Sngie
314168754Sbushman	return (-1);
315168754Sbushman}
316168754Sbushman
317168754Sbushman/* protoent_check_ambiguity() is needed when one port+proto is associated with
318168754Sbushman * more than one peice (these cases are usually marked as PROBLEM in
319291363Sngie * /etc/peices. This functions is needed also when one peice+proto is
320168754Sbushman * associated with several ports. We have to check all the protoent structures
321168754Sbushman * to make sure that pe really exists and correct */
322168754Sbushmanstatic int
323168754Sbushmanprotoent_check_ambiguity(struct protoent_test_data *td, struct protoent *pe)
324168754Sbushman{
325291363Sngie
326168754Sbushman	return (TEST_DATA_FIND(protoent, td, pe, compare_protoent,
327168754Sbushman		NULL) != NULL ? 0 : -1);
328168754Sbushman}
329168754Sbushman
330168754Sbushmanstatic int
331168754Sbushmanprotoent_test_getprotobyname(struct protoent *pe_model, void *mdata)
332168754Sbushman{
333168754Sbushman	char **alias;
334168754Sbushman	struct protoent *pe;
335291363Sngie
336292323Sngie	printf("testing getprotobyname() with the following data:\n");
337292323Sngie	dump_protoent(pe_model);
338168754Sbushman
339168754Sbushman	pe = getprotobyname(pe_model->p_name);
340168754Sbushman	if (protoent_test_correctness(pe, NULL) != 0)
341168754Sbushman		goto errfin;
342291363Sngie
343168754Sbushman	if ((compare_protoent(pe, pe_model, NULL) != 0) &&
344291363Sngie	    (protoent_check_ambiguity((struct protoent_test_data *)mdata, pe)
345168754Sbushman	    !=0))
346168754Sbushman	    goto errfin;
347291363Sngie
348168754Sbushman	for (alias = pe_model->p_aliases; *alias; ++alias) {
349168754Sbushman		pe = getprotobyname(*alias);
350291363Sngie
351168754Sbushman		if (protoent_test_correctness(pe, NULL) != 0)
352168754Sbushman			goto errfin;
353291363Sngie
354168754Sbushman		if ((compare_protoent(pe, pe_model, NULL) != 0) &&
355168754Sbushman		    (protoent_check_ambiguity(
356168754Sbushman		    (struct protoent_test_data *)mdata, pe) != 0))
357168754Sbushman		    goto errfin;
358168754Sbushman	}
359291363Sngie
360292323Sngie	printf("ok\n");
361168754Sbushman	return (0);
362291363Sngie
363168754Sbushmanerrfin:
364292323Sngie	printf("not ok\n");
365291363Sngie
366168754Sbushman	return (-1);
367168754Sbushman}
368168754Sbushman
369168754Sbushmanstatic int
370168754Sbushmanprotoent_test_getprotobynumber(struct protoent *pe_model, void *mdata)
371168754Sbushman{
372168754Sbushman	struct protoent *pe;
373291363Sngie
374292323Sngie	printf("testing getprotobyport() with the following data...\n");
375292323Sngie	dump_protoent(pe_model);
376291363Sngie
377168754Sbushman	pe = getprotobynumber(pe_model->p_proto);
378291363Sngie	if ((protoent_test_correctness(pe, NULL) != 0) ||
379168754Sbushman	    ((compare_protoent(pe, pe_model, NULL) != 0) &&
380168754Sbushman	    (protoent_check_ambiguity((struct protoent_test_data *)mdata, pe)
381168754Sbushman	    != 0))) {
382168754Sbushman		printf("not ok\n");
383292323Sngie		return (-1);
384168754Sbushman	} else {
385168754Sbushman		printf("ok\n");
386292323Sngie		return (0);
387168754Sbushman	}
388168754Sbushman}
389168754Sbushman
390291363Sngiestatic int
391319298Sngieprotoent_test_getprotoent(struct protoent *pe, void *mdata __unused)
392168754Sbushman{
393168754Sbushman	/* Only correctness can be checked when doing 1-pass test for
394168754Sbushman	 * getprotoent(). */
395168754Sbushman	return (protoent_test_correctness(pe, NULL));
396168754Sbushman}
397168754Sbushman
398319298Sngiestatic int
399292323Sngierun_tests(const char *snapshot_file, enum test_methods method)
400168754Sbushman{
401168754Sbushman	struct protoent_test_data td, td_snap, td_2pass;
402168754Sbushman	int rv;
403291363Sngie
404168754Sbushman	TEST_DATA_INIT(protoent, &td, clone_protoent, free_protoent);
405168754Sbushman	TEST_DATA_INIT(protoent, &td_snap, clone_protoent, free_protoent);
406168754Sbushman	if (snapshot_file != NULL) {
407291363Sngie		if (access(snapshot_file, W_OK | R_OK) != 0) {
408168754Sbushman			if (errno == ENOENT)
409168754Sbushman				method = TEST_BUILD_SNAPSHOT;
410168754Sbushman			else {
411292323Sngie				printf("can't access the file %s\n",
412292323Sngie				    snapshot_file);
413291363Sngie
414168754Sbushman				rv = -1;
415168754Sbushman				goto fin;
416168754Sbushman			}
417168754Sbushman		} else {
418168754Sbushman			if (method == TEST_BUILD_SNAPSHOT) {
419168754Sbushman				rv = 0;
420168754Sbushman				goto fin;
421168754Sbushman			}
422291363Sngie
423168754Sbushman			TEST_SNAPSHOT_FILE_READ(protoent, snapshot_file,
424168754Sbushman				&td_snap, protoent_read_snapshot_func);
425168754Sbushman		}
426168754Sbushman	}
427291363Sngie
428168754Sbushman	rv = protoent_fill_test_data(&td);
429168754Sbushman	if (rv == -1)
430168754Sbushman		return (-1);
431168754Sbushman	switch (method) {
432168754Sbushman	case TEST_GETPROTOBYNAME:
433168754Sbushman		if (snapshot_file == NULL)
434168754Sbushman			rv = DO_1PASS_TEST(protoent, &td,
435168754Sbushman				protoent_test_getprotobyname, (void *)&td);
436168754Sbushman		else
437291363Sngie			rv = DO_1PASS_TEST(protoent, &td_snap,
438168754Sbushman				protoent_test_getprotobyname, (void *)&td_snap);
439168754Sbushman		break;
440168754Sbushman	case TEST_GETPROTOBYNUMBER:
441168754Sbushman		if (snapshot_file == NULL)
442168754Sbushman			rv = DO_1PASS_TEST(protoent, &td,
443168754Sbushman				protoent_test_getprotobynumber, (void *)&td);
444168754Sbushman		else
445291363Sngie			rv = DO_1PASS_TEST(protoent, &td_snap,
446168754Sbushman				protoent_test_getprotobynumber, (void *)&td_snap);
447168754Sbushman		break;
448168754Sbushman	case TEST_GETPROTOENT:
449168754Sbushman		if (snapshot_file == NULL)
450291363Sngie			rv = DO_1PASS_TEST(protoent, &td,
451168754Sbushman				protoent_test_getprotoent, (void *)&td);
452168754Sbushman		else
453168754Sbushman			rv = DO_2PASS_TEST(protoent, &td, &td_snap,
454168754Sbushman				compare_protoent, NULL);
455168754Sbushman		break;
456168754Sbushman	case TEST_GETPROTOENT_2PASS:
457292323Sngie		TEST_DATA_INIT(protoent, &td_2pass, clone_protoent,
458292323Sngie		    free_protoent);
459292323Sngie		rv = protoent_fill_test_data(&td_2pass);
460292323Sngie		if (rv != -1)
461292323Sngie			rv = DO_2PASS_TEST(protoent, &td, &td_2pass,
462292323Sngie				compare_protoent, NULL);
463292323Sngie		TEST_DATA_DESTROY(protoent, &td_2pass);
464168754Sbushman		break;
465168754Sbushman	case TEST_BUILD_SNAPSHOT:
466168754Sbushman		if (snapshot_file != NULL)
467292323Sngie			rv = TEST_SNAPSHOT_FILE_WRITE(protoent, snapshot_file,
468292323Sngie			    &td, sdump_protoent);
469168754Sbushman		break;
470168754Sbushman	default:
471168754Sbushman		rv = 0;
472168754Sbushman		break;
473292323Sngie	}
474168754Sbushman
475168754Sbushmanfin:
476168754Sbushman	TEST_DATA_DESTROY(protoent, &td_snap);
477168754Sbushman	TEST_DATA_DESTROY(protoent, &td);
478292323Sngie
479168754Sbushman	return (rv);
480168754Sbushman}
481292323Sngie
482292323Sngie#define	SNAPSHOT_FILE	"snapshot_proto"
483292323Sngie
484292323SngieATF_TC_WITHOUT_HEAD(build_snapshot);
485292323SngieATF_TC_BODY(build_snapshot, tc)
486292323Sngie{
487292323Sngie
488292323Sngie	ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
489292323Sngie}
490292323Sngie
491292323SngieATF_TC_WITHOUT_HEAD(getprotoent);
492292323SngieATF_TC_BODY(getprotoent, tc)
493292323Sngie{
494292323Sngie
495292323Sngie	ATF_REQUIRE(run_tests(NULL, TEST_GETPROTOENT) == 0);
496292323Sngie}
497292323Sngie
498292323SngieATF_TC_WITHOUT_HEAD(getprotoent_with_snapshot);
499292323SngieATF_TC_BODY(getprotoent_with_snapshot, tc)
500292323Sngie{
501292323Sngie
502292323Sngie	ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
503292323Sngie	ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPROTOENT) == 0);
504292323Sngie}
505292323Sngie
506292323SngieATF_TC_WITHOUT_HEAD(getprotoent_with_two_pass);
507292323SngieATF_TC_BODY(getprotoent_with_two_pass, tc)
508292323Sngie{
509292323Sngie
510292323Sngie	ATF_REQUIRE(run_tests(NULL, TEST_GETPROTOENT_2PASS) == 0);
511292323Sngie}
512292323Sngie
513292323SngieATF_TC_WITHOUT_HEAD(getprotobyname);
514292323SngieATF_TC_BODY(getprotobyname, tc)
515292323Sngie{
516292323Sngie
517292323Sngie	ATF_REQUIRE(run_tests(NULL, TEST_GETPROTOBYNAME) == 0);
518292323Sngie}
519292323Sngie
520292323SngieATF_TC_WITHOUT_HEAD(getprotobyname_with_snapshot);
521292323SngieATF_TC_BODY(getprotobyname_with_snapshot, tc)
522292323Sngie{
523292323Sngie
524292323Sngie	ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
525292323Sngie	ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPROTOBYNAME) == 0);
526292323Sngie}
527292323Sngie
528292323SngieATF_TC_WITHOUT_HEAD(getprotobynumber);
529292323SngieATF_TC_BODY(getprotobynumber, tc)
530292323Sngie{
531292323Sngie
532292323Sngie	ATF_REQUIRE(run_tests(NULL, TEST_GETPROTOBYNUMBER) == 0);
533292323Sngie}
534292323Sngie
535292323SngieATF_TC_WITHOUT_HEAD(getprotobynumber_with_snapshot);
536292323SngieATF_TC_BODY(getprotobynumber_with_snapshot, tc)
537292323Sngie{
538292323Sngie
539292323Sngie	ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
540292323Sngie	ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPROTOBYNUMBER) == 0);
541292323Sngie}
542292323Sngie
543292323SngieATF_TP_ADD_TCS(tp)
544292323Sngie{
545292323Sngie
546292323Sngie	ATF_TP_ADD_TC(tp, build_snapshot);
547292323Sngie	ATF_TP_ADD_TC(tp, getprotoent);
548292323Sngie	ATF_TP_ADD_TC(tp, getprotoent_with_snapshot);
549292323Sngie	ATF_TP_ADD_TC(tp, getprotoent_with_two_pass);
550292323Sngie	ATF_TP_ADD_TC(tp, getprotobyname);
551292323Sngie	ATF_TP_ADD_TC(tp, getprotobyname_with_snapshot);
552292323Sngie	ATF_TP_ADD_TC(tp, getprotobynumber);
553292323Sngie	ATF_TP_ADD_TC(tp, getprotobynumber_with_snapshot);
554292323Sngie
555292323Sngie	return (atf_no_error());
556292323Sngie}
557