Blame SOURCES/test_systemtap.rb

d64dc0
require 'set'
d64dc0
d64dc0
LIBRUBY_SO = 'libruby.so'
d64dc0
PROBES_D = 'probes.d'
d64dc0
d64dc0
# These probes are excluded by VM_COLLECT_USAGE_DETAILS ifdef.
d64dc0
EXCLUDE_PROBES = Set.new %w(insn insn__operand)
d64dc0
d64dc0
## Detect SystemTap section headers presence
d64dc0
d64dc0
stap_headers = [
d64dc0
  '\.stapsdt\.base',
d64dc0
  '\.note\.stapsdt'
d64dc0
]
d64dc0
d64dc0
header_regexp = %r{ (#{stap_headers.join('|')}) }
d64dc0
d64dc0
section_headers = `readelf -S "#{LIBRUBY_SO}"`
d64dc0
detected_stap_headers = section_headers.scan(header_regexp).flatten
d64dc0
d64dc0
# Assume there are both headers until this is proven wrong ;)
d64dc0
unless detected_stap_headers.size == 2
d64dc0
  puts 'ERROR: SystemTap (DTrace) headers were not detected in resulting library.'
d64dc0
  exit false
d64dc0
end
d64dc0
d64dc0
## Find if every declared probe is propagated to resulting library
d64dc0
d64dc0
# Colect probes specified in probes.d file.
d64dc0
probes_declared = []
d64dc0
d64dc0
File.open(PROBES_D) do |file|
d64dc0
  file.each_line do |line|
d64dc0
    if probe = line[/probe (\S+)\(.*\);/, 1]
d64dc0
      probes_declared << probe
d64dc0
    end
d64dc0
  end
d64dc0
end
d64dc0
d64dc0
probes_declared = Set.new probes_declared
d64dc0
d64dc0
unless EXCLUDE_PROBES.subset? probes_declared
d64dc0
  puts 'ERROR: Change in SystemTap (DTrace) probes definition file detected.'
d64dc0
  exit false
d64dc0
end
d64dc0
d64dc0
probes_declared -= EXCLUDE_PROBES
d64dc0
d64dc0
# Detect probes in resulting library.
d64dc0
get_probes_detected = %r{
d64dc0
^\s*Provider:\s+ruby,\s+Name:\s+(\S+),\s+.*$
d64dc0
}
d64dc0
d64dc0
probes_detected = `eu-readelf -n "#{LIBRUBY_SO}"`
d64dc0
d64dc0
probes_detected = Set.new probes_detected.scan(get_probes_detected).flatten
d64dc0
d64dc0
# Both sets must be equal, otherwise something is wrong.
d64dc0
unless probes_declared == probes_detected
d64dc0
  puts 'ERROR: SystemTap (DTrace) probes were not correctly propagated into resulting library.'
d64dc0
  puts "       Undetected probes: #{(probes_declared - probes_detected).sort.join(', ')}\n",
d64dc0
       "       Additional detected probes: #{(probes_detected - probes_declared).sort.join(', ')}"
d64dc0
d64dc0
  exit false
d64dc0
end