Home | History | Annotate | Line # | Download | only in csu
t_hello.sh revision 1.2
      1 #	$NetBSD: t_hello.sh,v 1.2 2025/05/02 22:30:29 riastradh Exp $
      2 #
      3 # Copyright (c) 2025 The NetBSD Foundation, Inc.
      4 # All rights reserved.
      5 #
      6 # Redistribution and use in source and binary forms, with or without
      7 # modification, are permitted provided that the following conditions
      8 # are met:
      9 # 1. Redistributions of source code must retain the above copyright
     10 #    notice, this list of conditions and the following disclaimer.
     11 # 2. Redistributions in binary form must reproduce the above copyright
     12 #    notice, this list of conditions and the following disclaimer in the
     13 #    documentation and/or other materials provided with the distribution.
     14 #
     15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25 # POSSIBILITY OF SUCH DAMAGE.
     26 #
     27 
     28 checksupport()
     29 {
     30 	local prog
     31 
     32 	prog=$1
     33 	test -f "$(atf_get_srcdir)/${prog}" || atf_skip "not supported"
     34 }
     35 
     36 checkrun()
     37 {
     38 	local prog
     39 
     40 	prog=$1
     41 	atf_check -o inline:"${prog}: Hello, world! 42\n" \
     42 	    "$(atf_get_srcdir)/${prog}"
     43 }
     44 
     45 cleanup()
     46 {
     47 	local prog
     48 
     49 	prog=$1
     50 	test -f "${prog}.core" || return 0
     51 	readelf -rs "$(atf_get_srcdir)/${prog}"
     52 	gdb -batch -ex bt -ex 'info registers' -ex disas \
     53 	    "$(atf_get_srcdir)/${prog}" "${prog}.core"
     54 }
     55 
     56 atf_test_case dynamic cleanup
     57 dynamic_head()
     58 {
     59 	atf_set "descr" "Test a dynamic executable"
     60 }
     61 dynamic_body()
     62 {
     63 	checksupport h_hello_dyn
     64 	checkrun h_hello_dyn
     65 }
     66 dynamic_cleanup()
     67 {
     68 	cleanup h_hello_dyn
     69 }
     70 
     71 atf_test_case dynamicpie cleanup
     72 dynamicpie_head()
     73 {
     74 	atf_set "descr" "Test a dynamic position-independent executable"
     75 }
     76 dynamicpie_body()
     77 {
     78 	checksupport h_hello_dynpie
     79 	checkrun h_hello_dynpie
     80 }
     81 dynamicpie_cleanup()
     82 {
     83 	cleanup h_hello_dynpie
     84 }
     85 
     86 atf_test_case relr cleanup
     87 relr_head()
     88 {
     89 	atf_set "descr" "Test a static PIE executable with RELR relocations"
     90 }
     91 relr_body()
     92 {
     93 	checksupport h_hello_relr
     94 	case `uname -p` in
     95 	i386|x86_64)
     96 		# Actually csu missing RELR support for this, not ld.elf_so.
     97 		atf_expect_fail "PR bin/59360: ld.elf_so(8):" \
     98 		    " missing RELR support"
     99 		;;
    100 	*)	atf_expect_fail "PR lib/59359: static pies are broken"
    101 		;;
    102 	esac
    103 	checkrun h_hello_relr
    104 }
    105 relr_cleanup()
    106 {
    107 	cleanup h_hello_relr
    108 }
    109 
    110 atf_test_case static cleanup
    111 static_head()
    112 {
    113 	atf_set "descr" "Test a static executable"
    114 }
    115 static_body()
    116 {
    117 	checksupport h_hello_sta
    118 	checkrun h_hello_sta
    119 }
    120 static_cleanup()
    121 {
    122 	cleanup h_hello_sta
    123 }
    124 
    125 atf_test_case staticpie cleanup
    126 staticpie_head()
    127 {
    128 	atf_set "descr" "Test a static position-independent executable"
    129 }
    130 staticpie_body()
    131 {
    132 	checksupport h_hello_stapie
    133 	case `uname -p` in
    134 	i386|x86_64)
    135 		;;
    136 	*)	atf_expect_fail "PR lib/59359: static pies are broken"
    137 		;;
    138 	esac
    139 	checkrun h_hello_stapie
    140 }
    141 staticpie_cleanup()
    142 {
    143 	cleanup h_hello_stapie
    144 }
    145 
    146 atf_init_test_cases()
    147 {
    148 	atf_add_test_case dynamic
    149 	atf_add_test_case dynamicpie
    150 	atf_add_test_case relr
    151 	atf_add_test_case static
    152 	atf_add_test_case staticpie
    153 }
    154