File: 10-timers.t

package info (click to toggle)
liblinux-fd-perl 0.017-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 716 kB
  • sloc: perl: 49; makefile: 8
file content (49 lines) | stat: -rw-r--r-- 992 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# perl -T

use strict;
use warnings FATAL => 'all';

use Test::More;
use Linux::FD 'timerfd';
use Linux::FD::Timer;
use IO::Select;
use Time::HiRes qw/sleep/;

my $selector = IO::Select->new;

alarm 2;

my $fd = timerfd('realtime', 'non-blocking');
$selector->add($fd);

ok !$selector->can_read(0), 'Can\'t read an empty timerfd';

ok !defined $fd->receive, 'Can\'t read an empty signalfd directly';

$fd->set_timeout(0.1);

sleep 0.2;

ok $selector->can_read(0), 'Can read an triggered timerfd';

ok $fd->receive, 'Got timeout';

ok !$selector->can_read(0), 'Can\'t read an received timerfd';

$fd->set_timeout(0.1, 0.1);

my ($value, $interval) = $fd->get_timeout;

cmp_ok $value, '<=', 0.1, 'Value is right';
ok 0.099 < $interval && $interval < 0.101, 'Interval is right';

sleep 0.21;

is $fd->receive, 2, 'Got two timeouts';

my %clocks = map { $_ => 1 } Linux::FD::Timer->clocks;

ok $clocks{monotonic}, 'Has monotonic clock';
ok $clocks{realtime}, 'Has realtime clock';

done_testing;