demangle.exp revision 4627fc493db8459e6ef0597a4155a06b7d120d20
1# This file was written by Yao Qi <qiyao@cn.ibm.com>.
2
3set testfile "demangle"
4set srcfile ${testfile}.cpp
5set binfile ${testfile}
6set libfile "demangle-lib"
7set libsrc $srcdir/$subdir/$libfile.cpp
8set lib_sl $objdir/$subdir/lib$testfile.so
9
10verbose "compiling source file now....."
11if [get_compiler_info $binfile "c++"] {
12  return -1
13}
14
15verbose "compiling source file now....."
16if { [ltrace_compile_shlib $libsrc $lib_sl [list debug c++]] != ""
17  || [ltrace_compile $srcdir/$subdir/$srcfile $objdir/$subdir/$binfile executable [list debug shlib=$lib_sl c++] ] != ""} {
18  send_user "Testcase compile failed, so all tests in this file will automatically fail.\n"
19}
20
21# set options for ltrace.
22ltrace_options "-C"
23
24# Run PUT for ltrace.
25set exec_output [ltrace_runtest $objdir/$subdir $objdir/$subdir/$binfile]
26
27# Check the output of this program.
28verbose "ltrace runtest output: $exec_output\n"
29if [regexp {ELF from incompatible architecture} $exec_output] {
30	fail "32-bit ltrace can not perform on 64-bit PUTs and rebuild ltrace in 64 bit mode!"
31	return
32} elseif [ regexp {Couldn't get .hash data} $exec_output ] {
33	fail "Couldn't get .hash data!"
34	return
35}
36
37# read function declarations from demangle.cpp and verify them in demangle.ltrace.
38set fd [ open $srcdir/$subdir/$srcfile r]
39while { [gets $fd line] >= 0 } {
40    if [regexp {extern (double|float|void|char|int|short|long|void \*|void \*\*) ([^ ])\(} $line match type fun] {
41	ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $fun
42    }
43}
44close $fd
45
46#read member fucntions of classs from demangle-lib.cpp and verify them in demagle.ltrace.
47set fd [ open $srcdir/$subdir/$testfile-lib.cpp r]
48while { [gets $fd line] >= 0 } {
49    if [ regexp {((myclass|nested)::[^\(]*)\(} $line match fun] {
50	# For Debug purpose.
51        verbose "fun = $fun"
52	# Extract new/delete for remove extra SPACE in $fun, for example,
53	# $fun = "myclass::operator delete" will confuse ltrace_verify_output if it
54	# was an argument to it.
55	if [regexp {(new|delete)} $fun match sub_fun] {
56	    ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $sub_fun
57	} else {
58	    # Verify class member functions without SPACE.
59	    ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $fun
60	}
61    }
62}
63close $fd
64