linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Kacur <jkacur@redhat.com>
To: rt-users <linux-rt-users@vger.kernel.org>
Cc: Clark Williams <williams@redhat.com>, John Kacur <jkacur@redhat.com>
Subject: [PATCH 2/8] rt-tests: ssdd: Add short and long functions as well as help
Date: Mon, 25 Nov 2019 15:16:40 +0100	[thread overview]
Message-ID: <20191125141644.4429-2-jkacur@redhat.com> (raw)
In-Reply-To: <20191125141644.4429-1-jkacur@redhat.com>

Add short and long functions as well as help to make ssdd consistent
with the rest of the test suite. Add a help function as well

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/ssdd/ssdd.8 | 10 +++++++---
 src/ssdd/ssdd.c | 45 +++++++++++++++++++++++++++++++++++++++------
 2 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/src/ssdd/ssdd.8 b/src/ssdd/ssdd.8
index 44638489f0d1..99f30145d079 100644
--- a/src/ssdd/ssdd.8
+++ b/src/ssdd/ssdd.8
@@ -3,7 +3,7 @@
 ssdd \- have a tracer do a bunch of PTRACE_SINGLESTEPs
 .SH SYNOPSIS
 .B ssdd
-.RI "[nforks] [niters]"
+.RI "<options>"
 .SH DESCRIPTION
 Have a tracer do a bunch of PTRACE_SINGLESTEPs against
 a tracee as fast as possible.  Create several of these
@@ -12,15 +12,19 @@ interfere with each other.
 The tracer waits on each PTRACE_SINGLESTEP with a waitpid(2)
 and checks that waitpid's return values for correctness.
 .SH OPTIONS
-.B nforks
+.B \-f, \-\-forks
 number of tracer/tracee pairs to fork off.
 Default is 10.
 .br
 .TP
-.B niters
+.B \-i, \-\-iters
 number of PTRACE_SINGLESTEP iterations to
 do before declaring success, for each tracer/
 tracee pair set up. Default is 10,000.
+.br
+.TP
+.B \-h, \-\-help
+Display usage
 
 .SH AUTHOR
 ssdd was written by Joe Korty <joe.korty@concurrent-rt.com>
diff --git a/src/ssdd/ssdd.c b/src/ssdd/ssdd.c
index 2c3a779be9f1..080ed17107a8 100644
--- a/src/ssdd/ssdd.c
+++ b/src/ssdd/ssdd.c
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <stddef.h>
 #include <unistd.h>
+#include <getopt.h>
 #include <string.h>
 #include <signal.h>
 #include <errno.h>
@@ -65,6 +66,17 @@ static const char *get_state_name(int state)
 
 static int got_sigchld;
 
+enum option_value { OPT_NFORKS=1, OPT_NITERS, OPT_HELP };
+
+static void usage()
+{
+	printf("ssdd <options>\n");
+	printf("\t-f --forks=<number of forks>\n");
+	printf("\t-i --iters=<number of iterations>\n");
+	printf("\t-h --help\n");
+	exit(0);
+}
+
 static int do_wait(pid_t *wait_pid, int *ret_sig)
 {
 	int status, child_status;
@@ -276,13 +288,34 @@ int main(int argc, char **argv)
 
 	setbuf(stdout, NULL);
 
-	argc--, argv++;
-	if (argc) {
-		nforks = atoi(*argv);
-		argc--, argv++;
-		if (argc)
-			nsteps = atoi(*argv);
+	for (;;) {
+		int option_index = 0;
+
+		static struct option long_options[] = {
+			{"forks", required_argument, NULL, OPT_NFORKS},
+			{"iters", required_argument, NULL, OPT_NITERS},
+			{"help", no_argument, NULL, OPT_HELP},
+			{NULL, 0, NULL, 0},
+		};
+		int c = getopt_long(argc, argv, "f:i:h", long_options, &option_index);
+		if (c == -1)
+			break;
+		switch(c) {
+			case 'f':
+			case OPT_NFORKS:
+				nforks = atoi(optarg);
+				break;
+			case 'i':
+			case OPT_NITERS:
+				nsteps = atoi(optarg);
+				break;
+			case 'h':
+			case OPT_HELP:
+				usage();
+				break;
+		}
 	}
+
 	printf("#main : %d\n", getpid());
 	printf("#forks: %d\n", nforks);
 	printf("#steps: %d\n", nsteps);
-- 
2.20.1


  reply	other threads:[~2019-11-25 14:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-25 14:16 [PATCH 1/8] rt-tests: queuelat: Fix some warnings in determine_maximum_mpps.sh John Kacur
2019-11-25 14:16 ` John Kacur [this message]
2019-11-25 14:16 ` [PATCH 5/8] rt-tests: cyclictest: Get a snapshot of cyclictest without interuppting it John Kacur
2019-11-25 14:16 ` [PATCH 6/8] cyclictest: Sync manpage with the help option John Kacur
2019-11-25 14:16 ` [PATCH 7/8] svsematest: Add -S, --smp option to manpage John Kacur
2019-11-25 14:16 ` [PATCH 8/8] rt-tests: Add SPDX tags John Kacur
2019-11-25 14:33   ` Sebastian Andrzej Siewior

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=20191125141644.4429-2-jkacur@redhat.com \
    --to=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=williams@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).