public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: tim.gore@intel.com
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH v2 2/2] intel-gpu-tools: Re-use igt_subtest_init for simple tests
Date: Mon,  7 Jul 2014 10:49:17 +0100	[thread overview]
Message-ID: <1404726557-32207-3-git-send-email-tim.gore@intel.com> (raw)
In-Reply-To: <1404726557-32207-1-git-send-email-tim.gore@intel.com>

From: Tim Gore <tim.gore@intel.com>

igt_subtest_init mainly does stuff that we also want for
simple/single tests, such as looking for --list-subtests
and --help options and calling common_init. So just call
this from igt_simple_init and then set tests_with_subtests
to false. NOTE that this means that check_igt_exit is now
registered as an exit handler for single tests, so need to
make sure that ALL tests exit via igt_exit.

Signed-off-by: Tim Gore <tim.gore@intel.com>
---
 lib/igt_core.c         | 37 +++++++++++++++++++++----------------
 lib/igt_core.h         |  4 ++--
 tests/gem_gtt_hog.c    |  2 +-
 tests/igt_simulation.c |  4 ++--
 4 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index b822bc9..7871360 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -457,14 +457,21 @@ void igt_subtest_init(int argc, char **argv)
  * If there's not a reason to the contrary it's less error prone to just use an
  * #igt_simple_main block instead of stitching the tests's main() function together
  * manually.
+ * We now call through to the igt_subtest_init function since we want most of its
+ * functionality. Note that this will install the igt_exit_handler so you need to
+ * exit via igt_exit(), Dont call exit()
+ *
  */
-void __igt_simple_init(void)
+void __igt_simple_init(int argc, char **argv)
 {
-	print_version();
-
-	oom_adjust_for_doom();
-
-	common_init();
+        /* use igt_subtest_init, it does mostly what we want */
+	igt_subtest_init(argc, argv);
+	/* but of course we dont have subtests - so mark this */
+	test_with_subtests = false;
+	if (list_subtests)
+		igt_exit();
+	if (run_single_subtest)
+		igt_fail(1);    /* we dont have subtests ! */
 }
 
 /*
@@ -565,7 +572,7 @@ void igt_skip(const char *f, ...)
 		assert(in_fixture);
 		__igt_fixture_end();
 	} else {
-		exit(IGT_EXIT_SKIP);
+		igt_exit();
 	}
 }
 
@@ -655,7 +662,7 @@ void igt_fail(int exitcode)
 			__igt_fixture_end();
 		}
 
-		exit(exitcode);
+		igt_exit();
 	}
 }
 
@@ -713,18 +720,16 @@ void igt_exit(void)
 	if (igt_only_list_subtests())
 		exit(IGT_EXIT_SUCCESS);
 
-	if (!test_with_subtests)
-		exit(IGT_EXIT_SUCCESS);
-
-	/* Calling this without calling one of the above is a failure */
-	assert(skipped_one || succeeded_one || failed_one);
+	if (test_with_subtests)
+		/* Calling this without calling one of the above is a failure */
+		assert(skipped_one || succeeded_one || failed_one);
 
 	if (failed_one)
 		exit(igt_exitcode);
-	else if (succeeded_one)
-		exit(IGT_EXIT_SUCCESS);
-	else
+	else if (skipped_one)
 		exit(IGT_EXIT_SKIP);
+	else
+		exit(IGT_EXIT_SUCCESS);
 }
 
 /* fork support code */
diff --git a/lib/igt_core.h b/lib/igt_core.h
index 75ee60c..448beed 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -166,7 +166,7 @@ bool igt_only_list_subtests(void);
  *
  * Init for simple tests without subtests
  */
-void __igt_simple_init(void);
+void __igt_simple_init(int argc, char **argv);
 
 /**
  * igt_simple_main:
@@ -181,7 +181,7 @@ void __igt_simple_init(void);
 #define igt_simple_main \
 	static void igt_tokencat(__real_main, __LINE__)(int argc, char **argv); \
 	int main(int argc, char **argv) { \
-		__igt_simple_init(); \
+		__igt_simple_init(argc, argv); \
 		igt_tokencat(__real_main, __LINE__)(argc, argv); \
 		igt_exit(); \
 	} \
diff --git a/tests/gem_gtt_hog.c b/tests/gem_gtt_hog.c
index 5d47540..f607ea0 100644
--- a/tests/gem_gtt_hog.c
+++ b/tests/gem_gtt_hog.c
@@ -150,7 +150,7 @@ static void run(data_t *data, int child)
 	munmap(ptr, size);
 
 	igt_assert(x == canary);
-	exit(0);
+	_exit(0);
 }
 
 igt_simple_main
diff --git a/tests/igt_simulation.c b/tests/igt_simulation.c
index 6d8a59a..5d38026 100644
--- a/tests/igt_simulation.c
+++ b/tests/igt_simulation.c
@@ -53,11 +53,11 @@ static int do_fork(void)
 		assert(0);
 	case 0:
 		if (simple) {
-			__igt_simple_init();
+			__igt_simple_init(1, argv_run);
 
 			igt_skip_on_simulation();
 
-			exit(0);
+			igt_exit();
 		} else {
 			if (list_subtests)
 				igt_subtest_init(2, argv_list);
-- 
1.9.2

      parent reply	other threads:[~2014-07-07  9:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-07  9:49 [PATCH v2 0/2] Single tests to respond to --list-subtests tim.gore
2014-07-07  9:49 ` [PATCH v2 1/2] intel-gpu-tools: pass argc/argv to simple main tim.gore
2014-07-07  9:49 ` tim.gore [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1404726557-32207-3-git-send-email-tim.gore@intel.com \
    --to=tim.gore@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox