From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id D5E251FF15C for ; Wed, 21 Aug 2024 15:23:15 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 624E61A9C0; Wed, 21 Aug 2024 15:23:27 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Wed, 21 Aug 2024 15:23:02 +0200 Message-ID: <20240821132307.1352643-4-c.heiss@proxmox.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240821132307.1352643-1-c.heiss@proxmox.com> References: <20240821132307.1352643-1-c.heiss@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.032 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH installer v2 3/3] test: add test for kernel commandline parsing 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: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Signed-off-by: Christoph Heiss --- Changes v1 -> v2: * new patch Proxmox/Install/Config.pm | 2 +- test/Makefile | 7 +++- test/parse-kernel-cmdline.pl | 62 ++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100755 test/parse-kernel-cmdline.pl diff --git a/Proxmox/Install/Config.pm b/Proxmox/Install/Config.pm index 607f0bf..df9be2e 100644 --- a/Proxmox/Install/Config.pm +++ b/Proxmox/Install/Config.pm @@ -11,7 +11,7 @@ use Proxmox::Log; use Proxmox::Install::ISOEnv; use Proxmox::Sys::Net; -my sub parse_kernel_cmdline { +sub parse_kernel_cmdline { my ($cfg) = @_; my $cmdline = Proxmox::Install::RunEnv::get('kernel_cmdline'); diff --git a/test/Makefile b/test/Makefile index c473af8..70a05be 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,7 +3,8 @@ all: export PERLLIB=.. .PHONY: check -check: test-zfs-arc-max test-run-command test-parse-fqdn test-ui2-stdio test-zfs-get-pool-list +check: test-zfs-arc-max test-run-command test-parse-fqdn test-ui2-stdio \ + test-zfs-get-pool-list test-parse-kernel-cmdline .PHONY: test-zfs-arc-max test-zfs-arc-max: @@ -24,3 +25,7 @@ test-ui2-stdio: .PHONY: test-zfs-get-pool-list test-zfs-get-pool-list: ./zfs-get-pool-list.pl + +.PHONY: test-parse-kernel-cmdline +test-parse-kernel-cmdline: + ./parse-kernel-cmdline.pl diff --git a/test/parse-kernel-cmdline.pl b/test/parse-kernel-cmdline.pl new file mode 100755 index 0000000..10a59a4 --- /dev/null +++ b/test/parse-kernel-cmdline.pl @@ -0,0 +1,62 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Test::More; +use Test::MockModule qw(strict); + +use Proxmox::Install::RunEnv; +use Proxmox::Install::Config qw(parse_kernel_cmdline); + +my $proxmox_install_runenv = Test::MockModule->new('Proxmox::Install::RunEnv'); +my $proxmox_install_isoenv = Test::MockModule->new('Proxmox::Install::ISOEnv'); + +$proxmox_install_isoenv->redefine( + get => sub { + my ($k) = @_; + return { product => 'pve' } if !defined($k); + die "iso environment key $k not mocked!\n"; + }, +); + +my sub mock_kernel_cmdline { + my ($cmdline) = @_; + + $proxmox_install_runenv->redefine( + get => sub { + my ($k) = @_; + return $cmdline if $k eq 'kernel_cmdline'; + die "iso environment key $k not mocked!\n"; + }, + ); +} + +sub is_parsed { + my ($cmdline, $expected) = @_; + + mock_kernel_cmdline($cmdline); + my $cfg = Proxmox::Install::Config::parse_kernel_cmdline({}); + + is($cfg->{target_cmdline}, $expected, + "kernel cmdline matched excepted: $expected"); +} + +is_parsed( + 'BOOT_IMAGE=/vmlinuz-6.8.12-1-pve root=/dev/mapper/pve-root ro quiet', + '' +); + +is_parsed( + 'BOOT_IMAGE=/vmlinuz-6.8.12-1-pve root=/dev/mapper/pve-root ro= quiet', + 'ro=' +); + +is_parsed( + 'a BOOT_IMAGE=/vmlinuz-6.8.12-1-pve b root=/dev/mapper/pve-root c ro d quiet e', + 'a b c d e' +); + +is_parsed('proxmox-foo foo=bar proxtui', 'foo=bar'); + +done_testing(); -- 2.45.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel