t_servent.sh revision 313498
1163953Srrs# $NetBSD: t_servent.sh,v 1.2 2016/03/08 08:34:17 joerg Exp $ 2185694Srrs# 3235828Stuexen# Copyright (c) 2008 The NetBSD Foundation, Inc. 4235828Stuexen# All rights reserved. 5163953Srrs# 6163953Srrs# Redistribution and use in source and binary forms, with or without 7163953Srrs# modification, are permitted provided that the following conditions 8163953Srrs# are met: 9163953Srrs# 1. Redistributions of source code must retain the above copyright 10228653Stuexen# notice, this list of conditions and the following disclaimer. 11163953Srrs# 2. Redistributions in binary form must reproduce the above copyright 12163953Srrs# notice, this list of conditions and the following disclaimer in the 13163953Srrs# documentation and/or other materials provided with the distribution. 14228653Stuexen# 15163953Srrs# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16163953Srrs# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17163953Srrs# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18163953Srrs# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19163953Srrs# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20163953Srrs# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21163953Srrs# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22163953Srrs# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23163953Srrs# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24163953Srrs# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25163953Srrs# POSSIBILITY OF SUCH DAMAGE. 26163953Srrs# 27163953Srrs 28163953Srrsatf_test_case servent 29163953Srrsservent_head() 30163953Srrs{ 31163953Srrs atf_set "descr" "Checks {get,set,end}servent(3)" 32163953Srrs # libc doesn't include aliases 33163953Srrs atf_set "require.files" "/var/db/services.cdb" 34163953Srrs} 35163953Srrsservent_body() 36235828Stuexen{ 37235828Stuexen # 38163953Srrs # Munge original to: 39267724Stuexen # (1) match output format of the test program 40179157Srrs # (2) fold all names for the same port/proto together 41267724Stuexen # (3) prune duplicates 42267724Stuexen # 43167598Srrs tr '\t' ' ' </etc/services | awk ' 44167598Srrs function add(key, name, i, n, ar) { 45163953Srrs n = split(names[key], ar); 46167598Srrs for (i=1; i<=n; i++) { 47168299Srrs if (name == ar[i]) { 48167598Srrs return; 49167598Srrs } 50167598Srrs } 51167598Srrs delete ar; 52168299Srrs names[key] = names[key] " " name; 53168299Srrs } 54167598Srrs 55167598Srrs { 56167598Srrs sub("#.*", "", $0); 57168299Srrs gsub(" *", " ", $0); 58168299Srrs if (NF==0) { 59168299Srrs next; 60168299Srrs } 61167598Srrs add($2, $1, 0); 62168299Srrs for (i=3; i<=NF; i++) { 63167598Srrs add($2, $i, 1); 64171990Srrs } 65171990Srrs } 66171990Srrs END { 67171990Srrs for (key in names) { 68171990Srrs portproto = key; 69294157Stuexen sub("/", ", proto=", portproto); 70294157Stuexen portproto = "port=" portproto; 71167598Srrs 72167598Srrs n = split(names[key], ar); 73167598Srrs printf "name=%s, %s, aliases=", ar[1], portproto; 74170056Srrs for (i=2; i<=n; i++) { 75170181Srrs if (i>2) { 76170056Srrs printf " "; 77167598Srrs } 78167598Srrs printf "%s", ar[i]; 79167598Srrs } 80167598Srrs printf "\n"; 81167598Srrs delete ar; 82163953Srrs } 83163953Srrs } 84163953Srrs ' | sort >exp 85163953Srrs 86167598Srrs case "$(uname)" in 87167598Srrs FreeBSD) 88199866Stuexen # (3) Don't prune duplicates 89167598Srrs tr '\t' ' ' < /etc/services | 90218211Srrs sed 's/#.*//;s/ */ /g; /^$/d;s#\([0-9]\)/#\1 #;s/ *$//' | 91167598Srrs sort | 92218211Srrs while read l; do 93167598Srrs set $l 94167598Srrs name=$1; shift 95167598Srrs port=$1; shift 96167598Srrs proto=$1; shift 97167598Srrs alias="$@" 98171477Srrs printf "name=%s, port=%s, proto=%s, aliases=%s\n" \ 99171477Srrs $name $port $proto "$alias" 100171477Srrs done > exp 101171477Srrs ;; 102171440Srrs esac 103171440Srrs 104171440Srrs # run test program 105171440Srrs "$(atf_get_srcdir)/h_servent" | sed 's/ *$//' | sort >out 106171440Srrs 107163953Srrs diff -u exp out || atf_fail "Observed output does not match reference output" 108163953Srrs} 109163953Srrs 110163953Srrsatf_init_test_cases() 111163953Srrs{ 112163953Srrs atf_add_test_case servent 113163953Srrs} 114163953Srrs