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@xxxxxxxxxx> --- 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@xxxxxxxxxxxxxxxxx> 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