forked from dland/BSD-Sysctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-get.t
86 lines (70 loc) · 3.04 KB
/
01-get.t
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 01-get.t
# Basic sanity checks for BSD::Sysctl
#
# Copyright (C) 2006, 2009 David Landgren
use strict;
use Test::More tests => 23;
use BSD::Sysctl qw(sysctl sysctl_exists);
ok(BSD::Sysctl::_mib_exists('kern.maxproc'), 'mib exists');
{
my $sysctl_info = BSD::Sysctl::_mib_info('kern.ostype');
ok($sysctl_info, 'mib lookup kern.ostype');
my ($fmt, @oid) = unpack( 'i i/i', $sysctl_info );
is($fmt, BSD::Sysctl::FMT_A, '... display format type A');
is_deeply(\@oid, [1, 1], '... oid 1.1');
}
{
my $sysctl_info = BSD::Sysctl::_mib_info('kern.ipc.maxsockbuf');
ok($sysctl_info, 'mib lookup kern.ipc.maxsockbuf');
my ($fmt, @oid) = unpack( 'i i/i', $sysctl_info );
# This is FMT_INT for FreeBSD 4.x, deal with it
# is($fmt, BSD::Sysctl::FMT_ULONG, '... display format type ULONG');
is_deeply(\@oid, [1, 30, 1], '... oid 1.30.1');
}
{
my $sysctl_info = BSD::Sysctl::_mib_info('kern.ipc.maxsockbuf');
ok($sysctl_info, 'mib lookup kern.ipc.maxsockbuf');
my ($fmt, @oid) = unpack( 'i i/i', $sysctl_info );
# TODO: this will require a revision when OpenBSD or NetBSD support is added
my $osrelease = sysctl('kern.osrelease');
ok($osrelease, "sysctl('kern.osrelease')");
if ($osrelease =~ /^4\./) {
# FreeBSD 4.x stores this in a smaller data type
is($fmt, BSD::Sysctl::FMT_INT, '... display format type INT (on 4.x)');
}
else {
is($fmt, BSD::Sysctl::FMT_ULONG, '... display format type ULONG');
}
is_deeply(\@oid, [1, 30, 1], '... oid 1.30.1');
}
{
my $sysctl_info = BSD::Sysctl::_mib_info('kern.geom.confxml');
ok($sysctl_info, 'mib lookup kern.geom.confxml');
my ($fmt, @oid) = unpack( 'i i/i', $sysctl_info );
is($fmt, BSD::Sysctl::FMT_A, '... display format type A');
my $confxml = sysctl('kern.geom.confxml');
ok($confxml, 'value of "kern.geom.confxml" is defined');
like($confxml, qr(^\s*<([^>]+)>.*</\1>\s*$)m, 'value of "kern.geom.confxml" is XML');
}
{
my $sysctl_info = BSD::Sysctl::_mib_info('net.inet.ip.portrange.last');
my $portrange_last = BSD::Sysctl::_mib_lookup('net.inet.ip.portrange.last');
cmp_ok($portrange_last, '>', 1024, 'min value of net.inet.ip.portrange.last');
cmp_ok($portrange_last, '<=', 65535, 'max value of net.inet.ip.portrange.last');
}
ok(sysctl_exists('kern.maxusers'), 'kern.maxusers exists');
ok(!sysctl_exists('kern.maxbananas'), 'kern.maxbananas does not exist');
{
my $load_avg = sysctl('vm.loadavg');
is(ref($load_avg), 'ARRAY', 'vm.loadavg is an array');
is(scalar(@$load_avg), 3, 'vm.loadavg has 3 elements');
}
{
my $sysctl_openfiles = BSD::Sysctl->new('kern.openfiles');
my $nr_files = $sysctl_openfiles->get();
cmp_ok($nr_files, '>', 0, "got the number of open files ($nr_files, in case you were wondering)");
$nr_files = $sysctl_openfiles->get();
cmp_ok($nr_files, '>', 0, "got the number of open files again (now $nr_files)");
}
is(scalar(keys %BSD::Sysctl::MIB_CACHE), 7, 'cached mib count')
or do { diag("cached: [$_]") for sort keys %BSD::Sysctl::MIB_CACHE };