Module: xenomai-3
Branch: next
Commit: 0875a7e855da84e0a765e01793c7fe78726e98b6
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=0875a7e855da84e0a765e01793c7fe78726e98b6

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon May 11 21:09:50 2015 +0200

boilerplate/setup, utils, testsuite: enable application help strings

---

 include/xenomai/init.h      |    4 ++++
 lib/boilerplate/setup.c     |   12 ++++++++---
 testsuite/latency/latency.c |   42 ++++++++++++++++++++-----------------
 utils/autotune/autotune.c   |   49 +++++++++++++++++--------------------------
 utils/corectl/corectl.c     |   22 +++++++------------
 utils/hdb/hdb.c             |   16 ++++----------
 6 files changed, 66 insertions(+), 79 deletions(-)

diff --git a/include/xenomai/init.h b/include/xenomai/init.h
index 7ff469a..bd99da7 100644
--- a/include/xenomai/init.h
+++ b/include/xenomai/init.h
@@ -28,6 +28,10 @@ void xenomai_init(int *argcp, char *const **argvp);
 
 int xenomai_main(int argc, char *const argv[]);
 
+void xenomai_usage(void);
+
+void application_usage(void);
+
 extern const char *xenomai_version_string;
 
 #ifdef __cplusplus
diff --git a/lib/boilerplate/setup.c b/lib/boilerplate/setup.c
index efa1f3d..1d59bc3 100644
--- a/lib/boilerplate/setup.c
+++ b/lib/boilerplate/setup.c
@@ -253,12 +253,18 @@ static struct option *build_option_array(int 
*base_opt_startp)
        return options;
 }
 
