Module: xenomai-3
Branch: master
Commit: 1af2245c347942b444940676996a76b7ef4572b5
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=1af2245c347942b444940676996a76b7ef4572b5

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed May 13 14:11:04 2015 +0200

boilerplate/setup: sanitize verbosity option handling

---

 doc/asciidoc/man1/autotune.adoc |    6 ++---
 include/boilerplate/setup.h     |    2 +-
 include/boilerplate/tunables.h  |    8 +++----
 include/smokey/smokey.h         |    2 +-
 lib/boilerplate/setup.c         |   46 ++++++++++++++++++++-------------------
 lib/smokey/helpers.c            |    2 +-
 lib/smokey/init.c               |   14 ++++++------
 testsuite/smokey/main.c         |    2 +-
 utils/autotune/autotune.c       |   16 ++++++++------
 9 files changed, 51 insertions(+), 47 deletions(-)

diff --git a/doc/asciidoc/man1/autotune.adoc b/doc/asciidoc/man1/autotune.adoc
index a8e0df3..3462e6b 100644
--- a/doc/asciidoc/man1/autotune.adoc
+++ b/doc/asciidoc/man1/autotune.adoc
@@ -104,9 +104,9 @@ to eliminate irregular delays which tend to appear on fully 
idle
 systems.  Therefore, keeping the load generation enabled most often
 leads to a more accurate estimation.
 
-*--quiet[=level]*::
-Tame down verbosity of the auto-tuner. --quiet[=1] means fully quiet,
-any of --quiet=2, --quiet=semi or --quiet=almost means almost quiet.
+*--verbose[=level]*::
+Set verbosity to the desired level, 1 means almost quiet (default), 2
+means fully verbose.
 
 *--help*::
 Display a short help.
diff --git a/include/boilerplate/setup.h b/include/boilerplate/setup.h
index 5b9a77f..70b758d 100644
--- a/include/boilerplate/setup.h
+++ b/include/boilerplate/setup.h
@@ -27,7 +27,7 @@ struct base_setup_data {
        cpu_set_t cpu_affinity;
        int no_mlock;
        int no_sanity;
-       int quiet_mode;
+       int verbosity_level;
        const char *arg0;
 };
 
diff --git a/include/boilerplate/tunables.h b/include/boilerplate/tunables.h
index 796a19c..628b312 100644
--- a/include/boilerplate/tunables.h
+++ b/include/boilerplate/tunables.h
@@ -99,14 +99,14 @@ static inline read_config_tunable(no_sanity, int)
        return __base_setup_data.no_sanity;
 }
 
-static inline define_runtime_tunable(quiet_mode, int, mode)
+static inline define_runtime_tunable(verbosity_level, int, mode)
 {
-       __base_setup_data.quiet_mode = mode;
+       __base_setup_data.verbosity_level = mode;
 }
 
-static inline read_runtime_tunable(quiet_mode, int)
+static inline read_runtime_tunable(verbosity_level, int)
 {
-       return __base_setup_data.quiet_mode;
+       return __base_setup_data.verbosity_level;
 }
 
 #ifdef __cplusplus
diff --git a/include/smokey/smokey.h b/include/smokey/smokey.h
index 55c67aa..41f5e6e 100644
--- a/include/smokey/smokey.h
+++ b/include/smokey/smokey.h
@@ -125,6 +125,6 @@ extern struct pvlist smokey_test_list;
 
 extern int smokey_keep_going;
 
-extern int smokey_quiet_mode;
+extern int smokey_verbose_mode;
 
 #endif /* _XENOMAI_SMOKEY_SMOKEY_H */
diff --git a/lib/boilerplate/setup.c b/lib/boilerplate/setup.c
index 6a458a1..2ccb4f4 100644
--- a/lib/boilerplate/setup.c
+++ b/lib/boilerplate/setup.c
@@ -35,7 +35,7 @@
 
 struct base_setup_data __base_setup_data = {
        .no_sanity = !CONFIG_XENO_SANITY,
-       .quiet_mode = 0,
+       .verbosity_level = 1,
        .arg0 = NULL,
        .no_mlock = 0,
 };
