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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines