1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-07 00:35:37 +02:00
Files
pgbackrest/test/lib/pgBackRestTest/Common/VmTest.pm

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

494 lines
16 KiB
Perl
Raw Normal View History

####################################################################################################################################
# VmTest.pm - Vm constants and data
####################################################################################################################################
New simpler configuration and consistent project/exe/path naming. * The repo-path option now always refers to the repository where backups and archive are stored, whether local or remote, so the repo-remote-path option has been removed. The new spool-path option can be used to define a location for queueing WAL segments when archiving asynchronously. Otherwise, a local repository is no longer required. * Implemented a new config format which should be far simpler to use. See the User Guide and Configuration Reference for details but for a simple configuration all options can now be placed in the stanza section. Options that are shared between stanzas can be placed in the [global] section. More complex configurations can still make use of command sections though this should be a rare use case. * The default configuration filename is now pgbackrest.conf instead of pg_backrest.conf. This was done for consistency with other naming changes but also to prevent old config files from being loaded accidentally. * The default repository name was changed from /var/lib/backup to /var/lib/pgbackrest. * Lock files are now stored in /tmp/pgbackrest by default. These days /run/pgbackrest would be the preferred location but that would require init scripts which are not part of this release. The lock-path option can be used to configure the lock directory. * Log files are now stored in /var/log/pgbackrest by default and no longer have the date appended so they can be managed with logrotate. The log-path option can be used to configure the lock directory. * Executable filename changed from pg_backrest to pgbackrest.
2016-04-14 09:30:54 -04:00
package pgBackRestTest::Common::VmTest;
####################################################################################################################################
# Perl includes
####################################################################################################################################
use strict;
use warnings FATAL => qw(all);
use Carp qw(confess);
use Exporter qw(import);
our @EXPORT = qw();
use pgBackRestDoc::Common::Exception;
use pgBackRestDoc::Common::Log;
use pgBackRestDoc::Common::String;
use pgBackRestTest::Common::DbVersion;
####################################################################################################################################
# VM hash keywords
####################################################################################################################################
use constant VM_ARCH => 'arch';
push @EXPORT, qw(VM_ARCH);
use constant VM_DB => 'db';
push @EXPORT, qw(VM_DB);
use constant VM_DB_TEST => 'db-test';
push @EXPORT, qw(VM_DB_TEST);
use constant VMDEF_DEBUG_INTEGRATION => 'debug-integration';
push @EXPORT, qw(VMDEF_DEBUG_INTEGRATION);
use constant VM_CONTROL_MTR => 'control-mtr';
push @EXPORT, qw(VM_CONTROL_MTR);
# Will coverage testing be run for C?
use constant VMDEF_COVERAGE_C => 'coverage-c';
use constant VM_DEPRECATED => 'deprecated';
push @EXPORT, qw(VM_DEPRECATED);
use constant VM_IMAGE => 'image';
push @EXPORT, qw(VM_IMAGE);
use constant VM_OS_BASE => 'os-base';
push @EXPORT, qw(VM_OS_BASE);
use constant VMDEF_PG_REPO => 'pg-repo';
use constant VMDEF_PGSQL_BIN => 'psql-bin';
push @EXPORT, qw(VMDEF_PGSQL_BIN);
use constant VMDEF_WITH_LZ4 => 'with-lz4';
push @EXPORT, qw(VMDEF_WITH_LZ4);
use constant VMDEF_WITH_ZST => 'with-zst';
push @EXPORT, qw(VMDEF_WITH_ZST);
####################################################################################################################################
# Valid OS base List
####################################################################################################################################
Update unit tests to work with Alpine Linux and musl libc. A few bugs have been reported over the years on Alpine with musl libc and generally it has been possible to figure them out without testing on that platform but a few newer ones cannot be reproduced elsewhere. Also, testing with additional libc implementations helps portability so it makes sense to add support. For the most part musl libc works as expected with a few caveats: 1) The FD_*() macros won't accept an int file descriptor without warning when -Wsign-conversion is enabled. I opened https://www.openwall.com/lists/musl/2025/05/23/4 to discuss this and I was referred to https://www.openwall.com/lists/musl/2024/07/16/1 which explains why this happens. It was not a very satisfying answer but clearly it is not going to be addressed so a meson probe was added to detect the issue and disable the warning. 2) Floating point numbers are rounded differently than in GNU/Mac libc when formatted with printf() and friends. This is fine for the core code but causes issues in the unit tests that expect log entries to match exactly. This was solved in ad7ba46b by adding our own rough and ready formatting routines. 3) Some error messages are different from GNU/Mac libc. This was solved with a new error macro that accepts multiple messages in b5fbb16c. 4) For some reason ninja on Alpine outputs "nothing to do" messages to stderr whereas they go to stdout on other distributions. Redirecting stderr to stdout is our standard fix for this issue so do that. A non-zero result code will let us know that something has gone wrong. 5) It appears that profiling is not supported on Alpine, which is pretty surprising. For now fix this by only unit testing the profiling code when coverage is enabled. This is not a great solution since we would rather test profiling on any system that supports it but for now this will do.
2025-06-05 17:33:18 -04:00
use constant VM_OS_BASE_ALPINE => 'alpine';
push @EXPORT, qw(VM_OS_BASE_ALPINE);
use constant VM_OS_BASE_DEBIAN => 'debian';
push @EXPORT, qw(VM_OS_BASE_DEBIAN);
use constant VM_OS_BASE_RHEL => 'rhel';
push @EXPORT, qw(VM_OS_BASE_RHEL);
####################################################################################################################################
# Valid architecture list
####################################################################################################################################
use constant VM_ARCH_AARCH64 => 'aarch64';
push @EXPORT, qw(VM_ARCH_AARCH64);
use constant VM_ARCH_I386 => 'i386';
push @EXPORT, qw(VM_ARCH_I386);
use constant VM_ARCH_X86_64 => 'x86_64';
push @EXPORT, qw(VM_ARCH_X86_64);
####################################################################################################################################
# Valid VM list
####################################################################################################################################
use constant VM_ALL => 'all';
push @EXPORT, qw(VM_ALL);
use constant VM_NONE => 'none';
push @EXPORT, qw(VM_NONE);
Update unit tests to work with Alpine Linux and musl libc. A few bugs have been reported over the years on Alpine with musl libc and generally it has been possible to figure them out without testing on that platform but a few newer ones cannot be reproduced elsewhere. Also, testing with additional libc implementations helps portability so it makes sense to add support. For the most part musl libc works as expected with a few caveats: 1) The FD_*() macros won't accept an int file descriptor without warning when -Wsign-conversion is enabled. I opened https://www.openwall.com/lists/musl/2025/05/23/4 to discuss this and I was referred to https://www.openwall.com/lists/musl/2024/07/16/1 which explains why this happens. It was not a very satisfying answer but clearly it is not going to be addressed so a meson probe was added to detect the issue and disable the warning. 2) Floating point numbers are rounded differently than in GNU/Mac libc when formatted with printf() and friends. This is fine for the core code but causes issues in the unit tests that expect log entries to match exactly. This was solved in ad7ba46b by adding our own rough and ready formatting routines. 3) Some error messages are different from GNU/Mac libc. This was solved with a new error macro that accepts multiple messages in b5fbb16c. 4) For some reason ninja on Alpine outputs "nothing to do" messages to stderr whereas they go to stdout on other distributions. Redirecting stderr to stdout is our standard fix for this issue so do that. A non-zero result code will let us know that something has gone wrong. 5) It appears that profiling is not supported on Alpine, which is pretty surprising. For now fix this by only unit testing the profiling code when coverage is enabled. This is not a great solution since we would rather test profiling on any system that supports it but for now this will do.
2025-06-05 17:33:18 -04:00
use constant VM_A321 => 'a321';
push @EXPORT, qw(VM_A321);
use constant VM_D11 => 'd11';
push @EXPORT, qw(VM_D11);
use constant VM_RH8 => 'rh8';
push @EXPORT, qw(VM_RH8);
2025-06-22 17:46:54 -04:00
use constant VM_F42 => 'f42';
push @EXPORT, qw(VM_F42);
2021-04-08 14:38:20 -04:00
use constant VM_U20 => 'u20';
push @EXPORT, qw(VM_U20);
use constant VM_U22 => 'u22';
push @EXPORT, qw(VM_U22);
# List of default test VMs
use constant VM_LIST => (VM_U20, VM_D11, VM_RH8, VM_U22);
push @EXPORT, qw(VM_LIST);
my $oyVm =
{
# None
&VM_NONE =>
{
&VM_OS_BASE => VM_OS_BASE_DEBIAN,
&VM_ARCH => VM_ARCH_X86_64,
&VMDEF_COVERAGE_C => true,
&VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',
&VMDEF_WITH_ZST => true,
&VM_DB =>
[
PG_VERSION_10,
],
&VM_DB_TEST =>
[
PG_VERSION_10,
],
},
Update unit tests to work with Alpine Linux and musl libc. A few bugs have been reported over the years on Alpine with musl libc and generally it has been possible to figure them out without testing on that platform but a few newer ones cannot be reproduced elsewhere. Also, testing with additional libc implementations helps portability so it makes sense to add support. For the most part musl libc works as expected with a few caveats: 1) The FD_*() macros won't accept an int file descriptor without warning when -Wsign-conversion is enabled. I opened https://www.openwall.com/lists/musl/2025/05/23/4 to discuss this and I was referred to https://www.openwall.com/lists/musl/2024/07/16/1 which explains why this happens. It was not a very satisfying answer but clearly it is not going to be addressed so a meson probe was added to detect the issue and disable the warning. 2) Floating point numbers are rounded differently than in GNU/Mac libc when formatted with printf() and friends. This is fine for the core code but causes issues in the unit tests that expect log entries to match exactly. This was solved in ad7ba46b by adding our own rough and ready formatting routines. 3) Some error messages are different from GNU/Mac libc. This was solved with a new error macro that accepts multiple messages in b5fbb16c. 4) For some reason ninja on Alpine outputs "nothing to do" messages to stderr whereas they go to stdout on other distributions. Redirecting stderr to stdout is our standard fix for this issue so do that. A non-zero result code will let us know that something has gone wrong. 5) It appears that profiling is not supported on Alpine, which is pretty surprising. For now fix this by only unit testing the profiling code when coverage is enabled. This is not a great solution since we would rather test profiling on any system that supports it but for now this will do.
2025-06-05 17:33:18 -04:00
# Alpine 3.21
&VM_A321 =>
{
&VM_OS_BASE => VM_OS_BASE_ALPINE,
&VM_IMAGE => 'alpine:3.21',
&VM_ARCH => VM_ARCH_X86_64,
&VMDEF_PG_REPO => false,
&VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',
&VMDEF_WITH_ZST => true,
&VM_DB =>
[
PG_VERSION_17,
],
&VM_DB_TEST =>
[
PG_VERSION_17,
],
},
# Debian 11
&VM_D11 =>
{
&VM_OS_BASE => VM_OS_BASE_DEBIAN,
&VM_IMAGE => 'debian:11',
&VM_ARCH => VM_ARCH_I386,
&VMDEF_PG_REPO => false,
&VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',
&VMDEF_WITH_ZST => true,
&VM_DB =>
[
PG_VERSION_13,
],
&VM_DB_TEST =>
[
PG_VERSION_13,
],
},
# RHEL 8
&VM_RH8 =>
{
&VM_OS_BASE => VM_OS_BASE_RHEL,
&VM_IMAGE => 'rockylinux/rockylinux:8',
&VM_ARCH => VM_ARCH_X86_64,
&VMDEF_PGSQL_BIN => '/usr/pgsql-{[version]}/bin',
&VMDEF_DEBUG_INTEGRATION => false,
&VMDEF_WITH_ZST => true,
&VM_DB =>
[
PG_VERSION_13,
PG_VERSION_14,
2023-05-13 12:16:16 -04:00
PG_VERSION_15,
PG_VERSION_16,
PG_VERSION_17,
],
&VM_DB_TEST =>
[
PG_VERSION_14,
PG_VERSION_15,
PG_VERSION_16,
],
},
2025-06-22 17:46:54 -04:00
# Fedora 42
&VM_F42 =>
{
&VM_OS_BASE => VM_OS_BASE_RHEL,
2025-06-22 17:46:54 -04:00
&VM_IMAGE => 'fedora:42',
&VM_ARCH => VM_ARCH_X86_64,
&VMDEF_PGSQL_BIN => '/usr/pgsql-{[version]}/bin',
&VMDEF_COVERAGE_C => true,
&VMDEF_DEBUG_INTEGRATION => false,
&VMDEF_WITH_ZST => true,
&VM_DB =>
[
PG_VERSION_13,
PG_VERSION_14,
PG_VERSION_15,
PG_VERSION_16,
PG_VERSION_17,
],
&VM_DB_TEST =>
[
PG_VERSION_15,
],
},
2021-04-08 14:38:20 -04:00
# Ubuntu 20.04
&VM_U20 =>
{
&VM_OS_BASE => VM_OS_BASE_DEBIAN,
&VM_IMAGE => 'ubuntu:20.04',
&VM_ARCH => VM_ARCH_X86_64,
2021-04-08 14:38:20 -04:00
&VMDEF_COVERAGE_C => true,
&VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',
&VMDEF_WITH_ZST => true,
&VM_DB =>
[
PG_VERSION_95,
PG_VERSION_96,
PG_VERSION_10,
PG_VERSION_11,
PG_VERSION_12,
PG_VERSION_13,
PG_VERSION_14,
PG_VERSION_15,
PG_VERSION_16,
PG_VERSION_17,
2021-04-08 14:38:20 -04:00
],
&VM_DB_TEST =>
[
PG_VERSION_95,
PG_VERSION_96,
],
},
# Ubuntu 22.04
&VM_U22 =>
{
&VM_OS_BASE => VM_OS_BASE_DEBIAN,
&VM_IMAGE => 'ubuntu:22.04',
&VM_ARCH => VM_ARCH_X86_64,
&VMDEF_COVERAGE_C => true,
&VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',
&VMDEF_WITH_ZST => true,
&VM_DB =>
[
PG_VERSION_95,
PG_VERSION_96,
PG_VERSION_10,
PG_VERSION_11,
PG_VERSION_12,
PG_VERSION_13,
PG_VERSION_14,
PG_VERSION_15,
PG_VERSION_16,
PG_VERSION_17,
PG_VERSION_18,
],
2021-04-08 14:38:20 -04:00
&VM_DB_TEST =>
[
PG_VERSION_10,
PG_VERSION_11,
PG_VERSION_12,
PG_VERSION_17,
PG_VERSION_18,
2021-04-08 14:38:20 -04:00
],
},
};
####################################################################################################################################
# Set VM_DB_TEST to VM_DB if it is not defined so it doesn't have to be checked everywhere
####################################################################################################################################
foreach my $strVm (sort(keys(%{$oyVm})))
{
if (!defined($oyVm->{$strVm}{&VM_DB_TEST}))
{
$oyVm->{$strVm}{&VM_DB_TEST} = $oyVm->{$strVm}{&VM_DB};
}
}
####################################################################################################################################
# Verify that each version of PostgreSQL is represented in one and only one default VM
####################################################################################################################################
foreach my $strPgVersion (versionSupport())
{
my $strVmPgVersionRun;
my $bVmCoverageC = false;
foreach my $strVm (VM_LIST)
{
if (vmCoverageC($strVm))
{
$bVmCoverageC = true;
}
foreach my $strVmPgVersion (@{$oyVm->{$strVm}{&VM_DB_TEST}})
{
if ($strPgVersion eq $strVmPgVersion)
{
if (defined($strVmPgVersionRun))
{
confess &log(ASSERT, "PostgreSQL $strPgVersion is already configured to run on default vm $strVm");
}
$strVmPgVersionRun = $strVm;
}
}
}
my $strErrorSuffix = 'is not configured to run on a default vm';
if (!$bVmCoverageC)
{
confess &log(ASSERT, "C coverage ${strErrorSuffix}");
}
if (!defined($strVmPgVersionRun))
{
confess &log(ASSERT, "PostgreSQL ${strPgVersion} ${strErrorSuffix}");
}
}
2019-10-17 14:00:18 +02:00
####################################################################################################################################
# vmValid
####################################################################################################################################
sub vmValid
{
my $strVm = shift;
if (!defined($oyVm->{$strVm}))
{
confess &log(ERROR, "no definition for vm '${strVm}'");
2019-10-17 14:00:18 +02:00
}
}
push @EXPORT, qw(vmValid);
####################################################################################################################################
# vmPgRepo
####################################################################################################################################
sub vmPgRepo
{
my $strVm = shift;
vmValid($strVm);
if (!defined($oyVm->{$strVm}{&VMDEF_PG_REPO}))
{
return true;
}
return $oyVm->{$strVm}{&VMDEF_PG_REPO};
}
push @EXPORT, qw(vmPgRepo);
####################################################################################################################################
# vmGet
####################################################################################################################################
sub vmGet
{
return $oyVm;
}
push @EXPORT, qw(vmGet);
####################################################################################################################################
# vmBaseTest
####################################################################################################################################
sub vmBaseTest
{
my $strVm = shift;
my $strDistroTest = shift;
return $oyVm->{$strVm}{&VM_OS_BASE} eq $strDistroTest ? true : false;
}
push @EXPORT, qw(vmBaseTest);
####################################################################################################################################
# vmCoverageC
####################################################################################################################################
sub vmCoverageC
{
my $strVm = shift;
return $oyVm->{$strVm}{&VMDEF_COVERAGE_C} ? true : false;
}
push @EXPORT, qw(vmCoverageC);
####################################################################################################################################
# Get vm architecture
####################################################################################################################################
sub vmArch
{
my $strVm = shift;
return $oyVm->{$strVm}{&VM_ARCH};
}
push @EXPORT, qw(vmArch);
####################################################################################################################################
# Get vm architecture bits
####################################################################################################################################
sub vmArchBits
{
my $strVm = shift;
return (vmArch($strVm) eq VM_ARCH_I386 ? 32 : 64);
}
push @EXPORT, qw(vmArchBits);
####################################################################################################################################
# Get host architecture
####################################################################################################################################
my $strHostArch = undef;
sub hostArch
{
if (!defined($strHostArch))
{
$strHostArch = trim(`uname -m`);
# Mac M1 reports arm64 but we generally need aarch64 (which Linux reports)
if ($strHostArch eq 'arm64')
{
$strHostArch = VM_ARCH_AARCH64;
}
}
return $strHostArch;
}
push @EXPORT, qw(hostArch);
####################################################################################################################################
# Does the VM support liblz4?
####################################################################################################################################
sub vmWithLz4
{
my $strVm = shift;
return (defined($oyVm->{$strVm}{&VMDEF_WITH_LZ4}) ? $oyVm->{$strVm}{&VMDEF_WITH_LZ4} : true);
}
push @EXPORT, qw(vmWithLz4);
####################################################################################################################################
# Does the VM support liblzst?
####################################################################################################################################
sub vmWithZst
{
my $strVm = shift;
return (defined($oyVm->{$strVm}{&VMDEF_WITH_ZST}) ? $oyVm->{$strVm}{&VMDEF_WITH_ZST} : false);
}
push @EXPORT, qw(vmWithZst);
####################################################################################################################################
# Will integration tests be run in debug mode?
####################################################################################################################################
sub vmDebugIntegration
{
my $strVm = shift;
return (defined($oyVm->{$strVm}{&VMDEF_DEBUG_INTEGRATION}) ? $oyVm->{$strVm}{&VMDEF_DEBUG_INTEGRATION} : true);
}
push @EXPORT, qw(vmDebugIntegration);
1;