]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
support: Add optstring support
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 24 May 2017 12:17:34 +0000 (09:17 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 15 Jun 2017 19:01:38 +0000 (16:01 -0300)
This patch adds an option to test to add small command line option
through CMDLINE_OPTSTRING define.  For instance:

  #define CMDLINE_OPTSTRING "vd"

  static void
  cmdline_process_function (int c)
  {
    switch (c):
      'v':
        /* process '-v' option.  */
      break;
      'd':
        /* process '-d' option.  */
      break;
  }
  #define CMDLINE_PROCESS cmdline_process_function

It will add both '-v' and '-d' along with already default long options.

* support/support_test_main.c (support_test_main):  Use optstring
member for option string in getopt_long.
* support/test-driver.c: Add comment about CMDLINE_OPTSTRING.
(CMDLINE_OPTSTRING): New define.
* support/test-driver.h (test_config): Add optstring member.

ChangeLog
support/support_test_main.c
support/test-driver.c
support/test-driver.h

index 70faa63f6eb894ca160e17cadfd717a06c5bad4a..8fb6aaae0c331864aa2bd9baac6f899c92c9b437 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2017-06-15  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+
+        * support/support_test_main.c (support_test_main):  Use optstring
+        member for option string in getopt_long.
+        * support/test-driver.c: Add comment about CMDLINE_OPTSTRING.
+        (CMDLINE_OPTSTRING): New define.
+        * support/test-driver.h (test_config): Add optstring member.
+
 2017-06-15  H.J. Lu  <hongjiu.lu@intel.com>
 
        * sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Add
index 914d64f6036aa152beaa84357433d85c3aacefb2..3c411a467b04f4dec279ddb84841d1d2f6d56e70 100644 (file)
@@ -211,7 +211,8 @@ support_test_main (int argc, char **argv, const struct test_config *config)
         mallopt (M_PERTURB, 42);
     }
 
-  while ((opt = getopt_long (argc, argv, "+", options, NULL)) != -1)
+  while ((opt = getopt_long (argc, argv, config->optstring, options, NULL))
+        != -1)
     switch (opt)
       {
       case '?':
index 482066dbeb326bb2b6518649128017e8be3b36e9..47c387c2b485bc8415a17b1ce56fb6f49769a58d 100644 (file)
    has this type:
 
      void CMDLINE_PROCESS (int);
+
+   If the program also to process custom default short command line
+   argument (similar to getopt) it must define CMDLINE_OPTSTRING
+   with the expected options (for instance "vb").
 */
 
 #include <support/test-driver.h>
@@ -151,6 +155,11 @@ main (int argc, char **argv)
 #ifdef CMDLINE_PROCESS
   test_config.cmdline_function = CMDLINE_PROCESS;
 #endif
+#ifdef CMDLINE_OPTSTRING
+  test_config.optstring = "+" CMDLINE_OPTSTRING;
+#else
+  test_config.optstring = "+";
+#endif
 
   return support_test_main (argc, argv, &test_config);
 }
index af1971a9ca10acaf235b86e0cc3d68b07eba64af..a8fe9c3565cddbe3b4fe054202742acafbc43179 100644 (file)
@@ -35,6 +35,7 @@ struct test_config
   int expected_status;   /* Expected exit status.  */
   int expected_signal;   /* If non-zero, expect termination by signal.  */
   char no_mallopt;       /* Boolean flag to disable mallopt.  */
+  const char *optstring; /* Short command line options.  */
 };
 
 enum