From patchwork Wed Dec 6 22:48:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10097303 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 9DD9360327 for ; Wed, 6 Dec 2017 22:48:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F74C29B30 for ; Wed, 6 Dec 2017 22:48:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8415429BAA; Wed, 6 Dec 2017 22:48:09 +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 2588629B30 for ; Wed, 6 Dec 2017 22:48:09 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8190D20356267; Wed, 6 Dec 2017 14:43:36 -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=192.55.52.88; helo=mga01.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 0DEEE20352AB8 for ; Wed, 6 Dec 2017 14:43:34 -0800 (PST) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Dec 2017 14:48:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,369,1508828400"; d="scan'208";a="156657262" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by orsmga004.jf.intel.com with ESMTP; 06 Dec 2017 14:48:01 -0800 Subject: [PATCH v2 4/4] ndctl, test: firmware update unit test From: Dave Jiang To: dan.j.williams@intel.com Date: Wed, 06 Dec 2017 15:48:01 -0700 Message-ID: <151260048051.3630.14958915274940774469.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <151260039600.3630.12960859289293301854.stgit@djiang5-desk3.ch.intel.com> References: <151260039600.3630.12960859289293301854.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.22 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 | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 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..ff777b9 --- /dev/null +++ b/test/firmware-update.sh @@ -0,0 +1,74 @@ +#!/bin/bash -Ex + +# Copyright(c) 2017 Intel Corporation. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +[ -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 +