Home | History | Annotate | Line # | Download | only in ssp
t_ssp.sh revision 1.3
      1 # $NetBSD: t_ssp.sh,v 1.3 2011/02/25 18:11:53 pgoyette Exp $
      2 #
      3 # Copyright (c) 2008 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 h_pass()
     29 {
     30 	echo "Executing command [ $2$1 ]"
     31 	eval $2 atf_check -s exit:0 -o ignore -e ignore $1
     32 }
     33 
     34 h_fail()
     35 {
     36 	echo "Executing command [ $2$1 ]"
     37 	eval $2 atf_check -s signal:6 -o ignore -e ignore $1
     38 }
     39 
     40 atf_test_case raw
     41 raw_head()
     42 {
     43 	atf_set "descr" "Checks basic stack protection"
     44 }
     45 raw_body()
     46 {
     47 	prog="$(atf_get_srcdir)/h_raw"
     48 
     49 	atk_skip "Bogus test case"
     50 #	h_pass "$prog 9"
     51 #	h_fail "$prog 10"
     52 }
     53 
     54 atf_test_case sprintf
     55 sprintf_head()
     56 {
     57 	atf_set "descr" "Checks sprintf(3)"
     58 }
     59 sprintf_body()
     60 {
     61 	prog="$(atf_get_srcdir)/h_sprintf"
     62 
     63 	h_pass "$prog ok"
     64 	h_fail "$prog 0123456789"
     65 }
     66 
     67 atf_test_case vsprintf
     68 vsprintf_head()
     69 {
     70 	atf_set "descr" "Checks vsprintf(3)"
     71 }
     72 vsprintf_body()
     73 {
     74 	prog="$(atf_get_srcdir)/h_vsprintf"
     75 
     76 	h_pass "$prog ok"
     77 	h_fail "$prog 0123456789"
     78 }
     79 
     80 atf_test_case snprintf
     81 snprintf_head()
     82 {
     83 	atf_set "descr" "Checks snprintf(3)"
     84 }
     85 snprintf_body()
     86 {
     87 	prog="$(atf_get_srcdir)/h_snprintf"
     88 
     89 	h_pass "$prog 10"
     90 	h_fail "$prog 11"
     91 }
     92 
     93 atf_test_case vsnprintf
     94 vsnprintf_head()
     95 {
     96 	atf_set "descr" "Checks vsnprintf(3)"
     97 }
     98 vsnprintf_body()
     99 {
    100 	prog="$(atf_get_srcdir)/h_vsnprintf"
    101 
    102 	h_pass "$prog 10"
    103 	h_fail "$prog 11"
    104 }
    105 
    106 atf_test_case gets
    107 gets_head()
    108 {
    109 	atf_set "descr" "Checks gets(3)"
    110 }
    111 gets_body()
    112 {
    113 	prog="$(atf_get_srcdir)/h_gets"
    114 
    115 	h_pass "$prog" "echo ok |"
    116 	h_fail "$prog" "echo 0123456789 |"
    117 }
    118 
    119 atf_test_case fgets
    120 fgets_head()
    121 {
    122 	atf_set "descr" "Checks fgets(3)"
    123 }
    124 fgets_body()
    125 {
    126 	prog="$(atf_get_srcdir)/h_fgets"
    127 
    128 	h_pass "$prog 10" "echo ok |"
    129 	h_fail "$prog 11" "echo busted |"
    130 }
    131 
    132 atf_test_case memcpy
    133 memcpy_head()
    134 {
    135 	atf_set "descr" "Checks memcpy(3)"
    136 }
    137 memcpy_body()
    138 {
    139 	prog="$(atf_get_srcdir)/h_memcpy"
    140 
    141 	h_pass "$prog 10"
    142 	h_fail "$prog 11"
    143 }
    144 
    145 atf_test_case memmove
    146 memmove_head()
    147 {
    148 	atf_set "descr" "Checks memmove(3)"
    149 }
    150 memmove_body()
    151 {
    152 	prog="$(atf_get_srcdir)/h_memmove"
    153 
    154 	h_pass "$prog 10"
    155 	h_fail "$prog 11"
    156 }
    157 
    158 atf_test_case memset
    159 memset_head()
    160 {
    161 	atf_set "descr" "Checks memset(3)"
    162 }
    163 memset_body()
    164 {
    165 	prog="$(atf_get_srcdir)/h_memset"
    166 
    167 	h_pass "$prog 10"
    168 	h_fail "$prog 11"
    169 }
    170 
    171 atf_test_case strcpy
    172 strcpy_head()
    173 {
    174 	atf_set "descr" "Checks strcpy(3)"
    175 }
    176 strcpy_body()
    177 {
    178 	prog="$(atf_get_srcdir)/h_strcpy"
    179 
    180 	h_pass "$prog 0123456"
    181 	h_fail "$prog 0123456789"
    182 }
    183 
    184 atf_test_case strcat
    185 strcat_head()
    186 {
    187 	atf_set "descr" "Checks strcat(3)"
    188 }
    189 strcat_body()
    190 {
    191 	prog="$(atf_get_srcdir)/h_strcat"
    192 
    193 	h_pass "$prog 0123456"
    194 	h_fail "$prog 012345678"
    195 }
    196 
    197 atf_test_case strncpy
    198 strncpy_head()
    199 {
    200 	atf_set "descr" "Checks strncpy(3)"
    201 }
    202 strncpy_body()
    203 {
    204 	prog="$(atf_get_srcdir)/h_strncpy"
    205 
    206 	h_pass "$prog 10"
    207 	h_fail "$prog 11"
    208 }
    209 
    210 atf_test_case strncat
    211 strncat_head()
    212 {
    213 	atf_set "descr" "Checks strncat(3)"
    214 }
    215 strncat_body()
    216 {
    217 	prog="$(atf_get_srcdir)/h_strncat"
    218 
    219 	h_pass "$prog 8"
    220 	h_fail "$prog 9"
    221 }
    222 
    223 atf_test_case read
    224 read_head()
    225 {
    226 	atf_set "descr" "Checks read(2)"
    227 }
    228 read_body()
    229 {
    230 	prog="$(atf_get_srcdir)/h_read"
    231 
    232 	h_pass "$prog 1024" "echo foo |"
    233 	h_fail "$prog 1025" "echo bar |"
    234 }
    235 
    236 atf_test_case readlink
    237 readlink_head()
    238 {
    239 	atf_set "descr" "Checks readlink(2)"
    240 }
    241 readlink_body()
    242 {
    243 	prog="$(atf_get_srcdir)/h_readlink"
    244 
    245 	h_pass "$prog 1024"
    246 	h_fail "$prog 1025"
    247 }
    248 
    249 atf_test_case getcwd
    250 getcwd_head()
    251 {
    252 	atf_set "descr" "Checks getcwd(3)"
    253 }
    254 getcwd_body()
    255 {
    256 	prog="$(atf_get_srcdir)/h_getcwd"
    257 
    258 	h_pass "$prog 1024"
    259 	h_fail "$prog 1025"
    260 }
    261 
    262 atf_init_test_cases()
    263 {
    264 	atf_add_test_case raw
    265 	atf_add_test_case sprintf
    266 	atf_add_test_case vsprintf
    267 	atf_add_test_case snprintf
    268 	atf_add_test_case vsnprintf
    269 	atf_add_test_case gets
    270 	atf_add_test_case fgets
    271 	atf_add_test_case memcpy
    272 	atf_add_test_case memmove
    273 	atf_add_test_case memset
    274 	atf_add_test_case strcat
    275 	atf_add_test_case strcpy
    276 	atf_add_test_case strncat
    277 	atf_add_test_case strncpy
    278 	atf_add_test_case read
    279 	atf_add_test_case readlink
    280 	atf_add_test_case getcwd
    281 }
    282