3 # allocfail.sh -- Test for libbacktrace library.
4 # Copyright (C) 2018-2024 Free Software Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
10 # (1) Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
13 # (2) Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in
15 # the documentation and/or other materials provided with the
18 # (3) The name of the author may not be used to
19 # endorse or promote products derived from this software without
20 # specific prior written permission.
22 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31 # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
36 if [ ! -f .
/allocfail
]; then
41 allocs
=$
(.
/allocfail
2>&1)
42 if [ "$allocs" = "" ]; then
47 # This generates the following output:
51 # Status changed to 0 at 1
52 # Status changed to 1 at 3
53 # Status changed to 0 at 11
54 # Status changed to 1 at 12
55 # Status changed to 0 at 845
58 # We have status 0 for an allocation failure at:
59 # - 1 because backtrace_create_state handles failure robustly
60 # - 2 because the fail switches backtrace_full to !can_alloc mode.
61 # - 11 because failure of elf_open_debugfile_by_buildid does not generate an
62 # error callback beyond the one for the allocation failure itself.
64 echo "allocs: $allocs"
70 while [ $i -le $allocs ]; do
71 if .
/allocfail
$i >/dev
/null
2>&1; status
=$?
; then
74 if [ $status -gt 1 ]; then
75 echo "Unallowed fail found: $i"
80 # The test-case would run too long if we would excercise all allocs.
81 # So, run with step 1 initially, and increase the step once we have 10
82 # subsequent passes, and drop back to step 1 once we encounter another
83 # failure. This takes ~2.6 seconds on an i7-6600U CPU @ 2.60GHz.
84 if [ $status -eq 0 ]; then
85 passes
=$
(($passes + 1))
86 if [ $passes -ge 10 ]; then
90 elif [ $status -eq 1 ]; then
95 if [ $status -ne $prev_status ]; then
96 echo "Status changed to $status at $i"