From patchwork Thu Jul 5 11:23:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 10508763 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 18136600F5 for ; Thu, 5 Jul 2018 11:23:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 062682675C for ; Thu, 5 Jul 2018 11:23:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE5F328EE2; Thu, 5 Jul 2018 11:23:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D4F372675C for ; Thu, 5 Jul 2018 11:23:40 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 55E93210E4374; Thu, 5 Jul 2018 04:23:40 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=202.219.69.169; helo=mgwkm02.jp.fujitsu.com; envelope-from=qi.fuli@jp.fujitsu.com; receiver=linux-nvdimm@lists.01.org Received: from mgwkm02.jp.fujitsu.com (mgwkm02.jp.fujitsu.com [202.219.69.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8B49720968917 for ; Thu, 5 Jul 2018 04:23:37 -0700 (PDT) Received: from kw-mxoi2.gw.nic.fujitsu.com (unknown [192.168.231.133]) by mgwkm02.jp.fujitsu.com with smtp id 7725_255a_26dde135_9e60_45b8_8970_54c707bcd89c; Thu, 05 Jul 2018 20:23:32 +0900 Received: from m3051.s.css.fujitsu.com (m3051.s.css.fujitsu.com [10.134.21.209]) by kw-mxoi2.gw.nic.fujitsu.com (Postfix) with ESMTP id 84AFBAC00B6 for ; Thu, 5 Jul 2018 20:23:32 +0900 (JST) Received: from qi-fedora.fujitsu.com (unknown [10.124.196.110]) by m3051.s.css.fujitsu.com (Postfix) with ESMTP id 62B6B2B5; Thu, 5 Jul 2018 20:23:32 +0900 (JST) From: QI Fuli To: linux-nvdimm@lists.01.org Subject: [ndctl PATCH] ndctl, test: add a new unit test for monitor Date: Thu, 5 Jul 2018 20:23:04 +0900 Message-Id: <20180705112304.2656-1-qi.fuli@jp.fujitsu.com> X-Mailer: git-send-email 2.18.0 X-TM-AS-MML: disable X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Add a new unit test to test the follow options of the monitor command. --dimm --bus --region --namespace --logfile --config-file Based-on-patch-by: Yasunori Goto Signed-off-by: QI Fuli --- test/Makefile.am | 3 +- test/monitor.sh | 115 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 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..4f113c8 --- /dev/null +++ b/test/monitor.sh @@ -0,0 +1,115 @@ +#!/bin/bash -Ex + +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2018, FUJITSU LIMITED. All rights reserved. + +rc=77 +logfile="" +conf_file="" +monitor_pid=65536 +FILTER_DIMM="nmem1" +FILTER_BUS="ndbus1" +FILTER_BUS_MAP_DIMM="nmem0:nmem1:nmem2:nmem3" +FILTER_REGION="region1" +FILTER_REGION_MAP_DIMM="nmem0:nmem1" +FILTER_NAMESPACE="namespace1.0" +FILTER_NAMESPACE_MAP_DIMM="nmem0:nmem1" +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 +} + +call_notify() +{ + ./smart-notify $NFIT_TEST_BUS0 +} + +check_result() +{ + json=$(cat $logfile) + dimms=$(jq ."dimm"."dev" <<<$json | sort | uniq | sed -e ':loop; N; $!b loop; s/\n/:/g' | sed 's/\"//g') + [[ $1 == $dimms ]] +} + +stop_monitor() +{ + kill $monitor_pid + rm $logfile +} + +create_conf_file() +{ + conf_file=$(mktemp) + echo 'dimm=nmem1 nmem3' > $conf_file + cat $conf_file +} + +test_filter_dimm() +{ + start_monitor "-d $FILTER_DIMM" + call_notify + check_result "$FILTER_DIMM" + stop_monitor +} + +test_filter_bus() +{ + start_monitor "-b $FILTER_BUS" + call_notify + check_result $FILTER_BUS_MAP_DIMM + stop_monitor +} + +test_filter_region() +{ + start_monitor "-r $FILTER_REGION" + call_notify + check_result $FILTER_REGION_MAP_DIMM + stop_monitor +} + +test_filter_namespace() +{ + $NDCTL create-namespace -r region1 -n $FILTER_NAMESPACE + start_monitor "-n $FILTER_NAMESPACE" + call_notify + check_result $FILTER_NAMESPACE_MAP_DIMM + stop_monitor + $NDCTL destroy-namespace $FILTER_NAMESPACE -f +} + +test_conf_file() +{ + create_conf_file + start_monitor "-c $conf_file" + call_notify + check_result $CONF_FILE_SET_DIMM + stop_monitor + rm $conf_file +} + +do_tests() +{ + test_filter_dimm + test_filter_bus + test_filter_region + test_filter_namespace + test_conf_file +} + +modprobe nfit_test +rc=1 +do_tests +_cleanup +exit 0