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

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