diff mbox series

[rt-tests,v1,09/12] svsematest: Add quiet command line option

Message ID 20201118190642.16006-10-dwagner@suse.de
State New
Headers show
Series Add quiet command line option | expand

Commit Message

Daniel Wagner Nov. 18, 2020, 7:06 p.m. UTC
The quiet option is useful for automated test setups where
only the final result of the run is interesting. This avoids
to fill up the logs.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 src/svsematest/svsematest.8 |  5 ++++-
 src/svsematest/svsematest.c | 18 ++++++++++++++----
 2 files changed, 18 insertions(+), 5 deletions(-)

Comments

John Kacur Dec. 1, 2020, 7:12 a.m. UTC | #1
On Wed, 18 Nov 2020, Daniel Wagner wrote:

> The quiet option is useful for automated test setups where

> only the final result of the run is interesting. This avoids

> to fill up the logs.

> 

> Signed-off-by: Daniel Wagner <dwagner@suse.de>

> ---

>  src/svsematest/svsematest.8 |  5 ++++-

>  src/svsematest/svsematest.c | 18 ++++++++++++++----

>  2 files changed, 18 insertions(+), 5 deletions(-)

> 

> diff --git a/src/svsematest/svsematest.8 b/src/svsematest/svsematest.8

> index 5fcb96149bdd..828f9154e974 100644

> --- a/src/svsematest/svsematest.8

> +++ b/src/svsematest/svsematest.8

> @@ -4,7 +4,7 @@

>  \fBsvsematest\fR \- Start two threads or fork two processes and measure the latency of SYSV semaphores

>  .SH "SYNTAX"

>  .LP

> -svsematest [-a|--affinity NUM] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME] [-f|--fork [OPT]] [-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-S|--smp] [-t|--threads [NUM]]

> +svsematest [-a|--affinity NUM] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME] [-f|--fork [OPT]] [-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-q|--quiet] [-S|--smp] [-t|--threads [NUM]]

>  .br

>  .SH "DESCRIPTION"

>  .LP

> @@ -38,6 +38,9 @@ Set the number of loops. The default is 0 (endless). This option is useful for a

>  .B \-p, \-\-prio=PRIO

>  Set the priority of the process.

>  .TP

> +.B \-q, \-\-quiet

> +Print a summary only on exit. Useful for automated tests, where only the summary output needs to be captured.

> +.TP

>  .B \-S, \-\-smp

>  SMP testing: options -a -t and same priority of all threads

>  .TP

> diff --git a/src/svsematest/svsematest.c b/src/svsematest/svsematest.c

> index 7de20dc65445..7388efb3f488 100644

> --- a/src/svsematest/svsematest.c

> +++ b/src/svsematest/svsematest.c

> @@ -253,6 +253,7 @@ static int interval = 1000;

>  static int distance = 500;

>  static int smp;

>  static int sameprio;

> +static int quiet;

>  

>  static void process_options(int argc, char *argv[])

>  {

> @@ -273,11 +274,12 @@ static void process_options(int argc, char *argv[])

>  			{"interval",		required_argument,	NULL, 'i'},

>  			{"loops",		required_argument,	NULL, 'l'},

>  			{"priority",		required_argument,	NULL, 'p'},

> +			{"quiet",		no_argument,		NULL, 'q'},

>  			{"smp",			no_argument,		NULL, 'S'},

>  			{"threads",		optional_argument,	NULL, 't'},

>  			{NULL, 0, NULL, 0}

>  		};

> -		int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:St::",

> +		int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:qSt::",

>  			long_options, &option_index);

>  		if (c == -1)

>  			break;

> @@ -315,6 +317,7 @@ static void process_options(int argc, char *argv[])

>  		case 'i': interval = atoi(optarg); break;

>  		case 'l': max_cycles = atoi(optarg); break;

>  		case 'p': priority = atoi(optarg); break;

> +		case 'q': quiet = 1; break;

>  		case 'S':

>  			smp = 1;

>  			num_threads = max_cpus;

