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