-static void usage(void)
+void __weak application_usage(void)
+{
+}
+
+void xenomai_usage(void)
 {
        struct setup_descriptor *setup;
 
        print_version();
-        fprintf(stderr, "usage: program <options>, where options may be:\n");
+        fprintf(stderr, "usage: %s <options>, where options may be:\n",
+               basename(__base_setup_data.arg0) ?: "program");
+       application_usage();
         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");
@@ -345,7 +351,7 @@ static int parse_base_options(int *argcp, char *const 
**argvp,
                        dump_configuration();
                        exit(0);
                case help_opt:
-                       usage();
+                       xenomai_usage();
                        exit(0);
                default:
                        /* Skin option, don't process yet. */
diff --git a/testsuite/latency/latency.c b/testsuite/latency/latency.c
index e3dadae..b0a9362 100644
--- a/testsuite/latency/latency.c
+++ b/testsuite/latency/latency.c
@@ -15,6 +15,7 @@
 #include <xeno_config.h>
 #include <rtdm/testing.h>
 #include <boilerplate/trace.h>
+#include <xenomai/init.h>
 
 pthread_t latency_task, display_task;
 
@@ -573,6 +574,27 @@ static void sigdebug(int sig, siginfo_t *si, void *context)
 
 #endif /* CONFIG_XENO_COBALT */
 
+void application_usage(void)
+{
+       fprintf(stderr,
+               "-h                              print histograms of min, avg, 
max latencies\n"
+               "-g <file>                       dump histogram to <file> in 
gnuplot format\n"
+               "-s                              print statistics of min, avg, 
max latencies\n"
+               "-H <histogram-size>             default = 200, increase if 
your last bucket is full\n"
+               "-B <bucket-size>                default = 1000ns, decrease for 
more resolution\n"
+               "-p <period_us>                  sampling period\n"
+               "-l <data-lines per header>      default=21, 0 to supress 
headers\n"
+               "-T <test_duration_seconds>      default=0, so ^C to end\n"
+               "-q                              supresses RTD, RTH lines if -T 
is used\n"
+               "-D <testing_device_no>          number of testing device, 
default=0\n"
+               "-t <test_mode>                  0=user task (default), 
1=kernel task, 2=timer IRQ\n"
+               "-f                              freeze trace for each new max 
latency\n"
+               "-c <cpu>                        pin measuring task down to 
given CPU\n"
+               "-P <priority>                   task priority (test mode 0 and 
1 only)\n"
+               "-b                              break upon mode switch\n"
+               );
+}
+
 int main(int argc, char *const *argv)
 {
        struct sigaction sa __attribute__((unused));
@@ -658,25 +680,7 @@ int main(int argc, char *const *argv)
                        break;
 
                default:
-
-                       fprintf(stderr,
-"usage: latency [options]\n"
-"  [-h]                         # print histograms of min, avg, max 
latencies\n"
-"  [-g <file>]                  # dump histogram to <file> in gnuplot format\n"
-"  [-s]                         # print statistics of min, avg, max 
latencies\n"
-"  [-H <histogram-size>]        # default = 200, increase if your last bucket 
is full\n"
-"  [-B <bucket-size>]           # default = 1000ns, decrease for more 
resolution\n"
-"  [-p <period_us>]             # sampling period\n"
-"  [-l <data-lines per header>] # default=21, 0 to supress headers\n"
-"  [-T <test_duration_seconds>] # default=0, so ^C to end\n"
-"  [-q]                         # supresses RTD, RTH lines if -T is used\n"
-"  [-D <testing_device_no>]     # number of testing device, default=0\n"
-"  [-t <test_mode>]             # 0=user task (default), 1=kernel task, 
2=timer IRQ\n"
-"  [-f]                         # freeze trace for each new max latency\n"
-"  [-c <cpu>]                   # pin measuring task down to given CPU\n"
-"  [-P <priority>]              # task priority (test mode 0 and 1 only)\n"
-"  [-b]                         # break upon mode switch\n"
-);
+                       xenomai_usage();
                        exit(2);
                }
 
diff --git a/utils/autotune/autotune.c b/utils/autotune/autotune.c
index de1365b..32f77b5 100644
--- a/utils/autotune/autotune.c
+++ b/utils/autotune/autotune.c
@@ -27,7 +27,7 @@
 #include <error.h>
 #include <sys/cobalt.h>
 #include <rtdm/autotune.h>
-#include <boilerplate/setup.h>
+#include <xenomai/init.h>
 
 static int tune_irqlat, tune_kernlat, tune_userlat;
 
@@ -38,49 +38,42 @@ static int reset, noload, background;
 
 static const struct option base_options[] = {
        {
-#define help_opt       0
-               .name = "help",
-               .has_arg = 0,
-               .flag = NULL,
-               .val = 0
-       },
-       {
-#define irq_opt                1
+#define irq_opt                0
                .name = "irq",
                .flag = &tune_irqlat,
                .val = 1
        },
        {
-#define kernel_opt     2
+#define kernel_opt     1
                .name = "kernel",
                .flag = &tune_kernlat,
                .val = 1
        },
        {
-#define user_opt       3
+#define user_opt       2
                .name = "user",
                .flag = &tune_userlat,
                .val = 1
        },
        {
-#define reset_opt      4
+#define reset_opt      3
                .name = "reset",
                .flag = &reset,
                .val = 1
        },
        {
-#define noload_opt     5
+#define noload_opt     4
                .name = "noload",
                .flag = &noload,
                .val = 1
        },
        {
-#define period_opt     6
+#define period_opt     5
                .name = "period",
                .has_arg = 1,
        },
        {
-#define background_opt 7
+#define background_opt 6
                .name = "background",
                .flag = &background,
                .val = 1,
@@ -194,18 +187,17 @@ static void create_load(pthread_t *tid)
        pthread_setname_np(*tid, "loadgen");
 }
 
-static void usage(void)
+void application_usage(void)
 {
-       fprintf(stderr, "usage: autotune [options], tuning core timer for:\n");
-       fprintf(stderr, "   --irq               interrupt latency\n");
-       fprintf(stderr, "   --kernel            kernel scheduling latency\n");
-       fprintf(stderr, "   --user              user scheduling latency\n");
-       fprintf(stderr, "   --period            set the sampling period\n");
-       fprintf(stderr, "   --reset             reset core timer gravity to 
factory defaults\n");
-       fprintf(stderr, "   --noload            disable load generation\n");
-       fprintf(stderr, "   --background        run in the background\n");
-       fprintf(stderr, "   --help              print this help\n\n");
-       fprintf(stderr, "if no option is given, tune for all contexts using the 
default period.\n");
+       fprintf(stderr, "--irq                          tune for interrupt 
latency\n");
+       fprintf(stderr, "--kernel                       tune for kernel 
scheduling latency\n");
+       fprintf(stderr, "--user                         tune for user 
scheduling latency\n");
+       fprintf(stderr, "    [ if none of --irq, --kernel and --user is 
given,\n"
+                       "      tune for all contexts ]\n");
+       fprintf(stderr, "--period                       set the sampling 
period\n");
+       fprintf(stderr, "--reset                        reset core timer 
gravity to factory defaults\n");
+       fprintf(stderr, "--noload                       disable load 
generation\n");
+       fprintf(stderr, "--background                   run in the 
background\n");
 }
 
 static void run_tuner(int fd, unsigned int op, int period, const char *type)
@@ -253,16 +245,13 @@ int main(int argc, char *const argv[])
                if (c == EOF)
                        break;
                if (c == '?') {
-                       usage();
+                       xenomai_usage();
                        return EINVAL;
                }
                if (c > 0)
                        continue;
 
                switch (lindex) {
-               case help_opt:
-                       usage();
-                       exit(0);
                case period_opt:
                        period = atoi(optarg);
                        if (period <= 0)
diff --git a/utils/corectl/corectl.c b/utils/corectl/corectl.c
index 6d0b7b3..a7dc804 100644
--- a/utils/corectl/corectl.c
+++ b/utils/corectl/corectl.c
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <error.h>
 #include <sys/cobalt.h>
+#include <xenomai/init.h>
 
 int __cobalt_no_shadow = 1;
 
@@ -50,20 +51,14 @@ static const struct option options[] = {
                .flag = &action,
                .val = start_opt,
        },
-       {
-#define help_opt       3
-               .name = "help",
-       },
        { /* Sentinel */ }
 };
 
-static void usage(void)
+void application_usage(void)
 {
-       fprintf(stderr, "usage: corectl [options]:\n");
-       fprintf(stderr, "   --stop [<grace-seconds>]    stop Xenomai/cobalt 
services\n");
-       fprintf(stderr, "   --start                     start Xenomai/cobalt 
services\n");
-       fprintf(stderr, "   --status                    query Xenomai/cobalt 
status\n");
-       fprintf(stderr, "   --help                      print this help\n\n");
+       fprintf(stderr, "--stop [<grace-seconds>]       stop Xenomai/cobalt 
services\n");
+       fprintf(stderr, "--start                        start Xenomai/cobalt 
services\n");
+       fprintf(stderr, "--status                       query Xenomai/cobalt 
status\n");
 }
 
 static int core_stop(int grace_period)
@@ -117,16 +112,13 @@ int main(int argc, char *const argv[])
                if (c == EOF)
                        break;
                if (c == '?') {
-                       usage();
+                       xenomai_usage();
                        return EINVAL;
                }
                if (c > 0)
                        continue;
 
                switch (lindex) {
-               case help_opt:
-                       usage();
-                       exit(0);
                case stop_opt:
                        grace_period = optarg ? atoi(optarg) : 0;
                case start_opt:
@@ -148,7 +140,7 @@ int main(int argc, char *const argv[])
                ret = core_status();
                break;
        default:
-               usage();
+               xenomai_usage();
                exit(0);
        }
 
diff --git a/utils/hdb/hdb.c b/utils/hdb/hdb.c
index 233beb5..1d20e05 100644
--- a/utils/hdb/hdb.c
+++ b/utils/hdb/hdb.c
@@ -25,6 +25,7 @@
 #include <error.h>
 #include <fcntl.h>
 #include <copperplate/cluster.h>
+#include <xenomai/init.h>
 
 static const struct option options[] = {
        {
@@ -32,18 +33,12 @@ static const struct option options[] = {
                .name = "dump-cluster",
                .has_arg = 1,
        },
-       {
-#define help_opt       1
-               .name = "help",
-       },
        { /* Sentinel */ }
 };
 
-static void usage(void)
+void application_usage(void)
 {
-       fprintf(stderr, "usage: hdb [options]:\n");
-       fprintf(stderr, "   --dump-cluster <name>       dump cluster <name>\n");
-       fprintf(stderr, "   --help                      print this help\n\n");
+       fprintf(stderr, "--dump-cluster <name>          dump cluster <name>\n");
 }
 
 static int check_shared_heap(const char *cmd)
@@ -127,16 +122,13 @@ int main(int argc, char *const argv[])
                if (c == EOF)
                        break;
                if (c == '?') {
-                       usage();
+                       xenomai_usage();
                        return EINVAL;
                }
                if (c > 0)
                        continue;
 
                switch (lindex) {
-               case help_opt:
-                       usage();
-                       exit(0);
                case dump_cluster_opt:
                        cluster_name = optarg;
                        break;


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

Reply via email to