@@ -59,37 +59,43 @@ static const struct option base_options[] = {
                .has_arg = 1,
        },
        {
-#define quiet_opt      2
-               .name = "quiet",
+#define verbose_opt    2
+               .name = "verbose",
                .has_arg = 2,
        },
        {
 #define silent_opt     3
                .name = "silent",
-               .flag = &__base_setup_data.quiet_mode,
-               .val = 2,
+               .flag = &__base_setup_data.verbosity_level,
+               .val = 0,
+       },
+       {
+#define quiet_opt      4
+               .name = "quiet",
+               .flag = &__base_setup_data.verbosity_level,
+               .val = 0,
        },
        {
-#define version_opt    4
+#define version_opt    5
                .name = "version",
        },
        {
-#define dumpconfig_opt 5
+#define dumpconfig_opt 6
                .name = "dump-config",
        },
        {
-#define no_sanity_opt  6
+#define no_sanity_opt  7
                .name = "no-sanity",
                .flag = &__base_setup_data.no_sanity,
                .val = 1
        },
        {
-#define sanity_opt     7
+#define sanity_opt     8
                .name = "sanity",
                .flag = &__base_setup_data.no_sanity,
        },
        {
-#define no_mlock_opt   8
+#define no_mlock_opt   9
 #ifdef CONFIG_XENO_MERCURY
                .name = "no-mlock",
                .flag = &__base_setup_data.no_mlock,
@@ -297,8 +303,8 @@ void xenomai_usage(void)
 
         fprintf(stderr, "--cpu-affinity=<cpu[,cpu]...> set CPU affinity of 
threads\n");
         fprintf(stderr, "--[no-]sanity                 disable/enable sanity 
checks\n");
-        fprintf(stderr, "--quiet[=level]               tame down verbosity to 
desired level\n");
-        fprintf(stderr, "--silent                      same as --quiet\n");
+        fprintf(stderr, "--verbose[=level]             set verbosity to 
desired level\n");
+        fprintf(stderr, "--silent, --quiet             same as --verbose=0\n");
         fprintf(stderr, "--version                     get version 
information\n");
         fprintf(stderr, "--dump-config                 dump configuration 
settings\n");
 #ifdef CONFIG_XENO_MERCURY
@@ -351,17 +357,13 @@ static int parse_base_options(int *argcp, char *const 
**argvp,
                        if (ret)
                                return ret;
                        break;
-               case quiet_opt:
-                       __base_setup_data.quiet_mode = 2;
-                       if (optarg) {
-                               if (strcmp(optarg, "semi") == 0 ||
-                                   strcmp(optarg, "almost") == 0)
-                                       __base_setup_data.quiet_mode = 1;
-                               else
-                                       __base_setup_data.quiet_mode = 
atoi(optarg);
-                       }
+               case verbose_opt:
+                       __base_setup_data.verbosity_level = 1;
+                       if (optarg)
+                               __base_setup_data.verbosity_level = 
atoi(optarg);
                        break;
                case silent_opt:
+               case quiet_opt:
                case no_mlock_opt:
                case no_sanity_opt:
                case sanity_opt:
@@ -554,7 +556,7 @@ void xenomai_init(int *argcp, char *const **argvp)
        free(options);
 
 #ifdef CONFIG_XENO_DEBUG
-       if (__base_setup_data.quiet_mode == 0) {
+       if (__base_setup_data.verbosity_level > 0) {
                early_warning("Xenomai compiled with %s debug enabled,\n"
                        "                              "
                        "%shigh latencies expected [--enable-debug=%s]",
diff --git a/lib/smokey/helpers.c b/lib/smokey/helpers.c
index 49e2177..21b0084 100644
--- a/lib/smokey/helpers.c
+++ b/lib/smokey/helpers.c
@@ -124,7 +124,7 @@ void smokey_note(const char *fmt, ...)
 
        va_start(ap, fmt);
 
-       if (!smokey_quiet_mode)
+       if (smokey_verbose_mode)
                __RT(vfprintf(stdout, fmt, ap));
 
        va_end(ap);
diff --git a/lib/smokey/init.c b/lib/smokey/init.c
index 136f5c8..c6dfa79 100644
--- a/lib/smokey/init.c
+++ b/lib/smokey/init.c
@@ -184,9 +184,9 @@
  *   failure code from a smoke test should not abort the test loop.
  *   This flag is not otherwise interpreted by the Smokey API.
  *
- * - --quiet sets the boolean flag @a smokey_quiet_mode to a non-zero
- *   value, which is should be interpreted by all parties as an
- *   indication to tame down verbosity.
+ * - --verbose[=level] sets the integer @a smokey_verbose_mode to a
+ *   non-zero value, which should be interpreted by all parties as the
+ *   desired verbosity level (defaults to 1).
  *
  * @par Writing a test driver based on the Smokey API
  *
@@ -203,7 +203,7 @@
  *
  * The printf-like @a smokey_note() routine is available for issuing
  * progress messages to the output device (currently stdout), unless
- * --quiet was detected on the command line.
+ * --silent was detected on the command line.
  *
  * Therefore, a possible implementation of a test driver could be as
  * basic as:
@@ -246,7 +246,7 @@ static int test_count;
 
 static int do_list;
 
-int smokey_quiet_mode = 0;
+int smokey_verbose_mode = 1;
 
 static const struct option smokey_options[] = {
        {
@@ -449,9 +449,9 @@ static int smokey_parse_option(int optnum, const char 
*optarg)
 static int smokey_init(void)
 {
        if (pvlist_empty(&smokey_test_list))
-               set_runtime_tunable(quiet_mode, 1);
+               set_runtime_tunable(verbosity_level, 0);
        else
-               smokey_quiet_mode = get_runtime_tunable(quiet_mode);
+               smokey_verbose_mode = get_runtime_tunable(verbosity_level);
 
        return 0;
 }
diff --git a/testsuite/smokey/main.c b/testsuite/smokey/main.c
index 37af8b5..ea87390 100644
--- a/testsuite/smokey/main.c
+++ b/testsuite/smokey/main.c
@@ -38,7 +38,7 @@ int main(int argc, char *const argv[])
                        fails++;
                        if (smokey_keep_going)
                                continue;
-                       if (!smokey_quiet_mode)
+                       if (smokey_verbose_mode)
                                error(1, -ret, "test %s failed", t->name);
                }
                smokey_note("%s OK\n", t->name);
diff --git a/utils/autotune/autotune.c b/utils/autotune/autotune.c
index 140355a..57a34f8 100644
--- a/utils/autotune/autotune.c
+++ b/utils/autotune/autotune.c
@@ -33,8 +33,10 @@ static int tune_irqlat, tune_kernlat, tune_userlat;
 
 static int reset, noload, background;
 
-/* --quiet[=2] means fully quiet, quiet=1 means almost quiet */
-#define quiet_mode (__base_setup_data.quiet_mode)
+/*
+ * --verbosity_level=0 means fully quiet, =1 means almost quiet.
+ */
+#define verbose (__base_setup_data.verbosity_level)
 
 static const struct option base_options[] = {
        {
@@ -209,12 +211,12 @@ static void run_tuner(int fd, unsigned int op, int 
period, const char *type)
        int ret;
 
        setup.period = period;
-       setup.quiet = quiet_mode;
+       setup.quiet = verbose > 2 ? 0 : 2 - verbose;
        ret = ioctl(fd, op, &setup);
        if (ret)
                error(1, errno, "setup failed (%s)", type);
 
-       if (!quiet_mode) {
+       if (verbose) {
                printf("%s gravity... ", type);
                fflush(stdout);
        }
@@ -229,7 +231,7 @@ static void run_tuner(int fd, unsigned int op, int period, 
const char *type)
        if (op == AUTOTUNE_RTIOC_USER)
                pthread_cancel(sampler);
 
-       if (!quiet_mode)
+       if (verbose)
                printf("%u ns\n", gravity);
 }
 
@@ -295,7 +297,7 @@ int main(int argc, char *const argv[])
        if (tune_irqlat || tune_kernlat || tune_userlat) {
                if (!noload)
                        create_load(&load_pth);
-               if (!quiet_mode)
+               if (verbose)
                        printf("== auto-tuning started, period=%d ns (may take 
a while)\n",
                               period);
        } else
@@ -312,7 +314,7 @@ int main(int argc, char *const argv[])
        if (tune_userlat)
                run_tuner(fd, AUTOTUNE_RTIOC_USER, period, "user");
 
-       if (!quiet_mode && (tune_userlat || tune_kernlat || tune_userlat))
+       if (verbose && (tune_userlat || tune_kernlat || tune_userlat))
                printf("== auto-tuning completed after %ds\n",
                       (int)(time(NULL) - start));
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to