summaryrefslogtreecommitdiff
path: root/usr/src/test/util-tests/tests/ctf/ctftest-convert-non-c.ksh
blob: cfbdf3d724aaf4deeba2b40bb2acf0af1aac6ca6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/ksh
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# Copyright (c) 2019, Joyent, Inc.
#

set -e

result=0

progname=$(basename $0)

fail()
{
	echo "Failed: $*" 2>&1
	result=1
}

fail_non_c()
{
	cmd="$@"
	set +e
	out=$($ctf_convert $cmd 2>&1)

	if [[ $? -eq 0 ]]; then
		fail "$cmd succeeded but should have failed"
		set -e
		return;
	fi

	set -e

	if ! echo "$out" | \
	    grep "No C source to convert from" >/dev/null; then
		fail "$cmd: incorrect output $out"
		return;
	fi
}

no_ctf()
{
	for f in "$@"; do
		if elfdump -c -N .SUNW_ctf "$f" |
		    grep '.SUNW_ctf' >/dev/null; then
			fail "$f has CTF section"
			return
		fi
	done
}

cat <<EOF >file1.c
#include <stdio.h>
struct foo { int a; };
int main(void) { struct foo foo = { 4 }; printf("%d\n", foo.a); }
EOF

cat <<EOF >file2.cc
struct bar { char *tar; };
void mycxxfunc(char *c) { c[0] = '9'; };
EOF

cat <<EOF >file3.s
.globl caller
.type caller,@function
caller:
	movl 4(%ebp), %eax
	ret
EOF

echo "$progname: ctfconvert should fail on a .cc-derived object"
$ctf_cxx -c -o file2.o file2.cc
fail_non_c file2.o
$ctf_cxx -c -o file2.o file2.cc
$ctf_convert -i file2.o

echo "$progname: ctfconvert shouldn't process .cc-derived DWARF"
$ctf_cc $DEBUGFLAGS -c -o file2.o file2.cc
$ctf_convert -i file2.o
no_ctf file2.o

echo "$progname: ctfconvert should fail on a .s-derived object"
$ctf_as -o file3.o file3.s
fail_non_c file3.o
$ctf_as -o file3.o file3.s
$ctf_convert -i file3.o
no_ctf file3.o

echo "result is $result"
exit $result