samples: timers: hpet_example: Improve user experience
cover samples: timers: hpet_example: Improve user experience
Hi all,
This patch series improves user experience forsamples/timers/hpet_example
PATCH 1/2 --> Add support to print help text if user does not provide required arguments.
PATCH 2/2 --> add help text in timers Kconfig
Testing:
I have tested the changes on x86 with hpet device as follows.
1. Build the sample program
$ gcc hpet_example.c -o hpet_example
2. Run hpet program with no args
$ ./hpet_example
-hpet: requires command
Format: hpet_example <command> </dev/device_name>
Supported commands:
open-close
info
poll
fasyncExample: $ ./hpet_example info /dev/hpet
3. Run and verify hpet commands on /dev/hpet
$ sudo ./hpet_example info /dev/hpet -hpet: executing info hpet_info: hi_irqfreq 0x0 hi_flags 0x10 hi_hpet 0 hi_timer 0
Akhilesh Patil (2):
samples: timers: hpet_example: Improve argument parsing
samples: Kconfig: Add help for CONFIG_SAMPLE_TIMER
samples/Kconfig | 3 +++ samples/timers/hpet_example.c | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 samples: timers: hpet_example: Improve argument parsing
Improve user experience by adding helper text while argument parsing. Print format of the command line arguments for the program along with example invocation and supported commands.
Define and use ARRAY_SIZE() macro to iterate over command array to improve readability of the code.
Print as below upon incorrect invocation:
$ ./hpet_example
-hpet: requires command
Format: hpet_example <command> </dev/device_name>
Supported commands:
open-close
info
poll
fasync
Example: $ ./hpet_example info /dev/hpet
--- samples/timers/hpet_example.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
samples/timers/hpet_example.c +9 -2
@@ -25,6 +25,8 @@ extern void hpet_read(int, const char **);#include <sys/poll.h> #include <sys/ioctl.h> +#define ARRAY_SIZE (x) (sizeof(x) / sizeof(x[0])) +struct hpet_command {char *command;void (*func)(int argc,const char ** argv);
@@ -56,12 +58,17 @@ main(int argc, const char ** argv) argv++;if (!argc) { -fprintf (stderr,"-hpet: requires command\n" ); +fprintf (stderr,"-hpet: requires command\n" +"Format: hpet_example <command> </dev/device_name>\n" ); +fprintf (stderr,"Supported commands:\n" ); +for (i =0 ; i <ARRAY_SIZE (hpet_command); i++) +fprintf (stderr,"\t%s\n" , hpet_command[i].command); +fprintf (stderr,"\nExample: $ ./hpet_example info /dev/hpet\n" );return -1 ; } -for (i =0 ; i < (sizeof (hpet_command) /sizeof (hpet_command[0 ])); i++) +for (i =0 ; i <ARRAY_SIZE (hpet_command); i++)if (!strcmp (argv[0 ], hpet_command[i].command)) { argc--; argv++;
Signature · 1 line
2.34.1
PATCH 2/2 samples: Kconfig: Add help for CONFIG_SAMPLE_TIMER
In reply to Akhilesh PatilAdd help text in samples Kconfig for CONFIG_SAMPLE_TIMER to help user selecting this configuration.
--- samples/Kconfig | 3 +++ 1 file changed, 3 insertions(+)
samples/Kconfig +3 -0
@@ -183,6 +183,9 @@ config SAMPLE_SECCOMP config SAMPLE_TIMER bool "Timer sample" depends on CC_CAN_LINK && HEADERS_INSTALL + help + Build sample programs to demostrate timers. + Currenlty supports High Precision Event Timer (HPET) sample. config SAMPLE_TSM_MR tristate "TSM measurement sample"
Signature · 1 line
2.34.1
Quoted 17 lines · Akhilesh Patil
Hi all,
This patch series improves user experience forsamples/timers/hpet_examplePATCH 1/2 --> Add support to print help text if user does not provide required arguments.
PATCH 2/2 --> add help text in timers
KconfigTesting:
I have tested the changes on x86 with hpet device as follows.1. Build the sample program
$ gcc hpet_example.c -o hpet_example2. Run hpet program with no args
Quoted 8 lines
$ ./hpet_example
-hpet: requires command
Format: hpet_example <command> </dev/device_name>
Supported commands:
open-close
info
poll
fasyncHi all, I Would like to follow-up on this patch series for any feedback or improvements needed.
Regards,
Akhilesh