-
Notifications
You must be signed in to change notification settings - Fork 135
/
profiling.t
235 lines (175 loc) · 4.79 KB
/
profiling.t
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!./parrot-nqp
# Copyright (C) 2010, Parrot Foundation.
my $lib := pir::load_bytecode__ps('ProfTest.pbc');
for $lib.subs_by_tag('load') -> $sub { $sub(); }
Q:PIR{ .include "test_more.pir" };
plan(13);
my $pir_code :=
'.sub main :main
say "what"
.end';
my $prof := ProfTest::PIRProfile.new($pir_code);
ok(1, "profile creation didn't explode");
#Does the profile have a version string?
my $matcher := ProfTest::Matcher.new(
version()
);
ok( $matcher.matches($prof), "profile has a version number");
#Does the profile have a CLI invocation?
$matcher := ProfTest::Matcher.new(
cli()
);
ok( $matcher.matches($prof), "profile contains a CLI string");
#Does the profile have a 'say' op somewhere?
$matcher := ProfTest::Matcher.new(
op('say')
);
ok( $matcher.matches($prof), "profile has a say op");
#Does the profile have expected timing values?
$matcher := ProfTest::Matcher.new(
op('say', :time(1))
);
ok( $matcher.matches($prof), "profile has canonical timing information");
#Does the matcher fail to find the non-existent 'lollercoaster' opcode?
$matcher := ProfTest::Matcher.new(
op('lollercoaster')
);
ok( !$matcher.matches($prof), "matcher didn't find non-existent opcode");
#Does the profile show a 'say' op inside the 'main' sub?
$matcher := ProfTest::Matcher.new(
cs(:ns('main')),
any(:except('cs')),
op('say'),
);
ok( $matcher.matches($prof), "profile shows 'say' inside main sub");
$pir_code :=
".sub first :main
.local int i
i = 0
'second'()
inc i
.end
.sub second
.local pmc p
p = new ['Interger']
p = 1
.end";
$prof := ProfTest::PIRProfile.new($pir_code);
$matcher := ProfTest::Matcher.new(
cs(:ns('parrot;first'), :slurp_until('cs')),
cs(:ns('parrot;second'), :slurp_until('cs')),
cs(:ns('parrot;first')),
);
ok( $matcher.matches($prof), "profile properly reflects normal control flow (simple)");
$pir_code :=
".sub first :main
.local int i
i = 0
'second'()
inc i
.end
.sub second
.local pmc p
p = new ['Interger']
'third'()
p = 1
.end
.sub third
say 'in third'
.end";
$prof := ProfTest::PIRProfile.new($pir_code);
$matcher := ProfTest::Matcher.new(
cs(:ns('parrot;first'), :slurp_until('cs')),
cs(:ns('parrot;second'), :slurp_until('cs')),
cs(:ns('parrot;third'), :slurp_until('cs')),
cs(:ns('parrot;second'), :slurp_until('cs')),
cs(:ns('parrot;first')),
);
ok( $matcher.matches($prof), "profile properly reflects normal control flow (slightly less simple)");
#test: main calls foo, foo tailcalls bar, bar returns to main
$pir_code :=
".sub first :main
.local int i
i = 'foo'(9)
say i
.end
.sub foo
.param int i
i = i * i
.tailcall bar(i)
.end
.sub bar
.param int i
i = i + 2
.return (i)
.end";
$prof := ProfTest::PIRProfile.new($pir_code);
$matcher := ProfTest::Matcher.new(
cs(:ns('parrot;first'), :slurp_until('cs')),
cs(:ns('parrot;foo'), :slurp_until('cs')),
cs(:ns('parrot;bar'), :slurp_until('cs')),
cs(:ns('parrot;first')),
);
ok( $matcher.matches($prof), "profile properly reflects tailcall control flow");
#Does the profile show a 'say' op on line 2?
$matcher := ProfTest::Matcher.new(
op('say', :line('3')),
);
ok( $matcher.matches($prof), "profile shows say on the correct line");
my $uncaught_c_ex := '
.sub main :main
.local string s
s = <<"CODE"
.sub main :main
$P0 = new ["FixedPMCArray"], -10 #throw a C-level exception
.end
CODE
.local pmc f, comp
comp = compreg "PIR"
.local pmc eh
eh = new ["ExceptionHandler"]
set_label eh, handler
push_eh eh
f = comp(s)
f = f."main_sub"()
$S0 = typeof f
say $S0
f()
pop_eh
goto done
handler:
pop_eh
done:
.end';
my $uncaught_c_ex_prof := ProfTest::PIRProfile.new($uncaught_c_ex);
my $uncaught_c_ex_matcher := ProfTest::Matcher.new(
eor(),
);
ok( $uncaught_c_ex_matcher.matches($uncaught_c_ex_prof),
"pir with uncaught C exception in eval'd code shows END_OF_RUNLOOP");
my $nqp_code :=
'main();
sub main() {
pir::say("nqp");
}';
$prof := ProfTest::NQPProfile.new($nqp_code);
$matcher := ProfTest::Matcher.new(
cs(:ns('parrot;main') ),
any(:except('cs')),
op('say'),
);
ok( $matcher.matches($prof), "profile shows 'say' inside nqp sub");
# XXX workaround nqp-rx not generating :main
Q:PIR { exit 0 };
#convenience subs to avoid repetitive typing and visual noise
sub version(*@p, *%n) { ProfTest::Want::Version.new(|@p, |%n) }
sub cli(*@p, *%n) { ProfTest::Want::CLI.new(|@p, |%n) }
sub eor(*@p, *%n) { ProfTest::Want::EndOfRunloop.new(|@p, |%n) }
sub op(*@p, *%n) { ProfTest::Want::Op.new(|@p) }
sub cs(*@p, *%n) { ProfTest::Want::CS.new(|@p, |%n) }
sub any(*@p, *%n) { ProfTest::Want::Any.new(|@p) }
# Local Variables:
# mode: perl6
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=perl6