anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone
e0018b
From d12d5f82755db50277e50c8daa97be15107f924d Mon Sep 17 00:00:00 2001
e0018b
From: Dan Williams <dan.j.williams@intel.com>
e0018b
Date: Wed, 5 Jan 2022 13:32:42 -0800
e0018b
Subject: [PATCH 080/217] test: Prepare out of line builds
e0018b
e0018b
In preparation for converting to meson prepare the unit tests to run out of
e0018b
a build directory rather than out of the source directory. Introduce
e0018b
TEST_PATH for the location of the test executables.
e0018b
e0018b
Link: https://lore.kernel.org/r/164141836235.3990253.5237538466465550643.stgit@dwillia2-desk3.amr.corp.intel.com
e0018b
Tested-by: Alison Schofield <alison.schofield@intel.com>
e0018b
Tested-by: Vaibhav Jain <vaibhav@linux.ibm.com>
e0018b
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
---
e0018b
 test/btt-errors.sh     |  4 +---
e0018b
 test/common            | 37 +++++++++++++++++++++----------------
e0018b
 test/dax-pmd.c         | 11 +++++++++--
e0018b
 test/dax.sh            |  6 +++---
e0018b
 test/daxdev-errors.sh  |  4 ++--
e0018b
 test/device-dax-fio.sh |  2 +-
e0018b
 test/dm.sh             |  4 ++--
e0018b
 test/inject-smart.sh   |  2 +-
e0018b
 test/mmap.sh           |  6 +++---
e0018b
 test/monitor.sh        |  6 +++---
e0018b
 test/pmem-errors.sh    |  8 +++-----
e0018b
 test/sub-section.sh    |  4 ++--
e0018b
 test/track-uuid.sh     |  2 +-
e0018b
 13 files changed, 52 insertions(+), 44 deletions(-)
e0018b
e0018b
diff --git a/test/btt-errors.sh b/test/btt-errors.sh
e0018b
index 6e69178..18518d5 100755
e0018b
--- a/test/btt-errors.sh
e0018b
+++ b/test/btt-errors.sh
e0018b
@@ -11,14 +11,12 @@ rc=77
e0018b
 
e0018b
 cleanup()
e0018b
 {
e0018b
-	rm -f $FILE
e0018b
-	rm -f $MNT/$FILE
e0018b
 	if grep -q "$MNT" /proc/mounts; then
e0018b
 		umount $MNT
e0018b
 	else
e0018b
 		rc=77
e0018b
 	fi
e0018b
-	rmdir $MNT
e0018b
+	rm -rf $MNT
e0018b
 }
e0018b
 
e0018b
 force_raw()
e0018b
diff --git a/test/common b/test/common
e0018b
index b6d4712..fb48795 100644
e0018b
--- a/test/common
e0018b
+++ b/test/common
e0018b
@@ -4,27 +4,32 @@
e0018b
 # Global variables
e0018b
 
e0018b
 # NDCTL
e0018b
-#
e0018b
-if [ -f "../ndctl/ndctl" ] && [ -x "../ndctl/ndctl" ]; then
e0018b
-	export NDCTL=../ndctl/ndctl
e0018b
-elif [ -f "./ndctl/ndctl" ] && [ -x "./ndctl/ndctl" ]; then
e0018b
-	export NDCTL=./ndctl/ndctl
e0018b
-else
e0018b
-	echo "Couldn't find an ndctl binary"
e0018b
-	exit 1
e0018b
+if [ -z $NDCTL ]; then
e0018b
+	if [ -f "../ndctl/ndctl" ] && [ -x "../ndctl/ndctl" ]; then
e0018b
+		export NDCTL=../ndctl/ndctl
e0018b
+	elif [ -f "./ndctl/ndctl" ] && [ -x "./ndctl/ndctl" ]; then
e0018b
+		export NDCTL=./ndctl/ndctl
e0018b
+	else
e0018b
+		echo "Couldn't find an ndctl binary"
e0018b
+		exit 1
e0018b
+	fi
e0018b
 fi
e0018b
 
e0018b
 # DAXCTL
e0018b
-#
e0018b
-if [ -f "../daxctl/daxctl" ] && [ -x "../daxctl/daxctl" ]; then
e0018b
-	export DAXCTL=../daxctl/daxctl
e0018b
-elif [ -f "./daxctl/daxctl" ] && [ -x "./daxctl/daxctl" ]; then
e0018b
-	export DAXCTL=./daxctl/daxctl
e0018b
-else
e0018b
-	echo "Couldn't find an daxctl binary"
e0018b
-	exit 1
e0018b
+if [ -z $DAXCTL ]; then
e0018b
+	if [ -f "../daxctl/daxctl" ] && [ -x "../daxctl/daxctl" ]; then
e0018b
+		export DAXCTL=../daxctl/daxctl
e0018b
+	elif [ -f "./daxctl/daxctl" ] && [ -x "./daxctl/daxctl" ]; then
e0018b
+		export DAXCTL=./daxctl/daxctl
e0018b
+	else
e0018b
+		echo "Couldn't find an daxctl binary"
e0018b
+		exit 1
e0018b
+	fi
e0018b
 fi
