Back to index

glibc  2.9
tst-argp1.c
Go to the documentation of this file.
00001 /* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <argp.h>
00021 
00022 
00023 
00024 
00025 #define OPT_TO_THREAD              300
00026 #define OPT_TO_PROCESS             301
00027 #define OPT_SYNC_SIGNAL            302
00028 #define OPT_SYNC_JOIN              303
00029 #define OPT_TOPLEVEL        304
00030 
00031 
00032 static const struct argp_option test_options[] =
00033   {
00034     { NULL, 0, NULL, 0, "\
00035 This is a test for threads so we allow ther user to selection the number of \
00036 threads which are used at any one time.  Independently the total number of \
00037 rounds can be selected.  This is the total number of threads which will have \
00038 run when the process terminates:" },
00039     { "threads", 't', "NUMBER", 0, "Number of threads used at once" },
00040     { "starts", 's', "NUMBER", 0, "Total number of working threads" },
00041     { "toplevel", OPT_TOPLEVEL, "NUMBER", 0,
00042       "Number of toplevel threads which start the other threads; this \
00043 implies --sync-join" },
00044 
00045     { NULL, 0, NULL, 0, "\
00046 Each thread can do one of two things: sleep or do work.  The latter is 100% \
00047 CPU bound.  The work load is the probability a thread does work.  All values \
00048 from zero to 100 (inclusive) are valid.  How often each thread repeats this \
00049 can be determined by the number of rounds.  The work cost determines how long \
00050 each work session (not sleeping) takes.  If it is zero a thread would \
00051 effectively nothing.  By setting the number of rounds to zero the thread \
00052 does no work at all and pure thread creation times can be measured." },
00053     { "workload", 'w', "PERCENT", 0, "Percentage of time spent working" },
00054     { "workcost", 'c', "NUMBER", 0,
00055       "Factor in the cost of each round of working" },
00056     { "rounds", 'r', "NUMBER", 0, "Number of rounds each thread runs" },
00057 
00058     { NULL, 0, NULL, 0, "\
00059 There are a number of different methods how thread creation can be \
00060 synchronized.  Synchronization is necessary since the number of concurrently \
00061 running threads is limited." },
00062     { "sync-signal", OPT_SYNC_SIGNAL, NULL, 0,
00063       "Synchronize using a signal (default)" },
00064     { "sync-join", OPT_SYNC_JOIN, NULL, 0, "Synchronize using pthread_join" },
00065 
00066     { NULL, 0, NULL, 0, "\
00067 One parameter for each threads execution is the size of the stack.  If this \
00068 parameter is not used the system's default stack size is used.  If many \
00069 threads are used the stack size should be chosen quite small." },
00070     { "stacksize", 'S', "BYTES", 0, "Size of threads stack" },
00071     { "guardsize", 'g', "BYTES", 0,
00072       "Size of stack guard area; must fit into the stack" },
00073 
00074     { NULL, 0, NULL, 0, "Signal options:" },
00075     { "to-thread", OPT_TO_THREAD, NULL, 0, "Send signal to main thread" },
00076     { "to-process", OPT_TO_PROCESS, NULL, 0,
00077       "Send signal to process (default)" },
00078 
00079     { NULL, 0, NULL, 0, "Administrative options:" },
00080     { "progress", 'p', NULL, 0, "Show signs of progress" },
00081     { "timing", 'T', NULL, 0,
00082       "Measure time from startup to the last thread finishing" },
00083     { NULL, 0, NULL, 0, NULL }
00084   };
00085 
00086 /* Prototype for option handler.  */
00087 static error_t parse_opt (int key, char *arg, struct argp_state *state);
00088 
00089 /* Data structure to communicate with argp functions.  */
00090 static struct argp argp =
00091 {
00092   test_options, parse_opt
00093 };
00094 
00095 
00096 static int
00097 do_test (void)
00098 {
00099   int argc = 2;
00100   char *argv[3] = { (char *) "tst-argp1", (char *) "--help", NULL };
00101   int remaining;
00102 
00103   /* Parse and process arguments.  */
00104   argp_parse (&argp, argc, argv, 0, &remaining, NULL);
00105 
00106   return 0;
00107 }
00108 
00109 
00110 /* Handle program arguments.  */
00111 static error_t
00112 parse_opt (int key, char *arg, struct argp_state *state)
00113 {
00114   return ARGP_ERR_UNKNOWN;
00115 }
00116 
00117 #define TEST_FUNCTION do_test ()
00118 #include "../test-skeleton.c"