ndctl, test: fix tests for the array vs object listing fix
Vishal Verma
maintainerPATCH 1/2 ndctl, test: fix tests for the array vs object listing fix
The commit below updated json listings to always be arrays unless, potentially, --human was specified. As a fallout of the change, some unit tests that used jq to look for certain elements, or the json2var conversion broke in certain cases. Fix the jq query in sector-mode.sh, and fix json2var in test/common. The 'destructive' class of unit tests still need to be converted to the test/common scheme, and subsequently have their own local json2var instances. These will be fixed in a future commit by simply performing the test/common conversion.
--- test/common | 2 +- test/sector-mode.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
test/common +1 -1
@@ -79,5 +79,5 @@ _cleanup() # json2var() { - sed -e "s/[{}\",]//g; s/:/=/g" + sed -e "s/[{}\",]//g; s/\[//g; s/\]//g; s/:/=/g" }
test/sector-mode.sh +1 -1
@@ -31,7 +31,7 @@ $NDCTL enable-region -b $NFIT_TEST_BUS1 all rc=1 query=". | sort_by(.size) | reverse | .[0].dev" NAMESPACE=$($NDCTL list -b $NFIT_TEST_BUS1 -N | jq -r "$query") -REGION=$($NDCTL list -R --namespace=$NAMESPACE | jq -r ".dev") +REGION=$($NDCTL list -R --namespace=$NAMESPACE | jq -r "(.[]) | .dev") echo 0 > /sys/bus/nd/devices/$REGION/read_only $NDCTL create-namespace --no-autolabel -e $NAMESPACE -m sector -f -l 4K $NDCTL create-namespace --no-autolabel -e $NAMESPACE -m dax -f -a 4K
Signature · 6 lines
2.14.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH 2/2 ndctl, test: convert remaining tests to use test/common
The original test/common conversions missed the --enable-destructive class of tests. The json single object vs. array changes prompted changes to the json2var definitions, which these tests had a local copy of. Instead of fixing up these local copies, take the change to properly convert these tests to using test/common.
--- test/dax.sh | 18 +++++++++--------- test/device-dax-fio.sh | 23 +++++------------------ test/mmap.sh | 12 +++++------- 3 files changed, 19 insertions(+), 34 deletions(-)
test/dax.sh +9 -9
@@ -11,13 +11,13 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. +. ./common + MNT=test_dax_mnt FILE=image -NDCTL="../ndctl/ndctl" -json2var="s/[{}\",]//g; s/:/=/g" blockdev="" -err() { +cleanup() { echo "test-dax: failed at line $1" if [ -n "$blockdev" ]; then umount /dev/$blockdev
@@ -40,11 +40,11 @@ run_test() { set -e mkdir -p $MNT -trap 'err $LINENO' ERR +trap 'err $LINENO cleanup' ERR dev=$(./dax-dev) json=$($NDCTL list -N -n $dev) -eval $(echo $json | sed -e "$json2var") +eval $(json2var <<< "$json") rc=1 mkfs.ext4 /dev/$blockdev
@@ -55,7 +55,7 @@ umount $MNT # convert pmem to put the memmap on the device json=$($NDCTL create-namespace -m fsdax -M dev -f -e $dev) -eval $(echo $json | sed -e "$json2var") +eval $(json2var <<< "$json") [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 #note the blockdev returned from ndctl create-namespace lacks the /dev prefix
@@ -66,7 +66,7 @@ run_test umount $MNT json=$($NDCTL create-namespace -m raw -f -e $dev) -eval $(echo $json | sed -e "$json2var") +eval $(json2var <<< "$json") [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 mkfs.xfs -f /dev/$blockdev
@@ -77,7 +77,7 @@ umount $MNT # convert pmem to put the memmap on the device json=$($NDCTL create-namespace -m fsdax -M dev -f -e $dev) -eval $(echo $json | sed -e "$json2var") +eval $(json2var <<< "$json") [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 mkfs.xfs -f /dev/$blockdev
@@ -88,7 +88,7 @@ umount $MNT # revert namespace to raw mode json=$($NDCTL create-namespace -m raw -f -e $dev) -eval $(echo $json | sed -e "$json2var") +eval $(json2var <<< "$json") [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 exit $rc
test/device-dax-fio.sh +5 -18
@@ -11,30 +11,17 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. -NDCTL="../ndctl/ndctl" +. ./common + rc=77 set -e -err() { - echo "test/device-dax-fio.sh: failed at line $1" - exit $rc -} - -check_min_kver() -{ - local ver="$1" - : "${KVER:=$(uname -r)}" - - [ -n "$ver" ] || return 1 - [[ "$ver" == "$(echo -e "$ver\n$KVER" | sort -V | head -1)" ]] -} +check_min_kver "4.11" || do_skip "kernel may lack device-dax fixes" -check_min_kver "4.11" || { echo "kernel $KVER may lack latest device-dax fixes"; exit $rc; } - -set -e trap 'err $LINENO' ERR +check_prereq "fio" if ! fio --enghelp | grep -q "dev-dax"; then echo "fio lacks dev-dax engine" exit 77
@@ -79,7 +66,7 @@ do # revert namespace to raw mode json=$($NDCTL create-namespace -m raw -f -e $dev) - mode=$(echo $json | jq -r ".mode") + eval $(json2var <<< "$json") [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 done
test/mmap.sh +5 -7
@@ -11,15 +11,15 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. +. ./common + MNT=test_mmap_mnt FILE=image DEV="" TEST=./mmap -NDCTL="../ndctl/ndctl" -json2var="s/[{}\",]//g; s/:/=/g" rc=77 -err() { +cleanup() { echo "test-mmap: failed at line $1" if [ -n "$DEV" ]; then umount $DEV
@@ -31,8 +31,6 @@ err() { } test_mmap() { - trap 'err $LINENO' ERR - # SHARED $TEST -Mrwps $MNT/$FILE # mlock, populate, shared (mlock fail) $TEST -Arwps $MNT/$FILE # mlockall, populate, shared
@@ -58,11 +56,11 @@ test_mmap() { set -e mkdir -p $MNT -trap 'err $LINENO' ERR +trap 'err $LINENO cleanup' ERR dev=$(./dax-dev) json=$($NDCTL list -N -n $dev) -eval $(echo $json | sed -e "$json2var") +eval $(json2var <<< "$json") DEV="/dev/${blockdev}" rc=1
Signature · 6 lines
2.14.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [ndctl PATCH 2/2] ndctl, test: convert remaining tests to use test/common
Hi Vishal,
Looks good to me. Please feel free to add:
Thanks,
Masa
Quoted 173 lines · Vishal Verma
The original test/common conversions missed the --enable-destructive class of tests. The json single object vs. array changes prompted changes to the json2var definitions, which these tests had a local copy of. Instead of fixing up these local copies, take the change to properly convert these tests to using test/common.
Fixes 72c46ab194d9 ("ndctl list: always output array without --human")Cc Ross Zwisler <[email protected]>Cc Dan Williams <[email protected]>Cc Masayoshi Mizuma <[email protected]>Signed-off-by Vishal Verma <[email protected]>--- test/dax.sh | 18 +++++++++--------- test/device-dax-fio.sh | 23 +++++------------------ test/mmap.sh | 12 +++++------- 3 files changed, 19 insertions(+), 34 deletions(-)test/dax.sh +9
-9@@ -11,13 +11,13 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. +. ./common + MNT=test_dax_mnt FILE=image -NDCTL="../ndctl/ndctl" -json2var="s/[{}\",]//g; s/:/=/g" blockdev="" -err() { +cleanup() { echo "test-dax: failed at line $1" if [ -n "$blockdev" ]; then umount /dev/$blockdev@@ -40,11 +40,11 @@ run_test() { set -e mkdir -p $MNT -trap 'err $LINENO' ERR +trap 'err $LINENO cleanup' ERR dev=$(./dax-dev) json=$($NDCTL list -N -n $dev) -eval $(echo $json | sed -e "$json2var") +eval $(json2var <<< "$json") rc=1 mkfs.ext4 /dev/$blockdev@@ -55,7 +55,7 @@ umount $MNT # convert pmem to put the memmap on the device json=$($NDCTL create-namespace -m fsdax -M dev -f -e $dev) -eval $(echo $json | sed -e "$json2var") +eval $(json2var <<< "$json") [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 #note the blockdev returned from ndctl create-namespace lacks the /dev prefix@@ -66,7 +66,7 @@ run_test umount $MNT json=$($NDCTL create-namespace -m raw -f -e $dev) -eval $(echo $json | sed -e "$json2var") +eval $(json2var <<< "$json") [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 mkfs.xfs -f /dev/$blockdev@@ -77,7 +77,7 @@ umount $MNT # convert pmem to put the memmap on the device json=$($NDCTL create-namespace -m fsdax -M dev -f -e $dev) -eval $(echo $json | sed -e "$json2var") +eval $(json2var <<< "$json") [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 mkfs.xfs -f /dev/$blockdev@@ -88,7 +88,7 @@ umount $MNT # revert namespace to raw mode json=$($NDCTL create-namespace -m raw -f -e $dev) -eval $(echo $json | sed -e "$json2var") +eval $(json2var <<< "$json") [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 exit $rctest/device-dax-fio.sh +5
-18@@ -11,30 +11,17 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. -NDCTL="../ndctl/ndctl" +. ./common + rc=77 set -e -err() { - echo "test/device-dax-fio.sh: failed at line $1" - exit $rc -} - -check_min_kver() -{ - local ver="$1" - : "${KVER:=$(uname -r)}" - - [ -n "$ver" ] || return 1 - [[ "$ver" == "$(echo -e "$ver\n$KVER" | sort -V | head -1)" ]] -} +check_min_kver "4.11" || do_skip "kernel may lack device-dax fixes" -check_min_kver "4.11" || { echo "kernel $KVER may lack latest device-dax fixes"; exit $rc; } - -set -e trap 'err $LINENO' ERR +check_prereq "fio" if ! fio --enghelp | grep -q "dev-dax"; then echo "fio lacks dev-dax engine" exit 77@@ -79,7 +66,7 @@ do # revert namespace to raw mode json=$($NDCTL create-namespace -m raw -f -e $dev) - mode=$(echo $json | jq -r ".mode") + eval $(json2var <<< "$json") [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 donetest/mmap.sh +3
-5@@ -11,15 +11,15 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. +. ./common + MNT=test_mmap_mnt FILE=image DEV="" TEST=./mmap -NDCTL="../ndctl/ndctl" -json2var="s/[{}\",]//g; s/:/=/g" rc=77 -err() { +cleanup() { echo "test-mmap: failed at line $1" if [ -n "$DEV" ]; then umount $DEV@@ -31,8 +31,6 @@ err() { } test_mmap() { - trap 'err $LINENO' ERR - # SHARED $TEST -Mrwps $MNT/$FILE # mlock, populate, shared (mlock fail) $TEST -Arwps $MNT/$FILE # mlockall, populate, shared@@ -58,11 +56,11 @@ test_mmap() { set -e mkdir -p $MNT
test/mmap.sh test_mmap() { · line 66
Quoted 10 lines
test/mmap.sh +2
-2-trap 'err $LINENO' ERR +trap 'err $LINENO cleanup' ERR dev=$(./dax-dev) json=$($NDCTL list -N -n $dev) -eval $(echo $json | sed -e "$json2var") +eval $(json2var <<< "$json") DEV="/dev/${blockdev}" rc=1
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 9 lines · Vishal Verma
The commit below updated json listings to always be arrays unless, potentially, --human was specified. As a fallout of the change, some unit tests that used jq to look for certain elements, or the json2var conversion broke in certain cases. Fix the jq query in
sector-mode.sh, and fix json2var in test/common. The 'destructive' class of unit tests still need to be converted to the test/common scheme, and subsequently have their own local json2var instances. These will be fixed in a future commit by simply performing the test/common conversion.
Quoted 4 lines
Fixes 72c46ab194d9 ("ndctl list: always output array without --human")Cc Ross Zwisler <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Nice, thanks for the fixes.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm