libdl-simple.exp revision 679e4fe6bd3f433e7990e19617a3157ce733a9c7
1set testfile "libdl-simple"
2set srcfile ${testfile}.c
3set binfile ${testfile}
4set libfile "libdl-simple-lib"
5set libsrc $srcdir/$subdir/$libfile.c
6set lib_sl $objdir/$subdir/lib$testfile.so
7
8verbose "compiling source file now....."
9# Build the shared libraries this test case needs.
10if  { [ltrace_compile_shlib $libsrc $lib_sl [debug]] != ""
11      || [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${objdir}/${subdir}/${binfile}" executable {debug shlib=-ldl} ] != "" } {
12     send_user "Testcase compile failed, so all tests in this file will automatically fail.\n"
13}
14
15# set options for ltrace.
16ltrace_options "-x" "test_libdl"
17
18# Run PUT for ltrace.
19set exec_output [ltrace_runtest $objdir/$subdir $objdir/$subdir/$binfile]
20verbose "ltrace runtest output: $exec_output\n"
21
22# Check the output of this program.
23if [regexp {ELF from incompatible architecture} $exec_output] {
24	fail "32-bit ltrace can not perform on 64-bit PUTs and rebuild ltrace in 64 bit mode!"
25	return
26} elseif [ regexp {Couldn't get .hash data} $exec_output ] {
27	fail "Couldn't get .hash data!"
28	return
29}
30
31# Verify the time for calling sleep.
32set fd [ open $objdir/$subdir/$binfile.ltrace r]
33set FOUND 0
34while { [gets $fd line] >= 0 } {
35	# match the line with sleep and extract the spent time in sleep and sleep argument.
36	if [ regexp {(test_libdl)\(} $line match tester ] then {
37		verbose "test_libdl = $tester"
38
39		if { $tester == "test_libdl" } then {
40			pass "Successfully traced libdl loaded function."
41		} else {
42			fail "Failed to trace libdl loaded function."
43		}
44	set FOUND 1
45	break
46        }
47}
48close $fd
49
50if {$FOUND != 1} then {
51	fail "Fail to trace libdl loaded function!"
52}
53