[asterisk-commits] mmichelson: trunk r423784 - in /trunk: ./ tests/test_cdr.c tests/test_cel.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 23 09:36:04 CDT 2014


Author: mmichelson
Date: Tue Sep 23 09:36:00 2014
New Revision: 423784

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=423784
Log:
Make CDR and CEL unit tests less FRACKy.

Prior to this commit, CDR and CEL tests were expected to trigger
FRACKs (i.e. assertions) due to the fact that the channels they
create have no formats on them. Some code was independently added
recently that attempts to prevent FRACKs from occurring by failing
early when attempting to set up translation paths if one or both
channels support no formats. Unfortunately, this attempt to be helpful
made the CDR and CEL tests go from simply FRACKing to outright
failing and in some cases, failing so badly as to crash Asterisk.

This commit seeks to correct past mistakes by adding the ulaw format
to channels created by the CDR and CEL unit tests. This makes setting
up translation paths succeed, eliminates previously-seen FRACKs, and
ultimately causes the unit tests to succeed again.

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

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

Modified:
    trunk/   (props changed)
    trunk/tests/test_cdr.c
    trunk/tests/test_cel.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-13-merged' - no diff available.

Modified: trunk/tests/test_cdr.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_cdr.c?view=diff&rev=423784&r1=423783&r2=423784
==============================================================================
--- trunk/tests/test_cdr.c (original)
+++ trunk/tests/test_cdr.c Tue Sep 23 09:36:00 2014
@@ -46,6 +46,7 @@
 #include "asterisk/bridge_basic.h"
 #include "asterisk/stasis_channels.h"
 #include "asterisk/stasis_bridges.h"
+#include "asterisk/format_cache.h"
 
 #define EPSILON 0.001
 
@@ -231,10 +232,24 @@
 	ast_copy_string((expected_record)->linkedid, ast_channel_linkedid((channel_var)), sizeof((expected_record)->linkedid)); \
 	} while (0)
 
