diff --git a/src/test/Makefile b/src/test/Makefile index c3bd32990..c223ccae6 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -70,6 +70,8 @@ OBJ_TESTS = \ obj_memcheck\ obj_memcheck_register\ obj_memops\ + obj_ndctl_bb\ + obj_ndctl_sds\ obj_oid_thread\ obj_out_of_memory\ obj_persist_count\ diff --git a/src/test/obj_ndctl_bb/.gitignore b/src/test/obj_ndctl_bb/.gitignore new file mode 100644 index 000000000..1f5fdc3a5 --- /dev/null +++ b/src/test/obj_ndctl_bb/.gitignore @@ -0,0 +1 @@ +obj_ndctl_bb diff --git a/src/test/obj_ndctl_bb/Makefile b/src/test/obj_ndctl_bb/Makefile new file mode 100644 index 000000000..0c9ede86c --- /dev/null +++ b/src/test/obj_ndctl_bb/Makefile @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2026, Hewlett Packard Enterprise Development LP + +TARGET = obj_ndctl_bb +OBJS = obj_ndctl_bb.o + +LIBPMEMOBJ=internal-debug + +include ../Makefile.inc +LDFLAGS += $(call extract_funcs, obj_ndctl_bb.c) diff --git a/src/test/obj_ndctl_bb/TEST0 b/src/test/obj_ndctl_bb/TEST0 new file mode 100755 index 000000000..d4e670de3 --- /dev/null +++ b/src/test/obj_ndctl_bb/TEST0 @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2026, Hewlett Packard Enterprise Development LP +# +# +# obj_ndctl_bb/TEST0 -- check if the badblocks-related code is not run when no PMem is in use. +# DAOS-18296 +# + +. ../unittest/unittest.sh + +require_fs_type non-pmem +require_ndctl_enable +require_test_type short + +setup + +FILE=$DIR/testfile + +# obj_ndctl_bb commands +CREATE=c +OPEN=o + +expect_normal_exit obj_ndctl_bb $FILE $CREATE + +expect_normal_exit obj_ndctl_bb $FILE $OPEN + +check + +pass diff --git a/src/test/obj_ndctl_bb/TEST1 b/src/test/obj_ndctl_bb/TEST1 new file mode 100755 index 000000000..b01d40746 --- /dev/null +++ b/src/test/obj_ndctl_bb/TEST1 @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2026, Hewlett Packard Enterprise Development LP +# +# +# obj_ndctl_bb/TEST1 -- check if the executable works as intended. Sanity check. +# + +. ../unittest/unittest.sh + +require_real_pmem +require_ndctl_enable +require_test_type short + +setup + +TMP=tmp${UNITTEST_NUM}.log +rm -f $TMP + +FILE=$DIR/testfile + +# obj_ndctl_bb commands +CREATE=c +OPEN=o + +expect_abnormal_exit obj_ndctl_bb $FILE $CREATE +cat $ERR_LOG_FILE >> $TMP + +expect_normal_exit $PMEMPOOL$EXESUFFIX create obj $FILE + +expect_abnormal_exit obj_ndctl_bb $FILE $OPEN +cat $ERR_LOG_FILE >> $TMP + +# move combined error log in place +mv $TMP $ERR_LOG_FILE + +check + +pass diff --git a/src/test/obj_ndctl_bb/err1.log.match b/src/test/obj_ndctl_bb/err1.log.match new file mode 100644 index 000000000..2f43dc7dc --- /dev/null +++ b/src/test/obj_ndctl_bb/err1.log.match @@ -0,0 +1,2 @@ +{obj_ndctl_bb.c:$(N) __wrap_badblocks_check_poolset} obj_ndctl_bb/TEST1: Error: assertion failure: 0 +{obj_ndctl_bb.c:$(N) __wrap_badblocks_recovery_file_exists} obj_ndctl_bb/TEST1: Error: assertion failure: 0 diff --git a/src/test/obj_ndctl_bb/obj_ndctl_bb.c b/src/test/obj_ndctl_bb/obj_ndctl_bb.c new file mode 100644 index 000000000..993930e89 --- /dev/null +++ b/src/test/obj_ndctl_bb/obj_ndctl_bb.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2026, Hewlett Packard Enterprise Development LP */ + +/* + * obj_ndctl_bb.c -- crashes whenever badblocks-related code is run + */ + +#include + +#include "set.h" + +#include "unittest.h" + +FUNC_MOCK(badblocks_recovery_file_exists, int, struct pool_set *set) + FUNC_MOCK_RUN_DEFAULT { + UT_ASSERT(0); + } +FUNC_MOCK_END + +FUNC_MOCK(badblocks_check_poolset, int, struct pool_set *set, int create) + FUNC_MOCK_RUN_DEFAULT { + UT_ASSERT(0); + } +FUNC_MOCK_END + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "obj_ndctl_bb"); + if (argc < 3) { + UT_FATAL("usage: %s \nc - create\no - open", + argv[0]); + } + + const char *path = argv[1]; + const char *cmd = argv[2]; + PMEMobjpool *pop; + + if (strlen(cmd) != 1) { + UT_FATAL("unknown command: %s", cmd); + } + + switch (cmd[0]) { + case 'c': + pop = pmemobj_create(path, NULL, PMEMOBJ_MIN_POOL, + 0600); + break; + case 'o': + pop = pmemobj_open(path, NULL); + break; + default: + UT_FATAL("unknown command: %s", cmd); + } + + UT_ASSERTne(pop, NULL); + + pmemobj_close(pop); + + DONE(NULL); +} diff --git a/src/test/obj_ndctl_sds/.gitignore b/src/test/obj_ndctl_sds/.gitignore new file mode 100644 index 000000000..61c6a097a --- /dev/null +++ b/src/test/obj_ndctl_sds/.gitignore @@ -0,0 +1 @@ +obj_ndctl_sds diff --git a/src/test/obj_ndctl_sds/Makefile b/src/test/obj_ndctl_sds/Makefile new file mode 100644 index 000000000..35442695a --- /dev/null +++ b/src/test/obj_ndctl_sds/Makefile @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2026, Hewlett Packard Enterprise Development LP + +TARGET = obj_ndctl_sds +OBJS = obj_ndctl_sds.o + +LIBPMEMOBJ=internal-debug + +include ../Makefile.inc +LDFLAGS += $(call extract_funcs, obj_ndctl_sds.c) diff --git a/src/test/obj_ndctl_sds/TEST0 b/src/test/obj_ndctl_sds/TEST0 new file mode 100755 index 000000000..ccc519896 --- /dev/null +++ b/src/test/obj_ndctl_sds/TEST0 @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2026, Hewlett Packard Enterprise Development LP +# +# +# obj_ndctl_sds/TEST0 -- check if the shutdown-state-related code is not run when no PMem is in use. +# DAOS-18296 +# + +. ../unittest/unittest.sh + +require_fs_type non-pmem +require_ndctl_enable +require_test_type short + +setup + +FILE=$DIR/testfile + +# obj_ndctl_sds commands +CREATE=c +OPEN=o + +expect_normal_exit obj_ndctl_sds $FILE $CREATE + +expect_normal_exit obj_ndctl_sds $FILE $OPEN + +check + +pass diff --git a/src/test/obj_ndctl_sds/TEST1 b/src/test/obj_ndctl_sds/TEST1 new file mode 100755 index 000000000..44d9b37eb --- /dev/null +++ b/src/test/obj_ndctl_sds/TEST1 @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2026, Hewlett Packard Enterprise Development LP +# +# +# obj_ndctl_sds/TEST1 -- check if the executable works as intended. Sanity check. +# + +. ../unittest/unittest.sh + +require_real_pmem +require_ndctl_enable +require_test_type short + +setup + +TMP=tmp${UNITTEST_NUM}.log +rm -f $TMP + +FILE=$DIR/testfile + +# obj_ndctl_sds commands +CREATE=c +OPEN=o + +expect_abnormal_exit obj_ndctl_sds $FILE $CREATE +cat $ERR_LOG_FILE >> $TMP + +# The crashed process leaves $FILE in a half-baked state. Let's do it right. +rm -f $FILE +expect_normal_exit $PMEMPOOL$EXESUFFIX create obj $FILE + +expect_abnormal_exit obj_ndctl_sds $FILE $OPEN +cat $ERR_LOG_FILE >> $TMP + +# move combined error log in place +mv $TMP $ERR_LOG_FILE + +check + +pass diff --git a/src/test/obj_ndctl_sds/err1.log.match b/src/test/obj_ndctl_sds/err1.log.match new file mode 100644 index 000000000..7f0e7cab5 --- /dev/null +++ b/src/test/obj_ndctl_sds/err1.log.match @@ -0,0 +1,2 @@ +{obj_ndctl_sds.c:$(N) __wrap_shutdown_state_init} obj_ndctl_sds/TEST1: Error: assertion failure: 0 +{obj_ndctl_sds.c:$(N) __wrap_shutdown_state_init} obj_ndctl_sds/TEST1: Error: assertion failure: 0 diff --git a/src/test/obj_ndctl_sds/obj_ndctl_sds.c b/src/test/obj_ndctl_sds/obj_ndctl_sds.c new file mode 100644 index 000000000..ab3b75e45 --- /dev/null +++ b/src/test/obj_ndctl_sds/obj_ndctl_sds.c @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2026, Hewlett Packard Enterprise Development LP */ + +/* + * obj_ndctl_sds.c -- crashes whenever shutdown-state-related code is run + */ + +#include + +#include "set.h" + +#include "unittest.h" + +FUNC_MOCK(shutdown_state_init, int, struct shutdown_state *sds, + struct pool_replica *rep) + FUNC_MOCK_RUN_DEFAULT { + UT_ASSERT(0); + } +FUNC_MOCK_END + +FUNC_MOCK(shutdown_state_set_dirty, void, struct shutdown_state *sds, + struct pool_replica *rep) + FUNC_MOCK_RUN_DEFAULT { + UT_ASSERT(0); + } +FUNC_MOCK_END + +FUNC_MOCK(shutdown_state_check, int, struct shutdown_state *curr_sds, + struct shutdown_state *pool_sds, struct pool_replica *rep) + FUNC_MOCK_RUN_DEFAULT { + UT_ASSERT(0); + } +FUNC_MOCK_END + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "obj_ndctl_sds"); + if (argc < 3) { + UT_FATAL("usage: %s \nc - create\no - open", + argv[0]); + } + + const char *path = argv[1]; + const char *cmd = argv[2]; + PMEMobjpool *pop; + + if (strlen(cmd) != 1) { + UT_FATAL("unknown command: %s", cmd); + } + + switch (cmd[0]) { + case 'c': + pop = pmemobj_create(path, NULL, PMEMOBJ_MIN_POOL, + 0600); + break; + case 'o': + pop = pmemobj_open(path, NULL); + break; + default: + UT_FATAL("unknown command: %s", cmd); + } + + UT_ASSERTne(pop, NULL); + + pmemobj_close(pop); + + DONE(NULL); +}