Blame argp/tst-argp1.c

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