Blame SOURCES/test_systemtap.rb

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