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