summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.base/externalvar.exp
blob: f6553f454a43695833af8d9f721b8cb23207bf96 (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
set test "externalvar"
set testpath "$srcdir/$subdir"
set testsrc  "$testpath/$test.c"
set testsrclib  "$testpath/${test}_lib.c"
set testexe  "[pwd]/$test"
set testlibname  "$test"
set testlibdir "[pwd]"
set testso  "$testlibdir/lib${testlibname}.so"
set testflags "additional_flags=-g additional_flags=-O0"
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
}

set output {exevar_c = 42
exevar_i = 2
exevar_l = 21
exe_s->i = 1
exe_s->l = 2
exe_s->c = 3
exe_s->s1 = 0x0
exe_s == exe_s->s2
libvar = 42
lib_s->i = 1
lib_s->l = 2
lib_s->c = 3
lib_s == lib_s->s1
lib_s->s2 = 0x0}

# Got to run stap with both the exe and the libraries used as -d args.
set cmd [concat stap -d $testso -d $testexe -c $testexe $testpath/$test.stp]
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 $test
      send_log "line [expr $n + 1]: expected \"[lindex $expected $n]\", "
      send_log "Got \"$line\"\n"
      return
    }
    incr n
}
if { $n != $m } {
  fail $test
  send_log "Got \"$n\" lines, expected \"$m\" lines\n"
} else {
  pass $test
}
catch {exec rm -f $testexe $testso}