1*cf84ac9aSAndroid Build Coastguard Worker#!/bin/sh 2*cf84ac9aSAndroid Build Coastguard Worker# 3*cf84ac9aSAndroid Build Coastguard Worker# Check how strace -e signal=set works. 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-2017 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=.}/init.sh" 32*cf84ac9aSAndroid Build Coastguard Worker 33*cf84ac9aSAndroid Build Coastguard Workertest_one_sig() 34*cf84ac9aSAndroid Build Coastguard Worker{ 35*cf84ac9aSAndroid Build Coastguard Worker local sigs 36*cf84ac9aSAndroid Build Coastguard Worker sigs="$1"; shift 37*cf84ac9aSAndroid Build Coastguard Worker 38*cf84ac9aSAndroid Build Coastguard Worker run_prog "../$NAME" "$@" > /dev/null 39*cf84ac9aSAndroid Build Coastguard Worker run_strace -e trace=none -e signal="$sigs" "../$NAME" "$@" > "$EXP" 40*cf84ac9aSAndroid Build Coastguard Worker match_diff "$LOG" "$EXP" 41*cf84ac9aSAndroid Build Coastguard Worker} 42*cf84ac9aSAndroid Build Coastguard Worker 43*cf84ac9aSAndroid Build Coastguard Workertest_sigs() 44*cf84ac9aSAndroid Build Coastguard Worker{ 45*cf84ac9aSAndroid Build Coastguard Worker local first second sigs 46*cf84ac9aSAndroid Build Coastguard Worker first="$1"; shift 47*cf84ac9aSAndroid Build Coastguard Worker second="$1"; shift 48*cf84ac9aSAndroid Build Coastguard Worker 49*cf84ac9aSAndroid Build Coastguard Worker for sigs; do 50*cf84ac9aSAndroid Build Coastguard Worker test_one_sig "$sigs" 2 "$first" 15 "$second" 51*cf84ac9aSAndroid Build Coastguard Worker done 52*cf84ac9aSAndroid Build Coastguard Worker} 53*cf84ac9aSAndroid Build Coastguard Worker 54*cf84ac9aSAndroid Build Coastguard Workertest_sigs '' '' \ 55*cf84ac9aSAndroid Build Coastguard Worker none '!all' \ 56*cf84ac9aSAndroid Build Coastguard Worker CHLD SIGCHLD ALRM SIGALRM \ 57*cf84ac9aSAndroid Build Coastguard Worker chld sigchld alrm sigalrm \ 58*cf84ac9aSAndroid Build Coastguard Worker CHLD,SIGALRM ALRM,SIGCHLD \ 59*cf84ac9aSAndroid Build Coastguard Worker chld,sigalrm alrm,sigchld \ 60*cf84ac9aSAndroid Build Coastguard Worker 9 9,4 9,4,11 \ 61*cf84ac9aSAndroid Build Coastguard Worker 4,CHLD,11,ALRM,9 \ 62*cf84ac9aSAndroid Build Coastguard Worker '!2,15' '!INT,TERM' '!SIGINT,TERM' '!INT,SIGTERM' '!SIGTERM,SIGINT' \ 63*cf84ac9aSAndroid Build Coastguard Worker '!2,INT,TERM' '!2,SIGTERM' '!SIGINT,15' '!INT,SIGTERM,15' \ 64*cf84ac9aSAndroid Build Coastguard Worker '!2,4,15' '!15,9,2,11,4' 65*cf84ac9aSAndroid Build Coastguard Worker 66*cf84ac9aSAndroid Build Coastguard Workertest_sigs SIGINT '' \ 67*cf84ac9aSAndroid Build Coastguard Worker 2 INT SIGINT \ 68*cf84ac9aSAndroid Build Coastguard Worker CHLD,SIGINT SIGINT,SIGALRM \ 69*cf84ac9aSAndroid Build Coastguard Worker chld,sigint sigint,sigalrm \ 70*cf84ac9aSAndroid Build Coastguard Worker ALRM,2,SIGCHLD \ 71*cf84ac9aSAndroid Build Coastguard Worker '!15' '!TERM' '!SIGTERM' \ 72*cf84ac9aSAndroid Build Coastguard Worker '!15,TERM' '!SIGTERM,15,TERM' \ 73*cf84ac9aSAndroid Build Coastguard Worker '!SIGALRM,TERM' '!CHLD,SIGTERM' \ 74*cf84ac9aSAndroid Build Coastguard Worker '!ALRM,15' '!SIGCHLD,ALRM,SIGTERM,KILL' \ 75*cf84ac9aSAndroid Build Coastguard Worker '!4,15' '!15,9,11,4' 76*cf84ac9aSAndroid Build Coastguard Worker 77*cf84ac9aSAndroid Build Coastguard Workertest_sigs '' SIGTERM \ 78*cf84ac9aSAndroid Build Coastguard Worker 15 TERM SIGTERM \ 79*cf84ac9aSAndroid Build Coastguard Worker CHLD,SIGTERM SIGTERM,SIGALRM \ 80*cf84ac9aSAndroid Build Coastguard Worker chld,sigterm sigterm,sigalrm \ 81*cf84ac9aSAndroid Build Coastguard Worker ALRM,15,SIGCHLD \ 82*cf84ac9aSAndroid Build Coastguard Worker '!2' '!INT' '!SIGINT' \ 83*cf84ac9aSAndroid Build Coastguard Worker '!2,INT' '!SIGINT,2,INT' \ 84*cf84ac9aSAndroid Build Coastguard Worker '!SIGALRM,INT' '!CHLD,SIGINT' \ 85*cf84ac9aSAndroid Build Coastguard Worker '!ALRM,2' '!SIGCHLD,ALRM,SIGINT,KILL' \ 86*cf84ac9aSAndroid Build Coastguard Worker '!4,2' '!2,9,11,4' 87*cf84ac9aSAndroid Build Coastguard Worker 88*cf84ac9aSAndroid Build Coastguard Workertest_sigs SIGINT SIGTERM \ 89*cf84ac9aSAndroid Build Coastguard Worker all '!none' \ 90*cf84ac9aSAndroid Build Coastguard Worker INT,TERM SIGINT,TERM SIGTERM,INT SIGINT,SIGTERM \ 91*cf84ac9aSAndroid Build Coastguard Worker int,term sigint,term sigterm,int sigint,sigterm \ 92*cf84ac9aSAndroid Build Coastguard Worker 2,15 2,TERM SIGTERM,2 TERM,15,SIGINT,2 \ 93*cf84ac9aSAndroid Build Coastguard Worker '!CHLD' '!SIGCHLD' '!ALRM' '!SIGALRM' \ 94*cf84ac9aSAndroid Build Coastguard Worker '!CHLD,SIGALRM' '!ALRM,SIGCHLD' \ 95*cf84ac9aSAndroid Build Coastguard Worker '!9' '!9,4' '!9,4,11' '!4,CHLD,11,ALRM,9' 96*cf84ac9aSAndroid Build Coastguard Worker 97*cf84ac9aSAndroid Build Coastguard Workerfail_with() 98*cf84ac9aSAndroid Build Coastguard Worker{ 99*cf84ac9aSAndroid Build Coastguard Worker dump_log_and_fail_with \ 100*cf84ac9aSAndroid Build Coastguard Worker "strace -e signal=$* failed to handle an argument error properly" 101*cf84ac9aSAndroid Build Coastguard Worker} 102*cf84ac9aSAndroid Build Coastguard Worker 103*cf84ac9aSAndroid Build Coastguard Workerfor arg in ' ' invalid_signal_name SIG -1 256 1-1 \ 104*cf84ac9aSAndroid Build Coastguard Worker 1,2,4,8,16,32,64,128,256,512,1024 9,chdir; do 105*cf84ac9aSAndroid Build Coastguard Worker $STRACE -e signal="$arg" true 2> "$LOG" && 106*cf84ac9aSAndroid Build Coastguard Worker fail_with "$arg" 107*cf84ac9aSAndroid Build Coastguard Worker LC_ALL=C grep -F 'invalid signal' < "$LOG" > /dev/null || 108*cf84ac9aSAndroid Build Coastguard Worker fail_with "$arg" 109*cf84ac9aSAndroid Build Coastguard Workerdone 110*cf84ac9aSAndroid Build Coastguard Worker 111*cf84ac9aSAndroid Build Coastguard Workerexit 0 112