[svn-commits] branch russell/codetest - r7626 /team/russell/codetest/channels/chan_sip.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sun Dec 25 15:27:31 CST 2005


Author: russell
Date: Sun Dec 25 15:27:29 2005
New Revision: 7626

URL: http://svn.digium.com/view/asterisk?rev=7626&view=rev
Log:
add oej's callid uniqueness test

Modified:
    team/russell/codetest/channels/chan_sip.c

Modified: team/russell/codetest/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/russell/codetest/channels/chan_sip.c?rev=7626&r1=7625&r2=7626&view=diff
==============================================================================
--- team/russell/codetest/channels/chan_sip.c (original)
+++ team/russell/codetest/channels/chan_sip.c Sun Dec 25 15:27:29 2005
@@ -928,6 +928,15 @@
 static char *gettag(struct sip_request *req, char *header, char *tagbuf, int tagbufsize);
 int find_sip_method(char *msg);
 unsigned int parse_sip_options(struct sip_pvt *pvt, char *supported);
+
+#ifdef ENABLE_CODE_TEST
+static int test_tags_func(int fd, int argc, char *argv[]);
+static int test_callid_uniqueness_func(void);
+static struct sip_request *create_sip_message(int number);
+#endif
+
+AST_DEFINE_CODE_TEST(test_tags, "tags", test_tags_func);
+AST_DEFINE_CODE_TEST(test_callid_uniqueness, "callid_uniqueness", test_callid_uniqueness_func);
 
 /*! \brief Definition of this channel for PBX channel registration */
 static const struct ast_channel_tech sip_tech = {
@@ -13095,7 +13104,51 @@
 }
 #endif
 
-AST_DEFINE_CODE_TEST(test_tags, "tags", test_tags_func);
+#ifdef ENABLE_CODE_TEST
+/* Test call ID generation */
+/* Generate 10.000 call id:s and check if they are identical */
+static int test_callid_uniqueness_func(void)
+{
+	char *call_ids[10000];
+	char *our_ip="192.168.40.1";
+	char buf[BUFSIZ];
+	int i, j;
+	int errors = 0, localerrors;
+	struct sockaddr_in our_ip_addr;
+	ast_get_ip(&our_ip_addr, our_ip);
+	
+	for (i=0; i < 10000; i++) {
+		localerrors = 0;
+		build_callid(buf, sizeof(buf), our_ip_addr.sin_addr, "edvina.net");
+		for (j = 0; j < i; j++) {
+			if (ast_strlen_zero(buf)) {
+				localerrors++;
+				if (option_debug)
+					ast_log(LOG_DEBUG, "  No call ID generated ?? \n");
+			} else if (!strcmp(buf, call_ids[j])) {
+				localerrors++;
+				if (option_debug)
+					ast_log(LOG_DEBUG, "  Duplicate call ID found. Bad! Now %d errors.\n", localerrors);
+			}
+		}
+		call_ids[i] = strdup(buf);
+		if (localerrors && option_debug)
+			ast_log(LOG_DEBUG, "-- Found %d duplicates for call ID #%d\n", localerrors, i);
+		errors += localerrors;
+	}
+	
+	/* clean up memory allocations */
+	for (i=0; i < 10000; i++) {
+		if (call_ids[i])
+			free(call_ids[i]);
+	}
+
+
+	if (errors && option_debug)
+		ast_log(LOG_DEBUG, "Found %d duplicates among 10.000 generated call IDs\n", errors);
+	return errors;
+}
+#endif
 
 /*! \brief  sip_do_reload: Reload module */
 static int sip_do_reload(void)
@@ -13220,6 +13273,7 @@
 
 	/* Register code tests */
 	ast_register_codetest(&test_tags);
+	ast_register_codetest(&test_callid_uniqueness);
 
 	sip_poke_all_peers();	
 	sip_send_all_registers();
@@ -13260,6 +13314,7 @@
 
 	/* Unregister Code Tests */
 	ast_unregister_codetest(&test_tags);
+	ast_unregister_codetest(&test_callid_uniqueness);
 
 	if (!ast_mutex_lock(&iflock)) {
 		/* Hangup all interfaces if they have an owner */



More information about the svn-commits mailing list