1#!/bin/sh 2# 3# Ensure that strace -k works. 4# 5# Copyright (c) 2014 Masatake YAMATO <yamato@redhat.com> 6# Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org> 7# Copyright (c) 2014-2018 The strace developers. 8# All rights reserved. 9# 10# Redistribution and use in source and binary forms, with or without 11# modification, are permitted provided that the following conditions 12# are met: 13# 1. Redistributions of source code must retain the above copyright 14# notice, this list of conditions and the following disclaimer. 15# 2. Redistributions in binary form must reproduce the above copyright 16# notice, this list of conditions and the following disclaimer in the 17# documentation and/or other materials provided with the distribution. 18# 3. The name of the author may not be used to endorse or promote products 19# derived from this software without specific prior written permission. 20# 21# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 32. "${srcdir=.}/init.sh" 33 34# strace -k is implemented using /proc/$pid/maps 35[ -f /proc/self/maps ] || 36 framework_skip_ '/proc/self/maps is not available' 37 38check_prog grep 39check_prog sed 40check_prog tr 41 42run_prog "${test_prog=../stack-fcall}" 43run_strace -e getpid -k $args 44 45expected="$srcdir/$NAME.expected" 46awk ' 47/^[^ ]/ { 48 if (out != "") 49 print out 50 51 syscall = gensub(/^([[:alnum:]_]+)\(.*/, "\\1", 1) 52 signal = gensub(/^--- ([A-Z]+) .*/, "\\1", 1) 53 54 if (syscall != $0) { 55 out = syscall 56 stop = 0 57 } else if (signal != $0) { 58 out = signal 59 stop = 0 60 } else { 61 out = "" 62 } 63} 64 65/^ >[^(]+\(([^+]+)\+0x[a-f0-9]+\) / && !stop { 66 sym = gensub(/^ >[^(]+\(([^+]+)\+0x[a-f0-9]+\) .*$/, "\\1", 1) 67 out = out " " sym 68 if (sym == "main") 69 stop = 1 70}' "$LOG" > "$OUT" 71 72LC_ALL=C grep -E -x -f "$expected" < "$OUT" > /dev/null || { 73 cat >&2 <<__EOF__ 74Failed pattern of expected output: 75$(cat "$expected") 76Actual output: 77$(cat "$OUT") 78__EOF__ 79 80 pattern= 81 case "$STRACE_ARCH" in 82 aarch64|i386|ppc*|s390*|sparc*|x32|x86*) 83 # These architectures are supported by elfutils libdw, 84 # see grep '\<HOOK\>.*\<abi_cfi\>' elfutils/backends 85 ;; 86 arm) pattern='No DWARF information found' 87 # This is also supported by elfutils libdw 88 # but the latter needs debuginfo for unwinding. 89 ;; 90 *) pattern='Unwinding not supported for this architecture' 91 ;; 92 esac 93 if [ -n "$pattern" ] && 94 LC_ALL=C grep -x " > $pattern" < "$LOG" > /dev/null; then 95 cat < "$LOG" >&2 96 skip_ "stack tracing is not fully supported on $STRACE_ARCH yet" 97 fi 98 99 dump_log_and_fail_with "$STRACE $args output mismatch" 100} 101