[MERGED] osmo-hlr[master]: cosmetic: auc_3g_test: improve test debugging tools

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Wed Mar 1 12:21:17 UTC 2017


Neels Hofmeyr has submitted this change and it was merged.

Change subject: cosmetic: auc_3g_test: improve test debugging tools
......................................................................


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
---
M tests/auc/auc_3g_test.c
1 file changed, 66 insertions(+), 5 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



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 *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 @@
 	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);

-- 
To view, visit https://gerrit.osmocom.org/1871
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1b23da055b5edacba09310411caf43c4cd1c29bc
Gerrit-PatchSet: 1
Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list