From patchwork Thu Feb 1 16:47:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10195681 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 A97F260247 for ; Thu, 1 Feb 2018 16:48:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BD8928C87 for ; Thu, 1 Feb 2018 16:48:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 776742858F; Thu, 1 Feb 2018 16:48:57 +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=-1.9 required=2.0 tests=BAYES_00, 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 9D23F28F73 for ; Thu, 1 Feb 2018 16:47:44 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0A45021E0B9F0; Thu, 1 Feb 2018 08:42:07 -0800 (PST) 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=134.134.136.20; helo=mga02.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 312BC223CCF16 for ; Thu, 1 Feb 2018 08:42:06 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Feb 2018 08:47:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,444,1511856000"; d="scan'208";a="200590004" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by fmsmga006.fm.intel.com with ESMTP; 01 Feb 2018 08:47:41 -0800 Subject: [PATCH v5 4/4] ndctl, test: firmware update unit test From: Dave Jiang To: vishal.l.verma@intel.com, dan.j.williams@intel.com Date: Thu, 01 Feb 2018 09:47:41 -0700 Message-ID: <151750366160.3199.7502374610065525238.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <151750355438.3199.10739483451071461270.stgit@djiang5-desk3.ch.intel.com> References: <151750355438.3199.10739483451071461270.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Adding a unit test that will use nfit_test kernel module to test the firmware update sequence. Signed-off-by: Dave Jiang --- test/Makefile.am | 3 +- test/firmware-update.sh | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100755 test/firmware-update.sh diff --git a/test/Makefile.am b/test/Makefile.am index bd73a43..30bc02d 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -16,8 +16,9 @@ TESTS =\ blk-exhaust.sh \ sector-mode.sh \ inject-error.sh \ + btt-errors.sh \ hugetlb \ - btt-errors.sh + firmware-update.sh check_PROGRAMS =\ libndctl \ diff --git a/test/firmware-update.sh b/test/firmware-update.sh new file mode 100755 index 0000000..79767d2 --- /dev/null +++ b/test/firmware-update.sh @@ -0,0 +1,65 @@ +#!/bin/bash -Ex +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2018 Intel Corporation. All rights reserved. + +[ -f "../ndctl/ndctl" ] && [ -x "../ndctl/ndctl" ] && ndctl="../ndctl/ndctl" +[ -f "./ndctl/ndctl" ] && [ -x "./ndctl/ndctl" ] && ndctl="./ndctl/ndctl" +[ -z "$ndctl" ] && echo "Couldn't find an ndctl binary" && exit 1 +bus="nfit_test.0" +json2var="s/[{}\",]//g; s/:/=/g" +rc=77 +dev="" +image="update-fw.img" + +trap 'err $LINENO' ERR + +# $1: Line number +# $2: exit code +err() +{ + [ -n "$2" ] && rc="$2" + echo "test/firmware-update.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)" ]] +} + +reset() +{ + $ndctl disable-region -b "$bus" all + $ndctl zero-labels -b "$bus" all + $ndctl enable-region -b "$bus" all + if [ -f $image ]; then + rm -f $image + fi +} + +detect() +{ + dev=$($ndctl list -b "$bus" -D | jq .[0].dev | tr -d '"') + [ -n "$dev" ] || err "$LINENO" 2 +} + +do_tests() +{ + fallocate -l 196608 $image + $ndctl update-firmware -d $dev -f $image +} + +check_min_kver "4.16" || { echo "kernel $KVER may lack firmware update test handling"; exit +$rc; } +modprobe nfit_test +rc=1 +reset +detect +do_tests +reset +exit 0 +