about summary refs log tree commit diff
path: root/support/test-driver.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2017-05-24 09:17:34 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2017-06-15 16:01:38 -0300
commit244361ebaec57a6fbb9998bfa5ec71ee8d88f3e8 (patch)
treee98dba147ced72499f4754995d1556c7ba22404a /support/test-driver.c
parent70fe2eb79417166c39a36699f591138bfe5c5307 (diff)
downloadglibc-244361ebaec57a6fbb9998bfa5ec71ee8d88f3e8.tar.gz
glibc-244361ebaec57a6fbb9998bfa5ec71ee8d88f3e8.tar.xz
glibc-244361ebaec57a6fbb9998bfa5ec71ee8d88f3e8.zip
support: Add optstring support
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.
Diffstat (limited to 'support/test-driver.c')
-rw-r--r--support/test-driver.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/support/test-driver.c b/support/test-driver.c
index 482066dbeb..47c387c2b4 100644
--- a/support/test-driver.c
+++ b/support/test-driver.c
@@ -93,6 +93,10 @@
    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);
 }