Blame SOURCES/test_systemtap.rb

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