xref: /minix3/tests/bin/ps/t_ps.sh (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc# $NetBSD: t_ps.sh,v 1.2 2014/01/16 04:16:32 mlelstv Exp $
211be35a1SLionel Sambuc#
311be35a1SLionel Sambuc# Copyright (c) 2007 The NetBSD Foundation, Inc.
411be35a1SLionel Sambuc# All rights reserved.
511be35a1SLionel Sambuc#
611be35a1SLionel Sambuc# Redistribution and use in source and binary forms, with or without
711be35a1SLionel Sambuc# modification, are permitted provided that the following conditions
811be35a1SLionel Sambuc# are met:
911be35a1SLionel Sambuc# 1. Redistributions of source code must retain the above copyright
1011be35a1SLionel Sambuc#    notice, this list of conditions and the following disclaimer.
1111be35a1SLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright
1211be35a1SLionel Sambuc#    notice, this list of conditions and the following disclaimer in the
1311be35a1SLionel Sambuc#    documentation and/or other materials provided with the distribution.
1411be35a1SLionel Sambuc#
1511be35a1SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1611be35a1SLionel Sambuc# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1711be35a1SLionel Sambuc# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1811be35a1SLionel Sambuc# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1911be35a1SLionel Sambuc# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2011be35a1SLionel Sambuc# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2111be35a1SLionel Sambuc# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2211be35a1SLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2311be35a1SLionel Sambuc# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2411be35a1SLionel Sambuc# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2511be35a1SLionel Sambuc# POSSIBILITY OF SUCH DAMAGE.
2611be35a1SLionel Sambuc#
2711be35a1SLionel Sambuc
2811be35a1SLionel Sambuc# the implementation of "ps" to test
2911be35a1SLionel Sambuc: ${TEST_PS:="ps"}
3011be35a1SLionel Sambuc# tab and newline characters
3111be35a1SLionel Sambuctab="$(printf '\t')"
3211be35a1SLionel Sambuc# nl="$(printf '\n')" doesn't work
3311be35a1SLionel Sambucnl='
3411be35a1SLionel Sambuc'
3511be35a1SLionel Sambuc
3611be35a1SLionel Sambuc#
3711be35a1SLionel Sambuc# Parse the "keywords" file into a load of shell variables
3811be35a1SLionel Sambuc#
3911be35a1SLionel Sambucsetup_keywords()
4011be35a1SLionel Sambuc{
4111be35a1SLionel Sambuc	# Set variables representing the header text
4211be35a1SLionel Sambuc	# for all normal keywords (except aliases), and
4311be35a1SLionel Sambuc	# for regular expressions to match the text in left- or
4411be35a1SLionel Sambuc	# right-justified columns.
4511be35a1SLionel Sambuc	# For example, head_text_p_cpu="%CPU" head_regexp_p_cpu=" *%CPU".
4611be35a1SLionel Sambuc	while read keyword heading flag
4711be35a1SLionel Sambuc	do
4811be35a1SLionel Sambuc		case "$keyword" in
4911be35a1SLionel Sambuc		''|\#*)	continue
5011be35a1SLionel Sambuc			;;
5111be35a1SLionel Sambuc		esac
5211be35a1SLionel Sambuc		[ x"$flag" = x"ALIAS" ] && continue
5311be35a1SLionel Sambuc		kvar="${keyword}"
5411be35a1SLionel Sambuc		case "${keyword}" in
5511be35a1SLionel Sambuc		%*)	kvar="p_${keyword#%}"
5611be35a1SLionel Sambuc			;;
5711be35a1SLionel Sambuc		esac
5811be35a1SLionel Sambuc		eval head_text_${kvar}=\'"${heading}"\'
5911be35a1SLionel Sambuc		case "${flag}" in
6011be35a1SLionel Sambuc		'')	# right justified
6111be35a1SLionel Sambuc			eval head_regexp_${kvar}=\'" *${heading}"\'
6211be35a1SLionel Sambuc			;;
6311be35a1SLionel Sambuc		LJUST)	# left justified
6411be35a1SLionel Sambuc			eval head_regexp_${kvar}=\'"${heading} *"\'
6511be35a1SLionel Sambuc			;;
6611be35a1SLionel Sambuc		*)	atf_fail "unknown flag in keywords"
6711be35a1SLionel Sambuc			;;
6811be35a1SLionel Sambuc		esac
6911be35a1SLionel Sambuc	done <"$(atf_get_srcdir)/keywords"
7011be35a1SLionel Sambuc
7111be35a1SLionel Sambuc	# Now do the aliases.
7211be35a1SLionel Sambuc	while read keyword heading flag
7311be35a1SLionel Sambuc	do
7411be35a1SLionel Sambuc		case "$keyword" in
7511be35a1SLionel Sambuc		''|\#*)	continue
7611be35a1SLionel Sambuc			;;
7711be35a1SLionel Sambuc		esac
7811be35a1SLionel Sambuc		[ x"$flag" != x"ALIAS" ] && continue
7911be35a1SLionel Sambuc		kvar="${keyword}"
8011be35a1SLionel Sambuc		avar="${heading}"
8111be35a1SLionel Sambuc		case "${keyword}" in
8211be35a1SLionel Sambuc		%*)	kvar="p_${keyword#%}"
8311be35a1SLionel Sambuc			;;
8411be35a1SLionel Sambuc		esac
8511be35a1SLionel Sambuc		case "${heading}" in
8611be35a1SLionel Sambuc		%*)	avar="p_${heading#%}"
8711be35a1SLionel Sambuc			;;
8811be35a1SLionel Sambuc		esac
8911be35a1SLionel Sambuc		eval head_text_${kvar}=\"\$head_text_${avar}\"
9011be35a1SLionel Sambuc		eval head_regexp_${kvar}=\"\$head_regexp_${avar}\"
9111be35a1SLionel Sambuc	done <"$(atf_get_srcdir)/keywords"
9211be35a1SLionel Sambuc
9311be35a1SLionel Sambuc	# default sets of keywords
9411be35a1SLionel Sambuc	default_keywords='pid tty stat time command'
9511be35a1SLionel Sambuc	j_keywords='user pid ppid pgid sess jobc state tt time command'
9611be35a1SLionel Sambuc	l_keywords='uid pid ppid cpu pri nice vsz rss wchan state tt time command'
97*0a6a1f1dSLionel Sambuc	s_keywords='uid pid ppid cpu lid nlwp pri nice vsz rss wchan lstate tt ltime command'
9811be35a1SLionel Sambuc	u_keywords='user pid %cpu %mem vsz rss tt state start time command'
9911be35a1SLionel Sambuc	v_keywords='pid state time sl re pagein vsz rss lim tsiz %cpu %mem command'
10011be35a1SLionel Sambuc}
10111be35a1SLionel Sambuc
10211be35a1SLionel Sambuc# Convert a list of keywords like "pid comm" to a regexp
10311be35a1SLionel Sambuc# like " *PID COMMAND *"
10411be35a1SLionel Sambucheading_keywords_to_regexp()
10511be35a1SLionel Sambuc{
10611be35a1SLionel Sambuc	local keywords="$1"
10711be35a1SLionel Sambuc	local regexp
10811be35a1SLionel Sambuc	regexp="$(echo "$keywords" | \
10911be35a1SLionel Sambuc		sed -E -e 's/\%/p_/g' -e 's/(^| )/\1\$head_regexp_/g')"
11011be35a1SLionel Sambuc	eval regexp=\""${regexp}"\"
11111be35a1SLionel Sambuc	regexp="^${regexp}\$"
11211be35a1SLionel Sambuc	echo "$regexp"
11311be35a1SLionel Sambuc}
11411be35a1SLionel Sambuc
11511be35a1SLionel Sambuc#
11611be35a1SLionel Sambuc# Check that a string matches a regexp; use the specified id
11711be35a1SLionel Sambuc# in error or success messages.
11811be35a1SLionel Sambuc#
11911be35a1SLionel Sambuccheck_regexp() {
12011be35a1SLionel Sambuc	local id="$1" string="$2" regexp="$3"
12111be35a1SLionel Sambuc	if ! expr "$string" : "$regexp" >/dev/null
12211be35a1SLionel Sambuc	then
12311be35a1SLionel Sambuc		atf_fail "${id}: expected [${regexp}], got [${string}]"
12411be35a1SLionel Sambuc		false
12511be35a1SLionel Sambuc	fi
12611be35a1SLionel Sambuc}
12711be35a1SLionel Sambuc
12811be35a1SLionel Sambuc#
12911be35a1SLionel Sambuc# Run "ps $args -p $$"; check that only one line is printed,
13011be35a1SLionel Sambuc# without a preceding header line.
13111be35a1SLionel Sambuc#
13211be35a1SLionel Sambuccheck_no_heading_line()
13311be35a1SLionel Sambuc{
13411be35a1SLionel Sambuc	local args="$1"
13511be35a1SLionel Sambuc	local output="$(eval "${TEST_PS} $args -p $$")"
13611be35a1SLionel Sambuc	case "$output" in
13711be35a1SLionel Sambuc	*"$nl"*)
13811be35a1SLionel Sambuc		local firstline="${output%%${nl}*}"
13911be35a1SLionel Sambuc		atf_fail "check_no_heading_line [$args] got [$firstline]"
14011be35a1SLionel Sambuc		;;
14111be35a1SLionel Sambuc	*)
14211be35a1SLionel Sambuc		;;
14311be35a1SLionel Sambuc	esac
14411be35a1SLionel Sambuc}
14511be35a1SLionel Sambuc
14611be35a1SLionel Sambuc#
14711be35a1SLionel Sambuc# Run "ps $args"; check that the heading matches the expected regexp.
14811be35a1SLionel Sambuc#
14911be35a1SLionel Sambuccheck_heading_regexp()
15011be35a1SLionel Sambuc{
15111be35a1SLionel Sambuc	args="$1"
15211be35a1SLionel Sambuc	regexp="$2"
15311be35a1SLionel Sambuc	actual="$( eval "${TEST_PS} $args" | sed -e 1q )"
15411be35a1SLionel Sambuc	check_regexp "heading [$args]" "${actual}" "${regexp}"
15511be35a1SLionel Sambuc}
15611be35a1SLionel Sambuc
15711be35a1SLionel Sambuc#
15811be35a1SLionel Sambuc# Run "ps $args"; check that the heading matches a regexp constructed
15911be35a1SLionel Sambuc# from the specified keywords.
16011be35a1SLionel Sambuc#
16111be35a1SLionel Sambuccheck_heading_keywords()
16211be35a1SLionel Sambuc{
16311be35a1SLionel Sambuc	args="$1"
16411be35a1SLionel Sambuc	keywords="$2"
16511be35a1SLionel Sambuc	check_heading_regexp "$args" "$(heading_keywords_to_regexp "$keywords")"
16611be35a1SLionel Sambuc}
16711be35a1SLionel Sambuc
16811be35a1SLionel Sambuc#
16911be35a1SLionel Sambuc# Try several variations on "ps $flag", "ps -$flag", etc.,
17011be35a1SLionel Sambuc# and check that the heading always has the correct keywords.
17111be35a1SLionel Sambuc#
17211be35a1SLionel Sambuccheck_heading_variations()
17311be35a1SLionel Sambuc{
17411be35a1SLionel Sambuc	flag="$1"
17511be35a1SLionel Sambuc	keywords="$2"
17611be35a1SLionel Sambuc	for args in "$flag" "-$flag" "-$flag$flag -$flag"; do
17711be35a1SLionel Sambuc		check_heading_keywords "$args" "$keywords"
17811be35a1SLionel Sambuc	done
17911be35a1SLionel Sambuc}
18011be35a1SLionel Sambuc
18111be35a1SLionel Sambucatf_test_case default_columns
18211be35a1SLionel Sambucdefault_columns_head()
18311be35a1SLionel Sambuc{
18411be35a1SLionel Sambuc	atf_set "descr" "Checks that the default set of columns is correct" \
18511be35a1SLionel Sambuc	                "and also check that the columns printed by the -j," \
18611be35a1SLionel Sambuc	                "-l, -s, -u and -v flags alone are correct"
18711be35a1SLionel Sambuc}
18811be35a1SLionel Sambucdefault_columns_body()
18911be35a1SLionel Sambuc{
19011be35a1SLionel Sambuc	setup_keywords
19111be35a1SLionel Sambuc	check_heading_keywords '' "$default_keywords"
19211be35a1SLionel Sambuc	check_heading_variations 'j' "$j_keywords"
19311be35a1SLionel Sambuc	check_heading_variations 'l' "$l_keywords"
19411be35a1SLionel Sambuc	check_heading_variations 's' "$s_keywords"
19511be35a1SLionel Sambuc	check_heading_variations 'u' "$u_keywords"
19611be35a1SLionel Sambuc	check_heading_variations 'v' "$v_keywords"
19711be35a1SLionel Sambuc}
19811be35a1SLionel Sambuc
19911be35a1SLionel Sambucatf_test_case minus_O
20011be35a1SLionel Sambucminus_O_head()
20111be35a1SLionel Sambuc{
20211be35a1SLionel Sambuc	atf_set "descr" "Checks that 'ps -O foo' inserts columns just after" \
20311be35a1SLionel Sambuc	                "the pid column"
20411be35a1SLionel Sambuc}
20511be35a1SLionel Sambucminus_O_body()
20611be35a1SLionel Sambuc{
20711be35a1SLionel Sambuc	setup_keywords
20811be35a1SLionel Sambuc	check_heading_keywords '-O %cpu,%mem' \
20911be35a1SLionel Sambuc		"$(echo "${default_keywords}" | sed -e 's/pid/pid %cpu %mem/')"
21011be35a1SLionel Sambuc	check_heading_keywords '-O %cpu -O %mem' \
21111be35a1SLionel Sambuc		"$(echo "${default_keywords}" | sed -e 's/pid/pid %cpu %mem/')"
21211be35a1SLionel Sambuc	check_heading_keywords '-O%cpu -O%mem' \
21311be35a1SLionel Sambuc		"$(echo "${default_keywords}" | sed -e 's/pid/pid %cpu %mem/')"
21411be35a1SLionel Sambuc}
21511be35a1SLionel Sambuc
21611be35a1SLionel Sambucatf_test_case minus_o
21711be35a1SLionel Sambucminus_o_head()
21811be35a1SLionel Sambuc{
21911be35a1SLionel Sambuc	atf_set "descr" "Checks simple cases of 'ps -o foo' to control which" \
22011be35a1SLionel Sambuc	                "columns are printed; this does not test header" \
22111be35a1SLionel Sambuc	                "overriding via 'ps -o foo=BAR'"
22211be35a1SLionel Sambuc}
22311be35a1SLionel Sambucminus_o_body()
22411be35a1SLionel Sambuc{
22511be35a1SLionel Sambuc	setup_keywords
22611be35a1SLionel Sambuc	# Keywords for "-o name" override the default display
22711be35a1SLionel Sambuc	check_heading_keywords '-o pid,%cpu,%mem' \
22811be35a1SLionel Sambuc		"pid %cpu %mem"
22911be35a1SLionel Sambuc	check_heading_keywords '-o pid -o %cpu,%mem' \
23011be35a1SLionel Sambuc		"pid %cpu %mem"
23111be35a1SLionel Sambuc	check_heading_keywords '-opid -o %cpu,%mem' \
23211be35a1SLionel Sambuc		"pid %cpu %mem"
23311be35a1SLionel Sambuc	# Space works like comma
23411be35a1SLionel Sambuc	check_heading_keywords '-opid -o "%cpu %mem"' \
23511be35a1SLionel Sambuc		"pid %cpu %mem"
23611be35a1SLionel Sambuc	# Check missing pid
23711be35a1SLionel Sambuc	check_heading_keywords '-o comm' \
23811be35a1SLionel Sambuc		"comm"
23911be35a1SLionel Sambuc	# Check pid present but not first
24011be35a1SLionel Sambuc	check_heading_keywords '-o comm,pid' \
24111be35a1SLionel Sambuc		"comm pid"
24211be35a1SLionel Sambuc}
24311be35a1SLionel Sambuc
24411be35a1SLionel Sambucatf_test_case override_heading_simple
24511be35a1SLionel Sambucoverride_heading_simple_head()
24611be35a1SLionel Sambuc{
24711be35a1SLionel Sambuc	atf_set "descr" "Tests simple uses of header overriding via" \
24811be35a1SLionel Sambuc	                "'ps -o foo=BAR'.  This does not test columns " \
24911be35a1SLionel Sambuc	                "with null headings, or headings with embedded" \
25011be35a1SLionel Sambuc	                "space, ',' or '='."
25111be35a1SLionel Sambuc}
25211be35a1SLionel Sambucoverride_heading_simple_body()
25311be35a1SLionel Sambuc{
25411be35a1SLionel Sambuc	setup_keywords
25511be35a1SLionel Sambuc	check_heading_regexp '-o pid=PPP -o comm' \
25611be35a1SLionel Sambuc		'^ *PPP '"${head_text_comm}"'$' # no trailing space
25711be35a1SLionel Sambuc	check_heading_regexp '-o pid=PPP -o comm=CCC' \
25811be35a1SLionel Sambuc		'^ *PPP CCC$'
25911be35a1SLionel Sambuc	check_heading_regexp '-o pid,comm=CCC' \
26011be35a1SLionel Sambuc		'^'"${head_regexp_pid}"' CCC$'
26111be35a1SLionel Sambuc	check_heading_regexp '-o pid -o comm=CCC' \
26211be35a1SLionel Sambuc		'^'"${head_regexp_pid}"' CCC$'
26311be35a1SLionel Sambuc	# Check missing pid
26411be35a1SLionel Sambuc	check_heading_regexp '-o comm=CCC' \
26511be35a1SLionel Sambuc		'^CCC$'
26611be35a1SLionel Sambuc	# Check pid present but not first
26711be35a1SLionel Sambuc	check_heading_regexp '-o comm=CCC -o pid=PPP' \
26811be35a1SLionel Sambuc		'^CCC  *PPP$'
26911be35a1SLionel Sambuc	check_heading_regexp '-o comm,pid=PPP' \
27011be35a1SLionel Sambuc		'^'"${head_regexp_comm}"'  *PPP$'
27111be35a1SLionel Sambuc}
27211be35a1SLionel Sambuc
27311be35a1SLionel Sambucatf_test_case override_heading_embedded_specials
27411be35a1SLionel Sambucoverride_heading_embedded_specials_head()
27511be35a1SLionel Sambuc{
27611be35a1SLionel Sambuc	atf_set "descr" "Tests header overriding with embedded space," \
27711be35a1SLionel Sambuc	                "',' or '='.  Everything after the first '='" \
27811be35a1SLionel Sambuc	                "is part of the heading."
27911be35a1SLionel Sambuc}
28011be35a1SLionel Sambucoverride_heading_embedded_specials_body()
28111be35a1SLionel Sambuc{
28211be35a1SLionel Sambuc	setup_keywords
28311be35a1SLionel Sambuc	# Check embedded "," or "=" in override header.
28411be35a1SLionel Sambuc	check_heading_regexp '-o comm,pid==' \
28511be35a1SLionel Sambuc		'^'"${head_regexp_comm}"'  *=$'
28611be35a1SLionel Sambuc	check_heading_regexp '-o comm,pid=,' \
28711be35a1SLionel Sambuc		'^'"${head_regexp_comm}"'  *,$'
28811be35a1SLionel Sambuc	check_heading_regexp '-o pid=PPP,comm' \
28911be35a1SLionel Sambuc		'^ *PPP,comm$' # not like '-o pid=PPP -o comm'
29011be35a1SLionel Sambuc	check_heading_regexp '-o pid=PPP,comm=CCC' \
29111be35a1SLionel Sambuc		'^ *PPP,comm=CCC$' # not like '-o pid=PPP -o comm=CCC'
29211be35a1SLionel Sambuc	check_heading_regexp '-o comm,pid=PPP,QQQ' \
29311be35a1SLionel Sambuc		'^'"${head_regexp_comm}"'  *PPP,QQQ$'
29411be35a1SLionel Sambuc	check_heading_regexp '-o comm,pid=ppid,tty=state' \
29511be35a1SLionel Sambuc		'^'"${head_regexp_comm}"'  *ppid,tty=state$'
29611be35a1SLionel Sambuc	# Check embedded space or tab in override header.
29711be35a1SLionel Sambuc	check_heading_regexp '-o comm,pid="PPP QQQ"' \
29811be35a1SLionel Sambuc		'^'"${head_regexp_comm}"'  *PPP QQQ$'
29911be35a1SLionel Sambuc	check_heading_regexp '-o comm,pid="PPP${tab}QQQ"' \
30011be35a1SLionel Sambuc		'^'"${head_regexp_comm}"'  *PPP'"${tab}"'QQQ$'
30111be35a1SLionel Sambuc}
30211be35a1SLionel Sambuc
30311be35a1SLionel Sambucatf_test_case override_heading_some_null
30411be35a1SLionel Sambucoverride_heading_some_null_head()
30511be35a1SLionel Sambuc{
30611be35a1SLionel Sambuc	atf_set "descr" "Tests simple uses of null column headings" \
30711be35a1SLionel Sambuc	                "overriding via 'ps -o foo=BAR -o baz='.  This" \
30811be35a1SLionel Sambuc	                "does not test the case where all columns have" \
30911be35a1SLionel Sambuc	                "null headings."
31011be35a1SLionel Sambuc}
31111be35a1SLionel Sambucoverride_heading_some_null_body()
31211be35a1SLionel Sambuc{
31311be35a1SLionel Sambuc	setup_keywords
31411be35a1SLionel Sambuc	check_heading_regexp '-o pid=PPP -o comm=' \
31511be35a1SLionel Sambuc		'^ *PPP *$'
31611be35a1SLionel Sambuc	check_heading_regexp '-o pid= -o comm=CCC' \
31711be35a1SLionel Sambuc		'^ * CCC$'
31811be35a1SLionel Sambuc	check_heading_regexp '-o pid -o comm=' \
31911be35a1SLionel Sambuc		'^'"${head_regexp_pid}"' *$'
32011be35a1SLionel Sambuc	# Check missing pid
32111be35a1SLionel Sambuc	check_heading_regexp '-o ppid= -o comm=CCC' \
32211be35a1SLionel Sambuc		'^ * CCC$'
32311be35a1SLionel Sambuc	check_heading_regexp '-o ppid=PPP -o comm=' \
32411be35a1SLionel Sambuc		'^ *PPP *$'
32511be35a1SLionel Sambuc	# Check pid present but not first
32611be35a1SLionel Sambuc	check_heading_regexp '-o comm= -o pid=PPP' \
32711be35a1SLionel Sambuc		'^ * PPP$'
32811be35a1SLionel Sambuc	check_heading_regexp '-o comm,pid=' \
32911be35a1SLionel Sambuc		'^'"${head_regexp_comm}"' *$'
33011be35a1SLionel Sambuc	# A field with a null custom heading retains a minimum width
33111be35a1SLionel Sambuc	# derived from the default heading.  This does not apply
33211be35a1SLionel Sambuc	# to a field with a very short (non-null) custom heading.
33311be35a1SLionel Sambuc	#
33411be35a1SLionel Sambuc	# We choose "holdcnt" as a column whose width is likely to be
33511be35a1SLionel Sambuc	# determined entirely by the header width, because the values
33611be35a1SLionel Sambuc	# are likely to be very small.
33711be35a1SLionel Sambuc	check_heading_regexp '-o holdcnt -o holdcnt -o holdcnt' \
33811be35a1SLionel Sambuc		'^HOLDCNT HOLDCNT HOLDCNT$'
33911be35a1SLionel Sambuc	check_heading_regexp '-o holdcnt -o holdcnt= -o holdcnt' \
34011be35a1SLionel Sambuc		'^HOLDCNT         HOLDCNT$'
34111be35a1SLionel Sambuc	check_heading_regexp '-o holdcnt -o holdcnt=HH -o holdcnt' \
34211be35a1SLionel Sambuc		'^HOLDCNT HH HOLDCNT$'
34311be35a1SLionel Sambuc}
34411be35a1SLionel Sambuc
34511be35a1SLionel Sambucatf_test_case override_heading_all_null
34611be35a1SLionel Sambucoverride_heading_all_null_head()
34711be35a1SLionel Sambuc{
34811be35a1SLionel Sambuc	atf_set "descr" "Tests the use of 'ps -o foo= -o bar=' (with a" \
34911be35a1SLionel Sambuc	                "null heading for every column).  The heading" \
35011be35a1SLionel Sambuc	                "should not be printed at all in this case."
35111be35a1SLionel Sambuc}
35211be35a1SLionel Sambucoverride_heading_all_null_body()
35311be35a1SLionel Sambuc{
35411be35a1SLionel Sambuc	setup_keywords
35511be35a1SLionel Sambuc	# A heading with a space is not a null heading,
35611be35a1SLionel Sambuc	# so should not be suppressed
35711be35a1SLionel Sambuc	check_heading_regexp '-o comm=" "' \
35811be35a1SLionel Sambuc		'^ *$'
35911be35a1SLionel Sambuc	# Null headings should be suppressed
36011be35a1SLionel Sambuc	check_no_heading_line '-o pid= -o comm='
36111be35a1SLionel Sambuc	check_no_heading_line '-o pid= -o comm='
36211be35a1SLionel Sambuc	# Check missing pid
36311be35a1SLionel Sambuc	check_no_heading_line '-o ppid='
36411be35a1SLionel Sambuc	check_no_heading_line '-o comm='
36511be35a1SLionel Sambuc	check_no_heading_line '-o command='
36611be35a1SLionel Sambuc	check_no_heading_line '-o ppid= -o comm='
36711be35a1SLionel Sambuc	check_no_heading_line '-o comm= -o ppid='
36811be35a1SLionel Sambuc	# Check pid present but not first
36911be35a1SLionel Sambuc	check_no_heading_line '-o comm= -o pid='
37011be35a1SLionel Sambuc	check_no_heading_line '-o ppid= -o pid= -o command='
37111be35a1SLionel Sambuc}
37211be35a1SLionel Sambuc
37311be35a1SLionel Sambucatf_test_case duplicate_column
37411be35a1SLionel Sambucduplicate_column_head()
37511be35a1SLionel Sambuc{
37611be35a1SLionel Sambuc	atf_set "descr" "Tests the use of -o options to display the" \
37711be35a1SLionel Sambuc	                "same column more than once"
37811be35a1SLionel Sambuc}
37911be35a1SLionel Sambucduplicate_column_body()
38011be35a1SLionel Sambuc{
38111be35a1SLionel Sambuc	setup_keywords
38211be35a1SLionel Sambuc	# two custom headers
38311be35a1SLionel Sambuc	check_heading_regexp '-o pid=PPP -o pid=QQQ' \
38411be35a1SLionel Sambuc		'^ *PPP  *QQQ$'
38511be35a1SLionel Sambuc	# one custom header, before and after default header
38611be35a1SLionel Sambuc	check_heading_regexp '-o pid=PPP -o pid' \
38711be35a1SLionel Sambuc		'^ *PPP '"${head_regexp_pid}"'$'
38811be35a1SLionel Sambuc	check_heading_regexp '-o pid -o pid=QQQ' \
38911be35a1SLionel Sambuc		'^'"${head_regexp_pid}"'  *QQQ$'
39011be35a1SLionel Sambuc	# custom headers both before and after default header
39111be35a1SLionel Sambuc	check_heading_regexp '-o pid=PPP -o pid -o pid=QQQ' \
39211be35a1SLionel Sambuc		'^ *PPP '"${head_regexp_pid}"'  *QQQ$'
39311be35a1SLionel Sambuc}
39411be35a1SLionel Sambuc
39511be35a1SLionel Sambucatf_init_test_cases() {
39611be35a1SLionel Sambuc	atf_add_test_case default_columns
39711be35a1SLionel Sambuc	atf_add_test_case minus_O
39811be35a1SLionel Sambuc	atf_add_test_case minus_o
39911be35a1SLionel Sambuc	atf_add_test_case override_heading_simple
40011be35a1SLionel Sambuc	atf_add_test_case override_heading_embedded_specials
40111be35a1SLionel Sambuc	atf_add_test_case override_heading_some_null
40211be35a1SLionel Sambuc	atf_add_test_case override_heading_all_null
40311be35a1SLionel Sambuc	atf_add_test_case duplicate_column
40411be35a1SLionel Sambuc}
405