From patchwork Thu Apr 5 00:06:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 895222 X-Patchwork-Delegate: chrubis@suse.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40Gjn96kK5z9s0v for ; Thu, 5 Apr 2018 10:07:09 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 702883E6086 for ; Thu, 5 Apr 2018 02:07:06 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) by picard.linux.it (Postfix) with ESMTP id 659003E6086 for ; Thu, 5 Apr 2018 02:07:00 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 7113B1A007E3 for ; Thu, 5 Apr 2018 02:06:58 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1BBB9AFD3; Thu, 5 Apr 2018 00:06:58 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 5 Apr 2018 02:06:40 +0200 Message-Id: <20180405000644.18815-3-pvorel@suse.cz> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180405000644.18815-1-pvorel@suse.cz> References: <20180405000644.18815-1-pvorel@suse.cz> X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [RFC PATCH v4 2/6] tst_test.sh: Introduce TST_NO_DEFAULT_RUN X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" TST_NO_DEFAULT_RUN is somehow similar to TST_NO_DEFAULT_MAIN. It's meant to be used for libraries and tools using tst_test.sh. It helps to use part of test framework functionality without actually wanting to run any test (yet). For tests with defined TST_NO_DEFAULT_RUN and sourcing tst_test.sh all functions and variables are defined, but checks for requested variables are skipped. Signed-off-by: Petr Vorel Cc: Cyril Hrubis --- testcases/lib/tst_test.sh | 90 ++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh index 78bd328a2..6c2ee6a51 100644 --- a/testcases/lib/tst_test.sh +++ b/testcases/lib/tst_test.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) Linux Test Project, 2014-2017 +# Copyright (c) Linux Test Project, 2014-2018 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -371,67 +371,69 @@ tst_run() tst_do_exit } -if TST_TEST_PATH=$(which $0) 2>/dev/null; then - if ! grep -q tst_run "$TST_TEST_PATH"; then - tst_brk TBROK "Test $0 must call tst_run!" - fi -fi - if [ -z "$TST_ID" ]; then filename=$(basename $0) TST_ID=${filename%%.*} fi export TST_ID="$TST_ID" -if [ -z "$TST_TESTFUNC" ]; then - tst_brk TBROK "TST_TESTFUNC is not defined" +if [ -z "$LTPROOT" ]; then + export LTPROOT="$PWD" + export TST_DATAROOT="$LTPROOT/datafiles" +else + export TST_DATAROOT="$LTPROOT/testcases/data/$TST_ID" fi -if [ -n "$TST_CNT" ]; then - if ! tst_is_int "$TST_CNT"; then - tst_brk TBROK "TST_CNT must be integer" +if [ -z "$TST_NO_DEFAULT_RUN" ]; then + if TST_TEST_PATH=$(which $0) 2>/dev/null; then + if ! grep -q tst_run "$TST_TEST_PATH"; then + tst_brk TBROK "Test $0 must call tst_run!" + fi fi - if [ "$TST_CNT" -le 0 ]; then - tst_brk TBROK "TST_CNT must be > 0" + if [ -z "$TST_TESTFUNC" ]; then + tst_brk TBROK "TST_TESTFUNC is not defined" fi -fi -if [ -n "$TST_POS_ARGS" ]; then - if ! tst_is_int "$TST_POS_ARGS"; then - tst_brk TBROK "TST_POS_ARGS must be integer" - fi + if [ -n "$TST_CNT" ]; then + if ! tst_is_int "$TST_CNT"; then + tst_brk TBROK "TST_CNT must be integer" + fi - if [ "$TST_POS_ARGS" -le 0 ]; then - tst_brk TBROK "TST_POS_ARGS must be > 0" + if [ "$TST_CNT" -le 0 ]; then + tst_brk TBROK "TST_CNT must be > 0" + fi fi -fi -if [ -z "$LTPROOT" ]; then - export LTPROOT="$PWD" - export TST_DATAROOT="$LTPROOT/datafiles" -else - export TST_DATAROOT="$LTPROOT/testcases/data/$TST_ID" -fi + if [ -n "$TST_POS_ARGS" ]; then + if ! tst_is_int "$TST_POS_ARGS"; then + tst_brk TBROK "TST_POS_ARGS must be integer" + fi -TST_ARGS="$@" + if [ "$TST_POS_ARGS" -le 0 ]; then + tst_brk TBROK "TST_POS_ARGS must be > 0" + fi + fi -while getopts ":hi:$TST_OPTS" tst_name; do - case $tst_name in - 'h') TST_PRINT_HELP=1;; - *);; - esac -done + TST_ARGS="$@" -shift $((OPTIND - 1)) + while getopts ":hi:$TST_OPTS" tst_name; do + case $tst_name in + 'h') TST_PRINT_HELP=1;; + *);; + esac + done -if [ -n "$TST_POS_ARGS" ]; then - if [ -z "$TST_PRINT_HELP" -a $# -ne "$TST_POS_ARGS" ]; then - tst_brk TBROK "Invalid number of positional paramters:"\ - "have ($@) $#, expected ${TST_POS_ARGS}" - fi -else - if [ -z "$TST_PRINT_HELP" -a $# -ne 0 ]; then - tst_brk TBROK "Unexpected positional arguments '$@'" + shift $((OPTIND - 1)) + + if [ -n "$TST_POS_ARGS" ]; then + if [ -z "$TST_PRINT_HELP" -a $# -ne "$TST_POS_ARGS" ]; then + tst_brk TBROK "Invalid number of positional paramters:"\ + "have ($@) $#, expected ${TST_POS_ARGS}" + fi + else + if [ -z "$TST_PRINT_HELP" -a $# -ne 0 ]; then + tst_brk TBROK "Unexpected positional arguments '$@'" + fi fi fi