cgroup: cpu quota: fix resetting period length for v1
[pve-common.git] / test / procfs_tests.pl
CommitLineData
2f98cd72
TL
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use lib '../src';
7
8use Test::More;
9use Test::MockModule;
10
11use PVE::Tools;
12use PVE::ProcFSTools;
13
14# the proc "state"
15my $proc = {
16 version => '',
17};
18
19my $pve_common_tools;
20$pve_common_tools = Test::MockModule->new('PVE::Tools');
21$pve_common_tools->mock(
22 file_read_firstline => sub {
23 my ($filename) = @_;
24
25 $filename =~ s!^/proc/!!;
26
27 my $res = $proc->{$filename};
28
29 if (ref($res) eq 'CODE') {
30 $res = $res->();
31 }
32
33 chomp $res;
34 return $res;
35 },
36);
37
38
39# version tests
40
41my @kernel_versions = (
42{
43 version => 'Linux version 5.3.10-1-pve (build@pve) (gcc version 8.3.0 (Debian 8.3.0-6)) #1 SMP PVE 5.3.10-1 (Thu, 14 Nov 2019 10:43:13 +0100)',
44 expect => [5, 3, 10, '1-pve', '5.3.10-1-pve'],
45},
46{
47 version => 'Linux version 5.0.21-5-pve (build@pve) (gcc version 8.3.0 (Debian 8.3.0-6)) #1 SMP PVE 5.0.21-10 (Wed, 13 Nov 2019 08:27:10 +0100)',
48 expect => [5, 0, 21, '5-pve', '5.0.21-5-pve'],
49},
50{
51 version => 'Linux version 5.0.21+ (build@pve) (gcc version 8.3.0 (Debian 8.3.0-6)) #27 SMP Tue Nov 12 10:30:36 CET 2019',
52 expect => [5, 0, 21, '+', '5.0.21+'],
53},
54{
55 version => 'Linu$ version 2 (build@pve) (gcc version 8.3.0 (Debian 8.3.0-6)) #27 SMP Tue Nov 12 10:30:36 CET 2019',
56 expect => [0, 0, 0, '', ''],
57},
58);
59
60subtest 'test kernel_version parser' => sub {
61 for my $test (@kernel_versions) {
62 $proc->{version} = $test->{version};
63
64 my $res = [ PVE::ProcFSTools::kernel_version() ];
65
66 is_deeply($res, $test->{expect}, "got verison <". $res->[4] ."> same as expected");
67 }
68};
69
70
71done_testing();