public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com, "aderumier@odiso.com" <aderumier@odiso.com>
Subject: Re: [pve-devel] [PATCH v2 qemu-server 1/9] test: add memory tests
Date: Tue, 24 Jan 2023 14:04:25 +0100	[thread overview]
Message-ID: <08805109-d3d9-ff98-5664-57e6fe7ed4ef@proxmox.com> (raw)
In-Reply-To: <20230104064303.2898194-2-aderumier@odiso.com>

Am 04.01.23 um 07:42 schrieb Alexandre Derumier:
> Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
> ---
>  PVE/QemuServer/Memory.pm                      |  11 +-
>  test/cfg2cmd/memory-hotplug-hugepages.conf    |  12 ++
>  .../cfg2cmd/memory-hotplug-hugepages.conf.cmd |  62 +++++++
>  test/cfg2cmd/memory-hotplug.conf              |  11 ++
>  test/cfg2cmd/memory-hotplug.conf.cmd          | 174 ++++++++++++++++++
>  test/cfg2cmd/memory-hugepages-1g.conf         |  11 ++
>  test/cfg2cmd/memory-hugepages-1g.conf.cmd     |  30 +++
>  test/cfg2cmd/memory-hugepages-2m.conf         |  11 ++
>  test/cfg2cmd/memory-hugepages-2m.conf.cmd     |  30 +++
>  test/run_config2command_tests.pl              |  21 +++
>  10 files changed, 371 insertions(+), 2 deletions(-)
>  create mode 100644 test/cfg2cmd/memory-hotplug-hugepages.conf
>  create mode 100644 test/cfg2cmd/memory-hotplug-hugepages.conf.cmd
>  create mode 100644 test/cfg2cmd/memory-hotplug.conf
>  create mode 100644 test/cfg2cmd/memory-hotplug.conf.cmd
>  create mode 100644 test/cfg2cmd/memory-hugepages-1g.conf
>  create mode 100644 test/cfg2cmd/memory-hugepages-1g.conf.cmd
>  create mode 100644 test/cfg2cmd/memory-hugepages-2m.conf
>  create mode 100644 test/cfg2cmd/memory-hugepages-2m.conf.cmd
> 
> diff --git a/PVE/QemuServer/Memory.pm b/PVE/QemuServer/Memory.pm
> index f8fc534..6c1cd94 100644
> --- a/PVE/QemuServer/Memory.pm
> +++ b/PVE/QemuServer/Memory.pm
> @@ -348,7 +348,7 @@ sub config {
>  	    my $numa_memory = ($static_memory / $sockets);
>  
>  	    for (my $i = 0; $i < $sockets; $i++)  {
> -		die "host NUMA node$i doesn't exist\n" if ! -d "/sys/devices/system/node/node$i/" && $conf->{hugepages};
> +		die "host NUMA node$i doesn't exist\n" if !host_numanode_exist($i) && $conf->{hugepages};
>  
>  		my $mem_object = print_mem_object($conf, "ram-node$i", $numa_memory);
>  		push @$cmd, '-object', $mem_object;
> @@ -391,6 +391,13 @@ sub print_mem_object {
>  
>  }
>  
> +sub host_numanode_exist {
> +    my ($id) = @_;
> +
> +    return if ! -d "/sys/devices/system/node/node$id/";
> +    return 1;

Style nit: could be one line
return -d "/sys/devices/system/node/node$id/";

> +}
> +
>  sub print_numa_hostnodes {
>      my ($hostnodelists) = @_;
>  
> @@ -402,7 +409,7 @@ sub print_numa_hostnodes {
>  	$hostnodes .= "-$end" if defined($end);
>  	$end //= $start;
>  	for (my $i = $start; $i <= $end; ++$i ) {
> -	    die "host NUMA node$i doesn't exist\n" if ! -d "/sys/devices/system/node/node$i/";
> +	    die "host NUMA node$i doesn't exist\n" if !host_numanode_exist($i);
>  	}

Nit: Ideally, the above would be it's own patch (or combined with
extracting the other sub suggested below)

>      }
>      return $hostnodes;

(...)

> diff --git a/test/run_config2command_tests.pl b/test/run_config2command_tests.pl
> index f097811..9b49063 100755
> --- a/test/run_config2command_tests.pl
> +++ b/test/run_config2command_tests.pl
> @@ -178,6 +178,27 @@ $qemu_server_config->mock(
>      },
>  );
>  
> +my $qemu_server_memory;
> +$qemu_server_memory = Test::MockModule->new('PVE::QemuServer::Memory');
> +$qemu_server_memory->mock(
> +    hugepages_size => sub {

Rather than mocking the whole thing, we could also extract the
sub { -d  "/sys/kernel/mm/hugepages/hugepages-". ($_[0] * 1024) ."kB" }
from the original into a named sub and only mock that. Then we'd get all
the extra logic for checks like ($size & 1023) == 0, etc.

> +	my ($conf, $size) = @_;
> +
> +	if ($conf->{hugepages} eq 'any') {
> +	    return 1024;
> +	} else {
> +	    return $conf->{hugepages};
> +	}
> +    },
> +    host_numanode_exist => sub {
> +	my ($id) = @_;
> +	return 1;
> +    },
> +    get_host_phys_address_bits => sub {
> +	return 46;
> +    }
> +);
> +
>  my $pve_common_tools;
>  $pve_common_tools = Test::MockModule->new('PVE::Tools');
>  $pve_common_tools->mock(




  reply	other threads:[~2023-01-24 13:04 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-04  6:42 [pve-devel] [PATCH v2 qemu-server 0/9] rework memory hotplug + virtiomem Alexandre Derumier
2023-01-04  6:42 ` [pve-devel] [PATCH v2 qemu-server 1/9] test: add memory tests Alexandre Derumier
2023-01-24 13:04   ` Fiona Ebner [this message]
2023-01-04  6:42 ` [pve-devel] [PATCH v2 qemu-server 2/9] add memory parser Alexandre Derumier
2023-01-24 13:04   ` Fiona Ebner
2023-01-04  6:42 ` [pve-devel] [PATCH v2 qemu-server 3/9] memory: add get_static_mem Alexandre Derumier
2023-01-24 13:04   ` Fiona Ebner
2023-01-04  6:42 ` [pve-devel] [PATCH v2 qemu-server 4/9] config: memory: add 'max' option Alexandre Derumier
2023-01-24 13:05   ` Fiona Ebner
2023-01-27 15:03     ` DERUMIER, Alexandre
2023-01-30  8:03       ` Fiona Ebner
2023-01-30  8:45         ` DERUMIER, Alexandre
2023-01-04  6:42 ` [pve-devel] [PATCH v2 qemu-server 5/9] memory: get_max_mem: use config memory max Alexandre Derumier
2023-01-24 13:05   ` Fiona Ebner
2023-01-27 15:15     ` DERUMIER, Alexandre
2023-01-30  8:04       ` Fiona Ebner
2023-01-04  6:43 ` [pve-devel] [PATCH v2 qemu-server 6/9] memory: use 64 slots && static dimm size when max is defined Alexandre Derumier
2023-01-24 13:06   ` Fiona Ebner
2023-01-27 15:52     ` DERUMIER, Alexandre
2023-01-04  6:43 ` [pve-devel] [PATCH v2 qemu-server 7/9] test: add memory-max tests Alexandre Derumier
2023-01-24 13:06   ` Fiona Ebner
2023-01-04  6:43 ` [pve-devel] [PATCH v2 qemu-server 8/9] memory: add virtio-mem support Alexandre Derumier
2023-01-24 13:06   ` Fiona Ebner
2023-01-25  9:00     ` DERUMIER, Alexandre
2023-01-25  9:54       ` Fiona Ebner
2023-01-25 10:28         ` DERUMIER, Alexandre
2023-01-25 10:52           ` Fiona Ebner
2023-01-04  6:43 ` [pve-devel] [PATCH v2 qemu-server 9/9] tests: add virtio-mem tests Alexandre Derumier
2023-01-24 13:08   ` Fiona Ebner
2023-01-24 13:08 ` [pve-devel] [PATCH v2 qemu-server 0/9] rework memory hotplug + virtiomem Fiona Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=08805109-d3d9-ff98-5664-57e6fe7ed4ef@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=aderumier@odiso.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal