Skip to content

Commit

Permalink
test: introduce a test reproducing the #5583
Browse files Browse the repository at this point in the history
Ref: #5583

Signed-off-by: Jan Michalski <jan.michalski@intel.com>
  • Loading branch information
janekmi committed Jun 11, 2024
1 parent 6075d9e commit 8e09ed4
Show file tree
Hide file tree
Showing 13 changed files with 698 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ OBJ_TESTS = \
obj_tx_realloc\
obj_tx_strdup\
obj_tx_user_data\
obj_ulog_advanced\
obj_ulog_size\
obj_zones

Expand Down
1 change: 1 addition & 0 deletions src/test/obj_ulog_advanced/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj_ulog_advanced
17 changes: 17 additions & 0 deletions src/test/obj_ulog_advanced/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024, Intel Corporation

#
# src/test/obj_ulog_advanced/Makefile -- build obj_ulog_advanced test
#
TARGET = obj_ulog_advanced
OBJS = obj_ulog_advanced.o

BUILD_STATIC_DEBUG=n
BUILD_STATIC_NONDEBUG=n

# required for proper mock integration
LIBPMEMOBJ=internal-debug

include ../Makefile.inc
LDFLAGS += $(call extract_funcs, obj_ulog_advanced.c)
25 changes: 25 additions & 0 deletions src/test/obj_ulog_advanced/TEST0
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024, Intel Corporation

#
# src/test/obj_ulog_advanced/TEST0 -- a kick-start test
#
# Since this directory contains both Bash-based and Python-based tests and match
# files are used by some of them both groups cannot have overlapping numbering.
# Hence the real Bash-based tests' numbering starts where the Python-based tests'
# numbering ends. However, the Bash-based test framework relies on the existence
# of this TEST0 file to keep looking for other Bash-based tests.
#

. ../unittest/unittest.sh

. ./common.sh

require_fs_type any
require_build_type $COMMON_BUILD_TYPE
require_test_type short

setup

pass
29 changes: 29 additions & 0 deletions src/test/obj_ulog_advanced/TEST8
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024, Intel Corporation

#
# src/test/obj_ulog_advanced/TEST8 -- a test employing pmreorder WITHOUT error
# injection
#
# Please see the source code for the details of the tested scenario.
#

. ../unittest/unittest.sh

. ./common.sh

common_require

setup

ERROR_INJECT=0 # an error is NOT being injected
common_setup $ERROR_INJECT

common_init
common_record
common_replay_and_check $ERROR_INJECT

check

pass
29 changes: 29 additions & 0 deletions src/test/obj_ulog_advanced/TEST9
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024, Intel Corporation

#
# src/test/obj_ulog_advanced/TEST9 -- a test employing pmreorder WITH error
# injection
#
# Please see the source code for the details of the tested scenario.
#

. ../unittest/unittest.sh

. ./common.sh

common_require

setup

ERROR_INJECT=1 # an error is being injected
common_setup $ERROR_INJECT

common_init
common_record
common_replay_and_check $ERROR_INJECT

check

pass
82 changes: 82 additions & 0 deletions src/test/obj_ulog_advanced/TESTS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!../env.py
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024, Intel Corporation
#


import testframework as t
from testframework import granularity as g
from os import path


SIGABRT_EXIT_CODE = 134


@g.require_granularity(g.ANY)
# The 'debug' build is chosen arbitrarily to ensure these tests are run only
# once. No dynamic libraries are used nor .static_* builds are available.
@t.require_build('debug')
class OBJ_ULOG_ADVANCED(t.Test):
test_type = t.Short
test_case = 'test_init_publish_abort_and_verify'
error_inject = False

def run(self, ctx):
testfile = path.join(ctx.testdir, f'testfile{self.testnum}')
stderr_file = f'err{self.testnum}.log'
error_inject = 1 if self.error_inject else 0
# The verify will abort the process when the injected error will be
# discovered.
expected_exitcode = SIGABRT_EXIT_CODE if self.error_inject else 0
ctx.exec('obj_ulog_advanced', self.test_case, testfile, self.slot_num,
error_inject, expected_exitcode=expected_exitcode,
stderr_file=stderr_file)


class TEST0(OBJ_ULOG_ADVANCED):
# The number of slots not fully populating a single persistent redo log.
# Please see the source code for details.
slot_num = 30


