Blame SOURCES/test_systemtap.rb

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