From 21380ae55ec5b673847288fd54cc6dcf01350964 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Tue, 21 Feb 2017 21:53:38 +0100 Subject: cosmetic: auc_3g_test: improve test debugging tools In the test failure mismatch printf, better indicate the place of first mismatch. Helpful if some byte within a hexdump differs, the case when debugging AUTS. Copy some optarg code from openbsc's msc_vlr tests to provide verbose mode that prints log statements' source file and line. Change-Id: I1b23da055b5edacba09310411caf43c4cd1c29bc --- tests/auc/auc_3g_test.c | 71 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/tests/auc/auc_3g_test.c b/tests/auc/auc_3g_test.c index 7b12358..16c87f7 100644 --- a/tests/auc/auc_3g_test.c +++ b/tests/auc/auc_3g_test.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -76,9 +77,13 @@ char *vec_str(const struct osmo_auth_vector *vec) char *b = expect; \ for (; *a && *b; a++, b++) { \ if (*a != *b) { \ - while (a > _is && *(a-1) != '\n') a--; \ - fprintf(stderr, "mismatch at %d:\n" \ - "%s", (int)(a - _is), a); \ + fprintf(stderr, "mismatch at %d:\n", \ + (int)(a - _is)); \ + while (a > _is && *(a-1) != '\n') { \ + fprintf(stderr, " "); \ + a--; \ + } \ + fprintf(stderr, "v\n%s", a); \ break; \ } \ } \ @@ -547,11 +552,67 @@ void test_gen_vectors_bad_args() comment_end(); } -int main() +static struct { + bool verbose; +} cmdline_opts = { + .verbose = false, +}; + +static void print_help(const char *program) +{ + printf("Usage:\n" + " %s [-v] [N [N...]]\n" + "Options:\n" + " -h --help show this text.\n" + " -v --verbose print source file and line numbers\n", + program + ); +} + +static void handle_options(int argc, char **argv) +{ + while (1) { + int option_index = 0, c; + static struct option long_options[] = { + {"help", 0, 0, 'h'}, + {"verbose", 1, 0, 'v'}, + {0, 0, 0, 0} + }; + + c = getopt_long(argc, argv, "hv", + long_options, &option_index); + if (c == -1) + break; + + switch (c) { + case 'h': + print_help(argv[0]); + exit(0); + case 'v': + cmdline_opts.verbose = true; + break; + default: + /* catch unknown options *as well as* missing arguments. */ + fprintf(stderr, "Error in command line options. Exiting.\n"); + exit(-1); + break; + } + } + + if (optind < argc) { + fprintf(stderr, "too many args\n"); + exit(-1); + } +} + +int main(int argc, char **argv) { printf("auc_3g_test.c\n"); + + handle_options(argc, argv); + osmo_init_logging(&hlr_log_info); - log_set_print_filename(osmo_stderr_target, 0); + log_set_print_filename(osmo_stderr_target, cmdline_opts.verbose); log_set_print_timestamp(osmo_stderr_target, 0); log_set_use_color(osmo_stderr_target, 0); log_set_print_category(osmo_stderr_target, 1); -- cgit v1.2.3