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 # Begin FreeBSD 38 if true; then 39 eval $2 atf_check -s signal -o ignore -e ignore $1 40 else 41 # End FreeBSD 42 eval $2 atf_check -s signal:6 -o ignore -e ignore $1 43 # Begin FreeBSD 44 fi 45 # End FreeBSD 46} 47 48atf_test_case sprintf 49sprintf_head() 50{ 51 atf_set "descr" "Checks sprintf(3)" 52} 53sprintf_body() 54{ 55 prog="$(atf_get_srcdir)/h_sprintf" 56 57 h_pass "$prog ok" 58 # Begin FreeBSD 59 if true; then 60 h_fail "$prog 0123456789ab" 61 else 62 # End FreeBSD 63 h_fail "$prog 0123456789" 64 # Begin FreeBSD 65 fi 66 # End FreeBSD 67} 68 69atf_test_case vsprintf 70vsprintf_head() 71{ 72 atf_set "descr" "Checks vsprintf(3)" 73} 74vsprintf_body() 75{ 76 prog="$(atf_get_srcdir)/h_vsprintf" 77 78 h_pass "$prog ok" 79 # Begin FreeBSD 80 if true; then 81 h_fail "$prog 0123456789ab" 82 else 83 # End FreeBSD 84 h_fail "$prog 0123456789" 85 # Begin FreeBSD 86 fi 87 # End FreeBSD 88} 89 90atf_test_case snprintf 91snprintf_head() 92{ 93 atf_set "descr" "Checks snprintf(3)" 94} 95snprintf_body() 96{ 97 prog="$(atf_get_srcdir)/h_snprintf" 98 99 h_pass "$prog 10" 100 # Begin FreeBSD 101 if true; then 102 h_fail "$prog 13" 103 else 104 # End FreeBSD 105 h_fail "$prog 11" 106 # Begin FreeBSD 107 fi 108 # End FreeBSD 109} 110 111atf_test_case vsnprintf 112vsnprintf_head() 113{ 114 atf_set "descr" "Checks vsnprintf(3)" 115} 116vsnprintf_body() 117{ 118 prog="$(atf_get_srcdir)/h_vsnprintf" 119 120 h_pass "$prog 10" 121 # Begin FreeBSD 122 if true; then 123 h_fail "$prog 13" 124 else 125 # End FreeBSD 126 h_fail "$prog 11" 127 # Begin FreeBSD 128 fi 129 # End FreeBSD 130} 131 132atf_test_case gets 133gets_head() 134{ 135 atf_set "descr" "Checks gets(3)" 136} 137gets_body() 138{ 139 prog="$(atf_get_srcdir)/h_gets" 140 141 h_pass "$prog" "echo ok |" 142 # Begin FreeBSD 143 if true; then 144 h_fail "$prog" "echo 0123456789ab |" 145 else 146 # End FreeBSD 147 h_fail "$prog" "echo 0123456789 |" 148 # Begin FreeBSD 149 fi 150 # End FreeBSD 151} 152 153atf_test_case fgets 154fgets_head() 155{ 156 atf_set "descr" "Checks fgets(3)" 157} 158fgets_body() 159{ 160 prog="$(atf_get_srcdir)/h_fgets" 161 162 h_pass "$prog 10" "echo ok |" 163 # Begin FreeBSD 164 if true; then 165 h_fail "$prog 13" "echo 0123456789abc |" 166 else 167 # End FreeBSD 168 h_fail "$prog 11" "echo busted |" 169 # Begin FreeBSD 170 fi 171 # End FreeBSD 172} 173 174atf_test_case memcpy 175memcpy_head() 176{ 177 atf_set "descr" "Checks memcpy(3)" 178} 179memcpy_body() 180{ 181 prog="$(atf_get_srcdir)/h_memcpy" 182 183 h_pass "$prog 10" 184 # Begin FreeBSD 185 if true; then 186 h_fail "$prog 13" 187 else 188 # End FreeBSD 189 h_fail "$prog 11" 190 # Begin FreeBSD 191 fi 192 # End FreeBSD 193} 194 195atf_test_case memmove 196memmove_head() 197{ 198 atf_set "descr" "Checks memmove(3)" 199} 200memmove_body() 201{ 202 prog="$(atf_get_srcdir)/h_memmove" 203 204 h_pass "$prog 10" 205 # Begin FreeBSD 206 if true; then 207 h_fail "$prog 13" 208 else 209 # End FreeBSD 210 h_fail "$prog 11" 211 # Begin FreeBSD 212 fi 213 # End FreeBSD 214} 215 216atf_test_case memset 217memset_head() 218{ 219 atf_set "descr" "Checks memset(3)" 220} 221memset_body() 222{ 223 prog="$(atf_get_srcdir)/h_memset" 224 225 h_pass "$prog 10" 226 # Begin FreeBSD 227 if true; then 228 h_fail "$prog 13" 229 else 230 # End FreeBSD 231 h_fail "$prog 11" 232 # Begin FreeBSD 233 fi 234 # End FreeBSD 235} 236 237atf_test_case strcpy 238strcpy_head() 239{ 240 atf_set "descr" "Checks strcpy(3)" 241} 242strcpy_body() 243{ 244 prog="$(atf_get_srcdir)/h_strcpy" 245 246 h_pass "$prog 0123456" 247 # Begin FreeBSD 248 if true; then 249 h_fail "$prog 0123456789ab" 250 else 251 # End FreeBSD 252 h_fail "$prog 0123456789" 253 # Begin FreeBSD 254 fi 255 # End FreeBSD 256} 257 258atf_test_case stpcpy 259stpcpy_head() 260{ 261 atf_set "descr" "Checks stpcpy(3)" 262} 263stpcpy_body() 264{ 265 prog="$(atf_get_srcdir)/h_stpcpy" 266 267 h_pass "$prog 0123456" 268 # Begin FreeBSD 269 if true; then 270 h_fail "$prog 0123456789ab" 271 else 272 # End FreeBSD 273 h_fail "$prog 0123456789" 274 # Begin FreeBSD 275 fi 276 # End FreeBSD 277} 278 279atf_test_case strcat 280strcat_head() 281{ 282 atf_set "descr" "Checks strcat(3)" 283} 284strcat_body() 285{ 286 prog="$(atf_get_srcdir)/h_strcat" 287 288 h_pass "$prog 0123456" 289 h_fail "$prog 0123456789ABCDEF" 290} 291 292atf_test_case strncpy 293strncpy_head() 294{ 295 atf_set "descr" "Checks strncpy(3)" 296} 297strncpy_body() 298{ 299 prog="$(atf_get_srcdir)/h_strncpy" 300 301 h_pass "$prog 10" 302 # Begin FreeBSD 303 if true; then 304 h_fail "$prog 13" 305 else 306 # End FreeBSD 307 h_fail "$prog 11" 308 # Begin FreeBSD 309 fi 310 # End FreeBSD 311} 312 313atf_test_case stpncpy 314stpncpy_head() 315{ 316 atf_set "descr" "Checks stpncpy(3)" 317} 318stpncpy_body() 319{ 320 prog="$(atf_get_srcdir)/h_stpncpy" 321 322 h_pass "$prog 10" 323 # Begin FreeBSD 324 if true; then 325 h_fail "$prog 13" 326 else 327 # End FreeBSD 328 h_fail "$prog 11" 329 # Begin FreeBSD 330 fi 331 # End FreeBSD 332} 333 334atf_test_case strncat 335strncat_head() 336{ 337 atf_set "descr" "Checks strncat(3)" 338} 339strncat_body() 340{ 341 prog="$(atf_get_srcdir)/h_strncat" 342 343 # Begin FreeBSD 344 h_pass "$prog 8" 345 if true; then 346 h_fail "$prog 11" 347 else 348 # End FreeBSD 349 h_fail "$prog 9" 350 # Begin FreeBSD 351 fi 352 # End FreeBSD 353} 354 355atf_test_case raw 356raw_head() 357{ 358 atf_set "descr" "Checks raw array overflow" 359} 360raw_body() 361{ 362 prog="$(atf_get_srcdir)/h_raw" 363 364 h_pass "$prog 9" 365 # Begin FreeBSD 366 if true; then 367 h_fail "$prog 12" 368 else 369 # End FreeBSD 370 h_fail "$prog 10" 371 # Begin FreeBSD 372 fi 373 # End FreeBSD 374} 375 376atf_test_case read 377read_head() 378{ 379 atf_set "descr" "Checks read(2)" 380} 381read_body() 382{ 383 prog="$(atf_get_srcdir)/h_read" 384 385 h_pass "$prog 1024" "echo foo |" 386 # Begin FreeBSD 387 if true; then 388 h_fail "$prog 1027" "echo bar |" 389 else 390 # End FreeBSD 391 h_fail "$prog 1025" "echo bar |" 392 # Begin FreeBSD 393 fi 394 # End FreeBSD 395} 396 397atf_test_case readlink 398readlink_head() 399{ 400 atf_set "descr" "Checks readlink(2)" 401} 402readlink_body() 403{ 404 prog="$(atf_get_srcdir)/h_readlink" 405 406 # Begin FreeBSD 407 if true; then 408 h_pass "$prog 512" 409 h_fail "$prog 523" 410 else 411 # End FreeBSD 412 h_pass "$prog 1024" 413 h_fail "$prog 1025" 414 # Begin FreeBSD 415 fi 416 # End FreeBSD 417} 418 419atf_test_case getcwd 420getcwd_head() 421{ 422 atf_set "descr" "Checks getcwd(3)" 423} 424getcwd_body() 425{ 426 prog="$(atf_get_srcdir)/h_getcwd" 427 428 h_pass "$prog 1024" 429 # Begin FreeBSD 430 if false; then 431 # End FreeBSD 432 h_fail "$prog 1025" 433 # Begin FreeBSD 434 fi 435 # End FreeBSD 436} 437 438atf_init_test_cases() 439{ 440 atf_add_test_case sprintf 441 atf_add_test_case vsprintf 442 atf_add_test_case snprintf 443 atf_add_test_case vsnprintf 444 atf_add_test_case gets 445 atf_add_test_case fgets 446 atf_add_test_case memcpy 447 atf_add_test_case memmove 448 atf_add_test_case memset 449 atf_add_test_case stpcpy 450 atf_add_test_case stpncpy 451 atf_add_test_case strcat 452 atf_add_test_case strcpy 453 atf_add_test_case strncat 454 atf_add_test_case strncpy 455 atf_add_test_case raw 456 atf_add_test_case read 457 atf_add_test_case readlink 458 atf_add_test_case getcwd 459} 460