diff mbox

[3/3] pm_rps: Fix verbose option and streamline its use

Message ID 1389999366-19715-4-git-send-email-jeff.mcgee@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

jeff.mcgee@intel.com Jan. 17, 2014, 10:56 p.m. UTC
From: Jeff McGee <jeff.mcgee@intel.com>

Signed-off-by: Jeff McGee <jeff.mcgee@intel.com>
---
 tests/pm_rps.c | 52 ++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 42 insertions(+), 10 deletions(-)

Comments

Daniel Vetter Jan. 18, 2014, 2:23 p.m. UTC | #1
On Fri, Jan 17, 2014 at 04:56:06PM -0600, jeff.mcgee@intel.com wrote:
> From: Jeff McGee <jeff.mcgee@intel.com>
> 
> Signed-off-by: Jeff McGee <jeff.mcgee@intel.com>

Ah, now I understand your question for a unified verbose handling. I guess
if someone is bored (or if there's a need in testrunner frameworks for it)
we could add a bit of infrastructure for verbose logging and similar
things. I'll add a note on our i-g-t ideas wiki page.

All patches merged, thanks.
-Daniel

> ---
>  tests/pm_rps.c | 52 ++++++++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 42 insertions(+), 10 deletions(-)
> 
> diff --git a/tests/pm_rps.c b/tests/pm_rps.c
> index 4d64f0a..192dca7 100644
> --- a/tests/pm_rps.c
> +++ b/tests/pm_rps.c
> @@ -31,6 +31,7 @@
>  #include <stdlib.h>
>  #include <string.h>
>  #include <unistd.h>
> +#include <getopt.h>
>  #include "drmtest.h"
>  
>  static bool verbose = false;
> @@ -130,6 +131,8 @@ static void dumpit(void)
>  
>  	printf("\n");
>  }
> +#define dump() if (verbose) dumpit()
> +#define log(...) if (verbose) printf(__VA_ARGS__)
>  
>  static void pm_rps_exit_handler(int sig)
>  {
> @@ -142,8 +145,40 @@ static void pm_rps_exit_handler(int sig)
>  	}
>  }
>  
> -igt_main
> +static int opt_handler(int opt, int opt_index)
>  {
> +	switch (opt) {
> +	case 'v':
> +		verbose = true;
> +		break;
> +	default:
> +		assert(0);
> +	}
> +
> +	return 0;
> +}
> +
> +/* Mod of igt_subtest_init that adds our extra options */
> +void subtest_init(int argc, char **argv)
> +{
> +	struct option long_opts[] = {
> +		{"verbose", 0, 0, 'v'}
> +	};
> +	const char *help_str = "  -v, --verbose";
> +	int ret;
> +
> +	ret = igt_subtest_init_parse_opts(argc, argv, "v", long_opts, 
> +					  help_str, opt_handler);
> +
> +	if (ret < 0)
> +		/* exit with no error for -h/--help */
> +		exit(ret == -1 ? 0 : ret);
> +}
> +
> +int main(int argc, char **argv)
> +{
> +	subtest_init(argc, argv);
> +
>  	igt_skip_on_simulation();
>  
>  	igt_fixture {
> @@ -176,21 +211,16 @@ igt_main
>  	}
>  
>  	igt_subtest("min-max-config-at-idle") {
> -		if (verbose)
> -			printf("Original min = %d\nOriginal max = %d\n",
> -			        origmin, origmax);
> +		log("Original min = %d\nOriginal max = %d\n", origmin, origmax);
>  
> -		if (verbose)
> -			dumpit();
> +		dump();
>  
>  		checkit();
>  		setfreq(origmin);
> -		if (verbose)
> -			dumpit();
> +		dump();
>  		igt_assert(fcur == fmin);
>  		setfreq(origmax);
> -		if (verbose)
> -			dumpit();
> +		dump();
>  		igt_assert(fcur == fmax);
>  		checkit();
>  
> @@ -209,4 +239,6 @@ igt_main
>  		writeval(stuff[MIN].filp, origmin);
>  		writeval(stuff[MAX].filp, origmax);
>  	}
> +
> +	igt_exit();
>  }
> -- 
> 1.8.5.2
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Daniel Vetter Jan. 19, 2014, 9:33 p.m. UTC | #2
On Fri, Jan 17, 2014 at 04:56:06PM -0600, jeff.mcgee@intel.com wrote:
> From: Jeff McGee <jeff.mcgee@intel.com>
> 
> Signed-off-by: Jeff McGee <jeff.mcgee@intel.com>
> ---
>  tests/pm_rps.c | 52 ++++++++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 42 insertions(+), 10 deletions(-)
> 
> diff --git a/tests/pm_rps.c b/tests/pm_rps.c
> index 4d64f0a..192dca7 100644
> --- a/tests/pm_rps.c
> +++ b/tests/pm_rps.c
> @@ -31,6 +31,7 @@
>  #include <stdlib.h>
>  #include <string.h>
>  #include <unistd.h>
> +#include <getopt.h>
>  #include "drmtest.h"
>  
>  static bool verbose = false;
> @@ -130,6 +131,8 @@ static void dumpit(void)
>  
>  	printf("\n");
>  }
> +#define dump() if (verbose) dumpit()
> +#define log(...) if (verbose) printf(__VA_ARGS__)
>  
>  static void pm_rps_exit_handler(int sig)
>  {
> @@ -142,8 +145,40 @@ static void pm_rps_exit_handler(int sig)
>  	}
>  }
>  
> -igt_main
> +static int opt_handler(int opt, int opt_index)
>  {
> +	switch (opt) {
> +	case 'v':
> +		verbose = true;
> +		break;
> +	default:
> +		assert(0);
> +	}
> +
> +	return 0;
> +}
> +
> +/* Mod of igt_subtest_init that adds our extra options */
> +void subtest_init(int argc, char **argv)

