tst-argp1.c 4.2 KB

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