class TEST1(OBJ_ULOG_ADVANCED):
# The number of slots exactly populating a single persistent redo log.
# Please see the source code for details.
slot_num = 40


class TEST2(OBJ_ULOG_ADVANCED):
# The number of slots between the one used by TEST1 and TEST3.
slot_num = 50


class TEST3(OBJ_ULOG_ADVANCED):
# The number of slots exactly populating a persistent shadow log without
# triggering its growth. Please see the source code for details.
slot_num = 60


class TEST4(OBJ_ULOG_ADVANCED):
# The number of slots populating more than a single persistent redo log.
# It should trigger a persistent shadow log growth.
# Please see the source code for details.
slot_num = 70


# Note: Since the injected error value translates to 40 slots and it ought to
# be smaller than the number of populated slots, the error injection only takes
# effect when the number of populated slots is > 40.

class TEST5(TEST2):
# For details on the injected error please see the source code.
error_inject = True


class TEST6(TEST3):
# For details on the injected error please see the source code.
error_inject = True


class TEST7(TEST4):
# For details on the injected error please see the source code.
error_inject = True
62 changes: 62 additions & 0 deletions src/test/obj_ulog_advanced/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024, Intel Corporation

#
# src/test/obj_ulog_advanced/common.sh -- common bits and pieces
#

# The 'debug' build is chosen arbitrarily to ensure these tests are run only
# once. No dynamic libraries are used nor .static_* builds are available.
COMMON_BUILD_TYPE=debug

function common_require() {
require_fs_type any
require_build_type $COMMON_BUILD_TYPE
require_test_type medium
require_pmemcheck_version_ge 1 0
require_pmemcheck_version_lt 2 0
require_pmreorder
}

function common_setup() {
ERROR_INJECT=$1

export PMEMOBJ_LOG_LEVEL=10

BIN="./obj_ulog_advanced$EXESUFFIX"
TESTFILE=$DIR/testfile
ERR_LOG_FILE=err$UNITTEST_NUM.log
# This value was labourly calculated. Please see the source file for
# details.
SLOTS_NUM=60
PMEMCHECK_CMD="$BIN test_publish $TESTFILE $SLOTS_NUM $ERROR_INJECT"
PMREORDER_CMD="$BIN test_verify $SLOTS_NUM"
}

function common_init() {
expect_normal_exit $BIN test_init $TESTFILE
}

function common_record() {
pmreorder_create_store_log $TESTFILE "$PMEMCHECK_CMD"
}

function common_replay_and_check() {
ERROR_INJECT=$1

# skip reordering and checking stores outside of the markers
DEFAULT_ENGINE=NoReorderNoCheck
# The accumulative reordering is sufficient considering the nature of
# the scenario at hand where the key risk is that not all stores
# will be executed. The order of these stores is irrelevant.
# Please see the source code for the details of the tested scenario.
# Note: ReorderFull is too time-consuming for this scenario.
EXTENDED_MACROS="PMREORDER_PUBLISH=ReorderAccumulative"

if [ $ERROR_INJECT -eq 0 ]; then
pmreorder_expect_success $DEFAULT_ENGINE "$EXTENDED_MACROS" "$PMREORDER_CMD"
else
pmreorder_expect_failure $DEFAULT_ENGINE "$EXTENDED_MACROS" "$PMREORDER_CMD"
fi
}
1 change: 1 addition & 0 deletions src/test/obj_ulog_advanced/err5.log.match
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{$(nW).c:$(N) verify} obj_ulog_advanced/TEST$(N): Error: assertion failure: rootp->slots[i] (0x0) == exp (0x1)
1 change: 1 addition & 0 deletions src/test/obj_ulog_advanced/err6.log.match
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{$(nW).c:$(N) verify} obj_ulog_advanced/TEST$(N): Error: assertion failure: rootp->slots[i] (0x0) == exp (0x1)
1 change: 1 addition & 0 deletions src/test/obj_ulog_advanced/err7.log.match
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{$(nW).c:$(N) verify} obj_ulog_advanced/TEST$(N): Error: assertion failure: rootp->slots[i] (0x0) == exp (0x1)
1 change: 1 addition & 0 deletions src/test/obj_ulog_advanced/err9.log.match
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{$(nW).c:$(N) verify} obj_ulog_advanced/TEST$(N): Error: assertion failure: rootp->slots[i] (0x0) == exp (0x1)
Loading

0 comments on commit 8e09ed4

Please sign in to comment.