e0018b
 
e0018b
+if [ -z $TEST_PATH ]; then
e0018b
+	export TEST_PATH=.
e0018b
+fi
e0018b
 
e0018b
 # NFIT_TEST_BUS[01]
e0018b
 #
e0018b
diff --git a/test/dax-pmd.c b/test/dax-pmd.c
e0018b
index 7648e34..f840875 100644
e0018b
--- a/test/dax-pmd.c
e0018b
+++ b/test/dax-pmd.c
e0018b
@@ -24,7 +24,8 @@
e0018b
 	__func__, __LINE__, strerror(errno))
e0018b
 #define faili(i) fprintf(stderr, "%s: failed at: %d: %d (%s)\n", \
e0018b
 	__func__, __LINE__, i, strerror(errno))
e0018b
-#define TEST_FILE "test_dax_data"
e0018b
+#define TEST_DIR "test_dax_mnt"
e0018b
+#define TEST_FILE TEST_DIR "/test_dax_data"
e0018b
 
e0018b
 #define REGION_MEM_SIZE 4096*4
e0018b
 #define REGION_PM_SIZE        4096*512
e0018b
@@ -171,8 +172,14 @@ int test_dax_directio(int dax_fd, unsigned long align, void *dax_addr, off_t off
e0018b
 		}
e0018b
 		rc = -ENXIO;
e0018b
 
