xref: /illumos-gate/usr/src/test/util-tests/tests/ctf/ctftest-convert-non-c.ksh (revision 45ede40b2394db7967e59f19288fae9b62efd4aa)
1#!/usr/bin/ksh
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12# Copyright (c) 2019, Joyent, Inc.
13#
14
15set -e
16
17result=0
18
19progname=$(basename $0)
20
21fail()
22{
23	echo "Failed: $*" 2>&1
24	result=1
25}
26
27fail_non_c()
28{
29	cmd="$@"
30	set +e
31	out=$($ctf_convert $cmd 2>&1)
32
33	if [[ $? -eq 0 ]]; then
34		fail "$cmd succeeded but should have failed"
35		set -e
36		return;
37	fi
38
39	set -e
40
41	if ! echo "$out" | \
42	    grep "No C source to convert from" >/dev/null; then
43		fail "$cmd: incorrect output $out"
44		return;
45	fi
46}
47
48no_ctf()
49{
50	for f in "$@"; do
51		if elfdump -c -N .SUNW_ctf "$f" |
52		    grep '.SUNW_ctf' >/dev/null; then
53			fail "$f has CTF section"
54			return
55		fi
56	done
57}
58
59cat <<EOF >file1.c
60#include <stdio.h>
61struct foo { int a; };
62int main(void) { struct foo foo = { 4 }; printf("%d\n", foo.a); return (0); }
63EOF
64
65cat <<EOF >file2.cc
66struct bar { char *tar; };
67void mycxxfunc(char *c) { c[0] = '9'; };
68EOF
69
70cat <<EOF >file3.s
71.globl caller
72.type caller,@function
73caller:
74	movl 4(%ebp), %eax
75	ret
76EOF
77
78echo "$progname: ctfconvert should fail on a .cc-derived object"
79$ctf_cxx -c -o file2.o file2.cc
80fail_non_c file2.o
81$ctf_cxx -c -o file2.o file2.cc
82$ctf_convert -i file2.o
83
84echo "$progname: ctfconvert shouldn't process .cc-derived DWARF"
85$ctf_cc $DEBUGFLAGS -c -o file2.o file2.cc
86$ctf_convert -i file2.o
87no_ctf file2.o
88
89echo "$progname: ctfconvert should fail on a .s-derived object"
90$ctf_as -o file3.o file3.s
91fail_non_c file3.o
92$ctf_as -o file3.o file3.s
93$ctf_convert -i file3.o
94no_ctf file3.o
95
96echo "result is $result"
97exit $result
98