Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/tests/sys/kern/coredump_phnum_test.sh
39478 views
1
#
2
# Copyright (c) 2016 Dell EMC Isilon
3
# All rights reserved.
4
#
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions
7
# are met:
8
# 1. Redistributions of source code must retain the above copyright
9
# notice, this list of conditions, and the following disclaimer,
10
# without modification.
11
# 2. Redistributions in binary form must reproduce at minimum a disclaimer
12
# substantially similar to the "NO WARRANTY" disclaimer below
13
# ("Disclaimer") and any redistribution must be conditioned upon
14
# including a substantially similar Disclaimer requirement for further
15
# binary redistribution.
16
#
17
# NO WARRANTY
18
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
# HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
# POSSIBILITY OF SUCH DAMAGES.
29
#
30
31
atf_test_case coredump_phnum cleanup
32
coredump_phnum_head()
33
{
34
atf_set "descr" "More than 65534 segments"
35
atf_set "require.config" "allow_sysctl_side_effects"
36
atf_set "require.progs" "readelf procstat"
37
atf_set "require.user" "root"
38
}
39
coredump_phnum_body()
40
{
41
# Set up core dumping
42
atf_check -o save:coredump_phnum_restore_state sysctl -e \
43
kern.coredump kern.corefile
44
45
ulimit -c unlimited
46
atf_check -o ignore sysctl kern.coredump=1
47
atf_check -o ignore sysctl kern.corefile=coredump_phnum_helper.core
48
atf_check -o save:cuc sysctl -n kern.compress_user_cores
49
read cuc < cuc
50
51
atf_check -s signal:sigabrt "$(atf_get_srcdir)/coredump_phnum_helper"
52
53
case "$cuc" in
54
0)
55
unzip_status=0
56
;;
57
1)
58
gunzip coredump_phnum_helper.core.gz 2>unzip_stderr
59
unzip_status=$?
60
;;
61
2)
62
zstd -qd coredump_phnum_helper.core.zst 2>unzip_stderr
63
unzip_status=$?
64
;;
65
*)
66
atf_skip "unsupported kern.compress_user_cores=$cuc"
67
;;
68
esac
69
70
if [ $unzip_status -ne 0 ]; then
71
if grep -q 'No space left on device' unzip_stderr; then
72
atf_skip "file system full: $(df $PWD | tail -n 1)"
73
fi
74
atf_fail "unzip failed; status ${unzip_status}; " \
75
"stderr: $(cat unzip_stderr)"
76
fi
77
78
# Check that core looks good
79
if [ ! -f coredump_phnum_helper.core ]; then
80
atf_fail "Helper program did not dump core"
81
fi
82
83
if readelf --version | grep -q LLVM; then
84
atf_expect_fail "PR285547: llvm-objdump does not support large phdr count"
85
# See https://github.com/llvm/llvm-project/issues/132216
86
fi
87
88
# These magic numbers don't have any real significance. They are just
89
# the result of running the helper program and dumping core. The only
90
# important bit is that they're larger than 65535 (UINT16_MAX).
91
atf_check -o "match:65535 \(66[0-9]{3}\)" \
92
-x 'readelf -h coredump_phnum_helper.core | grep "Number of program headers:"'
93
atf_check -o "match:There are 66[0-9]{3} program headers" \
94
-x 'readelf -l coredump_phnum_helper.core | grep -1 "program headers"'
95
atf_check -o "match: 00000(0000000000)?1 .* 66[0-9]{3} " \
96
-x 'readelf -S coredump_phnum_helper.core | grep -A1 "^ \[ 0\] "'
97
98
atf_check -o "match:66[0-9]{3}" \
99
-x 'procstat -v coredump_phnum_helper.core | wc -l'
100
}
101
coredump_phnum_cleanup()
102
{
103
rm -f coredump_phnum_helper.core
104
if [ -f coredump_phnum_restore_state ]; then
105
sysctl -f coredump_phnum_restore_state
106
rm -f coredump_phnum_restore_state
107
fi
108
rm -f cuc
109
}
110
111
atf_init_test_cases()
112
{
113
atf_add_test_case coredump_phnum
114
}
115
116