Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/externalvar.exp

raw
1 set test "externalvar"
2 set testpath "$srcdir/$subdir"
3 set testsrc "$testpath/$test.c"
4 set testsrclib "$testpath/${test}_lib.c"
5 set testexe "[pwd]/$test"
6 set testlibname "$test"
7 set testlibdir "[pwd]"
8 set testso "$testlibdir/lib${testlibname}.so"
9 set testflags "additional_flags=-g"
10 set testlibflags "$testflags additional_flags=-fPIC additional_flags=-shared"
11 set maintestflags "$testflags additional_flags=-L$testlibdir additional_flags=-l$testlibname additional_flags=-Wl,-rpath,$testlibdir"
12
13 set output {exevar_c = 42
14 exevar_i = 2
15 exevar_l = 21
16 stat_exevar_c = 42
17 stat_exevar_i = 2
18 stat_exevar_l = 21
19 exe_s->i = 1
20 exe_s->l = 2
21 exe_s->c = 3
22 stat_exe_s->i = 1
23 stat_exe_s->l = 2
24 stat_exe_s->c = 3
25 exe_s->s1 = 0x0
26 exe_s == exe_s->s2
27 stat_exe_s->s1 = 0x0
28 stat_exe_s == exe_s->s2
29 libvar = 42
30 stat_libvar = 42
31 lib_s->i = 1
32 lib_s->l = 2
33 lib_s->c = 3
34 stat_lib_s->i = 1
35 stat_lib_s->l = 2
36 stat_lib_s->c = 3
37 lib_s == lib_s->s1
38 lib_s->s2 = 0x0
39 stat_lib_s == lib_s->s1
40 stat_lib_s->s2 = 0x0}
41
42 # Only run on make installcheck and utrace present.
43 if {! [installtest_p]} { untested "$test"; return }
44
45 proc dyninst_kfails {index} {
46 # The dyninst runtime isn't multi-arch, it only works on the
47 # native architecture. PR14490.
48 if {! [all_compile_flag_native_p $index]} {
49 setup_kfail 14490 "*-*-*"
50 }
51 }
52
53 for {set i 0} {$i < [all_compile_flags]} {incr i} {
54 set extra_flag [all_compile_flag $i]
55 set extra_name [all_compile_flag_name $i]
56
57 # Compile our test program and library.
58 set res [target_compile $testsrclib $testso executable \
59 "$testlibflags $extra_flag"]
60 if { $res != "" } {
61 verbose "target_compile for $testso failed: $res" 2
62 fail "unable to compile $testsrclib $extra_name"
63 continue
64 }
65 set res [target_compile $testsrc $testexe executable \
66 "$maintestflags $extra_flag"]
67 if { $res != "" } {
68 verbose "target_compile failed: $res" 2
69 fail "unable to compile $testsrc $extra_name"
70 continue
71 }
72
73 foreach runtime [get_runtime_list] {
74 set test_name "$test-$extra_name"
75 if {$runtime != ""} {
76 # Got to run stap with both the exe and the libraries used as -d
77 # args.
78 if {[info procs ${runtime}_kfails] ne ""} { ${runtime}_kfails $i }
79 set test_name "$test_name-$runtime"
80 set cmd [concat stap --runtime=$runtime -d $testso \
81 -d $testexe -c $testexe $testpath/$test.stp]
82 } elseif {[utrace_p] && [uprobes_p]} {
83 # Got to run stap with both the exe and the libraries used as -d
84 # args.
85 set cmd [concat stap -d $testso -d $testexe -c $testexe \
86 $testpath/$test.stp]
87 } else {
88 untested "$test_name"
89 continue
90 }
91 send_log "cmd: $cmd\n"
92 catch {eval exec $cmd} res
93 send_log "cmd output: $res\n"
94
95 set n 0
96 set m [llength [split $output "\n"]]
97 set expected [split $output "\n"]
98 foreach line [split $res "\n"] {
99 if {![string equal $line [lindex $expected $n]]} {
100 fail "$test_name"
101 send_log "line [expr $n + 1]: expected \"[lindex $expected $n]\", "
102 send_log "Got \"$line\"\n"
103 set n -1
104 break
105 }
106 incr n
107 }
108 if { $n < 0 } { continue }
109
110 if { $n != $m } {
111 fail "$test_name"
112 send_log "Got \"$n\" lines, expected \"$m\" lines\n"
113 } else {
114 pass $test_name
115 }
116 }
117 catch {exec rm -f $testexe $testso}
118 }