summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.exelib/exelib.exp
blob: 1337d5453f58e978acf4d737388d7d5895d8c59c (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# Builds various variants of an executable and a shared library
# (with gcc/g++, -O0/-O3, prelinked/pie, seperate debuginfo)
# Then runs tests with a list of execs.

# Don't enable all sub-tests by default, enable them separately when
# you want to track down an issue.
# Enable just the all-in-one test for regular test runs to safe time
#set subtestlist {lib mark uname ustack cleanup}
set subtestlist {libmarkunamestack cleanup}

proc seperate_debuginfo {elffile} {
    set objcopy [list "objcopy" "--only-keep-debug"]
    lappend objcopy "$elffile"
    lappend objcopy "${elffile}.debug"
    send_log "Executing: $objcopy\n"
    eval exec $objcopy
    
    set objcopy [list "objcopy" "--strip-debug"]
    lappend objcopy "$elffile"
    send_log "Executing: $objcopy\n"
    eval exec $objcopy
    
    set objcopy [list "objcopy"]
    lappend objcopy "--add-gnu-debuglink=${elffile}.debug"
    lappend objcopy "$elffile"
    send_log "Executing: $objcopy\n"
    eval exec $objcopy
}

set testnames   {}

set testpath    "$srcdir/$subdir"
set testsrc     "$testpath/uprobes_exe.c"
set testsrclib  "$testpath/uprobes_lib.c"
set testlibdir  "."

set arches [list "default"]
# BUG! non-default arch breaks mark and ustack tests PR10318 and PR10272
#switch -regexp $::tcl_platform(machine) {
#    {^(x86_64|ppc64)$} { lappend arches "-m32" }
#    {^s390x$} { lappend arches "-m31" }
#}

foreach arch $arches {

    # Compiling with plain gcc.  g++ is also supported but disabled
    # because it didn't add much interesting differences in binaries
    # and exploded the test search case a bit.
    foreach compiler {gcc} { # Add g++
	
	# Just try -O3.
	# Adding -O0, -O, -O2, -Os and mixing lib/exe is a bit overdone
	foreach opt {-O3} {
	    
	    foreach libprelink {no yes} {
		
		# not done yet, "no" lib debug.
		# seperate debuginfo can be done before or after prelinking
		# (after is only done if prelinking is also done
		foreach libdebug {yes sep sep-after} {
		    
		    set libname "uprobeslib${compiler}${opt}${arch}"
		    
		    if {$libprelink == "yes"} {
			set libname $libname-prelink
		    }

		    # This combination doesn't make sense
		    if {$libdebug == "sep-after" && $libprelink == "no"} {
			continue;
		    }
		    
		    if {$libdebug == "sep"} {
			set libname $libname-sep-debug
		    } elseif {$libdebug == "sep-after"} {
			set libname $libname-sep-debug-after
		    } else {
			set libname $libname-debug
		    }
		    
		    # General compiler flags
		    # We want the sdt.h from the source dir.
		    set testflags "additional_flags=-I$srcdir/../includes/sys"
		    # For now we always require debuginfo
		    set testflags "$testflags additional_flags=-g"
		    if {$arch != "default"} {
			set testflags "$testflags additional_flags=$arch"
		    }
		    if {$compiler == "g++"} {
			set testflags "$testflags additional_flags=-x additional_flags=c++"
		    }
		    set testflags "$testflags additional_flags=$opt"
		    
		    # Extra flags for libraries
		    set testlibflags "$testflags additional_flags=-fPIC"
		    set testlibflags "$testlibflags additional_flags=-shared"
		    
		    set testso "$testlibdir/lib${libname}.so"
		    set res [target_compile $testsrclib $testso executable $testlibflags]
		    if { $res != "" } {
			verbose "target_compile for $testso failed: $res" 2
			fail "$libname compile [file tail $testsrclib]"
			return
		    } else {
			pass "$libname compile [file tail $testsrclib]"
		    }
		    
		    # seperate debuginfo before prelinking
		    if {$libdebug == "sep"} {
			seperate_debuginfo $testso
		    }

		    if {$libprelink == "yes"} {
			set prelink_bin "/usr/sbin/prelink"
			set addr "-r 0x6400000"
			set prelink_cmd [concat $prelink_bin -vfNR $addr $testso]
			send_log "Executing: $prelink_cmd\n"
			catch {eval exec $prelink_cmd} result
			verbose -log "result is $result"
		    }
		    
		    # seperate debuginfo after prelinking
		    if {$libdebug == "sep-after"} {
			seperate_debuginfo $testso
		    }

		    # should we also prelink exes?
		    foreach exepie {no yes} {
			# not supported, "no" exe debug.
			foreach exedebug {yes sep} {
			    
			    set exename uprobes$compiler$opt$arch
			    
			    # Extra exe compile flags to include lib
			    set testexeflags "$testflags additional_flags=-L$testlibdir additional_flags=-l$libname additional_flags=-Wl,-rpath,$testlibdir"
			    
			    if {$exepie == "yes"} {
				set exename $exename-pie
				set testexeflags "$testexeflags additional_flags=-fPIE additional_flags=-pie"
			    }
			    
			    if {$exedebug == "sep"} {
				set exename $exename-sep-debug
			    } else {
				set exename $exename-debug
			    }
			    
			    set exename $exename-$libname
			    
			    set testexe "$testlibdir/${exename}_exe"
			    set res [target_compile $testsrc $testexe executable $testexeflags]
			    if { $res != "" } {
				verbose "target_compile for $testexe failed: $res" 2
				fail "$exename compile [file tail $testsrc]"
				return
			    } else {
				pass "$exename compile [file tail $testsrc]"
			    }
			    
			    if {$exedebug == "sep"} {
				seperate_debuginfo $testexe
			    }

			    set testname "${exename}_${libname}"
			    lappend testnames $testname
			}
		    }
		}
	    }
	}
    }
}

# Call a test for each exe, set lib to shared library used
foreach subtest $subtestlist {
    foreach testname $testnames {
	set exelib [split $testname {_}]
	set testexe [lindex $exelib 0]
	set testexe "${testlibdir}/${testexe}_exe"
	set testlib [lindex $exelib 1]
	set testlib "${testlibdir}/lib${testlib}.so"
	send_log "sourcing: $srcdir/$subdir/$subtest.tcl for $testname\n"
	source $srcdir/$subdir/$subtest.tcl
    }
}