]> git.proxmox.com Git - pve-installer.git/blame - test/zfs-arc-max.pl
tui: preserve autoreboot checkbox state when switching views
[pve-installer.git] / test / zfs-arc-max.pl
CommitLineData
9a0d66cb
CH
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7use Test::MockModule qw(strict);
8
9my $proxmox_install_runenv = Test::MockModule->new('Proxmox::Install::RunEnv');
10my $proxmox_install_isoenv = Test::MockModule->new('Proxmox::Install::ISOEnv');
11
12sub mock_product {
13 my ($product) = @_;
14
15 $proxmox_install_isoenv->redefine(
16 get => sub {
17 my ($k) = @_;
18 return $product if $k eq 'product';
19 die "iso environment key $k not mocked!\n";
20 },
21 );
22}
23
24my %default_tests = (
25 16 => 64, # at least 64 MiB
26 1024 => 102,
27 4 * 1024 => 410,
28 8 * 1024 => 819,
29 150 * 1024 => 15360,
30 160 * 1024 => 16384,
31 1024 * 1024 => 16384, # maximum of 16 GiB
32);
33
34while (my ($total_mem, $expected) = each %default_tests) {
35 $proxmox_install_runenv->redefine(
36 get => sub {
37 my ($k) = @_;
38 return $total_mem if $k eq 'total_memory';
39 die "runtime environment key $k not mocked!\n";
40 },
41 );
42
43 mock_product('pve');
44 is(Proxmox::Install::RunEnv::default_zfs_arc_max(), $expected,
45 "$expected MiB should be zfs_arc_max for PVE with $total_mem MiB system memory");
46
47 mock_product('pbs');
48 is(Proxmox::Install::RunEnv::default_zfs_arc_max(), 0,
49 "zfs_arc_max should default to `0` for PBS with $total_mem MiB system memory");
50
51 mock_product('pmg');
52 is(Proxmox::Install::RunEnv::default_zfs_arc_max(), 0,
53 "zfs_arc_max should default to `0` for PMG with $total_mem MiB system memory");
54}
55
56my @clamp_tests = (
57 # input, total system memory, expected
58 [ 0, 4 * 1024, 0 ],
59 [ 16, 4 * 1024, 64 ],
60 [ 4 * 1024, 4 * 1024, 4 * 1024 ],
61 [ 4 * 1024, 6 * 1024, 4 * 1024 ],
62 [ 8 * 1024, 4 * 1024, 4 * 1024 ],
63);
64
65mock_product('pve');
66foreach (@clamp_tests) {
67 my ($input, $total_mem, $expected) = @$_;
68
69 $proxmox_install_runenv->redefine(
70 get => sub {
71 my ($k) = @_;
72 return $total_mem if $k eq 'total_memory';
73 die "runtime environment key $k not mocked!\n";
74 },
75 );
76
77 is(Proxmox::Install::RunEnv::clamp_zfs_arc_max($input), $expected,
78 "$input MiB zfs_arc_max should be clamped to $expected MiB with $total_mem MiB system memory");
79}
80
81done_testing();