From patchwork Fri Aug 3 22:22:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 10555523 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DCB1157D for ; Fri, 3 Aug 2018 22:22:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3AC328595 for ; Fri, 3 Aug 2018 22:22:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7946285F9; Fri, 3 Aug 2018 22:22:47 +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 7FDE728595 for ; Fri, 3 Aug 2018 22:22:47 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 283D821A00AE6; Fri, 3 Aug 2018 15:22:47 -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=192.55.52.115; helo=mga14.intel.com; envelope-from=vishal.l.verma@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 31E4121A00AE6 for ; Fri, 3 Aug 2018 15:22:46 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Aug 2018 15:22:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,440,1526367600"; d="scan'208";a="73280551" Received: from vverma7-desk1.lm.intel.com ([10.232.112.133]) by fmsmga002.fm.intel.com with ESMTP; 03 Aug 2018 15:22:43 -0700 From: Vishal Verma To: Subject: [ndctl PATCH] ndctl, tests: add a new unit test for inject-smart Date: Fri, 3 Aug 2018 16:22:42 -0600 Message-Id: <20180803222242.10357-1-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.14.4 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.27 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 that exercises all the functionality provided by the ndctl inject-smart command. This performs injections, un-injections, and sets thresholds, and verifies all this happened successfully. Signed-off-by: Vishal Verma --- test/Makefile.am | 1 + test/inject-smart.sh | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100755 test/inject-smart.sh diff --git a/test/Makefile.am b/test/Makefile.am index 8c55056..6156a7a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -22,6 +22,7 @@ TESTS =\ firmware-update.sh \ ack-shutdown-count-set \ rescan-partitions.sh \ + inject-smart.sh \ monitor.sh check_PROGRAMS =\ diff --git a/test/inject-smart.sh b/test/inject-smart.sh new file mode 100755 index 0000000..18655ba --- /dev/null +++ b/test/inject-smart.sh @@ -0,0 +1,178 @@ +#!/bin/bash -Ex +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2018 Intel Corporation. All rights reserved. + +rc=77 +. ./common +bus="$NFIT_TEST_BUS0" +inj_val="42" + +trap 'err $LINENO' ERR + +# sample json: +# { +# "dev":"nmem0", +# "id":"cdab-0a-07e0-ffffffff", +# "handle":0, +# "phys_id":0, +# "health":{ +# "health_state":"non-critical", +# "temperature_celsius":23, +# "spares_percentage":75, +# "alarm_temperature":true, +# "alarm_spares":true, +# "temperature_threshold":40, +# "spares_threshold":5, +# "life_used_percentage":5, +# "shutdown_state":"clean" +# } +#} + +translate_field() +{ + local in="$1" + + case $in in + media-temperature) + echo "temperature_celsius" + ;; + ctrl-temperature) + echo "controller_temperature_celsius" + ;; + spares) + echo "spares_percentage" + ;; + media-temperature-alarm) + echo "alarm_temperature" + ;; + ctrl-temperature-alarm) + echo "alarm_controller_temperature" + ;; + spares-alarm) + echo "alarm_spares" + ;; + media-temperature-threshold) + echo "temperature_threshold" + ;; + spares-threshold) + echo "spares_threshold" + ;; + unsafe-shutdown) + echo "shutdown_state" + ;; + fatal) + echo "health_state" + ;; + *) + # passthrough + echo "$in" + return + ;; + esac +} + +translate_val() +{ + local in="$1" + + case $in in + dirty) + ;& + fatal) + ;& + true) + echo "1" + ;; + non-critical) + ;& + clean) + ;& + false) + echo "0" + ;; + *) + # passthrough + echo "$in" + ;; + esac +} + +get_field() +{ + local field="$1" + local smart_listing="$(translate_field $field)" + + json="$($NDCTL list -b $bus -d $dimm -H)" + val="$(jq -r ".[].dimms[].health.$smart_listing" <<< $json)" + val="$(translate_val $val)" + echo $val +} + +verify() +{ + local field="$1" + local val="$2" + + [[ "$val" == "$(get_field $field)" ]] +} + +test_field() +{ + local field="$1" + local val="$2" + local op="$3" + local old_val="" + + if [ -n "$val" ]; then + inj_opt="--${field}=${val}" + else + inj_opt="--${field}" + fi + + old_val=$(get_field $field) + if [[ "$old_val" == "0" || "$old_val" == "1" ]]; then + val=$(((old_val + 1) % 2)) + fi + $NDCTL inject-smart -b $bus $dimm $inj_opt + verify $field $val + + if [[ "$op" != "thresh" ]]; then + $NDCTL inject-smart -b $bus --${field}-uninject $dimm + verify $field $old_val + fi +} + +do_tests() +{ + local fields_val=(media-temperature spares) + local fields_bool=(unsafe-shutdown fatal) + local fields_thresh=(media-temperature-threshold spares-threshold) + local field="" + + $NDCTL inject-smart -b $bus --uninject-all $dimm + + # start tests + for field in "${fields_val[@]}"; do + test_field $field $inj_val + done + + for field in "${fields_bool[@]}"; do + test_field $field + done + + for field in "${fields_thresh[@]}"; do + test_field $field $inj_val "thresh" + done +} + +check_min_kver "4.19" || do_skip "kernel $KVER may not support smart (un)injection" +modprobe nfit_test +rc=1 + +jlist=$(./list-smart-dimm -b $bus) +dimm="$(jq '.[]."dev"?, ."dev"?' <<< $jlist | sort | head -1 | xargs)" +test -n "$dimm" + +do_tests +_cleanup +exit 0