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.10 by root, Thu Oct 21 15:13:42 2010 UTC

1BEGIN {
2 # many testers have totally overloaded machines with virtual machines
3 # running backwards in time etc. etc.
4 if (exists $ENV{AUTOMATED_TESTING}) {
5 print "1..0 # Skipped: Too many broken cpan tester setups.\n";
6 exit;
7 }
8}
9
1BEGIN { $| = 1; print "1..3002\n"; } 10BEGIN { $| = 1; print "1..6002\n"; }
11
12no warnings;
13use strict;
2 14
3use EV; 15use EV;
4 16
17my $fudge = 0.02; # allow rt and monotonic clock to disagree by this much
18
5my $id = 1; 19my $id = 1;
6my @timer; 20my @timer;
21my @periodic;
7 22
8my $base = EV::now; 23my $base = EV::now;
9my $prev = EV::now; 24my $prev = EV::now;
10 25
11for (1..1000) { 26for my $i (1..1000) {
12 my $t = $_ * $_ * 1.735435336; $t -= int $t; 27 my $t = $i * $i * 1.735435336; $t -= int $t;
13 push @timer, EV::timer $t, 0, sub { 28 push @timer, EV::timer $t, 0, sub {
14 print EV::now >= $prev ? "" : "not ", "ok ", ++$id, " # a ", EV::now, " >= ", $prev, "\n"; 29 my $now = EV::now;
15 print EV::now >= $base + $t ? "" : "not ", "ok ", ++$id, " # b ", EV::now, " >= ", $base + $t, "\n";
16 30
17 $prev = EV::now; 31 EV::default_loop->verify;
32
33 print $now + $fudge >= $prev ? "" : "not ", "ok ", ++$id, " # t0 $i $now + $fudge >= $prev\n";
34 print $now + $fudge >= $base + $t ? "" : "not ", "ok ", ++$id, " # t1 $i $now + $fudge >= $base + $t\n";
18 35
19 unless ($id % 3) { 36 unless ($id % 3) {
37 $t *= 0.0625;
20 $_[0]->set ($t * 0.0625); 38 $_[0]->set ($t);
39 $_[0]->start;
40 $t = $now + $t - $base;
41 }
42
43 $prev = $now;
44 };
45
46 my $t = $i * $i * 1.375475771; $t -= int $t;
47 push @periodic, EV::periodic $base + $t, 0, 0, sub {
48 my $now = EV::now;
49
50 EV::default_loop->verify;
51
52 print $now >= $prev ? "" : "not ", "ok ", ++$id, " # p0 $i $now >= $prev\n";
53 print $now >= $base + $t ? "" : "not ", "ok ", ++$id, " # p1 $i $now >= $base + $t\n";
54
55 unless ($id % 3) {
21 $t *= 1.0625; 56 $t *= 1.0625;
57 $_[0]->set ($base + $t);
22 $_[0]->start; 58 $_[0]->start;
23 } 59 }
60
61 $prev = $now;
24 }; 62 };
25} 63}
26 64
27print "ok 1\n"; 65print "ok 1\n";
28EV::loop; 66EV::run;
29print "ok 3002\n"; 67print "ok 6002\n";
30 68

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines