From patchwork Fri Nov 14 13:27:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Tulak X-Patchwork-Id: 5305971 Return-Path: X-Original-To: patchwork-fstests@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8B0E99F818 for ; Fri, 14 Nov 2014 13:30:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C794C20145 for ; Fri, 14 Nov 2014 13:30:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D97792013D for ; Fri, 14 Nov 2014 13:30:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934603AbaKNNaQ (ORCPT ); Fri, 14 Nov 2014 08:30:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48019 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933794AbaKNNaQ (ORCPT ); Fri, 14 Nov 2014 08:30:16 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sAEDTFGe028040 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 14 Nov 2014 08:29:15 -0500 Received: from jtulak.redhat.com (ovpn-112-57.ams2.redhat.com [10.36.112.57]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sAEDT1KP016807; Fri, 14 Nov 2014 08:29:14 -0500 From: =?UTF-8?q?Jan=20=C5=A4ul=C3=A1k?= To: fstests@vger.kernel.org Cc: =?UTF-8?q?Jan=20=C5=A4ul=C3=A1k?= , lczerner@redhat.com, david@fromorbit.com Subject: [PATCH 7/7] Adds functions for tests to call environment setup/cleaning Date: Fri, 14 Nov 2014 14:27:47 +0100 Message-Id: <1415971667-16873-7-git-send-email-jtulak@redhat.com> In-Reply-To: <1415971667-16873-1-git-send-email-jtulak@redhat.com> References: <1415971667-16873-1-git-send-email-jtulak@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds two functions into common/rc. These two functions are called by tests to setup and clean environment. They have a single argument - a target directory. So everything required in a test to support environments is to call _require_environment $target after requireing test or scratch dir, and then call the clean function at the end. Specific environment name is taken from variables exported by check script. Calling of the cleaning function is not critical as before setup, cleaning is called automatically. Signed-off-by: Jan ?ulák --- common/rc | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/common/rc b/common/rc index d5e3aff..14dbb1f 100644 --- a/common/rc +++ b/common/rc @@ -1037,6 +1037,55 @@ _supported_os() _notrun "not suitable for this OS: $HOSTOS" } +_require_environment() +{ + target="$1" + if [ "$target" = "" ];then + 1>&2 echo "Target directory for environment can't be empty! Aborting." + exit 1 + fi + + if [ "$env" != "" -a "$env" != "none" ];then + prepare_method="prepare-once" + if $env_force;then + prepare_method="prepare-always" + fi + bash ./environments/$env $prepare_method $target + sts=$? + if [ "$sts" != 0 ]; then + echo " [skipped]" + 1>&2 echo "Failed to prepare environment $env "\ + " (will skip the test)!" + 1>&2 echo "" + exit 1 + fi + fi +} + + + +_environment_clean() +{ + target="$1" + if [ "$target" = "" ];then + 1>&2 echo "Target directory for environment cleaning can't be empty!"\ + " Aborting." + exit 1 + fi + # Clean environment if there was some + # and the next environment is different. + # The variables are exported from check script. + if [ "$env" != "" -a "$env" != "none" -a "$env" != "$env_next" ];then + bash ./environments/$env clean $target + sts=$? + if [ "$sts" != "0" ];then + 1>&2 echo "An error happened when cleaning environment $env!" + 1>&2 echo "" + fi + fi + +} + # this test needs a scratch partition - check we're ok & unmount it # No post-test check of the device is required. e.g. the test intentionally # finishes the test with the filesystem in a corrupt state