> @@ -381,6 +384,9 @@ static void print_stat(FILE *fp, struct params *receiver, struct params *sender,

>  {

>  	int i;

>  

> +	if (quiet)

> +		return;

> +

>  	for (i = 0; i < num_threads; i++) {

>  		int receiver_pid, sender_pid;

>  

> @@ -646,8 +652,9 @@ int main(int argc, char *argv[])

>  			    sender[i].shutdown;

>  

>  		if (receiver[0].samples > oldsamples || mustshutdown) {

> -			print_stat(stdout, receiver, sender, 0, 0);

> -			printf("\033[%dA", num_threads*2);

> +			print_stat(stdout, receiver, sender, 0, quiet);

> +			if (!quiet)

> +				printf("\033[%dA", num_threads*2);

>  		}

>  

>  		sigemptyset(&sigset);

> @@ -662,7 +669,10 @@ int main(int argc, char *argv[])

>  		pthread_sigmask(SIG_SETMASK, &sigset, NULL);

>  	}

>  

> -	printf("\033[%dB", num_threads*2 + 2);

> +	if (!quiet)

> +		printf("\033[%dB", num_threads*2 + 2);

> +	else

> +		print_stat(stdout, receiver, sender, 0, 0);

>  

>  	for (i = 0; i < num_threads; i++) {

>  		receiver[i].shutdown = 1;

> -- 

> 2.29.2

> 

> 

Signed-off-by: John Kacur <jkacur@redhat.com>
diff mbox series

Patch

diff --git a/src/svsematest/svsematest.8 b/src/svsematest/svsematest.8
index 5fcb96149bdd..828f9154e974 100644
--- a/src/svsematest/svsematest.8
+++ b/src/svsematest/svsematest.8
@@ -4,7 +4,7 @@ 
 \fBsvsematest\fR \- Start two threads or fork two processes and measure the latency of SYSV semaphores
 .SH "SYNTAX"
 .LP
-svsematest [-a|--affinity NUM] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME] [-f|--fork [OPT]] [-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-S|--smp] [-t|--threads [NUM]]
+svsematest [-a|--affinity NUM] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME] [-f|--fork [OPT]] [-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-q|--quiet] [-S|--smp] [-t|--threads [NUM]]
 .br
 .SH "DESCRIPTION"
 .LP
@@ -38,6 +38,9 @@  Set the number of loops. The default is 0 (endless). This option is useful for a
 .B \-p, \-\-prio=PRIO
 Set the priority of the process.
 .TP
+.B \-q, \-\-quiet
+Print a summary only on exit. Useful for automated tests, where only the summary output needs to be captured.
+.TP
 .B \-S, \-\-smp
 SMP testing: options -a -t and same priority of all threads
 .TP
diff --git a/src/svsematest/svsematest.c b/src/svsematest/svsematest.c
index 7de20dc65445..7388efb3f488 100644
--- a/src/svsematest/svsematest.c
+++ b/src/svsematest/svsematest.c
@@ -253,6 +253,7 @@  static int interval = 1000;
 static int distance = 500;
 static int smp;
 static int sameprio;
+static int quiet;
 
 static void process_options(int argc, char *argv[])
 {
@@ -273,11 +274,12 @@  static void process_options(int argc, char *argv[])
 			{"interval",		required_argument,	NULL, 'i'},
 			{"loops",		required_argument,	NULL, 'l'},
 			{"priority",		required_argument,	NULL, 'p'},
+			{"quiet",		no_argument,		NULL, 'q'},
 			{"smp",			no_argument,		NULL, 'S'},
 			{"threads",		optional_argument,	NULL, 't'},
 			{NULL, 0, NULL, 0}
 		};
-		int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:St::",
+		int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:qSt::",
 			long_options, &option_index);
 		if (c == -1)
 			break;
@@ -315,6 +317,7 @@  static void process_options(int argc, char *argv[])
 		case 'i': interval = atoi(optarg); break;
 		case 'l': max_cycles = atoi(optarg); break;
 		case 'p': priority = atoi(optarg); break;
+		case 'q': quiet = 1; break;
 		case 'S':
 			smp = 1;
 			num_threads = max_cpus;
@@ -381,6 +384,9 @@  static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
 {
 	int i;
 
+	if (quiet)
+		return;
+
 	for (i = 0; i < num_threads; i++) {
 		int receiver_pid, sender_pid;
 
@@ -646,8 +652,9 @@  int main(int argc, char *argv[])
 			    sender[i].shutdown;
 
 		if (receiver[0].samples > oldsamples || mustshutdown) {
-			print_stat(stdout, receiver, sender, 0, 0);
-			printf("\033[%dA", num_threads*2);
+			print_stat(stdout, receiver, sender, 0, quiet);
+			if (!quiet)
+				printf("\033[%dA", num_threads*2);
 		}
 
 		sigemptyset(&sigset);
@@ -662,7 +669,10 @@  int main(int argc, char *argv[])
 		pthread_sigmask(SIG_SETMASK, &sigset, NULL);
 	}
 
-	printf("\033[%dB", num_threads*2 + 2);
+	if (!quiet)
+		printf("\033[%dB", num_threads*2 + 2);
+	else
+		print_stat(stdout, receiver, sender, 0, 0);
 
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;