[asterisk-commits] rmudgett: branch 13 r428604 - /branches/13/tests/test_channel_feature_hooks.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Nov 24 14:37:23 CST 2014


Author: rmudgett
Date: Mon Nov 24 14:37:19 2014
New Revision: 428604

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=428604
Log:
test_channel_feature_hooks.c: Fix unit test for DTMF hooks.

Fix the failing /channels/features/test_features_channel_dtmf unit test.

DTMF emulation does not work without a stream of packets to prod the
emulation code.

Review: https://reviewboard.asterisk.org/r/4199/

Modified:
    branches/13/tests/test_channel_feature_hooks.c

Modified: branches/13/tests/test_channel_feature_hooks.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/tests/test_channel_feature_hooks.c?view=diff&rev=428604&r1=428603&r2=428604
==============================================================================
--- branches/13/tests/test_channel_feature_hooks.c (original)
+++ branches/13/tests/test_channel_feature_hooks.c Mon Nov 24 14:37:19 2014
@@ -76,12 +76,10 @@
 /*! \brief Wait until a channel is not bridged */
 static void wait_for_unbridged(struct ast_channel *channel)
 {
-	struct timespec short_sleep = {0, 1000000};
 	ast_channel_lock(channel);
 	while (ast_channel_is_bridged(channel)) {
 		ast_channel_unlock(channel);
-		while ((nanosleep(&short_sleep, &short_sleep) == -1) && (errno == EINTR)) {
-		}
+		test_nanosleep(0, 1000000);
 		ast_channel_lock(channel);
 	}
 	ast_channel_unlock(channel);
@@ -128,6 +126,29 @@
 	int *callback_executed = obj;
 	(*callback_executed)++;
 	return 0;
+}
+
+/* Need to post null frames periodically so DTMF emulation can work. */
+static void stream_periodic_frames(struct ast_channel *chan, int ms, int interval_ms)
+{
+	long nanosecs;
+
+	ast_assert(chan != NULL);
+	ast_assert(0 < ms);
+	ast_assert(0 < interval_ms);
+
+	nanosecs = interval_ms * 1000000L;
+	while (0 < ms) {
+		ast_queue_frame(chan, &ast_null_frame);
+
+		if (interval_ms < ms) {
+			ms -= interval_ms;
+		} else {
+			nanosecs = ms * 1000000L;
+			ms = 0;
+		}
+		test_nanosleep(0, nanosecs);
+	}
 }
 
 AST_TEST_DEFINE(test_features_channel_dtmf)
@@ -185,7 +206,7 @@
 	ast_queue_frame(chan_alice, &f);
 	ast_queue_frame(chan_alice, &f);
 
-	test_nanosleep(1, 0);
+	stream_periodic_frames(chan_alice, 1000, 20);
 
 	/* Remove the channels from the bridge */
 	ast_test_validate(test, !ast_bridge_depart(chan_alice));
@@ -208,7 +229,7 @@
 	ast_queue_frame(chan_alice, &f);
 	ast_queue_frame(chan_alice, &f);
 
-	test_nanosleep(1, 0);
+	stream_periodic_frames(chan_alice, 1000, 20);
 
 	/* Remove the channels from the bridge */
 	ast_test_validate(test, !ast_bridge_depart(chan_alice));




More information about the asterisk-commits mailing list