Debian Codegraph @

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

raw
1 # hash_add_buildid.exp
2
3 set test "hash_add_buildid"
4 if {![uprobes_p]} { untested $test; return }
5
6 # Since we need a clean cache directory, we'll use a temporary
7 # systemtap directory and cache (add user name so make check and
8 # sudo make installcheck don't clobber each others)
9 set exe hash_add_buildid
10 set at_least_one_run 0
11 set passed 0
12 set local_systemtap_dir [exec pwd]/.cache_test-[exec whoami]
13 exec /bin/rm -rf $local_systemtap_dir
14 exec /bin/mkdir $local_systemtap_dir
15 if [info exists env(SYSTEMTAP_DIR)] {
16 set old_systemtap_dir $env(SYSTEMTAP_DIR)
17 }
18 set env(SYSTEMTAP_DIR) $local_systemtap_dir
19
20 # Set up the script we'll use.
21 set basic_script {"probe process(\"hash_add_buildid\").function(\"main\") { println(1) }" }
22
23 for {set i 0} {$i < [arch_compile_flags]} {incr i} {
24 set test_flags "additional_flags=-g"
25 set extra_flag [arch_compile_flag $i]
26 set arch_name [arch_compile_flag_name $i]
27
28 if { $extra_flag == ""} {
29 set arch "-default"
30 } else {
31 set arch "-${arch_name}"
32 set test_flags "$test_flags $extra_flag"
33 }
34
35
36 # Compile hash_add_buildid1.c and change the timestamp
37 # of the binary
38 exec cp $srcdir/$subdir/hash_add_buildid1.c $local_systemtap_dir/hash_add_buildid.c
39 set res [target_compile $local_systemtap_dir/hash_add_buildid.c $exe executable "$test_flags"]
40 if { $res != "" } {
41 continue
42 }
43
44 # Check that the build ID exists on this system
45 set cmd [concat {/usr/bin/eu-readelf -n hash_add_buildid}]
46 eval spawn $cmd
47 expect {
48 -timeout 180
49 -re {^[^\r\n]*GNU_BUILD_ID[^\r\n]*\r\n} {
50 set passed 1
51 exp_continue
52 }
53 -re {^[^\r\n]*\r\n} {
54 exp_continue
55 }
56 timeout {
57 set passed 0
58 }
59 }
60 catch { close }; catch { wait }
61
62 if {$passed == 0} {
63 continue
64 }
65
66 # Change the timestamp to a known value
67 file mtime $exe 970399800
68 file stat $exe stat1
69
70 # The 1st compilation of a script won't be cached,
71 # the 2nd should not be cached either.
72 cache_compile RUN1-($arch) [F_UNCACHED_COMPILE] $basic_script
73
74 # Recompile the test binary using hash_add_buildid2.c
75 # and change the timestamp to the same as the previous one.
76 exec cp $srcdir/$subdir/hash_add_buildid2.c $local_systemtap_dir/hash_add_buildid.c
77 set res [target_compile $local_systemtap_dir/hash_add_buildid.c $exe executable "$test_flags"]
78 if { $res != "" } {
79 continue
80 }
81
82 #Change the timestamp to the same as the previous one.
83 file mtime $exe 970399800
84 file stat $exe stat2
85
86 # This one should also not be cached.
87 cache_compile RUN2-($arch) [F_UNCACHED_COMPILE] $basic_script
88 set at_least_one_run 1
89
90 if {$stat1(size)!=$stat2(size)} {
91 fail "$exe.c file sizes are not the same"
92 }
93 if {$stat1(mtime) != $stat2(mtime)} {
94 fail "$exe.c files don't have the same timestamp"
95 }
96 }
97
98 if {$passed == 0} {
99 untested "$exe no build id available"
100 } elseif {$at_least_one_run == 0 } {
101 fail "$exe arch not supported"
102 }
103
104 # Cleanup.
105 exec /bin/rm -rf $local_systemtap_dir
106 if [info exists old_systemtap_dir] {
107 set env(SYSTEMTAP_DIR) $old_systemtap_dir
108 } else {
109 unset env(SYSTEMTAP_DIR)
110 }
111