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