Skip to content

Commit

Permalink
Migrate integration tests to C.
Browse files Browse the repository at this point in the history
The Perl integration tests were migrated as faithfully as possible, but there was some cruft and a few unit tests that it did not make sense to migrate.

Also remove all Perl code made obsolete by this migration.

All unit, performance, and integration tests are now written in C but significant parts of the test harness remain to be migrated.
  • Loading branch information
dwsteele committed Mar 5, 2024
1 parent 7f1bb3a commit 794c577
Show file tree
Hide file tree
Showing 51 changed files with 3,289 additions and 11,166 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Expand Up @@ -32,13 +32,13 @@ jobs:
- param: test --vm=d10 --param=no-performance --param=c-only

# All integration tests for 32-bit
- param: test --vm=d10 --param=module=mock --param=module=real
- param: test --vm=d10 --param=module=mock --param=module=integration

# Debian/Ubuntu documentation
- param: doc --vm=u20

# All integration tests
- param: test --vm=u22 --param=build-package --param=module=mock --param=module=real
- param: test --vm=u22 --param=build-package --param=module=mock --param=module=integration

# All unit tests with coverage, backtrace and alternate timezone
- param: test --vm=u22 --param=c-only --param=no-valgrind --param=tz=America/New_York
Expand All @@ -53,7 +53,7 @@ jobs:
- param: doc --vm=rh8

# All integration tests
- param: test --vm=rh7 --param=module=mock --param=module=real
- param: test --vm=rh7 --param=module=mock --param=module=integration

steps:
- name: Checkout Code
Expand Down
6 changes: 3 additions & 3 deletions doc/lib/pgBackRestDoc/Common/DocExecute.pm
Expand Up @@ -16,11 +16,11 @@ use File::Basename qw(dirname);
use Storable qw(dclone);

use pgBackRestTest::Common::ExecuteTest;
use pgBackRestTest::Common::HostTest;
use pgBackRestTest::Common::HostGroupTest;

use pgBackRestDoc::Common::DocManifest;
use pgBackRestDoc::Common::Exception;
use pgBackRestDoc::Common::Host;
use pgBackRestDoc::Common::HostGroup;
use pgBackRestDoc::Common::Ini;
use pgBackRestDoc::Common::Log;
use pgBackRestDoc::Common::String;
Expand Down Expand Up @@ -1050,7 +1050,7 @@ sub sectionChildProcess
$strOption =~ s/\{\[host\-repo\-path\]\}/${strHostRepoPath}/g;
}