+/*! \brief Set ulaw format on channel */
+#define SET_FORMATS(chan) do {\
+	struct ast_format_cap *caps;\
+	caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);\
+	ast_format_cap_append(caps, ast_format_ulaw, 0);\
+	ast_channel_nativeformats_set((chan), caps);\
+	ast_channel_set_writeformat((chan), ast_format_ulaw);\
+	ast_channel_set_rawwriteformat((chan), ast_format_ulaw);\
+	ast_channel_set_readformat((chan), ast_format_ulaw);\
+	ast_channel_set_rawreadformat((chan), ast_format_ulaw);\
+	ao2_ref(caps, -1);\
+} while (0)
+
 /*! \brief Create a \ref test_cdr_chan_tech for Alice, and set the expected
  * CDR records' linkedid and uniqueid. */
 #define CREATE_ALICE_CHANNEL(channel_var, caller_id, expected_record) do { \
 	(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, "100", "Alice", "100", "100", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/Alice"); \
+	SET_FORMATS((channel_var));\
 	ast_channel_set_caller((channel_var), (caller_id), NULL); \
 	ast_copy_string((expected_record)->uniqueid, ast_channel_uniqueid((channel_var)), sizeof((expected_record)->uniqueid)); \
 	ast_copy_string((expected_record)->linkedid, ast_channel_linkedid((channel_var)), sizeof((expected_record)->linkedid)); \
@@ -245,6 +260,7 @@
  * CDR records' linkedid and uniqueid. */
 #define CREATE_BOB_CHANNEL(channel_var, caller_id, expected_record) do { \
 	(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, "200", "Bob", "200", "200", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/Bob"); \
+	SET_FORMATS((channel_var));\
 	ast_channel_set_caller((channel_var), (caller_id), NULL); \
 	ast_copy_string((expected_record)->uniqueid, ast_channel_uniqueid((channel_var)), sizeof((expected_record)->uniqueid)); \
 	ast_copy_string((expected_record)->linkedid, ast_channel_linkedid((channel_var)), sizeof((expected_record)->linkedid)); \
@@ -255,6 +271,7 @@
  * CDR records' linkedid and uniqueid. */
 #define CREATE_CHARLIE_CHANNEL(channel_var, caller_id, expected_record) do { \
 	(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, "300", "Charlie", "300", "300", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/Charlie"); \
+	SET_FORMATS((channel_var));\
 	ast_channel_set_caller((channel_var), (caller_id), NULL); \
 	ast_copy_string((expected_record)->uniqueid, ast_channel_uniqueid((channel_var)), sizeof((expected_record)->uniqueid)); \
 	ast_copy_string((expected_record)->linkedid, ast_channel_linkedid((channel_var)), sizeof((expected_record)->linkedid)); \
@@ -265,6 +282,7 @@
  * CDR records' linkedid and uniqueid. */
 #define CREATE_DAVID_CHANNEL(channel_var, caller_id, expected_record) do { \
 	(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, "400", "David", "400", "400", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/David"); \
+	SET_FORMATS((channel_var));\
 	ast_channel_set_caller((channel_var), (caller_id), NULL); \
 	ast_copy_string((expected_record)->uniqueid, ast_channel_uniqueid((channel_var)), sizeof((expected_record)->uniqueid)); \
 	ast_copy_string((expected_record)->linkedid, ast_channel_linkedid((channel_var)), sizeof((expected_record)->linkedid)); \
@@ -583,6 +601,7 @@
 	ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
 
 	chan_bob = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_alice, 0, CHANNEL_TECH_NAME "/Bob");
+	SET_FORMATS(chan_bob);
 	ast_channel_unlock(chan_bob);
 	ast_copy_string(bob_expected.linkedid, ast_channel_linkedid(chan_bob), sizeof(bob_expected.linkedid));
 	ast_copy_string(bob_expected.uniqueid, ast_channel_uniqueid(chan_bob), sizeof(bob_expected.uniqueid));
@@ -1173,6 +1192,7 @@
 	EMULATE_APP_DATA(chan_caller, 1, "Dial", "CDRTestChannel/Bob");
 
 	chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
+	SET_FORMATS(chan_callee);
 	ast_channel_unlock(chan_callee);
 	ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
 	EMULATE_APP_DATA(chan_callee, 0, "AppDial", "(Outgoing Line)");
@@ -1235,6 +1255,7 @@
 	EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
 
 	chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
+	SET_FORMATS(chan_callee);
 	ast_channel_unlock(chan_callee);
 	ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
 	EMULATE_APP_DATA(chan_callee, 0, "AppDial", "(Outgoing Line)");
@@ -1296,6 +1317,7 @@
 	EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
 
 	chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
+	SET_FORMATS(chan_callee);
 	ast_channel_unlock(chan_callee);
 	ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
 	EMULATE_APP_DATA(chan_callee, 0, "AppDial", "(Outgoing Line)");
@@ -1357,6 +1379,7 @@
 	EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
 
 	chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
+	SET_FORMATS(chan_callee);
 	ast_channel_unlock(chan_callee);
 	ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
 	EMULATE_APP_DATA(chan_callee, 0, "AppDial", "(Outgoing Line)");
@@ -1419,6 +1442,7 @@
 	EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
 
 	chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
+	SET_FORMATS(chan_callee);
 	ast_channel_unlock(chan_callee);
 	ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
 	EMULATE_APP_DATA(chan_callee, 0, "AppDial", "(Outgoing Line)");
@@ -1521,16 +1545,19 @@
 
 	/* Outbound channels are created */
 	chan_bob = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
+	SET_FORMATS(chan_bob);
 	ast_channel_unlock(chan_bob);
 	ast_set_flag(ast_channel_flags(chan_bob), AST_FLAG_OUTGOING);
 	EMULATE_APP_DATA(chan_bob, 0, "AppDial", "(Outgoing Line)");
 
 	chan_charlie = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "300", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Charlie");
+	SET_FORMATS(chan_charlie);
 	ast_channel_unlock(chan_charlie);
 	ast_set_flag(ast_channel_flags(chan_charlie), AST_FLAG_OUTGOING);
 	EMULATE_APP_DATA(chan_charlie, 0, "AppDial", "(Outgoing Line)");
 
 	chan_david = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "400", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/David");
+	SET_FORMATS(chan_charlie);
 	ast_channel_unlock(chan_david);
 	ast_set_flag(ast_channel_flags(chan_david), AST_FLAG_OUTGOING);
 	EMULATE_APP_DATA(chan_david, 0, "AppDial", "(Outgoing Line)");
@@ -1637,6 +1664,7 @@
 	EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
 
 	chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
+	SET_FORMATS(chan_callee);
 	ast_channel_unlock(chan_callee);
 	ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
 	COPY_IDS(chan_callee, &bob_expected_one);
@@ -1705,6 +1733,7 @@
 	EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
 
 	chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
+	SET_FORMATS(chan_callee);
 	ast_channel_unlock(chan_callee);
 	ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
 	EMULATE_APP_DATA(chan_callee, 0, "AppDial", "(Outgoing Line)");
@@ -1781,6 +1810,7 @@
 	EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
 
 	chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
+	SET_FORMATS(chan_callee);
 	ast_channel_unlock(chan_callee);
 	ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
 	EMULATE_APP_DATA(chan_callee, 0, "AppDial", "(Outgoing Line)");
@@ -1940,6 +1970,7 @@
 	EMULATE_APP_DATA(chan_alice, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
 
 	chan_bob = ast_channel_alloc(0, AST_STATE_DOWN, "200", "Bob", "200", "200", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/Bob");
+	SET_FORMATS(chan_bob);
 	ast_channel_unlock(chan_bob);
 	ast_set_flag(ast_channel_flags(chan_bob), AST_FLAG_OUTGOING);
 	EMULATE_APP_DATA(chan_bob, 0, "AppDial", "(Outgoing Line)");
@@ -1954,6 +1985,7 @@
 	ast_copy_string(charlie_expected_two.linkedid, ast_channel_linkedid(chan_alice), sizeof(charlie_expected_two.linkedid));
 
 	chan_david = ast_channel_alloc(0, AST_STATE_DOWN, "400", "David", "400", "400", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/David");
+	SET_FORMATS(chan_david);
 	ast_channel_unlock(chan_david);
 	ast_set_flag(ast_channel_flags(chan_david), AST_FLAG_OUTGOING);
 	EMULATE_APP_DATA(chan_david, 0, "AppDial", "(Outgoing Line)");

Modified: trunk/tests/test_cel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_cel.c?view=diff&rev=423784&r1=423783&r2=423784
==============================================================================
--- trunk/tests/test_cel.c (original)
+++ trunk/tests/test_cel.c Tue Sep 23 09:36:00 2014
@@ -206,9 +206,23 @@
 /*! \brief David's Caller ID */
 #define DAVID_CALLERID { .id.name.str = "David", .id.name.valid = 1, .id.number.str = "400", .id.number.valid = 1, }
 
+/*! \brief Set ulaw format on channel */
+#define SET_FORMATS(chan) do {\
+	struct ast_format_cap *caps;\
+	caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);\
+	ast_format_cap_append(caps, ast_format_ulaw, 0);\
+	ast_channel_nativeformats_set((chan), caps);\
+	ast_channel_set_writeformat((chan), ast_format_ulaw);\
+	ast_channel_set_rawwriteformat((chan), ast_format_ulaw);\
+	ast_channel_set_readformat((chan), ast_format_ulaw);\
+	ast_channel_set_rawreadformat((chan), ast_format_ulaw);\
+	ao2_ref(caps, -1);\
+} while (0)
+
 /*! \brief Create a \ref test_cel_chan_tech for Alice. */
 #define CREATE_ALICE_CHANNEL(channel_var, caller_id) do { \
 	(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "100", "100", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/Alice"); \
+	SET_FORMATS((channel_var));\
 	APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
 	ast_channel_unlock((channel_var)); \
 	} while (0)
@@ -216,6 +230,7 @@
 /*! \brief Create a \ref test_cel_chan_tech for Bob. */
 #define CREATE_BOB_CHANNEL(channel_var, caller_id) do { \
 	(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "200", "200", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/Bob"); \
+	SET_FORMATS((channel_var));\
 	APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
 	ast_channel_unlock((channel_var)); \
 	} while (0)
@@ -223,6 +238,7 @@
 /*! \brief Create a \ref test_cel_chan_tech for Charlie. */
 #define CREATE_CHARLIE_CHANNEL(channel_var, caller_id) do { \
 	(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "300", "300", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/Charlie"); \
+	SET_FORMATS((channel_var));\
 	APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
 	ast_channel_unlock((channel_var)); \
 	} while (0)
@@ -230,6 +246,7 @@
 /*! \brief Create a \ref test_cel_chan_tech for David. */
 #define CREATE_DAVID_CHANNEL(channel_var, caller_id) do { \
 	(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "400", "400", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/David"); \
+	SET_FORMATS((channel_var));\
 	APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
 	ast_channel_unlock((channel_var)); \
 	} while (0)
@@ -738,6 +755,7 @@
 
 #define START_DIALED_FULL(caller, callee, number, name) do { \
 	callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, number, NULL, NULL, NULL, caller, 0, CHANNEL_TECH_NAME "/" name); \
+	SET_FORMATS(callee);\
 	ast_channel_unlock(callee); \
 	if (append_expected_event(callee, AST_CEL_CHANNEL_START, NULL, NULL, NULL)) { \
 		return AST_TEST_FAIL; \




More information about the asterisk-commits mailing list