tst-argp1.c 4.6 KB

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