Home | History | Annotate | Download | only in tests-m32
      1 #!/bin/sh
      2 #
      3 # Check how strace -e signal=set works.
      4 #
      5 # Copyright (c) 2016 Dmitry V. Levin <ldv (at] altlinux.org>
      6 # Copyright (c) 2016-2017 The strace developers.
      7 # All rights reserved.
      8 #
      9 # Redistribution and use in source and binary forms, with or without
     10 # modification, are permitted provided that the following conditions
     11 # are met:
     12 # 1. Redistributions of source code must retain the above copyright
     13 #    notice, this list of conditions and the following disclaimer.
     14 # 2. Redistributions in binary form must reproduce the above copyright
     15 #    notice, this list of conditions and the following disclaimer in the
     16 #    documentation and/or other materials provided with the distribution.
     17 # 3. The name of the author may not be used to endorse or promote products
     18 #    derived from this software without specific prior written permission.
     19 #
     20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30 
     31 . "${srcdir=.}/init.sh"
     32 
     33 test_one_sig()
     34 {
     35 	local sigs
     36 	sigs="$1"; shift
     37 
     38 	run_prog "../$NAME" "$@" > /dev/null
     39 	run_strace -e trace=none -e signal="$sigs" "../$NAME" "$@" > "$EXP"
     40 	match_diff "$LOG" "$EXP"
     41 }
     42 
     43 test_sigs()
     44 {
     45 	local first second sigs
     46 	first="$1"; shift
     47 	second="$1"; shift
     48 
     49 	for sigs; do
     50 		test_one_sig "$sigs" 2 "$first" 15 "$second"
     51 	done
     52 }
     53 
     54 test_sigs '' '' \
     55 	none '!all' \
     56 	CHLD SIGCHLD ALRM SIGALRM \
     57 	chld sigchld alrm sigalrm \
     58 	CHLD,SIGALRM ALRM,SIGCHLD \
     59 	chld,sigalrm alrm,sigchld \
     60 	9 9,4 9,4,11 \
     61 	4,CHLD,11,ALRM,9 \
     62 	'!2,15' '!INT,TERM' '!SIGINT,TERM' '!INT,SIGTERM' '!SIGTERM,SIGINT' \
     63 	'!2,INT,TERM' '!2,SIGTERM' '!SIGINT,15' '!INT,SIGTERM,15' \
     64 	'!2,4,15' '!15,9,2,11,4'
     65 
     66 test_sigs SIGINT '' \
     67 	2 INT SIGINT \
     68 	CHLD,SIGINT SIGINT,SIGALRM \
     69 	chld,sigint sigint,sigalrm \
     70 	ALRM,2,SIGCHLD \
     71 	'!15' '!TERM' '!SIGTERM' \
     72 	'!15,TERM' '!SIGTERM,15,TERM' \
     73 	'!SIGALRM,TERM' '!CHLD,SIGTERM' \
     74 	'!ALRM,15' '!SIGCHLD,ALRM,SIGTERM,KILL' \
     75 	'!4,15' '!15,9,11,4'
     76 
     77 test_sigs '' SIGTERM \
     78 	15 TERM SIGTERM \
     79 	CHLD,SIGTERM SIGTERM,SIGALRM \
     80 	chld,sigterm sigterm,sigalrm \
     81 	ALRM,15,SIGCHLD \
     82 	'!2' '!INT' '!SIGINT' \
     83 	'!2,INT' '!SIGINT,2,INT' \
     84 	'!SIGALRM,INT' '!CHLD,SIGINT' \
     85 	'!ALRM,2' '!SIGCHLD,ALRM,SIGINT,KILL' \
     86 	'!4,2' '!2,9,11,4'
     87 
     88 test_sigs SIGINT SIGTERM \
     89 	all '!none' \
     90 	INT,TERM SIGINT,TERM SIGTERM,INT SIGINT,SIGTERM \
     91 	int,term sigint,term sigterm,int sigint,sigterm \
     92 	2,15 2,TERM SIGTERM,2 TERM,15,SIGINT,2 \
     93 	'!CHLD' '!SIGCHLD' '!ALRM' '!SIGALRM' \
     94 	'!CHLD,SIGALRM' '!ALRM,SIGCHLD' \
     95 	'!9' '!9,4' '!9,4,11' '!4,CHLD,11,ALRM,9'
     96 
     97 fail_with()
     98 {
     99 	dump_log_and_fail_with \
    100 		"strace -e signal=$* failed to handle an argument error properly"
    101 }
    102 
    103 for arg in ' ' invalid_signal_name SIG -1 256 1-1 \
    104 	   1,2,4,8,16,32,64,128,256,512,1024 9,chdir; do
    105 	$STRACE -e signal="$arg" true 2> "$LOG" &&
    106 		fail_with "$arg"
    107 	LC_ALL=C grep -F 'invalid signal' < "$LOG" > /dev/null ||
    108 		fail_with "$arg"
    109 done
    110 
    111 exit 0
    112