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