11.1Spooka# $NetBSD: t_sh.sh,v 1.1 2011/03/03 11:54:12 pooka Exp $ 21.1Spooka# 31.1Spooka# Copyright (c) 2011 The NetBSD Foundation, Inc. 41.1Spooka# All rights reserved. 51.1Spooka# 61.1Spooka# Redistribution and use in source and binary forms, with or without 71.1Spooka# modification, are permitted provided that the following conditions 81.1Spooka# are met: 91.1Spooka# 1. Redistributions of source code must retain the above copyright 101.1Spooka# notice, this list of conditions and the following disclaimer. 111.1Spooka# 2. Redistributions in binary form must reproduce the above copyright 121.1Spooka# notice, this list of conditions and the following disclaimer in the 131.1Spooka# documentation and/or other materials provided with the distribution. 141.1Spooka# 151.1Spooka# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 161.1Spooka# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 171.1Spooka# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 181.1Spooka# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 191.1Spooka# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 201.1Spooka# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 211.1Spooka# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 221.1Spooka# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 231.1Spooka# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 241.1Spooka# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 251.1Spooka# POSSIBILITY OF SUCH DAMAGE. 261.1Spooka# 271.1Spooka 281.1Spooka# 291.1Spooka# Test various /bin/sh descriptor games. 301.1Spooka# 311.1Spooka# Note that there is an extra level of trickery here, since 321.1Spooka# we need to run an extra level of shell to "catch" LD_PRELOAD. 331.1Spooka# 341.1Spooka 351.1Spookarumpsrv='rump_server -lrumpvfs' 361.1Spookaexport RUMP_SERVER=unix://csock 371.1Spookaexout="this is the output you are looking for" 381.1Spooka 391.1Spookaatf_test_case runscript cleanup 401.1Spookarunscript_head() 411.1Spooka{ 421.1Spooka atf_set "descr" "can run /bin/sh scripts from rumpfs" 431.1Spooka} 441.1Spooka 451.1Spookarunscript_body() 461.1Spooka{ 471.1Spooka atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER} 481.1Spooka 491.1Spooka export LD_PRELOAD=/usr/lib/librumphijack.so 501.1Spooka echo "echo $exout" > thescript 511.1Spooka atf_check -s exit:0 mv thescript /rump 521.1Spooka atf_check -s exit:0 -o inline:"${exout}\n" -x sh /rump/thescript 531.1Spooka} 541.1Spooka 551.1Spookarunscript_cleanup() 561.1Spooka{ 571.1Spooka rump.halt 581.1Spooka} 591.1Spooka 601.1Spookaatf_test_case redirect cleanup 611.1Spookaredirect_head() 621.1Spooka{ 631.1Spooka atf_set "descr" "input/output redirection works with rumphijack" 641.1Spooka} 651.1Spooka 661.1Spookaredirect_body() 671.1Spooka{ 681.1Spooka atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER} 691.1Spooka export LD_PRELOAD=/usr/lib/librumphijack.so 701.1Spooka 711.1Spooka echo "echo $exout > /rump/thefile" > thescript 721.1Spooka atf_check -s exit:0 -x sh thescript 731.1Spooka 741.1Spooka # read it without input redirection 751.1Spooka atf_check -s exit:0 -o inline:"${exout}\n" cat /rump/thefile 761.1Spooka 771.1Spooka # read it with input redirection (note, need an exec'd shell again) 781.1Spooka echo "cat < /rump/thefile" > thescript 791.1Spooka atf_check -s exit:0 -o inline:"${exout}\n" -x sh thescript 801.1Spooka} 811.1Spooka 821.1Spookaredirect_cleanup() 831.1Spooka{ 841.1Spooka rump.halt 851.1Spooka} 861.1Spooka 871.1Spookaatf_init_test_cases() 881.1Spooka{ 891.1Spooka atf_add_test_case runscript 901.1Spooka atf_add_test_case redirect 911.1Spooka} 92