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