1#################################################################################################################################### 2# VmTest.pm - Vm constants and data 3#################################################################################################################################### 4package pgBackRestTest::Common::VmTest; 5 6#################################################################################################################################### 7# Perl includes 8#################################################################################################################################### 9use strict; 10use warnings FATAL => qw(all); 11use Carp qw(confess); 12 13use Exporter qw(import); 14 our @EXPORT = qw(); 15 16use pgBackRestDoc::Common::Exception; 17use pgBackRestDoc::Common::Log; 18use pgBackRestDoc::Common::String; 19 20use pgBackRestTest::Common::DbVersion; 21 22#################################################################################################################################### 23# VM hash keywords 24#################################################################################################################################### 25use constant VM_ARCH => 'arch'; 26 push @EXPORT, qw(VM_ARCH); 27use constant VM_DB => 'db'; 28 push @EXPORT, qw(VM_DB); 29use constant VM_DB_TEST => 'db-test'; 30 push @EXPORT, qw(VM_DB_TEST); 31use constant VMDEF_DEBUG_INTEGRATION => 'debug-integration'; 32 push @EXPORT, qw(VMDEF_DEBUG_INTEGRATION); 33use constant VM_CONTROL_MASTER => 'control-master'; 34 push @EXPORT, qw(VM_CONTROL_MASTER); 35# Will coverage testing be run for C? 36use constant VMDEF_COVERAGE_C => 'coverage-c'; 37use constant VM_DEPRECATED => 'deprecated'; 38 push @EXPORT, qw(VM_DEPRECATED); 39use constant VM_IMAGE => 'image'; 40 push @EXPORT, qw(VM_IMAGE); 41use constant VM_OS => 'os'; 42 push @EXPORT, qw(VM_OS); 43use constant VM_OS_BASE => 'os-base'; 44 push @EXPORT, qw(VM_OS_BASE); 45use constant VM_OS_REPO => 'os-repo'; 46 push @EXPORT, qw(VM_OS_REPO); 47use constant VMDEF_PGSQL_BIN => 'pgsql-bin'; 48 push @EXPORT, qw(VMDEF_PGSQL_BIN); 49use constant VMDEF_LCOV_VERSION => 'lcov-version'; 50 push @EXPORT, qw(VMDEF_LCOV_VERSION); 51use constant VMDEF_WITH_BACKTRACE => 'with-backtrace'; 52 push @EXPORT, qw(VMDEF_WITH_BACKTRACE); 53use constant VMDEF_WITH_LZ4 => 'with-lz4'; 54 push @EXPORT, qw(VMDEF_WITH_LZ4); 55use constant VMDEF_WITH_ZST => 'with-zst'; 56 push @EXPORT, qw(VMDEF_WITH_ZST); 57 58#################################################################################################################################### 59# Valid OS base List 60#################################################################################################################################### 61use constant VM_OS_BASE_DEBIAN => 'debian'; 62 push @EXPORT, qw(VM_OS_BASE_DEBIAN); 63use constant VM_OS_BASE_RHEL => 'rhel'; 64 push @EXPORT, qw(VM_OS_BASE_RHEL); 65 66#################################################################################################################################### 67# Valid OS list 68#################################################################################################################################### 69use constant VM_OS_CENTOS => 'centos'; 70 push @EXPORT, qw(VM_OS_CENTOS); 71use constant VM_OS_DEBIAN => 'debian'; 72 push @EXPORT, qw(VM_OS_DEBIAN); 73use constant VM_OS_UBUNTU => 'ubuntu'; 74 push @EXPORT, qw(VM_OS_DEBIAN); 75 76#################################################################################################################################### 77# Valid architecture list 78#################################################################################################################################### 79use constant VM_ARCH_I386 => 'i386'; 80 push @EXPORT, qw(VM_ARCH_I386); 81use constant VM_ARCH_AMD64 => 'amd64'; 82 push @EXPORT, qw(VM_ARCH_AMD64); 83 84#################################################################################################################################### 85# Valid VM list 86#################################################################################################################################### 87use constant VM_ALL => 'all'; 88 push @EXPORT, qw(VM_ALL); 89 90use constant VM_NONE => 'none'; 91 push @EXPORT, qw(VM_NONE); 92 93use constant VM_CO7 => 'co7'; 94 push @EXPORT, qw(VM_CO7); 95use constant VM_CO8 => 'co8'; 96 push @EXPORT, qw(VM_CO8); 97use constant VM_F33 => 'f33'; 98 push @EXPORT, qw(VM_F33); 99use constant VM_U16 => 'u16'; 100 push @EXPORT, qw(VM_U16); 101use constant VM_U18 => 'u18'; 102 push @EXPORT, qw(VM_U18); 103use constant VM_U20 => 'u20'; 104 push @EXPORT, qw(VM_U20); 105use constant VM_D8 => 'd8'; 106 push @EXPORT, qw(VM_D8); 107use constant VM_D9 => 'd9'; 108 push @EXPORT, qw(VM_D9); 109 110# Defines the vm that will be used for expect testing 111use constant VM_EXPECT => VM_CO7; 112 push @EXPORT, qw(VM_EXPECT); 113 114# VM aliases for run matrices (numbered oldest to newest) 115use constant VM2 => VM_U16; 116 push @EXPORT, qw(VM2); 117use constant VM3 => VM_CO7; 118 push @EXPORT, qw(VM3); 119use constant VM4 => VM_U20; 120 push @EXPORT, qw(VM4); 121 122# List of default test VMs 123use constant VM_LIST => (VM2, VM3, VM4); 124 push @EXPORT, qw(VM_LIST); 125 126my $oyVm = 127{ 128 # None 129 &VM_NONE => 130 { 131 &VM_OS_BASE => VM_OS_BASE_DEBIAN, 132 &VM_OS => VM_OS_UBUNTU, 133 &VM_ARCH => VM_ARCH_AMD64, 134 &VMDEF_COVERAGE_C => true, 135 &VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin', 136 137 &VMDEF_WITH_ZST => true, 138 139 &VM_DB => 140 [ 141 PG_VERSION_10, 142 ], 143 144 &VM_DB_TEST => 145 [ 146 PG_VERSION_10, 147 ], 148 }, 149 150 # CentOS 7 151 &VM_CO7 => 152 { 153 &VM_OS_BASE => VM_OS_BASE_RHEL, 154 &VM_OS => VM_OS_CENTOS, 155 &VM_IMAGE => 'centos:7', 156 &VM_ARCH => VM_ARCH_AMD64, 157 &VMDEF_PGSQL_BIN => '/usr/pgsql-{[version]}/bin', 158 159 &VMDEF_DEBUG_INTEGRATION => false, 160 &VMDEF_WITH_ZST => true, 161 162 &VM_DB => 163 [ 164 PG_VERSION_95, 165 PG_VERSION_96, 166 PG_VERSION_10, 167 PG_VERSION_11, 168 PG_VERSION_12, 169 PG_VERSION_13, 170 ], 171 172 &VM_DB_TEST => 173 [ 174 PG_VERSION_96, 175 ], 176 }, 177 178 # Fedora 33 179 &VM_F33 => 180 { 181 &VM_OS_BASE => VM_OS_BASE_RHEL, 182 &VM_OS => VM_OS_CENTOS, 183 &VM_IMAGE => 'fedora:33', 184 &VM_ARCH => VM_ARCH_AMD64, 185 &VMDEF_PGSQL_BIN => '/usr/pgsql-{[version]}/bin', 186 &VMDEF_COVERAGE_C => true, 187 188 &VMDEF_DEBUG_INTEGRATION => false, 189 &VMDEF_WITH_ZST => true, 190 191 &VM_DB => 192 [ 193 PG_VERSION_96, 194 PG_VERSION_10, 195 PG_VERSION_11, 196 PG_VERSION_12, 197 PG_VERSION_13, 198 ], 199 200 &VM_DB_TEST => 201 [ 202 PG_VERSION_12, 203 ], 204 }, 205 206 # Debian 8 207 &VM_D8 => 208 { 209 &VM_OS_BASE => VM_OS_BASE_DEBIAN, 210 &VM_OS => VM_OS_DEBIAN, 211 &VM_OS_REPO => 'jessie', 212 &VM_IMAGE => 'debian:8', 213 &VM_ARCH => VM_ARCH_AMD64, 214 &VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin', 215 216 &VM_DB => 217 [ 218 PG_VERSION_84, 219 PG_VERSION_90, 220 PG_VERSION_91, 221 PG_VERSION_92, 222 PG_VERSION_93, 223 PG_VERSION_94, 224 PG_VERSION_95, 225 PG_VERSION_96, 226 PG_VERSION_10, 227 PG_VERSION_11, 228 ], 229 230 &VM_DB_TEST => 231 [ 232 PG_VERSION_95, 233 ], 234 }, 235 236 # Debian 9 237 &VM_D9 => 238 { 239 &VM_OS_BASE => VM_OS_BASE_DEBIAN, 240 &VM_OS => VM_OS_DEBIAN, 241 &VM_OS_REPO => 'stretch', 242 &VM_IMAGE => 'debian:9', 243 &VM_ARCH => VM_ARCH_AMD64, 244 &VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin', 245 246 &VM_DB_TEST => 247 [ 248 PG_VERSION_92, 249 PG_VERSION_93, 250 PG_VERSION_94, 251 PG_VERSION_95, 252 PG_VERSION_96, 253 PG_VERSION_10, 254 PG_VERSION_11, 255 PG_VERSION_12, 256 ], 257 258 &VM_DB_TEST => 259 [ 260 PG_VERSION_96, 261 ], 262 }, 263 264 # Ubuntu 16.04 265 &VM_U16 => 266 { 267 &VM_OS_BASE => VM_OS_BASE_DEBIAN, 268 &VM_OS => VM_OS_UBUNTU, 269 &VM_OS_REPO => 'xenial', 270 &VM_IMAGE => 'i386/ubuntu:16.04', 271 &VM_ARCH => VM_ARCH_I386, 272 &VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin', 273 274 &VMDEF_WITH_BACKTRACE => true, 275 276 &VM_DB => 277 [ 278 PG_VERSION_83, 279 PG_VERSION_84, 280 PG_VERSION_90, 281 PG_VERSION_91, 282 PG_VERSION_92, 283 PG_VERSION_93, 284 PG_VERSION_94, 285 PG_VERSION_95, 286 PG_VERSION_96, 287 PG_VERSION_10, 288 PG_VERSION_11, 289 PG_VERSION_12, 290 PG_VERSION_13, 291 ], 292 293 &VM_DB_TEST => 294 [ 295 PG_VERSION_83, 296 PG_VERSION_84, 297 PG_VERSION_90, 298 PG_VERSION_91, 299 PG_VERSION_92, 300 ], 301 }, 302 303 # Ubuntu 18.04 304 &VM_U18 => 305 { 306 &VM_OS_BASE => VM_OS_BASE_DEBIAN, 307 &VM_OS => VM_OS_UBUNTU, 308 &VM_OS_REPO => 'bionic', 309 &VM_IMAGE => 'ubuntu:18.04', 310 &VM_ARCH => VM_ARCH_AMD64, 311 &VMDEF_COVERAGE_C => true, 312 &VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin', 313 314 &VMDEF_WITH_BACKTRACE => true, 315 &VMDEF_WITH_ZST => true, 316 317 &VM_DB => 318 [ 319 PG_VERSION_83, 320 PG_VERSION_84, 321 PG_VERSION_90, 322 PG_VERSION_91, 323 PG_VERSION_92, 324 PG_VERSION_93, 325 PG_VERSION_94, 326 PG_VERSION_95, 327 PG_VERSION_96, 328 PG_VERSION_10, 329 PG_VERSION_11, 330 PG_VERSION_12, 331 PG_VERSION_13, 332 ], 333 334 &VM_DB_TEST => 335 [ 336 PG_VERSION_93, 337 PG_VERSION_94, 338 PG_VERSION_95, 339 PG_VERSION_10, 340 PG_VERSION_11, 341 PG_VERSION_12, 342 PG_VERSION_13, 343 ], 344 }, 345 346 # Ubuntu 20.04 347 &VM_U20 => 348 { 349 &VM_OS_BASE => VM_OS_BASE_DEBIAN, 350 &VM_OS => VM_OS_UBUNTU, 351 &VM_OS_REPO => 'focal', 352 &VM_IMAGE => 'ubuntu:20.04', 353 &VM_ARCH => VM_ARCH_AMD64, 354 &VMDEF_COVERAGE_C => true, 355 &VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin', 356 357 &VMDEF_WITH_BACKTRACE => true, 358 &VMDEF_WITH_ZST => true, 359 360 &VM_DB => 361 [ 362 PG_VERSION_90, 363 PG_VERSION_91, 364 PG_VERSION_92, 365 PG_VERSION_93, 366 PG_VERSION_94, 367 PG_VERSION_95, 368 PG_VERSION_96, 369 PG_VERSION_10, 370 PG_VERSION_11, 371 PG_VERSION_12, 372 PG_VERSION_13, 373 PG_VERSION_14, 374 ], 375 376 &VM_DB_TEST => 377 [ 378 PG_VERSION_93, 379 PG_VERSION_94, 380 PG_VERSION_95, 381 PG_VERSION_10, 382 PG_VERSION_11, 383 PG_VERSION_12, 384 PG_VERSION_13, 385 PG_VERSION_14, 386 ], 387 }, 388}; 389 390#################################################################################################################################### 391# Set VM_DB_TEST to VM_DB if it is not defined so it doesn't have to be checked everywhere 392#################################################################################################################################### 393foreach my $strVm (sort(keys(%{$oyVm}))) 394{ 395 if (!defined($oyVm->{$strVm}{&VM_DB_TEST})) 396 { 397 $oyVm->{$strVm}{&VM_DB_TEST} = $oyVm->{$strVm}{&VM_DB}; 398 } 399} 400 401#################################################################################################################################### 402# Verify that each version of PostgreSQL is represented in one and only one default VM 403#################################################################################################################################### 404foreach my $strPgVersion (versionSupport()) 405{ 406 my $strVmPgVersionRun; 407 my $bVmCoverageC = false; 408 409 foreach my $strVm (VM_LIST) 410 { 411 if (vmCoverageC($strVm)) 412 { 413 $bVmCoverageC = true; 414 } 415 416 foreach my $strVmPgVersion (@{$oyVm->{$strVm}{&VM_DB_TEST}}) 417 { 418 if ($strPgVersion eq $strVmPgVersion) 419 { 420 if (defined($strVmPgVersionRun)) 421 { 422 confess &log(ASSERT, "PostgreSQL $strPgVersion is already configured to run on default vm $strVm"); 423 } 424 425 $strVmPgVersionRun = $strVm; 426 } 427 } 428 } 429 430 my $strErrorSuffix = 'is not configured to run on a default vm'; 431 432 if (!$bVmCoverageC) 433 { 434 confess &log(ASSERT, "C coverage ${strErrorSuffix}"); 435 } 436 437 if (!defined($strVmPgVersionRun)) 438 { 439 confess &log(ASSERT, "PostgreSQL ${strPgVersion} ${strErrorSuffix}"); 440 } 441} 442 443#################################################################################################################################### 444# vmValid 445#################################################################################################################################### 446sub vmValid 447{ 448 my $strVm = shift; 449 450 if (!defined($oyVm->{$strVm})) 451 { 452 confess &log(ERROR, "no definition for vm '${strVm}'"); 453 } 454} 455 456push @EXPORT, qw(vmValid); 457 458#################################################################################################################################### 459# Which vm to use for the test matrix. If one of the standard four, then use that, else use VM4. 460#################################################################################################################################### 461sub vmTest 462{ 463 my $strVm = shift; 464 465 if (grep(/^$strVm$/, VM_LIST)) 466 { 467 return $strVm; 468 } 469 470 return VM4; 471} 472 473push @EXPORT, qw(vmTest); 474 475#################################################################################################################################### 476# vmGet 477#################################################################################################################################### 478sub vmGet 479{ 480 return $oyVm; 481} 482 483push @EXPORT, qw(vmGet); 484 485#################################################################################################################################### 486# vmBaseTest 487#################################################################################################################################### 488sub vmBaseTest 489{ 490 my $strVm = shift; 491 my $strDistroTest = shift; 492 493 return $oyVm->{$strVm}{&VM_OS_BASE} eq $strDistroTest ? true : false; 494} 495 496push @EXPORT, qw(vmBaseTest); 497 498#################################################################################################################################### 499# vmCoverageC 500#################################################################################################################################### 501sub vmCoverageC 502{ 503 my $strVm = shift; 504 505 return $oyVm->{$strVm}{&VMDEF_COVERAGE_C} ? true : false; 506} 507 508push @EXPORT, qw(vmCoverageC); 509 510#################################################################################################################################### 511# Get vm architecture bits 512#################################################################################################################################### 513sub vmArchBits 514{ 515 my $strVm = shift; 516 517 return ($oyVm->{$strVm}{&VM_ARCH} eq VM_ARCH_AMD64 ? 64 : 32); 518} 519 520push @EXPORT, qw(vmArchBits); 521 522#################################################################################################################################### 523# Get host architecture 524#################################################################################################################################### 525my $strHostArch = undef; 526 527sub hostArch 528{ 529 if (!defined($strHostArch)) 530 { 531 $strHostArch = trim(`uname -m`); 532 533 # Mac M1 reports arm64 but we generally need aarch64 (which Linux reports) 534 if ($strHostArch eq 'arm64') 535 { 536 $strHostArch = 'aarch64'; 537 } 538 } 539 540 return $strHostArch; 541} 542 543push @EXPORT, qw(hostArch); 544 545#################################################################################################################################### 546# Does the VM support libbacktrace? 547#################################################################################################################################### 548sub vmWithBackTrace 549{ 550 my $strVm = shift; 551 552 return ($oyVm->{$strVm}{&VMDEF_WITH_BACKTRACE} ? true : false); 553} 554 555push @EXPORT, qw(vmWithBackTrace); 556 557#################################################################################################################################### 558# Does the VM support liblz4? 559#################################################################################################################################### 560sub vmWithLz4 561{ 562 my $strVm = shift; 563 564 return (defined($oyVm->{$strVm}{&VMDEF_WITH_LZ4}) ? $oyVm->{$strVm}{&VMDEF_WITH_LZ4} : true); 565} 566 567push @EXPORT, qw(vmWithLz4); 568 569#################################################################################################################################### 570# Does the VM support liblzst? 571#################################################################################################################################### 572sub vmWithZst 573{ 574 my $strVm = shift; 575 576 return (defined($oyVm->{$strVm}{&VMDEF_WITH_ZST}) ? $oyVm->{$strVm}{&VMDEF_WITH_ZST} : false); 577} 578 579push @EXPORT, qw(vmWithZst); 580 581#################################################################################################################################### 582# Will integration tests be run in debug mode? 583#################################################################################################################################### 584sub vmDebugIntegration 585{ 586 my $strVm = shift; 587 588 return (defined($oyVm->{$strVm}{&VMDEF_DEBUG_INTEGRATION}) ? $oyVm->{$strVm}{&VMDEF_DEBUG_INTEGRATION} : true); 589} 590 591push @EXPORT, qw(vmDebugIntegration); 592 5931; 594