2 # Copyright (c) 2017 Ngie Cooper <ngie@FreeBSD.org>
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
15 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
16 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
18 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 # POSSIBILITY OF SUCH DAMAGE.
31 PROG_PATH=$(atf_get_srcdir)/while1
37 echo "Starting program in background"
39 PROG_PATH=$(atf_get_srcdir)/$PROG_COMM
44 while [ $try -lt $MAX_TRIES ] && ! kill -0 $PROG_PID; do
48 if [ $try -ge $MAX_TRIES ]; then
49 atf_fail "Polled for program start $MAX_TRIES tries and failed"
53 atf_test_case binary_info
56 atf_set "descr" "Checks -b support"
60 start_program bogus-arg
62 line_format="$SP*%s$SP+%s$SP+%s$SP+%s$SP*"
63 header_re=$(printf "$line_format" "PID" "COMM" "OSREL" "PATH")
64 line_re=$(printf "$line_format" $PROG_PID $PROG_COMM "[[:digit:]]+" "$PROG_PATH")
66 atf_check -o save:procstat.out procstat -b $PROG_PID
68 atf_check -o match:"$header_re" head -n 1 procstat.out
69 atf_check -o match:"$line_re" tail -n 1 procstat.out
72 atf_test_case command_line_arguments
73 command_line_arguments_head()
75 atf_set "descr" "Checks -c support"
77 command_line_arguments_body()
79 arguments="my arguments"
81 start_program $arguments
83 line_format="$SP*%s$SP+%s$SP+%s$SP*"
84 header_re=$(printf "$line_format" "PID" "COMM" "ARGS")
85 line_re=$(printf "$line_format" $PROG_PID "$PROG_COMM" "$PROG_PATH $arguments")
87 atf_check -o save:procstat.out procstat -c $PROG_PID
88 atf_check -o match:"$header_re" head -n 1 procstat.out
89 atf_check -o match:"$line_re" tail -n 1 procstat.out
92 atf_test_case environment
95 atf_set "descr" "Checks -e support"
102 start_program my arguments
104 line_format="$SP*%s$SP+%s$SP+%s$SP*"
105 header_re=$(printf "$line_format" "PID" "COMM" "ENVIRONMENT")
106 line_re=$(printf "$line_format" $PROG_PID $PROG_COMM ".*$var.*")
108 atf_check -o save:procstat.out procstat -e $PROG_PID
110 atf_check -o match:"$header_re" head -n 1 procstat.out
111 atf_check -o match:"$line_re" tail -n 1 procstat.out
114 atf_test_case file_descriptor
115 file_descriptor_head()
117 atf_set "descr" "Checks -f support"
119 file_descriptor_body()
121 start_program my arguments
123 line_format="$SP*%s$SP+%s$SP+%s$SP+%s$SP+%s$SP+%s$SP+%s$SP+%s$SP+%s$SP%s$SP*"
124 header_re=$(printf "$line_format" "PID" "COMM" "FD" "T" "V" "FLAGS" "REF" "OFFSET" "PRO" "NAME")
125 # XXX: write a more sensible feature test
126 line_re=$(printf "$line_format" $PROG_PID $PROG_COMM ".+" ".+" ".+" ".+" ".+" ".+" ".+" ".+")
128 atf_check -o save:procstat.out procstat -f $PROG_PID
130 atf_check -o match:"$header_re" head -n 1 procstat.out
131 atf_check -o match:"$line_re" awk 'NR > 1' procstat.out
134 atf_init_test_cases()
136 atf_add_test_case binary_info
137 atf_add_test_case command_line_arguments
138 atf_add_test_case environment
139 atf_add_test_case file_descriptor