1e8e39fc2SConrad Meyer# 2e8e39fc2SConrad Meyer# Copyright (c) 2016 Dell EMC Isilon 3e8e39fc2SConrad Meyer# All rights reserved. 4e8e39fc2SConrad Meyer# 5e8e39fc2SConrad Meyer# Redistribution and use in source and binary forms, with or without 6e8e39fc2SConrad Meyer# modification, are permitted provided that the following conditions 7e8e39fc2SConrad Meyer# are met: 8e8e39fc2SConrad Meyer# 1. Redistributions of source code must retain the above copyright 9e8e39fc2SConrad Meyer# notice, this list of conditions, and the following disclaimer, 10e8e39fc2SConrad Meyer# without modification. 11e8e39fc2SConrad Meyer# 2. Redistributions in binary form must reproduce at minimum a disclaimer 12e8e39fc2SConrad Meyer# substantially similar to the "NO WARRANTY" disclaimer below 13e8e39fc2SConrad Meyer# ("Disclaimer") and any redistribution must be conditioned upon 14e8e39fc2SConrad Meyer# including a substantially similar Disclaimer requirement for further 15e8e39fc2SConrad Meyer# binary redistribution. 16e8e39fc2SConrad Meyer# 17e8e39fc2SConrad Meyer# NO WARRANTY 18e8e39fc2SConrad Meyer# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19e8e39fc2SConrad Meyer# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20e8e39fc2SConrad Meyer# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 21e8e39fc2SConrad Meyer# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22e8e39fc2SConrad Meyer# HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23e8e39fc2SConrad Meyer# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24e8e39fc2SConrad Meyer# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25e8e39fc2SConrad Meyer# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26e8e39fc2SConrad Meyer# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27e8e39fc2SConrad Meyer# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28e8e39fc2SConrad Meyer# POSSIBILITY OF SUCH DAMAGES. 29e8e39fc2SConrad Meyer# 30e8e39fc2SConrad Meyer 31e8e39fc2SConrad Meyeratf_test_case coredump_phnum cleanup 32e8e39fc2SConrad Meyercoredump_phnum_head() 33e8e39fc2SConrad Meyer{ 34e8e39fc2SConrad Meyer atf_set "descr" "More than 65534 segments" 35cebf0ec5SEnji Cooper atf_set "require.config" "allow_sysctl_side_effects" 36e8e39fc2SConrad Meyer atf_set "require.progs" "readelf procstat" 37e8e39fc2SConrad Meyer atf_set "require.user" "root" 38e8e39fc2SConrad Meyer} 39e8e39fc2SConrad Meyercoredump_phnum_body() 40e8e39fc2SConrad Meyer{ 41e8e39fc2SConrad Meyer # Set up core dumping 422b2ad2d6SEric van Gyzen atf_check -o save:coredump_phnum_restore_state sysctl -e \ 432b2ad2d6SEric van Gyzen kern.coredump kern.corefile 44e8e39fc2SConrad Meyer 45e8e39fc2SConrad Meyer ulimit -c unlimited 462b2ad2d6SEric van Gyzen atf_check -o ignore sysctl kern.coredump=1 472b2ad2d6SEric van Gyzen atf_check -o ignore sysctl kern.corefile=coredump_phnum_helper.core 482b2ad2d6SEric van Gyzen atf_check -o save:cuc sysctl -n kern.compress_user_cores 492b2ad2d6SEric van Gyzen read cuc < cuc 50e8e39fc2SConrad Meyer 51e8e39fc2SConrad Meyer atf_check -s signal:sigabrt "$(atf_get_srcdir)/coredump_phnum_helper" 52e8e39fc2SConrad Meyer 532b2ad2d6SEric van Gyzen case "$cuc" in 542b2ad2d6SEric van Gyzen 0) 55df4d65b1SEric van Gyzen unzip_status=0 562b2ad2d6SEric van Gyzen ;; 572b2ad2d6SEric van Gyzen 1) 58df4d65b1SEric van Gyzen gunzip coredump_phnum_helper.core.gz 2>unzip_stderr 59df4d65b1SEric van Gyzen unzip_status=$? 602b2ad2d6SEric van Gyzen ;; 612b2ad2d6SEric van Gyzen 2) 62df4d65b1SEric van Gyzen zstd -qd coredump_phnum_helper.core.zst 2>unzip_stderr 63df4d65b1SEric van Gyzen unzip_status=$? 642b2ad2d6SEric van Gyzen ;; 652b2ad2d6SEric van Gyzen *) 662b2ad2d6SEric van Gyzen atf_skip "unsupported kern.compress_user_cores=$cuc" 672b2ad2d6SEric van Gyzen ;; 682b2ad2d6SEric van Gyzen esac 692b2ad2d6SEric van Gyzen 70df4d65b1SEric van Gyzen if [ $unzip_status -ne 0 ]; then 71df4d65b1SEric van Gyzen if grep -q 'No space left on device' unzip_stderr; then 72df4d65b1SEric van Gyzen atf_skip "file system full: $(df $PWD | tail -n 1)" 73df4d65b1SEric van Gyzen fi 74df4d65b1SEric van Gyzen atf_fail "unzip failed; status ${unzip_status}; " \ 75df4d65b1SEric van Gyzen "stderr: $(cat unzip_stderr)" 76df4d65b1SEric van Gyzen fi 77df4d65b1SEric van Gyzen 78e8e39fc2SConrad Meyer # Check that core looks good 79e8e39fc2SConrad Meyer if [ ! -f coredump_phnum_helper.core ]; then 80e8e39fc2SConrad Meyer atf_fail "Helper program did not dump core" 81e8e39fc2SConrad Meyer fi 82e8e39fc2SConrad Meyer 83*5df8159dSEd Maste if readelf --version | grep -q LLVM; then 84*5df8159dSEd Maste atf_expect_fail "PR285547: llvm-objdump does not support large phdr count" 85*5df8159dSEd Maste # See https://github.com/llvm/llvm-project/issues/132216 86*5df8159dSEd Maste fi 87*5df8159dSEd Maste 88e8e39fc2SConrad Meyer # These magic numbers don't have any real significance. They are just 89e8e39fc2SConrad Meyer # the result of running the helper program and dumping core. The only 90e8e39fc2SConrad Meyer # important bit is that they're larger than 65535 (UINT16_MAX). 91695349e3SConrad Meyer atf_check -o "match:65535 \(66[0-9]{3}\)" \ 9283f5e032SEnji Cooper -x 'readelf -h coredump_phnum_helper.core | grep "Number of program headers:"' 93695349e3SConrad Meyer atf_check -o "match:There are 66[0-9]{3} program headers" \ 9483f5e032SEnji Cooper -x 'readelf -l coredump_phnum_helper.core | grep -1 "program headers"' 95616f60e8SEnji Cooper atf_check -o "match: 00000(0000000000)?1 .* 66[0-9]{3} " \ 9683f5e032SEnji Cooper -x 'readelf -S coredump_phnum_helper.core | grep -A1 "^ \[ 0\] "' 97e8e39fc2SConrad Meyer 9883f5e032SEnji Cooper atf_check -o "match:66[0-9]{3}" \ 9983f5e032SEnji Cooper -x 'procstat -v coredump_phnum_helper.core | wc -l' 100e8e39fc2SConrad Meyer} 101e8e39fc2SConrad Meyercoredump_phnum_cleanup() 102e8e39fc2SConrad Meyer{ 103e8e39fc2SConrad Meyer rm -f coredump_phnum_helper.core 1042b2ad2d6SEric van Gyzen if [ -f coredump_phnum_restore_state ]; then 1052b2ad2d6SEric van Gyzen sysctl -f coredump_phnum_restore_state 1062b2ad2d6SEric van Gyzen rm -f coredump_phnum_restore_state 107e8e39fc2SConrad Meyer fi 1082b2ad2d6SEric van Gyzen rm -f cuc 109e8e39fc2SConrad Meyer} 110e8e39fc2SConrad Meyer 111e8e39fc2SConrad Meyeratf_init_test_cases() 112e8e39fc2SConrad Meyer{ 113e8e39fc2SConrad Meyer atf_add_test_case coredump_phnum 114e8e39fc2SConrad Meyer} 115