summaryrefslogtreecommitdiff
path: root/x11perf.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2024-04-18 13:27:10 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2024-04-18 13:56:14 -0700
commit6deca4cb7bd0293760d0f1e3678387d74ca72251 (patch)
tree438f361f1b783327d0e68da2b8502d7df72192dd /x11perf.c
parent7e24793ede11649a412413ff2567bf20670ba4ef (diff)
Add -help [options|tests|all] and remove tests from default usage message
Previously, the error message when giving a bad option was over 350 lines long. This moves the list of tests out into the `-help tests` option and makes the usage error message a much more reasonable 32 lines long. (Also accepts but does not document --help.) Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Part-of: <https://gitlab.freedesktop.org/xorg/test/x11perf/-/merge_requests/10>
Diffstat (limited to 'x11perf.c')
-rw-r--r--x11perf.c111
1 files changed, 67 insertions, 44 deletions
diff --git a/x11perf.c b/x11perf.c
index cea0351..763d19d 100644
--- a/x11perf.c
+++ b/x11perf.c
@@ -319,7 +319,12 @@ ReportTimes(double usecs, int64_t n, char *str, int average)
************************************************/
static char *program_name;
-static void usage(void) _X_NORETURN;
+typedef enum {
+ USAGE_OPTIONS,
+ USAGE_TESTS,
+ USAGE_ALL
+} usage_contents;
+_X_NORETURN _X_COLD static void usage(usage_contents, int);
/*
* Get_Display_Name (argc, argv) Look for -display, -d, or host:dpy (obsolete)
@@ -337,7 +342,7 @@ Get_Display_Name(int *pargc, /* MODIFIED */
char *arg = argv[i];
if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) {
- if (++i >= argc) usage ();
+ if (++i >= argc) usage (USAGE_OPTIONS, EXIT_FAILURE);
displayname = argv[i];
*pargc -= 2;
@@ -467,7 +472,7 @@ AbortTest(void)
static void
-usage(void)
+usage(usage_contents show, int exit_status)
{
int i = 0;
static const char *help_message =
@@ -503,26 +508,27 @@ usage(void)
" -version print version and exit\n"
" -su request save unders on windows\n"
" -bs <backing_store_hint> WhenMapped or Always (default = NotUseful)\n"
+" -help [options|tests|all] list general options, test options, or both\n"
;
fflush(stdout);
- fprintf(stderr, "usage: %s [-options ...]\n%s", program_name, help_message);
- while (test[i].option != NULL) {
- if (test[i].versions & xparms.version ) {
- fprintf(stderr, " %-24s %s\n",
- test[i].option,
- test[i].label14 ? test[i].label14 : test[i].label);
- }
- i++;
+ if (show == USAGE_OPTIONS || show == USAGE_ALL) {
+ fprintf(stderr, "usage: %s [-options ...]\n%s",
+ program_name, help_message);
+ }
+ if (show == USAGE_TESTS || show == USAGE_ALL) {
+ while (test[i].option != NULL) {
+ if (test[i].versions & xparms.version ) {
+ fprintf(stderr, " %-24s %s\n",
+ test[i].option,
+ test[i].label14 ? test[i].label14 : test[i].label);
+ }
+ i++;
+ }
}
fprintf(stderr, "\n");
- /* Print out original command line as the above usage message is so long */
- for (i = 0; i != saveargc; i++) {
- fprintf(stderr, "%s ", saveargv[i]);
- }
- fprintf(stderr, "\n\n");
- exit (1);
+ exit (exit_status);
}
void
@@ -931,7 +937,7 @@ main(int argc, char *argv[])
char *cp2;
if (argc <= ++i)
- usage();
+ usage(USAGE_OPTIONS, EXIT_FAILURE);
cp1 = argv[i];
if (*cp1 == '-')
cp1++;
@@ -953,12 +959,12 @@ main(int argc, char *argv[])
(test[k].versions & xparms.version)) &&
test[++k].option != NULL);
if (*cp2 != '-' && test[k].option == NULL)
- usage();
+ usage(USAGE_OPTIONS, EXIT_FAILURE);
break;
}
}
if (test[j].option == NULL)
- usage();
+ usage(USAGE_OPTIONS, EXIT_FAILURE);
foundOne = True;
} else if (strcmp (argv[i], "-sync") == 0) {
synchronous = True;
@@ -971,44 +977,44 @@ main(int argc, char *argv[])
} else if (strcmp (argv[i], "-repeat") == 0) {
i++;
if (argc <= i)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
repeat = atoi (argv[i]);
if (repeat <= 0)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
} else if (strcmp (argv[i], "-time") == 0) {
i++;
if (argc <= i)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
seconds = atoi (argv[i]);
if (seconds <= 0)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
} else if (strcmp (argv[i], "-pause") == 0) {
++i;
if (argc <= i)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
delay = atoi (argv[i]);
if (delay < 0)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
} else if (strcmp(argv[i], "-fg") == 0) {
i++;
if (argc <= i)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
foreground = argv[i];
} else if (strcmp(argv[i], "-bg") == 0) {
i++;
if (argc <= i)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
background = argv[i];
if(ddbackground == NULL)
ddbackground = argv[i];
} else if (strcmp(argv[i], "-clips") == 0 ) {
i++;
if (argc <= i)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
clips = atoi( argv[i] );
} else if (strcmp(argv[i], "-ddbg") == 0) {
if (argc <= i)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
i++;
ddbackground = argv[i];
} else if (strcmp(argv[i], "-rop") == 0) {
@@ -1033,21 +1039,21 @@ main(int argc, char *argv[])
} else if (strcmp(argv[i], "-reps") == 0) {
i++;
if (argc <= i)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
fixedReps = atoi (argv[i]);
if (fixedReps <= 0)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
} else if (strcmp(argv[i], "-depth") == 0) {
i++;
if (argc <= i)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
depth = atoi(argv[i]);
if (depth <= 0)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
} else if (strcmp(argv[i], "-vclass") == 0) {
i++;
if (argc <= i)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
for (j = StaticGray; j <= DirectColor; j++) {
if (strcmp(argv[i], visualClassNames[j]) == 0) {
vclass = j;
@@ -1055,7 +1061,7 @@ main(int argc, char *argv[])
}
}
if (vclass < 0)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
} else if (strcmp(argv[i], "-subs") == 0) {
skip = GetNumbers (i+1, argc, argv, subWindows, &numSubWindows);
i += skip;
@@ -1064,16 +1070,33 @@ main(int argc, char *argv[])
} else if (strcmp(argv[i], "-bs") == 0) {
i++;
if (argc <= i)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
if (strcmp(argv[i], "WhenMapped") == 0) {
xparms.backing_store = WhenMapped;
} else if (strcmp(argv[i], "Always") == 0) {
xparms.backing_store = Always;
- } else usage ();
+ } else usage (USAGE_OPTIONS, EXIT_FAILURE);
} else if ((strcmp(argv[i], "-version") == 0) ||
(strcmp(argv[i], "--version") == 0)) {
puts(PACKAGE_STRING);
exit(EXIT_SUCCESS);
+ } else if ((strcmp(argv[i], "-help") == 0) ||
+ (strcmp(argv[i], "--help") == 0)) {
+ i++;
+ /* default is to just show general options */
+ if (argc <= i || (strcmp(argv[i], "options") == 0)) {
+ usage (USAGE_OPTIONS, EXIT_SUCCESS);
+ }
+ else if (strcmp(argv[i], "tests") == 0) {
+ usage (USAGE_TESTS, EXIT_SUCCESS);
+ }
+ else if (strcmp(argv[i], "all") == 0) {
+ usage (USAGE_ALL, EXIT_SUCCESS);
+ }
+ else {
+ fprintf(stderr, "unknown --help argument: %s\n", argv[i]);
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
+ }
} else {
int len,found;
ForEachTest (j) {
@@ -1100,7 +1123,7 @@ main(int argc, char *argv[])
}
}
if(!found)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
LegalOption:
foundOne = True;
}
@@ -1176,7 +1199,7 @@ main(int argc, char *argv[])
}
if (!foundOne)
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
xparms.d = Open_Display (displayName);
screen = DefaultScreen(xparms.d);
@@ -1422,7 +1445,7 @@ GetWords (int argi, int argc, char **argv, char **wordsp, int *nump)
int count;
if (argc <= argi)
- usage();
+ usage(USAGE_OPTIONS, EXIT_FAILURE);
count = 0;
while (argv[argi] && *(argv[argi]) != '-') {
*wordsp++ = argv[argi];
@@ -1497,7 +1520,7 @@ GetRops (int argi, int argc, char **argv, int *ropsp, int *nump)
}
}
if (rop == NUM_ROPS) {
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
fprintf (stderr, "unknown rop name %s\n", words[i]);
}
}
@@ -1529,7 +1552,7 @@ GetPops (int argi, int argc, char **argv, int *popsp, int *nump)
}
}
if (pop == NUM_POPS) {
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
fprintf (stderr, "unknown picture op name %s\n", words[i]);
}
}
@@ -1574,7 +1597,7 @@ GetFormats (int argi, int argc, char **argv, int *formatsp, int *nump)
}
format = FormatFromName (words[i]);
if (format < 0) {
- usage ();
+ usage (USAGE_OPTIONS, EXIT_FAILURE);
fprintf (stderr, "unknown format name %s\n", words[i]);
}
formatsp[i] = format;