e0018b
+		rc = mkdir(TEST_DIR, 0600);
e0018b
+		if (rc < 0 && errno != EEXIST) {
e0018b
+			faili(i);
e0018b
+			munmap(addr, 2 * align);
e0018b
+			break;
e0018b
+		}
e0018b
 		fd2 = open(TEST_FILE, O_CREAT|O_TRUNC|O_DIRECT|O_RDWR,
e0018b
-				DEFFILEMODE);
e0018b
+				0600);
e0018b
 		if (fd2 < 0) {
e0018b
 			faili(i);
e0018b
 			munmap(addr, 2*align);
e0018b
diff --git a/test/dax.sh b/test/dax.sh
e0018b
index bcdd4e9..bb9848b 100755
e0018b
--- a/test/dax.sh
e0018b
+++ b/test/dax.sh
e0018b
@@ -15,13 +15,13 @@ cleanup() {
e0018b
 	else
e0018b
 		rc=77
e0018b
 	fi
e0018b
-	rmdir $MNT
e0018b
+	rm -rf $MNT
e0018b
 	exit $rc
e0018b
 }
e0018b
 
e0018b
 run_test() {
e0018b
 	rc=0
e0018b
-	if ! trace-cmd record -e fs_dax:dax_pmd_fault_done ./dax-pmd $MNT/$FILE; then
e0018b
+	if ! trace-cmd record -e fs_dax:dax_pmd_fault_done $TEST_PATH/dax-pmd $MNT/$FILE; then
e0018b
 		rc=$?
e0018b
 		if [ "$rc" -ne 77 ] && [ "$rc" -ne 0 ]; then
e0018b
 			cleanup "$1"
e0018b
@@ -104,7 +104,7 @@ set -e
e0018b
 mkdir -p $MNT
e0018b
 trap 'err $LINENO cleanup' ERR
e0018b
 
e0018b
-dev=$(./dax-dev)
e0018b
+dev=$($TEST_PATH/dax-dev)
e0018b
 json=$($NDCTL list -N -n $dev)
e0018b
 eval $(json2var <<< "$json")
e0018b
 rc=1
e0018b
diff --git a/test/daxdev-errors.sh b/test/daxdev-errors.sh
e0018b
index e13453d..7f79718 100755
e0018b
--- a/test/daxdev-errors.sh
e0018b
+++ b/test/daxdev-errors.sh
e0018b
@@ -62,8 +62,8 @@ read sector len < /sys/bus/nd/devices/$region/badblocks
e0018b
 echo "sector: $sector len: $len"
e0018b
 
e0018b
 # run the daxdev-errors test
e0018b
-test -x ./daxdev-errors
e0018b
-./daxdev-errors $busdev $region
e0018b
+test -x $TEST_PATH/daxdev-errors
e0018b
+$TEST_PATH/daxdev-errors $busdev $region
e0018b
 
e0018b
 # check badblocks, should be empty
e0018b
 if read sector len < /sys/bus/platform/devices/nfit_test.0/$busdev/$region/badblocks; then
e0018b
diff --git a/test/device-dax-fio.sh b/test/device-dax-fio.sh
e0018b
index f57a9d2..c43ac05 100755
e0018b
--- a/test/device-dax-fio.sh
e0018b
+++ b/test/device-dax-fio.sh
e0018b
@@ -18,7 +18,7 @@ if ! fio --enghelp | grep -q "dev-dax"; then
e0018b
 	exit 77
e0018b
 fi
e0018b
 
e0018b
-dev=$(./dax-dev)
e0018b
+dev=$($TEST_PATH/dax-dev)
e0018b
 for align in 4k 2m 1g
e0018b
 do
e0018b
 	json=$($NDCTL create-namespace -m devdax -a $align -f -e $dev)
e0018b
diff --git a/test/dm.sh b/test/dm.sh
e0018b
index 4656e5b..b780a65 100755
e0018b
--- a/test/dm.sh
e0018b
+++ b/test/dm.sh
e0018b
@@ -8,7 +8,7 @@ SKIP=77
e0018b
 FAIL=1
e0018b
 SUCCESS=0
e0018b
 
e0018b
-. ./common
e0018b
+. $(dirname $0)/common
e0018b
 
e0018b
 MNT=test_dax_mnt
e0018b
 TEST_DM_PMEM=/dev/mapper/test_pmem
e0018b
@@ -30,7 +30,7 @@ cleanup() {
e0018b
 	if [ -L $TEST_DM_PMEM ]; then
e0018b
 		dmsetup remove $TEST_DM_PMEM
e0018b
 	fi
e0018b
-	rmdir $MNT
e0018b
+	rm -rf $MNT
e0018b
 	# opportunistic cleanup, not fatal if these fail
e0018b
 	namespaces=$($NDCTL list -N | jq -r ".[] | select(.name==\"$NAME\") | .dev")
e0018b
 	for i in $namespaces
e0018b
diff --git a/test/inject-smart.sh b/test/inject-smart.sh
e0018b
index 4ca83b8..8b91360 100755
e0018b
--- a/test/inject-smart.sh
e0018b
+++ b/test/inject-smart.sh
e0018b
@@ -170,7 +170,7 @@ check_prereq "jq"
e0018b
 modprobe nfit_test
e0018b
 rc=1
e0018b
 
e0018b
-jlist=$(./list-smart-dimm -b $bus)
e0018b
+jlist=$($TEST_PATH/list-smart-dimm -b $bus)
e0018b
 dimm="$(jq '.[]."dev"?, ."dev"?' <<< $jlist | sort | head -1 | xargs)"
e0018b
 test -n "$dimm"
e0018b
 
e0018b
diff --git a/test/mmap.sh b/test/mmap.sh
e0018b
index 50a1d34..760257d 100755
e0018b
--- a/test/mmap.sh
e0018b
+++ b/test/mmap.sh
e0018b
@@ -7,7 +7,7 @@
e0018b
 MNT=test_mmap_mnt
e0018b
 FILE=image
e0018b
 DEV=""
e0018b
-TEST=./mmap
e0018b
+TEST=$TEST_PATH/mmap
e0018b
 rc=77
e0018b
 
e0018b
 cleanup() {
e0018b
@@ -17,7 +17,7 @@ cleanup() {
e0018b
 	else
e0018b
 		rc=77
e0018b
 	fi
e0018b
-	rmdir $MNT
e0018b
+	rm -rf $MNT
e0018b
 	exit $rc
e0018b
 }
e0018b
 
e0018b
@@ -49,7 +49,7 @@ set -e
e0018b
 mkdir -p $MNT
e0018b
 trap 'err $LINENO cleanup' ERR
e0018b
 
e0018b
-dev=$(./dax-dev)
e0018b
+dev=$($TEST_PATH/dax-dev)
e0018b
 json=$($NDCTL list -N -n $dev)
e0018b
 eval $(json2var <<< "$json")
e0018b
 DEV="/dev/${blockdev}"
e0018b
diff --git a/test/monitor.sh b/test/monitor.sh
e0018b
index 6aa4196..e58c908 100755
e0018b
--- a/test/monitor.sh
e0018b
+++ b/test/monitor.sh
e0018b
@@ -31,7 +31,7 @@ start_monitor()
e0018b
 set_smart_supported_bus()
e0018b
 {
e0018b
 	smart_supported_bus=$NFIT_TEST_BUS0
e0018b
-	monitor_dimms=$(./list-smart-dimm -b $smart_supported_bus | jq -r .[0].dev)
e0018b
+	monitor_dimms=$($TEST_PATH/list-smart-dimm -b $smart_supported_bus | jq -r .[0].dev)
e0018b
 	if [ -z $monitor_dimms ]; then
e0018b
 		smart_supported_bus=$NFIT_TEST_BUS1
e0018b
 	fi
e0018b
@@ -39,14 +39,14 @@ set_smart_supported_bus()
e0018b
 
e0018b
 get_monitor_dimm()
e0018b
 {
e0018b
-	jlist=$(./list-smart-dimm -b $smart_supported_bus $1)
e0018b
+	jlist=$($TEST_PATH/list-smart-dimm -b $smart_supported_bus $1)
e0018b
 	monitor_dimms=$(jq '.[]."dev"?, ."dev"?' <<<$jlist | sort | uniq | xargs)
e0018b
 	echo $monitor_dimms
e0018b
 }
e0018b
 
e0018b
 call_notify()
e0018b
 {
e0018b
-	./smart-notify $smart_supported_bus
e0018b
+	$TEST_PATH/smart-notify $smart_supported_bus
e0018b
 	sync; sleep 3
e0018b
 }
e0018b
 
e0018b
diff --git a/test/pmem-errors.sh b/test/pmem-errors.sh
e0018b
index 2065780..9a59c25 100755
e0018b
--- a/test/pmem-errors.sh
e0018b
+++ b/test/pmem-errors.sh
e0018b
@@ -10,14 +10,12 @@ rc=77
e0018b
 
e0018b
 cleanup()
e0018b
 {
e0018b
-	rm -f $FILE
e0018b
-	rm -f $MNT/$FILE
e0018b
 	if [ -n "$blockdev" ]; then
e0018b
 		umount /dev/$blockdev
e0018b
 	else
e0018b
 		rc=77
e0018b
 	fi
e0018b
-	rmdir $MNT
e0018b
+	rm -rf $MNT
e0018b
 }
e0018b
 
e0018b
 check_min_kver "4.7" || do_skip "may lack dax error handling"
e0018b
@@ -82,8 +80,8 @@ echo $start_sect 8 > /sys/block/$blockdev/badblocks
e0018b
 dd if=$MNT/$FILE of=/dev/null iflag=direct bs=4096 count=1 && err $LINENO || true
e0018b
 
e0018b
 # run the dax-errors test
e0018b
-test -x ./dax-errors
e0018b
-./dax-errors $MNT/$FILE
e0018b
+test -x $TEST_PATH/dax-errors
e0018b
+$TEST_PATH/dax-errors $MNT/$FILE
e0018b
 
e0018b
 # TODO: disable this check till we have clear-on-write in the kernel
e0018b
 #if read sector len < /sys/block/$blockdev/badblocks; then
e0018b
diff --git a/test/sub-section.sh b/test/sub-section.sh
e0018b
index 92ae816..77b9633 100755
e0018b
--- a/test/sub-section.sh
e0018b
+++ b/test/sub-section.sh
e0018b
@@ -8,7 +8,7 @@ SKIP=77
e0018b
 FAIL=1
e0018b
 SUCCESS=0
e0018b
 
e0018b
-. ./common
e0018b
+. $(dirname $0)/common
e0018b
 
e0018b
 check_min_kver "5.3" || do_skip "may lack align sub-section hotplug support"
e0018b
 
e0018b
@@ -30,7 +30,7 @@ cleanup() {
e0018b
 	if mountpoint -q $MNT; then
e0018b
 		umount $MNT
e0018b
 	fi
e0018b
-	rmdir $MNT
e0018b
+	rm -rf $MNT
e0018b
 	# opportunistic cleanup, not fatal if these fail
e0018b
 	namespaces=$($NDCTL list -N | jq -r ".[] | select(.name==\"$NAME\") | .dev")
e0018b
 	for i in $namespaces
e0018b
diff --git a/test/track-uuid.sh b/test/track-uuid.sh
e0018b
index 3bacd2c..a967d0e 100755
e0018b
--- a/test/track-uuid.sh
e0018b
+++ b/test/track-uuid.sh
e0018b
@@ -5,7 +5,7 @@
e0018b
 blockdev=""
e0018b
 rc=77
e0018b
 
e0018b
-. ./common
e0018b
+. $(dirname $0)/common
e0018b
 
e0018b
 set -e
e0018b
 trap 'err $LINENO' ERR
e0018b
-- 
e0018b
2.27.0
e0018b