1require 'dtrace/helper'
2
3module DTrace
4  class TestCMethod < TestCase
5    def test_entry
6      probe = <<-eoprobe
7ruby$target:::cmethod-entry
8{
9  printf("%s %s %s %d\\n", copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3);
10}
11      eoprobe
12
13      trap_probe(probe, ruby_program) { |d_file, rb_file, probes|
14	foo_calls = probes.map { |line| line.split }.find_all { |row|
15	  row[1] == 'times'
16	}
17
18	assert_equal 1, foo_calls.length
19      }
20    end
21
22    def test_exit
23      probe = <<-eoprobe
24ruby$target:::cmethod-return
25{
26  printf("%s %s %s %d\\n", copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3);
27}
28      eoprobe
29
30      trap_probe(probe, ruby_program) { |d_file, rb_file, probes|
31	foo_calls = probes.map { |line| line.split }.find_all { |row|
32	  row[1] == 'times'
33	}
34
35	assert_equal 1, foo_calls.length
36      }
37    end
38
39    def ruby_program
40      <<-eoruby
41      class Foo
42	def self.foo; end
43      end
44      10.times { Foo.foo }
45      eoruby
46    end
47  end
48end if defined?(DTrace::TestCase)
49
50