Blame SOURCES/0080-test-Prepare-out-of-line-builds.patch

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