summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-02-21 21:53:38 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-02-22 03:25:30 +0100
commit21380ae55ec5b673847288fd54cc6dcf01350964 (patch)
treeed68766a1b53ed48219ffb5a94aa3e8bb36c894b /tests
parentb5b11e31fbe23466129b39d37d47b91ae7c42366 (diff)
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
Diffstat (limited to 'tests')
-rw-r--r--tests/auc/auc_3g_test.c71
1 files 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 <stdio.h>
#include <string.h>
#include <inttypes.h>
+#include <getopt.h>
#include <osmocom/core/application.h>
#include <osmocom/core/utils.h>
@@ -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);