diff mbox

[libosmo-netif,11/18] tests: osmux: factor out main test loop

Message ID 1437488613-3943-12-git-send-email-pablo@gnumonks.org
State Accepted
Headers show

Commit Message

Pablo Neira Ayuso July 21, 2015, 2:23 p.m. UTC
From: Pablo Neira Ayuso <pablo@soleta.eu>

Move main test loop routine to the new osmux_test_loop() function.
---
 tests/osmux/osmux_test.c |   64 ++++++++++++++++++++++++++--------------------
 1 file changed, 36 insertions(+), 28 deletions(-)
diff mbox

Patch

diff --git a/tests/osmux/osmux_test.c b/tests/osmux/osmux_test.c
index 1b87db7..51f026c 100644
--- a/tests/osmux/osmux_test.c
+++ b/tests/osmux/osmux_test.c
@@ -112,7 +112,7 @@  static void sigalarm_handler(int foo)
 	exit(EXIT_FAILURE);
 }
 
-int main(void)
+static void osmux_test_loop(int ccid)
 {
 	struct msgb *msg;
 	char buf[1024];
@@ -120,32 +120,10 @@  int main(void)
 	uint16_t seq;
 	int i, j, k = 0;
 
-	if (signal(SIGALRM, sigalarm_handler) == SIG_ERR) {
-		perror("signal");
-		exit(EXIT_FAILURE);
-	}
-
-	/* This test doesn't use it, but osmux requires it internally. */
-	osmo_init_logging(&osmux_test_log_info);
-	log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
-
-	osmux_xfrm_input_init(&h_input);
-	osmux_xfrm_output_init(&h_output, 0x7000000);
-
-	/* If the test takes longer than 10 seconds, abort it */
-	alarm(10);
-
-	for (i = 0; i < 2; i++)
-		osmux_xfrm_input_open_circuit(&h_input, i, 0);
-
-	/* Add two circuits with dummy padding */
-	osmux_xfrm_input_open_circuit(&h_input, 2, 1);
-	osmux_xfrm_input_open_circuit(&h_input, 3, 1);
-
-	for (i=1; i<64; i++) {
+	for (i = 1; i < 64; i++) {
 		msg = msgb_alloc(1500, "test");
 		if (!msg)
-			return 0;
+			exit(EXIT_FAILURE);
 
 		memcpy(msg->data, rtp_pkt, sizeof(rtp_pkt));
 		msgb_put(msg, sizeof(rtp_pkt));
@@ -155,7 +133,7 @@  int main(void)
 		rtph->sequence = htons(seq);
 
 		osmo_rtp_snprintf(buf, sizeof(buf), msg);
-		fprintf(stderr, "adding to ccid=%u %s\n", i % 2, buf);
+		fprintf(stderr, "adding to ccid=%u %s\n", (i % 2) + ccid, buf);
 		rtp_pkts++;
 
 		k++;
@@ -164,7 +142,7 @@  int main(void)
 		 * gaps between two messages to test the osmux replaying
 		 * feature.
 		 */
-		osmux_xfrm_input(&h_input, msg, i % 2);
+		osmux_xfrm_input(&h_input, msg, (i % 2) + ccid);
 
 		if (i % 4 == 0) {
 			gettimeofday(&last, NULL);
@@ -179,12 +157,42 @@  int main(void)
 			 * messages that are extracted from OSMUX has been
 			 * delivered.
 			 */
-			for (j=0; j<k-2; j++)
+			for (j = 0; j < k-2; j++)
 				osmo_select_main(0);
 
 			k = 0;
 		}
 	}
+}
+
+int main(void)
+{
+	int i;
+
+	if (signal(SIGALRM, sigalarm_handler) == SIG_ERR) {
+		perror("signal");
+		exit(EXIT_FAILURE);
+	}
+
+	/* This test doesn't use it, but osmux requires it internally. */
+	osmo_init_logging(&osmux_test_log_info);
+	log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
+
+	osmux_xfrm_input_init(&h_input);
+	osmux_xfrm_output_init(&h_output, 0x7000000);
+
+	/* If the test takes longer than 10 seconds, abort it */
+	alarm(10);
+
+	for (i = 0; i < 2; i++)
+		osmux_xfrm_input_open_circuit(&h_input, i, 0);
+
+	/* Add two circuits with dummy padding */
+	osmux_xfrm_input_open_circuit(&h_input, 2, 1);
+	osmux_xfrm_input_open_circuit(&h_input, 3, 1);
+
+	/* Start pushing voice data to circuits 0 and 1 */
+	osmux_test_loop(0);
 
 	for (i = 0; i < 4; i++)
 		osmux_xfrm_input_close_circuit(&h_input, i);