2004-12-16 Roland McGrath <roland@redhat.com>
[glibc.git] / argp / tst-argp1.c
blob2367d219e8a9e7f2f91f4fee80c4b127e64838b6
1 /* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <argp.h>
25 #define OPT_TO_THREAD 300
26 #define OPT_TO_PROCESS 301
27 #define OPT_SYNC_SIGNAL 302
28 #define OPT_SYNC_JOIN 303
29 #define OPT_TOPLEVEL 304
32 static const struct argp_option test_options[] =
34 { NULL, 0, NULL, 0, "\
35 This is a test for threads so we allow ther user to selection the number of \
36 threads which are used at any one time. Independently the total number of \
37 rounds can be selected. This is the total number of threads which will have \
38 run when the process terminates:" },
39 { "threads", 't', "NUMBER", 0, "Number of threads used at once" },
40 { "starts", 's', "NUMBER", 0, "Total number of working threads" },
41 { "toplevel", OPT_TOPLEVEL, "NUMBER", 0,
42 "Number of toplevel threads which start the other threads; this \
43 implies --sync-join" },
45 { NULL, 0, NULL, 0, "\
46 Each thread can do one of two things: sleep or do work. The latter is 100% \
47 CPU bound. The work load is the probability a thread does work. All values \
48 from zero to 100 (inclusive) are valid. How often each thread repeats this \
49 can be determined by the number of rounds. The work cost determines how long \
50 each work session (not sleeping) takes. If it is zero a thread would \
51 effectively nothing. By setting the number of rounds to zero the thread \
52 does no work at all and pure thread creation times can be measured." },
53 { "workload", 'w', "PERCENT", 0, "Percentage of time spent working" },
54 { "workcost", 'c', "NUMBER", 0,
55 "Factor in the cost of each round of working" },
56 { "rounds", 'r', "NUMBER", 0, "Number of rounds each thread runs" },
58 { NULL, 0, NULL, 0, "\
59 There are a number of different methods how thread creation can be \
60 synchronized. Synchronization is necessary since the number of concurrently \
61 running threads is limited." },
62 { "sync-signal", OPT_SYNC_SIGNAL, NULL, 0,
63 "Synchronize using a signal (default)" },
64 { "sync-join", OPT_SYNC_JOIN, NULL, 0, "Synchronize using pthread_join" },
66 { NULL, 0, NULL, 0, "\
67 One parameter for each threads execution is the size of the stack. If this \
68 parameter is not used the system's default stack size is used. If many \
69 threads are used the stack size should be chosen quite small." },
70 { "stacksize", 'S', "BYTES", 0, "Size of threads stack" },
71 { "guardsize", 'g', "BYTES", 0,
72 "Size of stack guard area; must fit into the stack" },
74 { NULL, 0, NULL, 0, "Signal options:" },
75 { "to-thread", OPT_TO_THREAD, NULL, 0, "Send signal to main thread" },
76 { "to-process", OPT_TO_PROCESS, NULL, 0,
77 "Send signal to process (default)" },
79 { NULL, 0, NULL, 0, "Administrative options:" },
80 { "progress", 'p', NULL, 0, "Show signs of progress" },
81 { "timing", 'T', NULL, 0,
82 "Measure time from startup to the last thread finishing" },
83 { NULL, 0, NULL, 0, NULL }
86 /* Prototype for option handler. */
87 static error_t parse_opt (int key, char *arg, struct argp_state *state);
89 /* Data structure to communicate with argp functions. */
90 static struct argp argp =
92 test_options, parse_opt
96 static int
97 do_test (void)
99 int argc = 2;
100 char *argv[3] = { (char *) "tst-argp1", (char *) "--help", NULL };
101 int remaining;
103 /* Parse and process arguments. */
104 argp_parse (&argp, argc, argv, 0, &remaining, NULL);
106 return 0;
110 /* Handle program arguments. */
111 static error_t
112 parse_opt (int key, char *arg, struct argp_state *state)
114 return ARGP_ERR_UNKNOWN;
117 #define TEST_FUNCTION do_test ()
118 #include "../test-skeleton.c"