summaryrefslogtreecommitdiff
path: root/jni/ruby/test/dtrace/test_require.rb
blob: 46a1d7652a6b1228cfffb4fa9501a1181d5ed2de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require_relative 'helper'

module DTrace
  class TestRequire < TestCase
    def test_require_entry
      probe = <<-eoprobe
ruby$target:::require-entry
{
  printf("%s %s %d\\n", copyinstr(arg0), copyinstr(arg1), arg2);
}
      eoprobe
      trap_probe(probe, ruby_program) { |d_file, rb_file, saw|
        required = saw.map { |s| s.split }.find_all do |(required, _)|
          required == 'dtrace/dummy'
        end
        assert_equal 10, required.length
      }
    end

    def test_require_return
      probe = <<-eoprobe
ruby$target:::require-return
{
  printf("%s\\n", copyinstr(arg0));
}
      eoprobe
    end

    private
    def ruby_program
      "10.times { require 'dtrace/dummy' }"
    end
  end
end if defined?(DTrace::TestCase)