nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: QI Fuli <qi.fuli@jp.fujitsu.com>
To: linux-nvdimm@lists.01.org
Subject: [ndctl PATCH v2] ndctl, test: add a new unit test for monitor
Date: Fri,  6 Jul 2018 14:22:27 +0900	[thread overview]
Message-ID: <20180706052227.14393-1-qi.fuli@jp.fujitsu.com> (raw)

Add a new unit test to test the following options of the monitor command.
   --dimm
   --bus
   --region
   --namespace
   --logfile
   --config-file

Based-on-patch-by: Yasunori Goto <y-goto@jp.fujitsu.com>
Acked-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Signed-off-by: QI Fuli <qi.fuli@jp.fujitsu.com>
---
v1 -> v2:
 - Add init()
 - Add get_filter_dimm() to get the filter dimms by ndctl list command
   instead of hard-cording
 - Add sleep to call_notify()

 test/Makefile.am |   3 +-
 test/monitor.sh  | 131 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 133 insertions(+), 1 deletion(-)
 create mode 100755 test/monitor.sh

diff --git a/test/Makefile.am b/test/Makefile.am
index cd451e9..8c76462 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -21,7 +21,8 @@ TESTS =\
 	btt-pad-compat.sh \
 	firmware-update.sh \
 	ack-shutdown-count-set \
-	rescan-partitions.sh
+	rescan-partitions.sh \
+	monitor.sh
 
 check_PROGRAMS =\
 	libndctl \
diff --git a/test/monitor.sh b/test/monitor.sh
new file mode 100755
index 0000000..dbd2013
--- /dev/null
+++ b/test/monitor.sh
@@ -0,0 +1,131 @@
+#!/bin/bash -Ex
+
+# SPDX-License-Identifier: GPL-2.0
+# Copyright(c) 2018, FUJITSU LIMITED. All rights reserved.
+
+rc=77
+logfile=""
+conf_file=""
+filter_dimms=""
+monitor_pid=65536
+FILTER_DIMM="nmem1"
+FILTER_REGION="region1"
+FILTER_NAMESPACE="namespace1.0"
+CONF_FILE_SET_DIMM="nmem1:nmem3"
+
+. ./common
+
+trap 'err $LINENO' ERR
+
+check_min_kver "4.15" || do_skip "kernel $KVER may not support monitor service"
+
+start_monitor()
+{
+	logfile=$(mktemp)
+	$NDCTL monitor -l $logfile $1 &
+	monitor_pid=$!
+	truncate --size 0 $logfile #remove startup log
+}
+
+get_filter_dimm()
+{
+	jlist=$($NDCTL list -D -b $NFIT_TEST_BUS0 $1)
+	filter_dimms=$(jq '.[]."dev"?, ."dev"?' <<<$jlist | sort | uniq | sed -e ':loop; N; $!b loop; s/\n/:/g' | sed 's/\"//g')
+}
+
+call_notify()
+{
+	./smart-notify $NFIT_TEST_BUS0
+	sync; sleep 3
+}
+
+check_result()
+{
+	jlog=$(cat $logfile)
+	notify_dimms=$(jq ."dimm"."dev" <<<$jlog | sort | uniq | sed -e ':loop; N; $!b loop; s/\n/:/g' | sed 's/\"//g')
+	[[ $filter_dimms == $notify_dimms ]]
+}
+
+stop_monitor()
+{
+	kill $monitor_pid
+	rm $logfile
+}
+
+create_conf_file()
+{
+	conf_file=$(mktemp)
+	echo 'dimm=nmem1 nmem3' > $conf_file
+}
+
+test_filter_dimm()
+{
+	get_filter_dimm "-d $FILTER_DIMM"
+	start_monitor "-d $FILTER_DIMM"
+	call_notify
+	check_result
+	stop_monitor
+}
+
+test_filter_bus()
+{
+	get_filter_dimm
+	start_monitor "-b $NFIT_TEST_BUS0"
+	call_notify
+	check_result
+	stop_monitor
+}
+
+test_filter_region()
+{
+	get_filter_dimm "-r $FILTER_REGION"
+	start_monitor "-r $FILTER_REGION"
+	call_notify
+	check_result
+	stop_monitor
+}
+
+test_filter_namespace()
+{
+	$NDCTL create-namespace -r region1 -n $FILTER_NAMESPACE
+	get_filter_dimm "-n $FILTER_NAMESPACE"
+	start_monitor "-n $FILTER_NAMESPACE"
+	call_notify
+	check_result
+	stop_monitor
+	$NDCTL destroy-namespace $FILTER_NAMESPACE -f
+}
+
+test_conf_file()
+{
+	filter_dimms=$CONF_FILE_SET_DIMM
+	create_conf_file
+	start_monitor "-c $conf_file"
+	call_notify
+	check_result
+	stop_monitor
+	rm $conf_file
+}
+
+do_tests()
+{
+	test_filter_dimm
+	test_filter_bus
+	test_filter_region
+	test_filter_namespace
+	test_conf_file
+}
+
+init()
+{
+	$NDCTL disable-region -b $NFIT_TEST_BUS0 all
+	$NDCTL zero-labels -b $NFIT_TEST_BUS0 all
+	$NDCTL enable-region -b $NFIT_TEST_BUS0 all
+}
+
+modprobe nfit_test
+rc=1
+init
+do_tests
+_cleanup
+exit 0
-- 
2.18.0


_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

             reply	other threads:[~2018-07-06  5:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-06  5:22 QI Fuli [this message]
2018-07-06 15:08 ` [ndctl PATCH v2] ndctl, test: add a new unit test for monitor Masayoshi Mizuma
2018-07-07  1:48   ` QI Fuli
2018-07-07  3:43     ` Dan Williams
2018-07-07  6:21       ` Verma, Vishal L
2018-07-07  3:57 ` Dan Williams
2018-07-07  4:20   ` Qi, Fuli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180706052227.14393-1-qi.fuli@jp.fujitsu.com \
    --to=qi.fuli@jp.fujitsu.com \
    --cc=linux-nvdimm@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).