Blame SOURCES/test_systemtap.rb

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