my $oHost = new pgBackRestTest::Common::HostTest(
my $oHost = new pgBackRestDoc::Common::Host(
$$hCacheKey{name}, "doc-$$hCacheKey{name}", $strImage, $strHostUser,
defined($strMount) ? [$strMount] : undef, $strOption, $$hCacheKey{param}, $$hCacheKey{'update-hosts'});

Expand Down
@@ -1,7 +1,7 @@
####################################################################################################################################
# HostTest.pm - Encapsulate a docker host for testing
# HostTest.pm - Encapsulate a docker host
####################################################################################################################################
package pgBackRestTest::Common::HostTest;
package pgBackRestDoc::Common::Host;

####################################################################################################################################
# Perl includes
Expand Down
@@ -1,7 +1,7 @@
####################################################################################################################################
# HostGroupTest.pm - Encapsulate a group of docker containers for testing
# HostGroupTest.pm - Encapsulate a group of docker containers
####################################################################################################################################
package pgBackRestTest::Common::HostGroupTest;
package pgBackRestDoc::Common::HostGroup;

####################################################################################################################################
# Perl includes
Expand Down Expand Up @@ -177,7 +177,7 @@ sub hostGroupGet
{
if (!defined($oHostGroup))
{
$oHostGroup = new pgBackRestTest::Common::HostGroupTest();
$oHostGroup = new pgBackRestDoc::Common::HostGroup();
}

return $oHostGroup;
Expand Down
20 changes: 11 additions & 9 deletions src/build/common/exec.c
Expand Up @@ -9,10 +9,11 @@ Execute Process Extensions

/**********************************************************************************************************************************/
static String *
execProcess(Exec *const this)
execProcess(Exec *const this, const ExecOneParam param)
{
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM(EXEC, this);
FUNCTION_LOG_PARAM(INT, param.resultExpect);
FUNCTION_LOG_END();

String *const result = strNew();
Expand All @@ -35,7 +36,7 @@ execProcess(Exec *const this)
// If the process exited normally but without a success status
if (WIFEXITED(processStatus))
{
if (WEXITSTATUS(processStatus) != 0)
if (WEXITSTATUS(processStatus) != param.resultExpect)
execCheckStatusError(this, processStatus, strTrim(result));
}
// Else if the process did not exit normally then it must have been a signal
Expand All @@ -53,31 +54,32 @@ execOne(const String *const command, const ExecOneParam param)
{
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM(STRING, command);
(void)param;
FUNCTION_LOG_PARAM(STRING, param.shell);
FUNCTION_LOG_PARAM(INT, param.resultExpect);
FUNCTION_LOG_END();

String *result = NULL;

MEM_CONTEXT_TEMP_BEGIN()
{
const StringList *const shellList = strLstNewSplitZ(param.shell != NULL ? param.shell : STRDEF("sh -c"), " ");
StringList *const param = strLstNew();
StringList *const paramList = strLstNew();

ASSERT(strLstSize(shellList) != 0);

for (unsigned int shellIdx = 1; shellIdx < strLstSize(shellList); shellIdx++)
strLstAdd(param, strLstGet(shellList, shellIdx));
strLstAdd(paramList, strLstGet(shellList, shellIdx));

strLstAddFmt(param, "%s 2>&1", strZ(command));
strLstAddZ(param, "2>&1");
strLstAddFmt(paramList, "%s 2>&1", strZ(command));
strLstAddZ(paramList, "2>&1");

Exec *const exec = execNew(strLstGet(shellList, 0), param, command, ioTimeoutMs());
Exec *const exec = execNew(strLstGet(shellList, 0), paramList, command, ioTimeoutMs());

execOpen(exec);

MEM_CONTEXT_PRIOR_BEGIN()
{
result = execProcess(exec);
result = execProcess(exec, param);
}
MEM_CONTEXT_PRIOR_END();
}
Expand Down
1 change: 1 addition & 0 deletions src/build/common/exec.h
Expand Up @@ -17,6 +17,7 @@ typedef struct ExecOneParam
{
VAR_PARAM_HEADER;
const String *shell; // Shell command to use for exec (default is sh -c)
int resultExpect; // Expected result, if not 0
} ExecOneParam;

#define execOneP(command, ...) \
Expand Down
6 changes: 3 additions & 3 deletions test/certificate/pgbackrest-test-server.cnf
Expand Up @@ -37,6 +37,6 @@ DNS.4 = 127.0.0.1
IP.1 = 127.0.0.1

# Used in integration tests
DNS.5 = db-primary
DNS.6 = db-standby
DNS.7 = backup
DNS.5 = pg1
DNS.6 = pg2
DNS.7 = repo
33 changes: 16 additions & 17 deletions test/certificate/pgbackrest-test-server.crt
@@ -1,8 +1,8 @@
-----BEGIN CERTIFICATE-----
MIIGAjCCA+qgAwIBAgIUW0gPWoZD5DqjIWIP3PliYA0IAOQwDQYJK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unpUQx4NFGPZJSs6z5z4BlT/+5mJVHC9qsrZBtkndYpRWo37xbVhRqP0+FSTbzrx
Gj2td3PoqQBgA/AmSKIpwagGzw7cSor1r4uEjkVxxyOMRbjuuASHMHUM7MtQV3YR
rz9UspvGfoKBdUkzMoqKRwxZWuh+uAoM+1GWXBjqlN6uAdQxpV2wZ75iRJp3Y4Bk
/CkXTLZ83lARGLqS/E5EFfg7Z9Bre2f5fHzV8C/h6WGpvCt/GlZqTx8fix/mMPT2
CFq+FcSmvF5JsIMxUnpvTw1hcTDNRPnOkFKnO1bjf9+jGCwzDUoGReYpb5veFSxh
IFkQ3oyw3/6v11aPstXSADTvRTFMyRklqu5NIHkMVQCPwQCAE3346KpEsT5HO2T7
X57sP05alMESjUv1sR260yYC3GUr0dbmf8gthVDhH1SsP3Drn/A3l70xGASnJA46
LCZwAJZ0KI6G/ok17lTZe9Hjwn2DkmVf1CKD7gXjmroYQI9O+etUtD/g+B2AISTG
SP60NakteOBWqmcSirV5npKh/SZR8Il5oaLS+3HerhgwvNDJ078=
-----END CERTIFICATE-----
4 changes: 2 additions & 2 deletions test/ci.pl
Expand Up @@ -183,7 +183,7 @@ sub processEnd
# Build list of packages that need to be installed
my $strPackage =
"make gcc ccache python3-pip git rsync zlib1g-dev libssl-dev libxml2-dev libpq-dev libyaml-dev pkg-config" .
" uncrustify libssh2-1-dev";
" uncrustify libssh2-1-dev valgrind";

# Add lcov when testing coverage
if (vmCoverageC($strVm))
Expand All @@ -194,7 +194,7 @@ sub processEnd
# Extra packages required when testing without containers
if ($strVm eq VM_NONE)
{
$strPackage .= " valgrind liblz4-dev liblz4-tool zstd libzstd-dev bzip2 libbz2-dev";
$strPackage .= " liblz4-dev liblz4-tool zstd libzstd-dev bzip2 libbz2-dev";
}
# Else packages needed for integration tests on containers
else
Expand Down
12 changes: 9 additions & 3 deletions test/define.yaml
Expand Up @@ -608,7 +608,9 @@ unit:
# ----------------------------------------------------------------------------------------------------------------------------
- name: sftp
total: 19
harness: libSsh2
harness:
name: libSsh2
integration: false
harness:
name: fd
shim:
Expand All @@ -635,7 +637,9 @@ unit:
# ----------------------------------------------------------------------------------------------------------------------------
- name: client
total: 1
harness: pq
harness:
name: pq
integration: false

coverage:
- postgres/client
Expand Down Expand Up @@ -881,6 +885,7 @@ unit:
total: 12
harness:
name: backup
integration: false
shim:
command/backup/backup:
function:
Expand Down Expand Up @@ -1004,13 +1009,14 @@ unit:
integration:

# ********************************************************************************************************************************
- name: real
- name: integration
db: true

test:
# ----------------------------------------------------------------------------------------------------------------------------
- name: all
total: 1
harness: host

# **********************************************************************************************************************************
# Performance tests
Expand Down
26 changes: 25 additions & 1 deletion test/lib/pgBackRestTest/Common/CoverageTest.pm
Expand Up @@ -26,7 +26,31 @@ use pgBackRestTest::Common::ContainerTest;
use pgBackRestTest::Common::DefineTest;
use pgBackRestTest::Common::ExecuteTest;
use pgBackRestTest::Common::ListTest;
use pgBackRestTest::Common::RunTest;

####################################################################################################################################
# testRunName
#
# Create module/test names by upper-casing the first letter and then inserting capitals after each -.
####################################################################################################################################
sub testRunName
{
my $strName = shift;
my $bInitCapFirst = shift;

$bInitCapFirst = defined($bInitCapFirst) ? $bInitCapFirst : true;
my $bFirst = true;

my @stryName = split('\-', $strName);
$strName = undef;

foreach my $strPart (@stryName)
{
$strName .= ($bFirst && $bInitCapFirst) || !$bFirst ? ucfirst($strPart) : $strPart;
$bFirst = false;
}

return $strName;
}

####################################################################################################################################
# Generate an lcov configuration file
Expand Down

0 comments on commit 794c577

Please sign in to comment.