ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/t/01_timer.t
(Generate patch)

Comparing EV/t/01_timer.t (file contents):
Revision 1.2 by root, Sat Nov 17 01:41:33 2007 UTC vs.
Revision 1.7 by root, Thu May 22 02:44:57 2008 UTC

1BEGIN { $| = 1; print "1..3002\n"; } 1BEGIN { $| = 1; print "1..6002\n"; }
2
3no warnings;
4use strict;
2 5
3use EV; 6use EV;
4 7
8my $fudge = 0.02; # allow rt and monotonic clock to disagree by this much
9
5my $id = 1; 10my $id = 1;
6my @timer; 11my @timer;
12my @periodic;
7 13
8my $base = EV::now; 14my $base = EV::now;
9my $prev = EV::now; 15my $prev = EV::now;
10 16
11for (1..1000) { 17for my $i (1..1000) {
12 my $t = $_ * $_ * 1.735435336; $t -= int $t; 18 my $t = $i * $i * 1.735435336; $t -= int $t;
13 push @timer, EV::timer $t, 0, sub { 19 push @timer, EV::timer $t, 0, sub {
14 print EV::now >= $prev ? "" : "not ", "ok ", ++$id, " # a ", EV::now, " >= ", $prev, "\n"; 20 my $now = EV::now;
15 print EV::now >= $base + $t ? "" : "not ", "ok ", ++$id, " # b ", EV::now, " >= ", $base + $t, "\n";
16 21
17 $prev = EV::now; 22 EV::default_loop->loop_verify;
23
24 print $now + $fudge >= $prev ? "" : "not ", "ok ", ++$id, " # t0 $i $now + $fudge >= $prev\n";
25 print $now + $fudge >= $base + $t ? "" : "not ", "ok ", ++$id, " # t1 $i $now + $fudge >= $base + $t\n";
18 26
19 unless ($id % 3) { 27 unless ($id % 3) {
28 $t *= 0.0625;
20 $_[0]->set ($t * 0.0625); 29 $_[0]->set ($t);
30 $_[0]->start;
31 $t = $now + $t - $base;
32 }
33
34 $prev = $now;
35 };
36
37 my $t = $i * $i * 1.375475771; $t -= int $t;
38 push @periodic, EV::periodic $base + $t, 0, 0, sub {
39 my $now = EV::now;
40
41 EV::default_loop->loop_verify;
42
43 print $now >= $prev ? "" : "not ", "ok ", ++$id, " # p0 $i $now >= $prev\n";
44 print $now >= $base + $t ? "" : "not ", "ok ", ++$id, " # p1 $i $now >= $base + $t\n";
45
46 unless ($id % 3) {
21 $t *= 1.0625; 47 $t *= 1.0625;
48 $_[0]->set ($base + $t);
22 $_[0]->start; 49 $_[0]->start;
23 } 50 }
51
52 $prev = $now;
24 }; 53 };
25} 54}
26 55
27print "ok 1\n"; 56print "ok 1\n";
28EV::loop; 57EV::loop;
29print "ok 3002\n"; 58print "ok 6002\n";
30 59

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines