test_channel_feature_hooks.c: Fix unit test for DTMF hooks.
authorRichard Mudgett <rmudgett@digium.com>
Mon, 24 Nov 2014 20:39:01 +0000 (20:39 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Mon, 24 Nov 2014 20:39:01 +0000 (20:39 +0000)
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/
........

Merged revisions 428604 from http://svn.asterisk.org/svn/asterisk/branches/13

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@428605 65c4cc65-6c06-0410-ace0-fbb531ad65f3

tests/test_channel_feature_hooks.c

index 2fc9765..478cf36 100644 (file)
@@ -76,12 +76,10 @@ static void wait_for_bridged(struct ast_channel *channel)
 /*! \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);
@@ -130,6 +128,29 @@ static int feature_callback(struct ast_bridge_channel *bridge_channel, void *obj
        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)
 {
        RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
@@ -185,7 +206,7 @@ AST_TEST_DEFINE(test_features_channel_dtmf)
        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_TEST_DEFINE(test_features_channel_dtmf)
        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));