[pve-devel] [PATCH v2 qemu-server 1/9] test: add memory tests
Fiona Ebner
f.ebner at proxmox.com
Tue Jan 24 14:04:25 CET 2023
Am 04.01.23 um 07:42 schrieb Alexandre Derumier:
> Signed-off-by: Alexandre Derumier <aderumier at 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(
More information about the pve-devel
mailing list