From patchwork Wed Jun 13 01:56:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masayoshi Mizuma X-Patchwork-Id: 10461461 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 9C63F601A0 for ; Wed, 13 Jun 2018 01:56:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9359A28892 for ; Wed, 13 Jun 2018 01:56:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87BB228C20; Wed, 13 Jun 2018 01:56:44 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, T_DKIM_INVALID 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 39EA128892 for ; Wed, 13 Jun 2018 01:56:44 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0932D2131BA29; Tue, 12 Jun 2018 18:56:44 -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=2607:f8b0:400d:c09::241; helo=mail-qk0-x241.google.com; envelope-from=msys.mizuma@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-qk0-x241.google.com (mail-qk0-x241.google.com [IPv6:2607:f8b0:400d:c09::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 999D021314737 for ; Tue, 12 Jun 2018 18:56:42 -0700 (PDT) Received: by mail-qk0-x241.google.com with SMTP id y4-v6so634684qka.5 for ; Tue, 12 Jun 2018 18:56:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ELHdBLoWmIjWG1HTDdmZmjuwC3m6VTAwI6EOV9eY7L4=; b=T4NM9vkF0bgX+ngq+As52PPpiDH02cS/n9OQAcuDmwUPFKULcEUZ/WLfy6t86/8dya 9Uf2B1mljEui7qwPWHV5TzukjmKxhAnADDTk8gCjnEBpbJ0Vu8FnoKIw63HYpaGRgyME mBEzXbvaNbk0xryRUcVuop1PsJRio5siNrK8viQcSZqJ78hmIXRoZCzTzaD8TMNCbEF8 6TzA584n+N6IYSzoSdjsF9T/xB5wmCeVcRLdgBUazbuyru9fxbzs0gPrJ5Cwzrk2sVzO ZPbNc3ahGufaA72fduv46nKjVNTpFktvqr/jFYDzuI6b5Ffnb+s7wtfow8YFyNYf8Rxk 62lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ELHdBLoWmIjWG1HTDdmZmjuwC3m6VTAwI6EOV9eY7L4=; b=qssNuKl1IwilyNZRUe/yvwCIkT8FVjKDiZTpS7rtWi7nWGx738QNdVYCIIkEOdU2d9 zHsQlJxsJLAGfLKgzAEKbi/4N3xtCoWftJK9Hfhk/KhMlXE8jADjYN1HXtxfb+ZWqm/S YnT2c+XZ4DktvtcLiPQ5ptAucfZLgNDzpBJbhBGrV/n/bg+ZMLge/XoMYdnVuFY/5HyA tX6A7BBTKPBCUDED5I6LpcUJksLkxSwPweGERiCKTJa9GlhLJr+Uyp8fd8+Frfj2JEAp zek5ufL+ASYSKDh50D0m8S1KZJ3ytiGKt9kuie33Ke2ohMvSXdnnhkxno7a4CZmRAxC3 6heQ== X-Gm-Message-State: APt69E0yyiKYus2irh8cnisytOgyP2EuEEEJi6gUq6WoLx4q1fMrgTDg 65b60GKInB2fGfNbpOWTdZhj X-Google-Smtp-Source: ADUXVKKEQq/dwGsmOZC7/9zGCRrqoV1aFLGttYW+X+5qiaY2b5RTeqVDla83PKGDApXB+YngN2KsLQ== X-Received: by 2002:a37:13a4:: with SMTP id 36-v6mr2839696qkt.26.1528855001748; Tue, 12 Jun 2018 18:56:41 -0700 (PDT) Received: from gabell.redhat.com ([2601:18f:600:d880:fc16:7472:bb50:990d]) by smtp.gmail.com with ESMTPSA id w21-v6sm1328715qkb.36.2018.06.12.18.56.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jun 2018 18:56:41 -0700 (PDT) From: Masayoshi Mizuma To: linux-nvdimm@lists.01.org Subject: [PATCH v2 1/2] ndctl, test: add some helper function for test script Date: Tue, 12 Jun 2018 21:56:15 -0400 Message-Id: <20180613015616.26487-2-msys.mizuma@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180613015616.26487-1-msys.mizuma@gmail.com> References: <20180613015616.26487-1-msys.mizuma@gmail.com> 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: , Cc: Masayoshi Mizuma MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP From: Masayoshi Mizuma Some test scripts have same function. So, this patch introduces the functions to 'test/common' new file. Signed-off-by: Masayoshi Mizuma --- test/common | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 test/common diff --git a/test/common b/test/common new file mode 100644 index 0000000..8fafa91 --- /dev/null +++ b/test/common @@ -0,0 +1,60 @@ + +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2018, FUJITSU LIMITED. All rights reserved. + +# Global variables + +# ndctl +# +if [ -f "../ndctl/ndctl" ] && [ -x "../ndctl/ndctl" ]; then + export ndctl=../ndctl/ndctl +elif [ -f "./ndctl/ndctl" ] && [ -x "./ndctl/ndctl" ]; then + export ndctl=./ndctl/ndctl +else + echo "Couldn't find an ndctl binary" + exit 1 +fi + +# Functions + +# err +# $1: line number which error detected +# $2: cleanup function (optional) +# +err() +{ + echo test/$(basename $0): failed at line $1 + [ -n "$2" ] && "$2" + exit $rc +} + +# check_min_kver +# $1: Supported kernel version. format: X.Y +# +check_min_kver() +{ + local ver="$1" + : "${KVER:=$(uname -r)}" + + [ -n "$ver" ] || return 1 + [[ "$ver" == "$(echo -e "$ver\n$KVER" | sort -V | head -1)" ]] +} + +# do_skip +# $1: Skip message +# +do_skip() +{ + echo kernel $(uname -r): $1 + exit 77 +} + +# check_prereq +# $1: command to check +# +check_prereq() +{ + if ! command -v "$1" >/dev/null; then + do_skip "missing $1, skipping..." + fi +}