1#! /bin/sh -efu
2#
3# Common code for per-personality qualification tests
4#
5# Copyright (c) 2018 The strace developers.
6# All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    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 the
15#    documentation and/or other materials provided with the distribution.
16# 3. The name of the author may not be used to endorse or promote products
17#    derived from this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30. "${srcdir=.}/init.sh"
31
32[ 2 -le "$#" ] ||
33	fail_ 'No personality designation ("64", "32", "x32") specified'
34
35pers="$1"
36shift
37trace_expr="$1"
38shift
39skip="${1-}"
40
41case "$STRACE_NATIVE_ARCH" in
42x86_64)
43	supported_pers='64 32 x32'
44	;;
45x32)
46	supported_pers='x32 32'
47	;;
48aarch64|powerpc64|riscv|s390x|sparc64|tile)
49	supported_pers='64 32'
50	;;
51*)
52	supported_pers="$(($SIZEOF_LONG * 8))"
53	;;
54esac
55
56# Detect current personality designation
57if [ "x$STRACE_NATIVE_ARCH" = "x$STRACE_ARCH" ]; then
58	case "$STRACE_NATIVE_ARCH" in
59	x32)
60		cur_pers=x32
61		;;
62	*)
63		cur_pers="$(($SIZEOF_LONG * 8))"
64		;;
65	esac
66else
67	if [ "x$SIZEOF_KERNEL_LONG_T" = "x$SIZEOF_LONG" ]; then
68		[ 4 -eq "$SIZEOF_LONG" ] ||
69			fail_ "sizeof(long) = $SIZEOF_LONG != 4"
70		cur_pers=32
71	else
72		[ 8 -eq "$SIZEOF_KERNEL_LONG_T" ] ||
73			fail_ "sizeof(kernel_long_t) = $SIZEOF_KERNEL_LONG_T != 8"
74		[ 4 -eq "$SIZEOF_LONG" ] ||
75			fail_ "sizeof(long) = $SIZEOF_LONG != 4"
76		cur_pers=x32
77	fi
78fi
79
80pers_found=0
81set -- $supported_pers
82for i; do
83	[ "x$pers" != "x$i" ] || pers_found=1
84done
85
86[ "$pers_found" = 1 ] ||
87	skip_ "Personality '$pers' is not supported on architecture" \
88	      "'$STRACE_NATIVE_ARCH' (supported personalities: $supported_pers)"
89
90# If tested personality is not equivalent to current personality, reset $NAME,
91# so "$NAME.in", which is used by test_trace_expr, points to an empty file.
92[ "x$pers" = "x$cur_pers" ] || NAME=qualify_personality_empty
93
94test_trace_expr "$skip" -e trace="${trace_expr}@${pers}"
95