From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 0D91A892B for ; Tue, 22 Aug 2023 12:26:11 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E3AD9ADC8 for ; Tue, 22 Aug 2023 12:25:40 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 22 Aug 2023 12:25:39 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 11C5D432CD for ; Tue, 22 Aug 2023 12:25:39 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Tue, 22 Aug 2023 12:24:51 +0200 Message-ID: <20230822102533.295530-4-c.heiss@proxmox.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230822102533.295530-1-c.heiss@proxmox.com> References: <20230822102533.295530-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.039 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [zfs-arc-max.pl, unconfigured.sh, spice-vdagent.sh] Subject: [pve-devel] [PATCH installer 3/6] fix #4829: test: add tests for new zfs_arc_max calculations X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Aug 2023 10:26:11 -0000 Signed-off-by: Christoph Heiss --- Makefile | 3 ++ debian/control | 1 + test/Makefile | 10 ++++++ test/zfs-arc-max.pl | 81 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 test/Makefile create mode 100755 test/zfs-arc-max.pl diff --git a/Makefile b/Makefile index dc180b2..979897d 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,7 @@ $(BUILDDIR): proxmox-low-level-installer \ proxmox-tui-installer/ \ spice-vdagent.sh \ + test/ \ unconfigured.sh \ xinitrc \ $@.tmp @@ -75,7 +76,9 @@ $(DSC): $(BUILDDIR) sbuild: $(DSC) sbuild $(DSC) +.PHONY: test test: + $(MAKE) -C test check $(CARGO) test --workspace $(CARGO_BUILD_ARGS) DESTDIR= diff --git a/debian/control b/debian/control index 3d13019..d77b12a 100644 --- a/debian/control +++ b/debian/control @@ -11,6 +11,7 @@ Build-Depends: cargo:native, librust-regex-1+default-dev (>= 1.7~~), librust-serde-1+default-dev, librust-serde-json-1+default-dev, + libtest-mockmodule-perl, perl, rustc:native, Standards-Version: 4.5.1 diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..fb80fc4 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,10 @@ +all: + +export PERLLIB=.. + +.PHONY: check +check: test-zfs-arc-max + +.PHONY: test-zfs-arc-max +test-zfs-arc-max: + ./zfs-arc-max.pl diff --git a/test/zfs-arc-max.pl b/test/zfs-arc-max.pl new file mode 100755 index 0000000..74cb9b5 --- /dev/null +++ b/test/zfs-arc-max.pl @@ -0,0 +1,81 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; +use Test::MockModule qw(strict); + +my $proxmox_install_runenv = Test::MockModule->new('Proxmox::Install::RunEnv'); +my $proxmox_install_isoenv = Test::MockModule->new('Proxmox::Install::ISOEnv'); + +sub mock_product { + my ($product) = @_; + + $proxmox_install_isoenv->redefine( + get => sub { + my ($k) = @_; + return $product if $k eq 'product'; + die "iso environment key $k not mocked!\n"; + }, + ); +} + +my %default_tests = ( + 16 => 64, # at least 64 MiB + 1024 => 102, + 4 * 1024 => 410, + 8 * 1024 => 819, + 150 * 1024 => 15360, + 160 * 1024 => 16384, + 1024 * 1024 => 16384, # maximum of 16 GiB +); + +while (my ($total_mem, $expected) = each %default_tests) { + $proxmox_install_runenv->redefine( + get => sub { + my ($k) = @_; + return $total_mem if $k eq 'total_memory'; + die "runtime environment key $k not mocked!\n"; + }, + ); + + mock_product('pve'); + is(Proxmox::Install::RunEnv::default_zfs_arc_max(), $expected, + "$expected MiB should be zfs_arc_max for PVE with $total_mem MiB system memory"); + + mock_product('pbs'); + is(Proxmox::Install::RunEnv::default_zfs_arc_max(), 0, + "zfs_arc_max should default to `0` for PBS with $total_mem MiB system memory"); + + mock_product('pmg'); + is(Proxmox::Install::RunEnv::default_zfs_arc_max(), 0, + "zfs_arc_max should default to `0` for PMG with $total_mem MiB system memory"); +} + +my @clamp_tests = ( + # input, total system memory, expected + [ 0, 4 * 1024, 0 ], + [ 16, 4 * 1024, 64 ], + [ 4 * 1024, 4 * 1024, 4 * 1024 ], + [ 4 * 1024, 6 * 1024, 4 * 1024 ], + [ 8 * 1024, 4 * 1024, 4 * 1024 ], +); + +mock_product('pve'); +foreach (@clamp_tests) { + my ($input, $total_mem, $expected) = @$_; + + $proxmox_install_runenv->redefine( + get => sub { + my ($k) = @_; + return $total_mem if $k eq 'total_memory'; + die "runtime environment key $k not mocked!\n"; + }, + ); + + is(Proxmox::Install::RunEnv::clamp_zfs_arc_max($input), $expected, + "$input MiB zfs_arc_max should be clamped to $expected MiB with $total_mem MiB system memory"); +} + +done_testing(); -- 2.41.0