t_pgrep.sh revision 1.2.4.2 1 1.2.4.2 kre # $NetBSD: t_pgrep.sh,v 1.2.4.2 2017/02/21 21:22:46 kre Exp $
2 1.2.4.2 kre #
3 1.2.4.2 kre # Copyright (c) 2016 The NetBSD Foundation, Inc.
4 1.2.4.2 kre # All rights reserved.
5 1.2.4.2 kre #
6 1.2.4.2 kre # Redistribution and use in source and binary forms, with or without
7 1.2.4.2 kre # modification, are permitted provided that the following conditions
8 1.2.4.2 kre # are met:
9 1.2.4.2 kre # 1. Redistributions of source code must retain the above copyright
10 1.2.4.2 kre # notice, this list of conditions and the following disclaimer.
11 1.2.4.2 kre # 2. Redistributions in binary form must reproduce the above copyright
12 1.2.4.2 kre # notice, this list of conditions and the following disclaimer in the
13 1.2.4.2 kre # documentation and/or other materials provided with the distribution.
14 1.2.4.2 kre #
15 1.2.4.2 kre # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.2.4.2 kre # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.2.4.2 kre # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.2.4.2 kre # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.2.4.2 kre # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.2.4.2 kre # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.2.4.2 kre # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.2.4.2 kre # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.2.4.2 kre # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.2.4.2 kre # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.2.4.2 kre # POSSIBILITY OF SUCH DAMAGE.
26 1.2.4.2 kre #
27 1.2.4.2 kre
28 1.2.4.2 kre atf_test_case pr50934
29 1.2.4.2 kre basic_shift_test_head() {
30 1.2.4.2 kre atf_set "descr" "Test fix for PR bin/50934 (null argv[0])"
31 1.2.4.2 kre }
32 1.2.4.2 kre pr50934_body() {
33 1.2.4.2 kre atf_require_prog pgrep
34 1.2.4.2 kre atf_require_prog cc
35 1.2.4.2 kre
36 1.2.4.2 kre cat > t.c <<'!'
37 1.2.4.2 kre #include <stdlib.h>
38 1.2.4.2 kre #include <unistd.h>
39 1.2.4.2 kre
40 1.2.4.2 kre int
41 1.2.4.2 kre main(int argc, char **argv)
42 1.2.4.2 kre {
43 1.2.4.2 kre sleep(2);
44 1.2.4.2 kre argv[0] = 0;
45 1.2.4.2 kre pause();
46 1.2.4.2 kre exit(0);
47 1.2.4.2 kre }
48 1.2.4.2 kre !
49 1.2.4.2 kre
50 1.2.4.2 kre cc -o t0123456789abcdefg-beef t.c || atf_fail "t.c compile failed"
51 1.2.4.2 kre
52 1.2.4.2 kre ./t0123456789abcdefg-beef &
53 1.2.4.2 kre PID=$!
54 1.2.4.2 kre
55 1.2.4.2 kre pgrep -l t0123456 >OUT ; # should find the process
56 1.2.4.2 kre pgrep -l beef >>OUT ; # should find the process
57 1.2.4.2 kre
58 1.2.4.2 kre sleep 5 ; # allow time for sleep in t.c and argv[0]=0
59 1.2.4.2 kre
60 1.2.4.2 kre pgrep -l t0123456 >>OUT ; # should find the process
61 1.2.4.2 kre pgrep -l beef >>OUT ; # should find nothing
62 1.2.4.2 kre
63 1.2.4.2 kre kill -9 $PID
64 1.2.4.2 kre cat OUT ; # just for the log
65 1.2.4.2 kre
66 1.2.4.2 kre # note that pgrep -l only ever prints p_comm which is of limited sicze
67 1.2.4.2 kre atf_check_equal "$(cat OUT)" \
68 1.2.4.2 kre "$PID t0123456789abcde $PID t0123456789abcde $PID t0123456789abcde"
69 1.2.4.2 kre
70 1.2.4.2 kre return 0
71 1.2.4.2 kre }
72 1.2.4.2 kre
73 1.2.4.2 kre atf_init_test_cases() {
74 1.2.4.2 kre atf_add_test_case pr50934
75 1.2.4.2 kre }
76