Path: blob/main/tests/sys/kern/coredump_phnum_test.sh
39478 views
#1# Copyright (c) 2016 Dell EMC Isilon2# All rights reserved.3#4# Redistribution and use in source and binary forms, with or without5# modification, are permitted provided that the following conditions6# are met:7# 1. Redistributions of source code must retain the above copyright8# notice, this list of conditions, and the following disclaimer,9# without modification.10# 2. Redistributions in binary form must reproduce at minimum a disclaimer11# substantially similar to the "NO WARRANTY" disclaimer below12# ("Disclaimer") and any redistribution must be conditioned upon13# including a substantially similar Disclaimer requirement for further14# binary redistribution.15#16# NO WARRANTY17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT21# HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,25# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING26# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE27# POSSIBILITY OF SUCH DAMAGES.28#2930atf_test_case coredump_phnum cleanup31coredump_phnum_head()32{33atf_set "descr" "More than 65534 segments"34atf_set "require.config" "allow_sysctl_side_effects"35atf_set "require.progs" "readelf procstat"36atf_set "require.user" "root"37}38coredump_phnum_body()39{40# Set up core dumping41atf_check -o save:coredump_phnum_restore_state sysctl -e \42kern.coredump kern.corefile4344ulimit -c unlimited45atf_check -o ignore sysctl kern.coredump=146atf_check -o ignore sysctl kern.corefile=coredump_phnum_helper.core47atf_check -o save:cuc sysctl -n kern.compress_user_cores48read cuc < cuc4950atf_check -s signal:sigabrt "$(atf_get_srcdir)/coredump_phnum_helper"5152case "$cuc" in530)54unzip_status=055;;561)57gunzip coredump_phnum_helper.core.gz 2>unzip_stderr58unzip_status=$?59;;602)61zstd -qd coredump_phnum_helper.core.zst 2>unzip_stderr62unzip_status=$?63;;64*)65atf_skip "unsupported kern.compress_user_cores=$cuc"66;;67esac6869if [ $unzip_status -ne 0 ]; then70if grep -q 'No space left on device' unzip_stderr; then71atf_skip "file system full: $(df $PWD | tail -n 1)"72fi73atf_fail "unzip failed; status ${unzip_status}; " \74"stderr: $(cat unzip_stderr)"75fi7677# Check that core looks good78if [ ! -f coredump_phnum_helper.core ]; then79atf_fail "Helper program did not dump core"80fi8182if readelf --version | grep -q LLVM; then83atf_expect_fail "PR285547: llvm-objdump does not support large phdr count"84# See https://github.com/llvm/llvm-project/issues/13221685fi8687# These magic numbers don't have any real significance. They are just88# the result of running the helper program and dumping core. The only89# important bit is that they're larger than 65535 (UINT16_MAX).90atf_check -o "match:65535 \(66[0-9]{3}\)" \91-x 'readelf -h coredump_phnum_helper.core | grep "Number of program headers:"'92atf_check -o "match:There are 66[0-9]{3} program headers" \93-x 'readelf -l coredump_phnum_helper.core | grep -1 "program headers"'94atf_check -o "match: 00000(0000000000)?1 .* 66[0-9]{3} " \95-x 'readelf -S coredump_phnum_helper.core | grep -A1 "^ \[ 0\] "'9697atf_check -o "match:66[0-9]{3}" \98-x 'procstat -v coredump_phnum_helper.core | wc -l'99}100coredump_phnum_cleanup()101{102rm -f coredump_phnum_helper.core103if [ -f coredump_phnum_restore_state ]; then104sysctl -f coredump_phnum_restore_state105rm -f coredump_phnum_restore_state106fi107rm -f cuc108}109110atf_init_test_cases()111{112atf_add_test_case coredump_phnum113}114115116