Skip to content

Commit 51ec79e

Browse files
janekmiosalyk
authored andcommitted
test: check if no NDCTL-related code is in use without PMem (#30)
DAOS-18296 Signed-off-by: Jan Michalski <jan-marian.michalski@hpe.com>
1 parent ff2f05c commit 51ec79e

13 files changed

Lines changed: 297 additions & 0 deletions

File tree

src/test/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ OBJ_TESTS = \
7070
obj_memcheck\
7171
obj_memcheck_register\
7272
obj_memops\
73+
obj_ndctl_bb\
74+
obj_ndctl_sds\
7375
obj_oid_thread\
7476
obj_out_of_memory\
7577
obj_persist_count\

src/test/obj_ndctl_bb/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
obj_ndctl_bb

src/test/obj_ndctl_bb/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright 2026, Hewlett Packard Enterprise Development LP
3+
4+
TARGET = obj_ndctl_bb
5+
OBJS = obj_ndctl_bb.o
6+
7+
LIBPMEMOBJ=internal-debug
8+
9+
include ../Makefile.inc
10+
LDFLAGS += $(call extract_funcs, obj_ndctl_bb.c)

src/test/obj_ndctl_bb/TEST0

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
# Copyright 2026, Hewlett Packard Enterprise Development LP
4+
#
5+
#
6+
# obj_ndctl_bb/TEST0 -- check if the badblocks-related code is not run when no PMem is in use.
7+
# DAOS-18296
8+
#
9+
10+
. ../unittest/unittest.sh
11+
12+
require_fs_type non-pmem
13+
require_ndctl_enable
14+
require_test_type short
15+
16+
setup
17+
18+
FILE=$DIR/testfile
19+
20+
# obj_ndctl_bb commands
21+
CREATE=c
22+
OPEN=o
23+
24+
expect_normal_exit obj_ndctl_bb $FILE $CREATE
25+
26+
expect_normal_exit obj_ndctl_bb $FILE $OPEN
27+
28+
check
29+
30+
pass

src/test/obj_ndctl_bb/TEST1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
# Copyright 2026, Hewlett Packard Enterprise Development LP
4+
#
5+
#
6+
# obj_ndctl_bb/TEST1 -- check if the executable works as intended. Sanity check.
7+
#
8+
9+
. ../unittest/unittest.sh
10+
11+
require_real_pmem
12+
require_ndctl_enable
13+
require_test_type short
14+
15+
setup
16+
17+
TMP=tmp${UNITTEST_NUM}.log
18+
rm -f $TMP
19+
20+
FILE=$DIR/testfile
21+
22+
# obj_ndctl_bb commands
23+
CREATE=c
24+
OPEN=o
25+
26+
expect_abnormal_exit obj_ndctl_bb $FILE $CREATE
27+
cat $ERR_LOG_FILE >> $TMP
28+
29+
expect_normal_exit $PMEMPOOL$EXESUFFIX create obj $FILE
30+
31+
expect_abnormal_exit obj_ndctl_bb $FILE $OPEN
32+
cat $ERR_LOG_FILE >> $TMP
33+
34+
# move combined error log in place
35+
mv $TMP $ERR_LOG_FILE
36+
37+
check
38+
39+
pass
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{obj_ndctl_bb.c:$(N) __wrap_badblocks_check_poolset} obj_ndctl_bb/TEST1: Error: assertion failure: 0
2+
{obj_ndctl_bb.c:$(N) __wrap_badblocks_recovery_file_exists} obj_ndctl_bb/TEST1: Error: assertion failure: 0
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
/* Copyright 2026, Hewlett Packard Enterprise Development LP */
3+
4+
/*
5+
* obj_ndctl_bb.c -- crashes whenever badblocks-related code is run
6+
*/
7+
8+
#include <libpmemobj.h>
9+
10+
#include "set.h"
11+
12+
#include "unittest.h"
13+
14+
FUNC_MOCK(badblocks_recovery_file_exists, int, struct pool_set *set)
15+
FUNC_MOCK_RUN_DEFAULT {
16+
UT_ASSERT(0);
17+
}
18+
FUNC_MOCK_END
19+
20+
FUNC_MOCK(badblocks_check_poolset, int, struct pool_set *set, int create)
21+
FUNC_MOCK_RUN_DEFAULT {
22+
UT_ASSERT(0);
23+
}
24+
FUNC_MOCK_END
25+
26+
int
27+
main(int argc, char *argv[])
28+
{
29+
START(argc, argv, "obj_ndctl_bb");
30+
if (argc < 3) {
31+
UT_FATAL("usage: %s <path> <c|o>\nc - create\no - open",
32+
argv[0]);
33+
}
34+
35+
const char *path = argv[1];
36+
const char *cmd = argv[2];
37+
PMEMobjpool *pop;
38+
39+
if (strlen(cmd) != 1) {
40+
UT_FATAL("unknown command: %s", cmd);
41+
}
42+
43+
switch (cmd[0]) {
44+
case 'c':
45+
pop = pmemobj_create(path, NULL, PMEMOBJ_MIN_POOL,
46+
0600);
47+
break;
48+
case 'o':
49+
pop = pmemobj_open(path, NULL);
50+
break;
51+
default:
52+
UT_FATAL("unknown command: %s", cmd);
53+
}
54+
55+
UT_ASSERTne(pop, NULL);
56+
57+
pmemobj_close(pop);
58+
59+
DONE(NULL);
60+
}

src/test/obj_ndctl_sds/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
obj_ndctl_sds

src/test/obj_ndctl_sds/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright 2026, Hewlett Packard Enterprise Development LP
3+
4+
TARGET = obj_ndctl_sds
5+
OBJS = obj_ndctl_sds.o
6+
7+
LIBPMEMOBJ=internal-debug
8+
9+
include ../Makefile.inc
10+
LDFLAGS += $(call extract_funcs, obj_ndctl_sds.c)

src/test/obj_ndctl_sds/TEST0

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
# Copyright 2026, Hewlett Packard Enterprise Development LP
4+
#
5+
#
6+
# obj_ndctl_sds/TEST0 -- check if the shutdown-state-related code is not run when no PMem is in use.
7+
# DAOS-18296
8+
#
9+
10+
. ../unittest/unittest.sh
11+
12+
require_fs_type non-pmem
13+
require_ndctl_enable
14+
require_test_type short
15+
16+
setup
17+
18+
FILE=$DIR/testfile
19+
20+
# obj_ndctl_sds commands
21+
CREATE=c
22+
OPEN=o
23+
24+
expect_normal_exit obj_ndctl_sds $FILE $CREATE
25+
26+
expect_normal_exit obj_ndctl_sds $FILE $OPEN
27+
28+
check
29+
30+
pass

0 commit comments

Comments
 (0)