Missing static here. I've added it back in.
-Daniel

> +{
> +	struct option long_opts[] = {
> +		{"verbose", 0, 0, 'v'}
> +	};
> +	const char *help_str = "  -v, --verbose";
> +	int ret;
> +
> +	ret = igt_subtest_init_parse_opts(argc, argv, "v", long_opts,
> +					  help_str, opt_handler);
> +
> +	if (ret < 0)
> +		/* exit with no error for -h/--help */
> +		exit(ret == -1 ? 0 : ret);
> +}
> +
> +int main(int argc, char **argv)
> +{
> +	subtest_init(argc, argv);
> +
>  	igt_skip_on_simulation();
>  
>  	igt_fixture {
> @@ -176,21 +211,16 @@ igt_main
>  	}
>  
>  	igt_subtest("min-max-config-at-idle") {
> -		if (verbose)
> -			printf("Original min = %d\nOriginal max = %d\n",
> -			        origmin, origmax);
> +		log("Original min = %d\nOriginal max = %d\n", origmin, origmax);
>  
> -		if (verbose)
> -			dumpit();
> +		dump();
>  
>  		checkit();
>  		setfreq(origmin);
> -		if (verbose)
> -			dumpit();
> +		dump();
>  		igt_assert(fcur == fmin);
>  		setfreq(origmax);
> -		if (verbose)
> -			dumpit();
> +		dump();
>  		igt_assert(fcur == fmax);
>  		checkit();
>  
> @@ -209,4 +239,6 @@ igt_main
>  		writeval(stuff[MIN].filp, origmin);
>  		writeval(stuff[MAX].filp, origmax);
>  	}
> +
> +	igt_exit();
>  }
> -- 
> 1.8.5.2
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
diff mbox

Patch

diff --git a/tests/pm_rps.c b/tests/pm_rps.c
index 4d64f0a..192dca7 100644
--- a/tests/pm_rps.c
+++ b/tests/pm_rps.c
@@ -31,6 +31,7 @@ 
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <getopt.h>
 #include "drmtest.h"
 
 static bool verbose = false;
@@ -130,6 +131,8 @@  static void dumpit(void)
 
 	printf("\n");
 }
+#define dump() if (verbose) dumpit()
+#define log(...) if (verbose) printf(__VA_ARGS__)
 
 static void pm_rps_exit_handler(int sig)
 {
@@ -142,8 +145,40 @@  static void pm_rps_exit_handler(int sig)
 	}
 }
 
-igt_main
+static int opt_handler(int opt, int opt_index)
 {
+	switch (opt) {
+	case 'v':
+		verbose = true;
+		break;
+	default:
+		assert(0);
+	}
+
+	return 0;
+}
+
+/* Mod of igt_subtest_init that adds our extra options */
+void subtest_init(int argc, char **argv)
+{
+	struct option long_opts[] = {
+		{"verbose", 0, 0, 'v'}
+	};
+	const char *help_str = "  -v, --verbose";
+	int ret;
+
+	ret = igt_subtest_init_parse_opts(argc, argv, "v", long_opts,
+					  help_str, opt_handler);
+
+	if (ret < 0)
+		/* exit with no error for -h/--help */
+		exit(ret == -1 ? 0 : ret);
+}
+
+int main(int argc, char **argv)
+{
+	subtest_init(argc, argv);
+
 	igt_skip_on_simulation();
 
 	igt_fixture {
@@ -176,21 +211,16 @@  igt_main
 	}
 
 	igt_subtest("min-max-config-at-idle") {
-		if (verbose)
-			printf("Original min = %d\nOriginal max = %d\n",
-			        origmin, origmax);
+		log("Original min = %d\nOriginal max = %d\n", origmin, origmax);
 
-		if (verbose)
-			dumpit();
+		dump();
 
 		checkit();
 		setfreq(origmin);
-		if (verbose)
-			dumpit();
+		dump();
 		igt_assert(fcur == fmin);
 		setfreq(origmax);
-		if (verbose)
-			dumpit();
+		dump();
 		igt_assert(fcur == fmax);
 		checkit();
 
@@ -209,4 +239,6 @@  igt_main
 		writeval(stuff[MIN].filp, origmin);
 		writeval(stuff[MAX].filp, origmax);
 	}
+
+	igt_exit();
 }