1313498Sngie#       $NetBSD: t_exec.sh,v 1.9 2016/08/10 21:10:18 kre Exp $
2272343Sngie#
3272343Sngie# Copyright (c) 2011 The NetBSD Foundation, Inc.
4272343Sngie# All rights reserved.
5272343Sngie#
6272343Sngie# Redistribution and use in source and binary forms, with or without
7272343Sngie# modification, are permitted provided that the following conditions
8272343Sngie# are met:
9272343Sngie# 1. Redistributions of source code must retain the above copyright
10272343Sngie#    notice, this list of conditions and the following disclaimer.
11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright
12272343Sngie#    notice, this list of conditions and the following disclaimer in the
13272343Sngie#    documentation and/or other materials provided with the distribution.
14272343Sngie#
15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18272343Sngie# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25272343Sngie# POSSIBILITY OF SUCH DAMAGE.
26272343Sngie#
27272343Sngie
28313498Sngierumpsrv='rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpdev -lrumpvfs'
29272343Sngieexport RUMP_SERVER=unix://csock
30272343Sngieexport RUMPHIJACK_RETRYCONNECT='die'
31272343Sngie
32272343Sngieatf_test_case noexec cleanup
33272343Sngienoexec_head()
34272343Sngie{
35272343Sngie        atf_set "descr" "check that we see what we expect without exec"
36272343Sngie}
37272343Sngie
38272343Sngienoexec_body()
39272343Sngie{
40272343Sngie
41272343Sngie	atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER}
42272343Sngie	atf_check -s exit:0 env $(atf_get_srcdir)/h_exec
43272343Sngie	atf_check -s exit:0 -o save:sstat.out rump.sockstat -n
44272343Sngie	atf_check -s exit:0 -o match:'^root.*h_exec.*tcp.*\*\.1234' \
45272343Sngie	    sed -n 2p sstat.out
46272343Sngie	atf_check -s exit:0 -o match:'^root.*h_exec.*tcp.*\*\.2345' \
47272343Sngie	    sed -n 3p sstat.out
48272343Sngie}
49272343Sngie
50272343Sngienoexec_cleanup()
51272343Sngie{
52272343Sngie	rump.halt
53272343Sngie}
54272343Sngie
55272343Sngieatf_test_case exec cleanup
56272343Sngieexec_head()
57272343Sngie{
58272343Sngie        atf_set "descr" "check that client names changes after exec"
59272343Sngie}
60272343Sngie
61272343Sngieexec_body()
62272343Sngie{
63272343Sngie
64272343Sngie	atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER}
65272343Sngie	atf_check -s exit:0 $(atf_get_srcdir)/h_exec $(atf_get_srcdir)/h_exec
66272343Sngie	atf_check -s exit:0 -o save:sstat.out rump.sockstat -n
67272343Sngie	atf_check -s exit:0 -o match:'^root.*h_ution.*tcp.*\*\.1234' \
68272343Sngie	    sed -n 2p sstat.out
69272343Sngie	atf_check -s exit:0 -o match:'^root.*h_ution.*tcp.*\*\.2345' \
70272343Sngie	    sed -n 3p sstat.out
71272343Sngie}
72272343Sngie
73272343Sngieexec_cleanup()
74272343Sngie{
75272343Sngie	rump.halt
76272343Sngie}
77272343Sngie
78272343Sngieatf_test_case cloexec cleanup
79272343Sngiecloexec_head()
80272343Sngie{
81272343Sngie        atf_set "descr" "check that FD_CLOEXEC works"
82272343Sngie}
83272343Sngie
84272343Sngiecloexec_body()
85272343Sngie{
86272343Sngie
87272343Sngie	atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER}
88272343Sngie	atf_check -s exit:0  \
89272343Sngie	    $(atf_get_srcdir)/h_exec $(atf_get_srcdir)/h_exec cloexec1
90272343Sngie	atf_check -s exit:0 -o save:sstat.out rump.sockstat -n
91272343Sngie	atf_check -s exit:0 -o inline:'2\n' sed -n '$=' sstat.out
92272343Sngie	atf_check -s exit:0 -o match:'^root.*h_ution.*tcp.*\*\.2345' \
93272343Sngie	    sed -n 2p sstat.out
94272343Sngie}
95272343Sngie
96272343Sngiecloexec_cleanup()
97272343Sngie{
98272343Sngie	rump.halt
99272343Sngie}
100272343Sngie
101272343Sngieatf_test_case vfork cleanup
102272343Sngievfork_head()
103272343Sngie{
104272343Sngie        atf_set "descr" "test rumpclient_vfork()"
105272343Sngie}
106272343Sngie
107272343Sngievfork_body()
108272343Sngie{
109272343Sngie
110272343Sngie	atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER}
111272343Sngie	atf_check -s exit:0  \
112272343Sngie	    $(atf_get_srcdir)/h_exec $(atf_get_srcdir)/h_exec vfork_please
113272343Sngie	atf_check -s exit:0 -o save:sstat.out rump.sockstat -n
114272343Sngie	atf_check -s exit:0 -o inline:'5\n' sed -n '$=' sstat.out
115272343Sngie	atf_check -s exit:0 -o match:'^root.*h_ution.*tcp.*\*\.1234' \
116272343Sngie	    cat sstat.out
117272343Sngie	atf_check -s exit:0 -o match:'^root.*h_ution.*tcp.*\*\.2345' \
118272343Sngie	    cat sstat.out
119272343Sngie	atf_check -s exit:0 -o match:'^root.*fourchette.*tcp.*\*\.1234' \
120272343Sngie	    cat sstat.out
121272343Sngie	atf_check -s exit:0 -o match:'^root.*fourchette.*tcp.*\*\.2345' \
122272343Sngie	    cat sstat.out
123272343Sngie}
124272343Sngie
125272343Sngievfork_cleanup()
126272343Sngie{
127272343Sngie	rump.halt
128272343Sngie}
129272343Sngie
130272343Sngieatf_test_case threxec cleanup
131272343Sngiethrexec_head()
132272343Sngie{
133272343Sngie	atf_set "descr" "check that threads are killed before exec continues"
134272343Sngie}
135272343Sngie
136272343Sngiethrexec_body()
137272343Sngie{
138272343Sngie	atf_check -s exit:0 rump_server ${RUMP_SERVER}
139272343Sngie	atf_check -s exit:0 $(atf_get_srcdir)/h_execthr
140272343Sngie}
141272343Sngie
142272343Sngiethrexec_cleanup()
143272343Sngie{
144272343Sngie	rump.halt
145272343Sngie}
146272343Sngie
147272343Sngieatf_init_test_cases()
148272343Sngie{
149272343Sngie	atf_add_test_case noexec
150272343Sngie	atf_add_test_case exec
151272343Sngie	atf_add_test_case cloexec
152272343Sngie	atf_add_test_case vfork
153272343Sngie	atf_add_test_case threxec
154272343Sngie}
155