summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.context/usymbols.exp
blob: 39b3b44201d3285efbfa3cd28fcd4f93c4d22073 (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
set test "./usymbols"
set testpath "$srcdir/$subdir"
set testsrc  "$testpath/usymbols.c"
set testsrclib  "$testpath/usymbols_lib.c"
set testexe  "[pwd]/usymbols"
set testlibname  "usymbols"
set testlibdir "[pwd]"
set testso  "$testlibdir/lib${testlibname}.so"
set testflags "additional_flags=-g additional_flags=-O"
set testlibflags "testflags additional_flags=-fPIC additional_flags=-shared"
set maintestflags "$testflags additional_flags=-L$testlibdir additional_flags=-l$testlibname additional_flags=-Wl,-rpath,$testlibdir"

# Only run on make installcheck and utrace present.
if {! [installtest_p]} { untested "$test"; return }
if {! [utrace_p]} { untested "$test"; return }

# Compile our test program and library.
set res [target_compile $testsrclib $testso executable $testlibflags]
if { $res != "" } {
    verbose "target_compile for $testso failed: $res" 2
    fail "unable to compile $testsrclib"
    return
}
set res [target_compile $testsrc $testexe executable $maintestflags]
if { $res != "" } {
    verbose "target_compile failed: $res" 2
    fail "unable to compile $testsrc"
    return
}

# We need the execname() trick to work around (the workaround of) PR6964
# otherwise we get also the rt_sigactions of stapio. Get the handler
# (comes from the executable or the library).
set testscript {
    probe syscall.rt_sigaction {
      if (pid() == target() && execname() == "%s") {
	  handler = $act->sa_handler;
	  printf("handler: %%s\n", usymname(handler));
      }
    }
    /* track through uprobes, so as to make sure we have the symbols */
    probe process("%s").function("*") { printf(""); }
}

set output {handler: main_handler
handler: lib_handler}

# Got to run stap with both the exe and the libraries used as -d args.
# XXX Note how we need the fully resolved (absolute) path...
set script [format $testscript usymbols $testexe]
catch {eval exec [concat ldd $testexe | grep $testlibname]} libpath
set libpath [lindex [split $libpath " "] 2]
send_log "libpath: $libpath\n"
if {[string equal "link" [file type $libpath]]} {
    set libpath [file join [file dirname $libpath] [file readlink $libpath]]
}
send_log "libpath: $libpath\n"

set cmd [concat stap -d $libpath -d $testexe -c $testexe -e {$script}]
send_log "cmd: $cmd\n"
catch {eval exec $cmd} res
send_log "cmd output: $res\n"

set n 0
set m [llength [split $output "\n"]]
set expected [split $output "\n"]
foreach line [split $res "\n"] {
    if {![string equal $line [lindex $expected $n]]} {
      fail usymbols
      send_log "line [expr $n + 1]: expected \"[lindex $expected $n]\", "
      send_log "Got \"$line\"\n"
      return
    }
    incr n
}
if { $n != $m } {
  fail usymbols
  send_log "Got \"$n\" lines, expected \"$m\" lines\n"
} else {
  pass usymbols
}
exec rm -f $testexe $testso