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