* t/oo/composition.t, t/oo/mro-c3.t, t/op/calling.t:
[parrot.git] / t / pmc / timer.t
blob8445e17b3b1781651efe43bb729957143f8f61b7
1 #! perl
2 # Copyright (C) 2001-2005, The Perl Foundation.
3 # $Id$
5 use strict;
6 use warnings;
7 use lib qw( . lib ../lib ../../lib );
8 use Test::More;
9 use Parrot::Test tests => 8;
11 =head1 NAME
13 t/pmc/timer.t - Timer PMCs
15 =head1 SYNOPSIS
17     % prove t/pmc/timer.t
19 =head1 DESCRIPTION
21 Tests the Timer PMC.
23 =cut
25 my %platforms = map { $_ => 1 } qw/
26     aix
27     cygwin
28     darwin
29     dec_osf
30     freebsd
31     hpux
32     irix
33     linux
34     openbsd
35     MSWin32
36     /;
38 pasm_output_is( <<'CODE', <<'OUT', "Timer setup" );
39 .include "timer.pasm"
40     new P0, 'Timer'
41     set P0[.PARROT_TIMER_SEC], 7
42     set I0, P0[.PARROT_TIMER_SEC]
43     eq I0, 7, ok1
44     print "not "
45 ok1:
46     print "ok 1\n"
47     set I0, P0[.PARROT_TIMER_USEC]
48     eq I0, 0, ok2
49     print "not "
50 ok2:
51     print "ok 2\n"
53     set I0, P0[.PARROT_TIMER_RUNNING]
54     eq I0, 0, ok3
55     print "not "
56 ok3:
57     print "ok 3\n"
58     end
59 CODE
60 ok 1
61 ok 2
62 ok 3
63 OUT
65 pasm_output_is( <<'CODE', <<'OUT', "Timer setup - initializer" );
66 .include "timer.pasm"
67     new P1, 'SArray'
68     set P1, 4
69     set P1[0], .PARROT_TIMER_SEC
70     set P1[1], 8
71     set P1[2], .PARROT_TIMER_USEC
72     set P1[3], 400000
74     new P0, 'Timer', P1
75     set I0, P0[.PARROT_TIMER_SEC]
76     eq I0, 8, ok1
77     print "not "
78 ok1:
79     print "ok 1\n"
80     set I0, P0[.PARROT_TIMER_USEC]
81     eq I0, 400000, ok2
82     eq I0, 400001, ok2
83     eq I0, 399999, ok2
84     print "not "
85 ok2:
86     print "ok 2\n"
88     set I0, P0[.PARROT_TIMER_RUNNING]
89     eq I0, 0, ok3
90     print "not "
91 ok3:
92     print "ok 3\n"
93     end
94 CODE
95 ok 1
96 ok 2
97 ok 3
98 OUT
100 SKIP: {
101     skip( "No thread config yet", 5 ) unless ( $platforms{$^O} );
103     pasm_output_is( <<'CODE', <<'OUT', "Timer setup - initializer/start" );
104 .include "timer.pasm"
105     new P1, 'SArray'
106     set P1, 6
107     set P1[0], .PARROT_TIMER_NSEC
108     set P1[1], 0.5
109     set P1[2], .PARROT_TIMER_HANDLER
110     get_global P2, "_timer_sub"
111     set P1[3], P2
112     set P1[4], .PARROT_TIMER_RUNNING
113     set P1[5], 1
115     new P0, 'Timer', P1
116     print "ok 1\n"
117     sleep 1
118     print "ok 3\n"
119     end
120 .pcc_sub _timer_sub:
121     print "ok 2\n"
122     returncc
123 CODE
124 ok 1
125 ok 2
126 ok 3
129     pasm_output_is( <<'CODE', <<'OUT', "Timer setup - initializer/start/stop" );
130 .include "timer.pasm"
131     new P1, 'SArray'
132     set P1, 6
133     set P1[0], .PARROT_TIMER_NSEC
134     set P1[1], 0.5
135     set P1[2], .PARROT_TIMER_HANDLER
136     get_global P2, "_timer_sub"
137     set P1[3], P2
138     set P1[4], .PARROT_TIMER_RUNNING
139     set P1[5], 1
141     new P0, 'Timer', P1
142     print "ok 1\n"
143     # stop the timer
144     set P0[.PARROT_TIMER_RUNNING], 0
145     sleep 1
146     print "ok 2\n"
147     end
148 .pcc_sub _timer_sub:
149     print "never\n"
150     returncc
151 CODE
152 ok 1
153 ok 2
156     pasm_output_is( <<'CODE', <<'OUT', "Timer setup - initializer/start/repeat" );
157 .include "timer.pasm"
158     new P1, 'SArray'
159     set P1, 8
160     set P1[0], .PARROT_TIMER_NSEC
161     set P1[1], 0.2
162     set P1[2], .PARROT_TIMER_HANDLER
163     get_global P2, "_timer_sub"
164     set P1[3], P2
165     set P1[4], .PARROT_TIMER_REPEAT
166     set P1[5], 2
167     set P1[6], .PARROT_TIMER_RUNNING
168     set P1[7], 1
170     new P0, 'Timer', P1
171     print "ok 1\n"
172     sleep 1
173     print "ok 3\n"
174     end
175 .pcc_sub _timer_sub:
176     print "ok 2\n"
177     returncc
178 CODE
179 ok 1
180 ok 2
181 ok 2
182 ok 2
183 ok 3
186     pasm_output_is( <<'CODE', <<'OUT', "Timer setup - initializer/start/destroy" );
187 .include "timer.pasm"
188     new P1, 'SArray'
189     set P1, 6
190     set P1[0], .PARROT_TIMER_NSEC
191     set P1[1], 0.5
192     set P1[2], .PARROT_TIMER_HANDLER
193     get_global P2, "_timer_sub"
194     set P1[3], P2
195     set P1[4], .PARROT_TIMER_RUNNING
196     set P1[5], 1
198     sweep 0
199     new P0, 'Timer', P1
200     print "ok 1\n"
201     sweep 0
202     # destroy
203     null P0
204     # do a lazy DOD run
205     sweep 0
206     sleep 1
207     print "ok 2\n"
208     end
209 .pcc_sub _timer_sub:
210     print "never\n"
211     returncc
212 CODE
213 ok 1
214 ok 2
217     pasm_output_is( <<'CODE', <<'OUT', "Timer setup - timer in array destroy" );
218 .include "timer.pasm"
219     new P1, 'SArray'
220     set P1, 6
221     set P1[0], .PARROT_TIMER_NSEC
222     set P1[1], 0.5
223     set P1[2], .PARROT_TIMER_HANDLER
224     get_global P2, "_timer_sub"
225     set P1[3], P2
226     set P1[4], .PARROT_TIMER_RUNNING
227     set P1[5], 1
229     new P0, 'Timer', P1
230     print "ok 1\n"
231     sweep 0
232     # hide timer in array
233     set P1[0], P0
234     new P0, 'Undef'
235     sweep 0
236     # un-anchor the array
237     new P1, 'Undef'
238     # do a lazy DOD run
239     sweep 0
240     sleep 1
241     print "ok 2\n"
242     end
243 .pcc_sub _timer_sub:
244     print "never\n"
245     returncc
246 CODE
247 ok 1
248 ok 2
252 pir_output_is( << 'CODE', << 'OUTPUT', "check whether interface is done" );
254 .sub _main
255     .local pmc pmc1
256     pmc1 = new 'Timer'
257     .local int bool1
258     does bool1, pmc1, "scalar"
259     print bool1
260     print "\n"
261     does bool1, pmc1, "event"
262     print bool1
263     print "\n"
264     does bool1, pmc1, "no_interface"
265     print bool1
266     print "\n"
267     end
268 .end
269 CODE
273 OUTPUT
275 # Local Variables:
276 #   mode: cperl
277 #   cperl-indent-level: 4
278 #   fill-column: 100
279 # End:
280 # vim: expandtab shiftwidth=4: