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.1 by root, Tue Nov 13 02:43:26 2007 UTC vs.
Revision 1.6 by root, Thu Nov 22 04:52:24 2007 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, "\n"; 20 my $now = EV::now;
15 print EV::now >= $base + $t ? "" : "not ", "ok ", ++$id, "\n"; 21
22 print $now + $fudge >= $prev ? "" : "not ", "ok ", ++$id, " # t0 $i $now + $fudge >= $prev\n";
23 print $now + $fudge >= $base + $t ? "" : "not ", "ok ", ++$id, " # t1 $i $now + $fudge >= $base + $t\n";
16 24
17 unless ($id % 3) { 25 unless ($id % 3) {
26 $t *= 0.0625;
18 $_[0]->set ($t * 0.0625); 27 $_[0]->set ($t);
28 $_[0]->start;
29 $t = $now + $t - $base;
30 }
31
32 $prev = $now;
33 };
34
35 my $t = $i * $i * 1.375475771; $t -= int $t;
36 push @periodic, EV::periodic $base + $t, 0, 0, sub {
37 my $now = EV::now;
38
39 print $now >= $prev ? "" : "not ", "ok ", ++$id, " # p0 $i $now >= $prev\n";
40 print $now >= $base + $t ? "" : "not ", "ok ", ++$id, " # p1 $i $now >= $base + $t\n";
41
42 unless ($id % 3) {
19 $t *= 1.0625; 43 $t *= 1.0625;
44 $_[0]->set ($base + $t);
20 $_[0]->start; 45 $_[0]->start;
21 } 46 }
47
48 $prev = $now;
22 }; 49 };
23} 50}
24 51
25print "ok 1\n"; 52print "ok 1\n";
26EV::loop; 53EV::loop;
27print "ok 3002\n"; 54print "ok 6002\n";
28 55

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines