From patchwork Wed Jul 23 10:57:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Wood X-Patchwork-Id: 4609901 Return-Path: X-Original-To: patchwork-intel-gfx@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 1BA049F375 for ; Wed, 23 Jul 2014 10:58:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 37749200EC for ; Wed, 23 Jul 2014 10:58:14 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 06286201DE for ; Wed, 23 Jul 2014 10:58:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9FFDF6E625; Wed, 23 Jul 2014 03:58:10 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by gabe.freedesktop.org (Postfix) with ESMTP id 332076E624 for ; Wed, 23 Jul 2014 03:58:06 -0700 (PDT) Received: by mail-wi0-f181.google.com with SMTP id bs8so1973547wib.2 for ; Wed, 23 Jul 2014 03:58:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BfzEcfkZks5ALi2joRjyQhTn79wu4/C9/bQOsRHpk30=; b=eMsAyqhLxuw3urarcOEtcaJfJ9nMws1eocSA8J6swpGMgDxukOLSueFvyyYioI8/qL PPiSedMOlWmqDJMygNNuQ4sLuQIhnwM48aTqdtZoEmlMOFlLMawir45bK5Q/09ePEgwP c4ZgpjT72QGRTaVxBEsYbGggQmSaHfbIrIkQygk1cyF492W+tVim5x8S74OZs0WARDb8 MEO4Le4SFZF+bWbxCXOPtcwgDyH1Vgvf0Vj81LcvpxNQkgmpPBPALFVaU0jwsMCRPydV ABnPT/jYPp+2+cjTBoehfoXS2qh//R6IuunUEjuQh46V3sjJDJsm6Jy/pMRv366qXQvR 9w4g== X-Gm-Message-State: ALoCoQnccls7ffuC0bF5Ol6BCCa+/S8dRaMCSMST6DH60TMK7C7tbu6doNvAZyeKIJEpL10sSVlq X-Received: by 10.194.172.167 with SMTP id bd7mr760449wjc.74.1406113082423; Wed, 23 Jul 2014 03:58:02 -0700 (PDT) Received: from pistachio.icx.intel.com ([83.217.123.106]) by mx.google.com with ESMTPSA id de5sm7787760wib.18.2014.07.23.03.58.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jul 2014 03:58:01 -0700 (PDT) From: Thomas Wood To: intel-gfx@lists.freedesktop.org Date: Wed, 23 Jul 2014 11:57:50 +0100 Message-Id: <1406113075-30860-4-git-send-email-thomas.wood@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1406113075-30860-1-git-send-email-thomas.wood@intel.com> References: <1406113075-30860-1-git-send-email-thomas.wood@intel.com> Cc: daniel.vetter@ffwll.ch Subject: [Intel-gfx] [PATCH i-g-t 3/8] lib: move option parsing into common_init X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 Move option parsing into common_init so it can be shared between simple tests and tests with subtests. This allows for more common command line behaviour across all tests. Signed-off-by: Thomas Wood Reviewed-by: Tim Gore --- lib/igt_core.c | 118 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 44 deletions(-) diff --git a/lib/igt_core.c b/lib/igt_core.c index 5c20581..ee6f90c 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -291,30 +291,11 @@ static void oom_adjust_for_doom(void) igt_assert(write(fd, always_kill, sizeof(always_kill)) == sizeof(always_kill)); } -/** - * igt_subtest_init_parse_opts: - * @argc: argc from the test's main() - * @argv: argv from the test's main() - * @extra_short_opts: getopt_long() compliant list with additional short options - * @extra_long_opts: getopt_long() compliant list with additional long options - * @help_str: help string for the additional options - * @extra_opt_handler: handler for the additional options - * - * This function handles the subtest related cmdline options and allows an - * arbitrary set of additional options. This is useful for tests which have - * additional knobs to tune when run manually like the number of rounds execute - * or the size of the allocated buffer objects. - * - * Tests without special needs should just use igt_subtest_init() or use - * #igt_main directly instead of their own main() function. - * - * Returns: Forwards any option parsing errors from getopt_long. - */ -int igt_subtest_init_parse_opts(int argc, char **argv, - const char *extra_short_opts, - struct option *extra_long_opts, - const char *help_str, - igt_opt_handler_t extra_opt_handler) +static int common_init(int argc, char **argv, + const char *extra_short_opts, + struct option *extra_long_opts, + const char *help_str, + igt_opt_handler_t extra_opt_handler) { int c, option_index = 0; static struct option long_options[] = { @@ -328,8 +309,18 @@ int igt_subtest_init_parse_opts(int argc, char **argv, int extra_opt_count; int all_opt_count; int ret = 0; + char *env = getenv("IGT_LOG_LEVEL"); - test_with_subtests = true; + if (env) { + if (strcmp(env, "debug") == 0) + igt_log_level = IGT_LOG_DEBUG; + else if (strcmp(env, "info") == 0) + igt_log_level = IGT_LOG_INFO; + else if (strcmp(env, "warn") == 0) + igt_log_level = IGT_LOG_WARN; + else if (strcmp(env, "none") == 0) + igt_log_level = IGT_LOG_NONE; + } command_str = argv[0]; if (strrchr(command_str, '/')) @@ -389,36 +380,70 @@ int igt_subtest_init_parse_opts(int argc, char **argv, } } - igt_install_exit_handler(check_igt_exit); oom_adjust_for_doom(); out: free(short_opts); free(combined_opts); + + /* exit immediately if this test has no subtests and a subtest or the + * list of subtests has been requested */ + if (!test_with_subtests) { + if (run_single_subtest) { + igt_warn("Unknown subtest: %s\n", run_single_subtest); + exit(-1); + } + if (list_subtests) + exit(-1); + } + + if (ret < 0) + /* exit with no error for -h/--help */ + exit(ret == -1 ? 0 : ret); + print_version(); return ret; } -enum igt_log_level igt_log_level = IGT_LOG_INFO; -static void common_init(void) +/** + * igt_subtest_init_parse_opts: + * @argc: argc from the test's main() + * @argv: argv from the test's main() + * @extra_short_opts: getopt_long() compliant list with additional short options + * @extra_long_opts: getopt_long() compliant list with additional long options + * @help_str: help string for the additional options + * @extra_opt_handler: handler for the additional options + * + * This function handles the subtest related cmdline options and allows an + * arbitrary set of additional options. This is useful for tests which have + * additional knobs to tune when run manually like the number of rounds execute + * or the size of the allocated buffer objects. + * + * Tests without special needs should just use igt_subtest_init() or use + * #igt_main directly instead of their own main() function. + * + * Returns: Forwards any option parsing errors from getopt_long. + */ +int igt_subtest_init_parse_opts(int argc, char **argv, + const char *extra_short_opts, + struct option *extra_long_opts, + const char *help_str, + igt_opt_handler_t extra_opt_handler) { - char *env = getenv("IGT_LOG_LEVEL"); + int ret; - if (!env) - return; + test_with_subtests = true; + ret = common_init(argc, argv, extra_short_opts, extra_long_opts, + help_str, extra_opt_handler); + igt_install_exit_handler(check_igt_exit); - if (strcmp(env, "debug") == 0) - igt_log_level = IGT_LOG_DEBUG; - else if (strcmp(env, "info") == 0) - igt_log_level = IGT_LOG_INFO; - else if (strcmp(env, "warn") == 0) - igt_log_level = IGT_LOG_WARN; - else if (strcmp(env, "none") == 0) - igt_log_level = IGT_LOG_NONE; + return ret; } +enum igt_log_level igt_log_level = IGT_LOG_INFO; + /** * igt_subtest_init: * @argc: argc from the test's main() @@ -446,8 +471,6 @@ void igt_subtest_init(int argc, char **argv) /* reset opt parsing */ optind = 1; - - common_init(); } /** @@ -463,11 +486,18 @@ void igt_subtest_init(int argc, char **argv) */ void igt_simple_init(int argc, char **argv) { - print_version(); + int ret; - oom_adjust_for_doom(); + /* supress getopt errors about unknown options */ + opterr = 0; + + ret = common_init(argc, argv, NULL, NULL, NULL, NULL); + if (ret < 0) + /* exit with no error for -h/--help */ + exit(ret == -1 ? 0 : ret); - common_init(); + /* reset opt parsing */ + optind = 1; } /*