1*cf84ac9aSAndroid Build Coastguard Worker#!/bin/sh 2*cf84ac9aSAndroid Build Coastguard Worker# 3*cf84ac9aSAndroid Build Coastguard Worker# Check strace options syntax. 4*cf84ac9aSAndroid Build Coastguard Worker# 5*cf84ac9aSAndroid Build Coastguard Worker# Copyright (c) 2016 Dmitry V. Levin <[email protected]> 6*cf84ac9aSAndroid Build Coastguard Worker# Copyright (c) 2016-2018 The strace developers. 7*cf84ac9aSAndroid Build Coastguard Worker# All rights reserved. 8*cf84ac9aSAndroid Build Coastguard Worker# 9*cf84ac9aSAndroid Build Coastguard Worker# Redistribution and use in source and binary forms, with or without 10*cf84ac9aSAndroid Build Coastguard Worker# modification, are permitted provided that the following conditions 11*cf84ac9aSAndroid Build Coastguard Worker# are met: 12*cf84ac9aSAndroid Build Coastguard Worker# 1. Redistributions of source code must retain the above copyright 13*cf84ac9aSAndroid Build Coastguard Worker# notice, this list of conditions and the following disclaimer. 14*cf84ac9aSAndroid Build Coastguard Worker# 2. Redistributions in binary form must reproduce the above copyright 15*cf84ac9aSAndroid Build Coastguard Worker# notice, this list of conditions and the following disclaimer in the 16*cf84ac9aSAndroid Build Coastguard Worker# documentation and/or other materials provided with the distribution. 17*cf84ac9aSAndroid Build Coastguard Worker# 3. The name of the author may not be used to endorse or promote products 18*cf84ac9aSAndroid Build Coastguard Worker# derived from this software without specific prior written permission. 19*cf84ac9aSAndroid Build Coastguard Worker# 20*cf84ac9aSAndroid Build Coastguard Worker# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21*cf84ac9aSAndroid Build Coastguard Worker# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22*cf84ac9aSAndroid Build Coastguard Worker# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23*cf84ac9aSAndroid Build Coastguard Worker# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24*cf84ac9aSAndroid Build Coastguard Worker# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25*cf84ac9aSAndroid Build Coastguard Worker# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26*cf84ac9aSAndroid Build Coastguard Worker# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27*cf84ac9aSAndroid Build Coastguard Worker# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28*cf84ac9aSAndroid Build Coastguard Worker# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29*cf84ac9aSAndroid Build Coastguard Worker# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30*cf84ac9aSAndroid Build Coastguard Worker 31*cf84ac9aSAndroid Build Coastguard Worker. "${srcdir=.}/syntax.sh" 32*cf84ac9aSAndroid Build Coastguard Worker 33*cf84ac9aSAndroid Build Coastguard Workercheck_e "Invalid process id: '0'" -p 0 34*cf84ac9aSAndroid Build Coastguard Workercheck_e "Invalid process id: '-42'" -p -42 35*cf84ac9aSAndroid Build Coastguard Workercheck_e "Invalid process id: '$$.'" -p $$. 36*cf84ac9aSAndroid Build Coastguard Workercheck_e "Invalid process id: 'a'" -p 1,a 37*cf84ac9aSAndroid Build Coastguard Workercheck_e "Syscall 'chdir' for -b isn't supported" -b chdir 38*cf84ac9aSAndroid Build Coastguard Workercheck_e "Syscall 'chdir' for -b isn't supported" -b execve -b chdir 39*cf84ac9aSAndroid Build Coastguard Worker 40*cf84ac9aSAndroid Build Coastguard Workercheck_e_using_grep 'exec: File *name too long' "$(printf '%4096s' ' ')" 41*cf84ac9aSAndroid Build Coastguard Worker 42*cf84ac9aSAndroid Build Coastguard Workerff_name="$(printf '%4084s' ' ')" 43*cf84ac9aSAndroid Build Coastguard Workercheck_e_using_grep "$ff_name: File *name too long" -ff -o "$ff_name" true 44*cf84ac9aSAndroid Build Coastguard Worker 45*cf84ac9aSAndroid Build Coastguard Workercheck_h 'must have PROG [ARGS] or -p PID' 46*cf84ac9aSAndroid Build Coastguard Workercheck_h 'PROG [ARGS] must be specified with -D' -D -p $$ 47*cf84ac9aSAndroid Build Coastguard Workercheck_h '-c and -C are mutually exclusive' -c -C true 48*cf84ac9aSAndroid Build Coastguard Workercheck_h '-c and -C are mutually exclusive' -C -c true 49*cf84ac9aSAndroid Build Coastguard Workercheck_h '(-c or -C) and -ff are mutually exclusive' -c -ff true 50*cf84ac9aSAndroid Build Coastguard Workercheck_h '(-c or -C) and -ff are mutually exclusive' -C -ff true 51*cf84ac9aSAndroid Build Coastguard Workercheck_h '-w must be given with (-c or -C)' -w true 52*cf84ac9aSAndroid Build Coastguard Workercheck_h 'piping the output and -ff are mutually exclusive' -o '|' -ff true 53*cf84ac9aSAndroid Build Coastguard Workercheck_h 'piping the output and -ff are mutually exclusive' -o '!' -ff true 54*cf84ac9aSAndroid Build Coastguard Workercheck_h "invalid -a argument: '-42'" -a -42 55*cf84ac9aSAndroid Build Coastguard Workercheck_h "invalid -O argument: '-42'" -O -42 56*cf84ac9aSAndroid Build Coastguard Workercheck_h "invalid -s argument: '-42'" -s -42 57*cf84ac9aSAndroid Build Coastguard Workercheck_h "invalid -s argument: '1073741824'" -s 1073741824 58*cf84ac9aSAndroid Build Coastguard Workercheck_h "invalid -I argument: '5'" -I 5 59*cf84ac9aSAndroid Build Coastguard Workercheck_h "invalid -X argument: 'test'" -Xtest 60*cf84ac9aSAndroid Build Coastguard Workercheck_h "invalid -X argument: 'a'" -Xa 61*cf84ac9aSAndroid Build Coastguard Workercheck_h "invalid -X argument: 'abbreviated'" -X abbreviated 62*cf84ac9aSAndroid Build Coastguard Worker 63*cf84ac9aSAndroid Build Coastguard Workercheck_h "incorrect personality designator '' in qualification 'getcwd@'" -e trace=getcwd@ 64*cf84ac9aSAndroid Build Coastguard Workercheck_h "incorrect personality designator '42' in qualification 'getcwd@42'" -e trace=getcwd@42 65*cf84ac9aSAndroid Build Coastguard Workercheck_h "incorrect personality designator '42' in qualification 'getcwd@42'" -e trace=gettid,getcwd@42 66*cf84ac9aSAndroid Build Coastguard Workercheck_h "incorrect personality designator '42' in qualification '23@42'" -e trace=23@42,123 67*cf84ac9aSAndroid Build Coastguard Worker 68*cf84ac9aSAndroid Build Coastguard Workercheck_e "invalid system call '/getcwd@ohmy'" -e trace=/getcwd@ohmy 69*cf84ac9aSAndroid Build Coastguard Workercheck_e "invalid -e kvm= argument: 'chdir'" -e kvm=chdir 70*cf84ac9aSAndroid Build Coastguard Worker 71*cf84ac9aSAndroid Build Coastguard Workercase "$STRACE_NATIVE_ARCH" in 72*cf84ac9aSAndroid Build Coastguard Workerx86_64) 73*cf84ac9aSAndroid Build Coastguard Worker check_h "must have PROG [ARGS] or -p PID" -e trace=getcwd@64 74*cf84ac9aSAndroid Build Coastguard Worker check_h "must have PROG [ARGS] or -p PID" -e trace=getcwd@32 75*cf84ac9aSAndroid Build Coastguard Worker check_h "must have PROG [ARGS] or -p PID" -e trace=getcwd@x32 76*cf84ac9aSAndroid Build Coastguard Worker ;; 77*cf84ac9aSAndroid Build Coastguard Workerx32) 78*cf84ac9aSAndroid Build Coastguard Worker check_h "incorrect personality designator '64' in qualification 'getcwd@64'" -e trace=getcwd@64 79*cf84ac9aSAndroid Build Coastguard Worker check_h "must have PROG [ARGS] or -p PID" -e trace=getcwd@32 80*cf84ac9aSAndroid Build Coastguard Worker check_h "must have PROG [ARGS] or -p PID" -e trace=getcwd@x32 81*cf84ac9aSAndroid Build Coastguard Worker ;; 82*cf84ac9aSAndroid Build Coastguard Workeraarch64|powerpc64|riscv|s390x|sparc64|tile) 83*cf84ac9aSAndroid Build Coastguard Worker check_h "must have PROG [ARGS] or -p PID" -e trace=getcwd@64 84*cf84ac9aSAndroid Build Coastguard Worker check_h "must have PROG [ARGS] or -p PID" -e trace=getcwd@32 85*cf84ac9aSAndroid Build Coastguard Worker check_h "incorrect personality designator 'x32' in qualification 'getcwd@x32'" -e trace=getcwd@x32 86*cf84ac9aSAndroid Build Coastguard Worker ;; 87*cf84ac9aSAndroid Build Coastguard Worker*) 88*cf84ac9aSAndroid Build Coastguard Worker pers="$((SIZEOF_LONG * 8))" 89*cf84ac9aSAndroid Build Coastguard Worker inv_pers="$((96 - pers))" 90*cf84ac9aSAndroid Build Coastguard Worker check_h "must have PROG [ARGS] or -p PID" -e trace=getcwd@"$pers" 91*cf84ac9aSAndroid Build Coastguard Worker check_h "incorrect personality designator '$inv_pers' in qualification 'getcwd@$inv_pers'" -e trace=getcwd@"$inv_pers" 92*cf84ac9aSAndroid Build Coastguard Worker check_h "incorrect personality designator 'x32' in qualification 'getcwd@x32'" -e trace=getcwd@x32 93*cf84ac9aSAndroid Build Coastguard Workeresac 94*cf84ac9aSAndroid Build Coastguard Worker 95*cf84ac9aSAndroid Build Coastguard Worker../zeroargc "$STRACE_EXE" /bin/true 2> "$LOG" && 96*cf84ac9aSAndroid Build Coastguard Worker dump_log_and_fail_with \ 97*cf84ac9aSAndroid Build Coastguard Worker 'zeroargc strace failed to handle the error properly' 98*cf84ac9aSAndroid Build Coastguard Workercat > "$EXP" << __EOF__ 99*cf84ac9aSAndroid Build Coastguard Worker$STRACE_EXE: must have PROG [ARGS] or -p PID 100*cf84ac9aSAndroid Build Coastguard WorkerTry '$STRACE_EXE -h' for more information. 101*cf84ac9aSAndroid Build Coastguard Worker__EOF__ 102*cf84ac9aSAndroid Build Coastguard Workerdiff -u -- "$EXP" "$LOG" > /dev/null || { 103*cf84ac9aSAndroid Build Coastguard Worker cat > "$EXP" <<- '__EOF__' 104*cf84ac9aSAndroid Build Coastguard Worker strace: must have PROG [ARGS] or -p PID 105*cf84ac9aSAndroid Build Coastguard Worker Try 'strace -h' for more information. 106*cf84ac9aSAndroid Build Coastguard Worker __EOF__ 107*cf84ac9aSAndroid Build Coastguard Worker match_diff "$LOG" "$EXP" \ 108*cf84ac9aSAndroid Build Coastguard Worker "zeroargc $STRACE $args output mismatch" 109*cf84ac9aSAndroid Build Coastguard Worker} 110*cf84ac9aSAndroid Build Coastguard Worker 111*cf84ac9aSAndroid Build Coastguard Workeruid="${UID:-`id -u`}" 112*cf84ac9aSAndroid Build Coastguard Workerif [ "$uid" -ge 0 ]; then 113*cf84ac9aSAndroid Build Coastguard Worker if [ "$uid" -eq 0 ]; then 114*cf84ac9aSAndroid Build Coastguard Worker umsg="Cannot find user ':nosuchuser:'" 115*cf84ac9aSAndroid Build Coastguard Worker else 116*cf84ac9aSAndroid Build Coastguard Worker umsg='You must be root to use the -u option' 117*cf84ac9aSAndroid Build Coastguard Worker fi 118*cf84ac9aSAndroid Build Coastguard Worker 119*cf84ac9aSAndroid Build Coastguard Worker check_e "$umsg" -u :nosuchuser: true 120*cf84ac9aSAndroid Build Coastguard Worker 121*cf84ac9aSAndroid Build Coastguard Worker for c in i r t T y; do 122*cf84ac9aSAndroid Build Coastguard Worker check_e "-$c has no effect with -c 123*cf84ac9aSAndroid Build Coastguard Worker$STRACE_EXE: $umsg" -u :nosuchuser: -c -$c true 124*cf84ac9aSAndroid Build Coastguard Worker done 125*cf84ac9aSAndroid Build Coastguard Worker check_e "-i has no effect with -c 126*cf84ac9aSAndroid Build Coastguard Worker$STRACE_EXE: -r has no effect with -c 127*cf84ac9aSAndroid Build Coastguard Worker$STRACE_EXE: -t has no effect with -c 128*cf84ac9aSAndroid Build Coastguard Worker$STRACE_EXE: -T has no effect with -c 129*cf84ac9aSAndroid Build Coastguard Worker$STRACE_EXE: -y has no effect with -c 130*cf84ac9aSAndroid Build Coastguard Worker$STRACE_EXE: $umsg" -u :nosuchuser: -cirtTy true 131*cf84ac9aSAndroid Build Coastguard Workerfi 132*cf84ac9aSAndroid Build Coastguard Worker 133*cf84ac9aSAndroid Build Coastguard Workerargs='-p 2147483647' 134*cf84ac9aSAndroid Build Coastguard Worker$STRACE $args 2> "$LOG" && 135*cf84ac9aSAndroid Build Coastguard Worker dump_log_and_fail_with \ 136*cf84ac9aSAndroid Build Coastguard Worker "strace $args failed to handle the error properly" 137*cf84ac9aSAndroid Build Coastguard Worker 138*cf84ac9aSAndroid Build Coastguard Workerfor cmd in PTRACE_SEIZE PTRACE_ATTACH; do 139*cf84ac9aSAndroid Build Coastguard Worker cat > "$EXP" << __EOF__ 140*cf84ac9aSAndroid Build Coastguard Worker$STRACE_EXE: attach: ptrace($cmd, 2147483647): No such process 141*cf84ac9aSAndroid Build Coastguard Worker__EOF__ 142*cf84ac9aSAndroid Build Coastguard Worker diff -- "$EXP" "$LOG" || 143*cf84ac9aSAndroid Build Coastguard Worker continue 144*cf84ac9aSAndroid Build Coastguard Worker args= 145*cf84ac9aSAndroid Build Coastguard Worker break 146*cf84ac9aSAndroid Build Coastguard Workerdone 147*cf84ac9aSAndroid Build Coastguard Worker 148*cf84ac9aSAndroid Build Coastguard Worker[ -z "$args" ] || 149*cf84ac9aSAndroid Build Coastguard Worker dump_log_and_fail_with \ 150*cf84ac9aSAndroid Build Coastguard Worker "strace $args failed to print expected diagnostics" 151