]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use lib '../src'; | |
7 | ||
8 | use Test::More; | |
9 | use Test::MockModule; | |
10 | ||
11 | use PVE::Tools; | |
12 | use PVE::ProcFSTools; | |
13 | ||
14 | # the proc "state" | |
15 | my $proc = { | |
16 | version => '', | |
17 | }; | |
18 | ||
19 | my $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 | ||
41 | my @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 | ||
60 | subtest '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 | ||
71 | done_testing(); |