t_protoent.sh revision 1.4
11.4Sjschauma# $NetBSD: t_protoent.sh,v 1.4 2022/11/28 17:41:00 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.1Spgoyette 281.1Spgoyetteatf_test_case protoent 291.1Spgoyetteprotoent_head() 301.1Spgoyette{ 311.1Spgoyette atf_set "descr" "Checks {get,set,end}protoent(3)" 321.1Spgoyette} 331.1Spgoyetteprotoent_body() 341.1Spgoyette{ 351.1Spgoyette # 361.1Spgoyette # Munge original to: 371.1Spgoyette # (1) match output format of the test program 381.1Spgoyette # (2) fold all names for the same port/proto together 391.1Spgoyette # (3) prune duplicates 401.1Spgoyette # 411.1Spgoyette tr '\t' ' ' </etc/protocols | awk ' 421.2Schristos function add(key, name, i, n, ar) { 431.1Spgoyette n = split(names[key], ar); 441.2Schristos for (i = 1; i <= n; i++) { 451.1Spgoyette if (name == ar[i]) { 461.2Schristos return; 471.1Spgoyette } 481.1Spgoyette } 491.1Spgoyette delete ar; 501.1Spgoyette names[key] = names[key] " " name; 511.2Schristos } 521.2Schristos { 531.1Spgoyette sub("#.*", "", $0); 541.1Spgoyette gsub(" *", " ", $0); 551.2Schristos if (NF == 0) { 561.1Spgoyette next; 571.1Spgoyette } 581.1Spgoyette add($2, $1, 0); 591.2Schristos for (i = 3; i <= NF; i++) { 601.1Spgoyette add($2, $i, 1); 611.1Spgoyette } 621.2Schristos } 631.2Schristos END { 641.1Spgoyette for (key in names) { 651.1Spgoyette proto = key; 661.1Spgoyette 671.1Spgoyette n = split(names[key], ar); 681.1Spgoyette printf "name=%s, proto=%s, aliases=", ar[1], proto; 691.1Spgoyette for (i=2; i<=n; i++) { 701.3Sjschauma if (i>2) { 711.3Sjschauma printf " "; 721.3Sjschauma } 731.4Sjschauma printf "%s", ar[i]; 741.1Spgoyette } 751.1Spgoyette printf "\n"; 761.1Spgoyette delete ar; 771.1Spgoyette } 781.3Sjschauma } 791.1Spgoyette ' | sort >exp 801.1Spgoyette 811.1Spgoyette # run test program 821.1Spgoyette "$(atf_get_srcdir)/h_protoent" | sed 's/ *$//' | sort >out 831.1Spgoyette 841.1Spgoyette diff -u exp out || \ 851.1Spgoyette atf_fail "Observed output does not match reference output" 861.1Spgoyette} 871.1Spgoyette 881.1Spgoyetteatf_init_test_cases() 891.1Spgoyette{ 901.1Spgoyette atf_add_test_case protoent 911.1Spgoyette} 92