From patchwork Wed Jan 31 22:06:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10194901 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 3AF90603EE for ; Wed, 31 Jan 2018 22:06:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20D8528759 for ; Wed, 31 Jan 2018 22:06:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1593F287F4; Wed, 31 Jan 2018 22:06:10 +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 A40E728759 for ; Wed, 31 Jan 2018 22:06:09 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 09C0521E256B5; Wed, 31 Jan 2018 14:00:33 -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.65; helo=mga03.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 815E221945DF3 for ; Wed, 31 Jan 2018 14:00:31 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2018 14:06:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,441,1511856000"; d="scan'208";a="14082168" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by orsmga007.jf.intel.com with ESMTP; 31 Jan 2018 14:06:07 -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: Wed, 31 Jan 2018 15:06:07 -0700 Message-ID: <151743636731.50357.13469426517564809891.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <151743627634.50357.2692734095508615676.stgit@djiang5-desk3.ch.intel.com> References: <151743627634.50357.2692734095508615676.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 d4c2bd6..d5ef648 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -16,7 +16,8 @@ TESTS =\ blk-exhaust.sh \ sector-mode.sh \ inject-error.sh \ - btt-errors.sh + 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 +