t_sh.sh revision 272343
1272343Sngie# $NetBSD: t_sh.sh,v 1.1 2011/03/03 11:54:12 pooka 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 28272343Sngie# 29272343Sngie# Test various /bin/sh descriptor games. 30272343Sngie# 31272343Sngie# Note that there is an extra level of trickery here, since 32272343Sngie# we need to run an extra level of shell to "catch" LD_PRELOAD. 33272343Sngie# 34272343Sngie 35272343Sngierumpsrv='rump_server -lrumpvfs' 36272343Sngieexport RUMP_SERVER=unix://csock 37272343Sngieexout="this is the output you are looking for" 38272343Sngie 39272343Sngieatf_test_case runscript cleanup 40272343Sngierunscript_head() 41272343Sngie{ 42272343Sngie atf_set "descr" "can run /bin/sh scripts from rumpfs" 43272343Sngie} 44272343Sngie 45272343Sngierunscript_body() 46272343Sngie{ 47272343Sngie atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER} 48272343Sngie 49272343Sngie export LD_PRELOAD=/usr/lib/librumphijack.so 50272343Sngie echo "echo $exout" > thescript 51272343Sngie atf_check -s exit:0 mv thescript /rump 52272343Sngie atf_check -s exit:0 -o inline:"${exout}\n" -x sh /rump/thescript 53272343Sngie} 54272343Sngie 55272343Sngierunscript_cleanup() 56272343Sngie{ 57272343Sngie rump.halt 58272343Sngie} 59272343Sngie 60272343Sngieatf_test_case redirect cleanup 61272343Sngieredirect_head() 62272343Sngie{ 63272343Sngie atf_set "descr" "input/output redirection works with rumphijack" 64272343Sngie} 65272343Sngie 66272343Sngieredirect_body() 67272343Sngie{ 68272343Sngie atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER} 69272343Sngie export LD_PRELOAD=/usr/lib/librumphijack.so 70272343Sngie 71272343Sngie echo "echo $exout > /rump/thefile" > thescript 72272343Sngie atf_check -s exit:0 -x sh thescript 73272343Sngie 74272343Sngie # read it without input redirection 75272343Sngie atf_check -s exit:0 -o inline:"${exout}\n" cat /rump/thefile 76272343Sngie 77272343Sngie # read it with input redirection (note, need an exec'd shell again) 78272343Sngie echo "cat < /rump/thefile" > thescript 79272343Sngie atf_check -s exit:0 -o inline:"${exout}\n" -x sh thescript 80272343Sngie} 81272343Sngie 82272343Sngieredirect_cleanup() 83272343Sngie{ 84272343Sngie rump.halt 85272343Sngie} 86272343Sngie 87272343Sngieatf_init_test_cases() 88272343Sngie{ 89272343Sngie atf_add_test_case runscript 90272343Sngie atf_add_test_case redirect 91272343Sngie} 92