11.5Sjschauma# $NetBSD: t_protoent.sh,v 1.5 2022/12/04 02:53:17 jschauma Exp $ 21.1Spgoyette# 31.1Spgoyette# Copyright (c) 2008 The NetBSD Foundation, Inc. 41.1Spgoyette# All rights reserved. 51.1Spgoyette# 61.1Spgoyette# Redistribution and use in source and binary forms, with or without 71.1Spgoyette# modification, are permitted provided that the following conditions 81.1Spgoyette# are met: 91.1Spgoyette# 1. Redistributions of source code must retain the above copyright 101.1Spgoyette# notice, this list of conditions and the following disclaimer. 111.1Spgoyette# 2. Redistributions in binary form must reproduce the above copyright 121.1Spgoyette# notice, this list of conditions and the following disclaimer in the 131.1Spgoyette# documentation and/or other materials provided with the distribution. 141.1Spgoyette# 151.1Spgoyette# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 161.1Spgoyette# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 171.1Spgoyette# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 181.1Spgoyette# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 191.1Spgoyette# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 201.1Spgoyette# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 211.1Spgoyette# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 221.1Spgoyette# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 231.1Spgoyette# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 241.1Spgoyette# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 251.1Spgoyette# POSSIBILITY OF SUCH DAMAGE. 261.1Spgoyette# 271.5Sjschauma: ${TEST_FILE:="/etc/protocols"} 281.1Spgoyette 291.1Spgoyetteatf_test_case protoent 301.1Spgoyetteprotoent_head() 311.1Spgoyette{ 321.1Spgoyette atf_set "descr" "Checks {get,set,end}protoent(3)" 331.1Spgoyette} 341.1Spgoyetteprotoent_body() 351.1Spgoyette{ 361.1Spgoyette # 371.1Spgoyette # Munge original to: 381.1Spgoyette # (1) match output format of the test program 391.1Spgoyette # (2) fold all names for the same port/proto together 401.1Spgoyette # (3) prune duplicates 411.1Spgoyette # 421.5Sjschauma tr '\t' ' ' <"${TEST_FILE}" | awk ' 431.2Schristos function add(key, name, i, n, ar) { 441.1Spgoyette n = split(names[key], ar); 451.2Schristos for (i = 1; i <= n; i++) { 461.1Spgoyette if (name == ar[i]) { 471.2Schristos return; 481.1Spgoyette } 491.1Spgoyette } 501.1Spgoyette delete ar; 511.1Spgoyette names[key] = names[key] " " name; 521.2Schristos } 531.2Schristos { 541.1Spgoyette sub("#.*", "", $0); 551.1Spgoyette gsub(" *", " ", $0); 561.2Schristos if (NF == 0) { 571.1Spgoyette next; 581.1Spgoyette } 591.1Spgoyette add($2, $1, 0); 601.2Schristos for (i = 3; i <= NF; i++) { 611.1Spgoyette add($2, $i, 1); 621.1Spgoyette } 631.2Schristos } 641.2Schristos END { 651.1Spgoyette for (key in names) { 661.1Spgoyette proto = key; 671.1Spgoyette 681.1Spgoyette n = split(names[key], ar); 691.1Spgoyette printf "name=%s, proto=%s, aliases=", ar[1], proto; 701.1Spgoyette for (i=2; i<=n; i++) { 711.3Sjschauma if (i>2) { 721.3Sjschauma printf " "; 731.3Sjschauma } 741.4Sjschauma printf "%s", ar[i]; 751.1Spgoyette } 761.1Spgoyette printf "\n"; 771.1Spgoyette delete ar; 781.1Spgoyette } 791.3Sjschauma } 801.1Spgoyette ' | sort >exp 811.1Spgoyette 821.1Spgoyette # run test program 831.1Spgoyette "$(atf_get_srcdir)/h_protoent" | sed 's/ *$//' | sort >out 841.1Spgoyette 851.1Spgoyette diff -u exp out || \ 861.1Spgoyette atf_fail "Observed output does not match reference output" 871.1Spgoyette} 881.1Spgoyette 891.1Spgoyetteatf_init_test_cases() 901.1Spgoyette{ 911.1Spgoyette atf_add_test_case protoent 921.1Spgoyette} 93