Blame argp/tst-argp1.c

Packit 6c4009
/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <argp.h>
Packit 6c4009
Packit 6c4009
Packit 6c4009
Packit 6c4009
Packit 6c4009
#define OPT_TO_THREAD		300
Packit 6c4009
#define OPT_TO_PROCESS		301
Packit 6c4009
#define OPT_SYNC_SIGNAL		302
Packit 6c4009
#define OPT_SYNC_JOIN		303
Packit 6c4009
#define OPT_TOPLEVEL		304
Packit 6c4009
Packit 6c4009
Packit 6c4009
static const struct argp_option test_options[] =
Packit 6c4009
  {
Packit 6c4009
    { NULL, 0, NULL, 0, "\
Packit 6c4009
This is a test for threads so we allow ther user to selection the number of \
Packit 6c4009
threads which are used at any one time.  Independently the total number of \
Packit 6c4009
rounds can be selected.  This is the total number of threads which will have \
Packit 6c4009
run when the process terminates:" },
Packit 6c4009
    { "threads", 't', "NUMBER", 0, "Number of threads used at once" },
Packit 6c4009
    { "starts", 's', "NUMBER", 0, "Total number of working threads" },
Packit 6c4009
    { "toplevel", OPT_TOPLEVEL, "NUMBER", 0,
Packit 6c4009
      "Number of toplevel threads which start the other threads; this \
Packit 6c4009
implies --sync-join" },
Packit 6c4009
Packit 6c4009
    { NULL, 0, NULL, 0, "\
Packit 6c4009
Each thread can do one of two things: sleep or do work.  The latter is 100% \
Packit 6c4009
CPU bound.  The work load is the probability a thread does work.  All values \
Packit 6c4009
from zero to 100 (inclusive) are valid.  How often each thread repeats this \
Packit 6c4009
can be determined by the number of rounds.  The work cost determines how long \
Packit 6c4009
each work session (not sleeping) takes.  If it is zero a thread would \
Packit 6c4009
effectively nothing.  By setting the number of rounds to zero the thread \
Packit 6c4009
does no work at all and pure thread creation times can be measured." },
Packit 6c4009
    { "workload", 'w', "PERCENT", 0, "Percentage of time spent working" },
Packit 6c4009
    { "workcost", 'c', "NUMBER", 0,
Packit 6c4009
      "Factor in the cost of each round of working" },
Packit 6c4009
    { "rounds", 'r', "NUMBER", 0, "Number of rounds each thread runs" },
Packit 6c4009
Packit 6c4009
    { NULL, 0, NULL, 0, "\
Packit 6c4009
There are a number of different methods how thread creation can be \
Packit 6c4009
synchronized.  Synchronization is necessary since the number of concurrently \
Packit 6c4009
running threads is limited." },
Packit 6c4009
    { "sync-signal", OPT_SYNC_SIGNAL, NULL, 0,
Packit 6c4009
      "Synchronize using a signal (default)" },
Packit 6c4009
    { "sync-join", OPT_SYNC_JOIN, NULL, 0, "Synchronize using pthread_join" },
Packit 6c4009
Packit 6c4009
    { NULL, 0, NULL, 0, "\
Packit 6c4009
One parameter for each threads execution is the size of the stack.  If this \
Packit 6c4009
parameter is not used the system's default stack size is used.  If many \
Packit 6c4009
threads are used the stack size should be chosen quite small." },
Packit 6c4009
    { "stacksize", 'S', "BYTES", 0, "Size of threads stack" },
Packit 6c4009
    { "guardsize", 'g', "BYTES", 0,
Packit 6c4009
      "Size of stack guard area; must fit into the stack" },
Packit 6c4009
Packit 6c4009
    { NULL, 0, NULL, 0, "Signal options:" },
Packit 6c4009
    { "to-thread", OPT_TO_THREAD, NULL, 0, "Send signal to main thread" },
Packit 6c4009
    { "to-process", OPT_TO_PROCESS, NULL, 0,
Packit 6c4009
      "Send signal to process (default)" },
Packit 6c4009
Packit 6c4009
    { NULL, 0, NULL, 0, "Administrative options:" },
Packit 6c4009
    { "progress", 'p', NULL, 0, "Show signs of progress" },
Packit 6c4009
    { "timing", 'T', NULL, 0,
Packit 6c4009
      "Measure time from startup to the last thread finishing" },
Packit 6c4009
    { NULL, 0, NULL, 0, NULL }
Packit 6c4009
  };
Packit 6c4009
Packit 6c4009
/* Prototype for option handler.  */
Packit 6c4009
static error_t parse_opt (int key, char *arg, struct argp_state *state);
Packit 6c4009
Packit 6c4009
/* Data structure to communicate with argp functions.  */
Packit 6c4009
static struct argp argp =
Packit 6c4009
{
Packit 6c4009
  test_options, parse_opt
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  int argc = 2;
Packit 6c4009
  char *argv[3] = { (char *) "tst-argp1", (char *) "--help", NULL };
Packit 6c4009
  int remaining;
Packit 6c4009
Packit 6c4009
  /* Parse and process arguments.  */
Packit 6c4009
  argp_parse (&argp, argc, argv, 0, &remaining, NULL);
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Handle program arguments.  */
Packit 6c4009
static error_t
Packit 6c4009
parse_opt (int key, char *arg, struct argp_state *state)
Packit 6c4009
{
Packit 6c4009
  return ARGP_ERR_UNKNOWN;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
#include "../test-skeleton.c"