[asterisk-commits] branch oej/moduletest - r7603 in /team/oej/moduletest: ./ channels/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Dec 22 16:42:07 CST 2005


Author: oej
Date: Thu Dec 22 16:42:05 2005
New Revision: 7603

URL: http://svn.digium.com/view/asterisk?rev=7603&view=rev
Log:
The SIP test code always fails, but is anyway an example of what can be done.

We might want to have some standardized way of returning result to a test tool
script.


Modified:
    team/oej/moduletest/Makefile
    team/oej/moduletest/channels/chan_sip.c

Modified: team/oej/moduletest/Makefile
URL: http://svn.digium.com/view/asterisk/team/oej/moduletest/Makefile?rev=7603&r1=7602&r2=7603&view=diff
==============================================================================
--- team/oej/moduletest/Makefile (original)
+++ team/oej/moduletest/Makefile Thu Dec 22 16:42:05 2005
@@ -44,7 +44,7 @@
 #K6OPT  = -DK6OPT
 
 #Tell gcc to optimize the code
-OPTIMIZE+=-O6
+#OPTIMIZE+=-O6
 endif
 
 #Overwite config files on "make samples"

Modified: team/oej/moduletest/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/moduletest/channels/chan_sip.c?rev=7603&r1=7602&r2=7603&view=diff
==============================================================================
--- team/oej/moduletest/channels/chan_sip.c (original)
+++ team/oej/moduletest/channels/chan_sip.c Thu Dec 22 16:42:05 2005
@@ -13236,10 +13236,186 @@
 
 /*--------------- Test functions -------------------*/
 #ifdef ENABLE_CODE_TEST
+/* -- Forward declarations */
+static struct sip_request *create_sip_message(int number);
+/* Test functions */
+static int test_tags(void);
+static int test_get_header(void);
+static int test_callid_uniqueness(void);
+
+/*! \brief Test interface to core PBX cli function */
 int codetest(int fd)
 {
+	int res = 0;
 	ast_cli(fd, "Testing chan_sip functions.... \n");	
 	ast_log(LOG_VERBOSE, "Testing chan_sip functions ... \n");
+	ast_cli(fd, "* Testing tag functions \n");
+	res = test_tags();
+	ast_cli(fd, "* Testing header functions \n");
+	res += test_get_header();
+	ast_cli(fd, "* Testing callid generation (random generator) \n");
+	res += test_callid_uniqueness();
+	if (!res)
+		ast_cli(fd, "OK :: Chan_sip.so passed test without errors\n");
+	else
+		ast_cli(fd, "FAIL :: Chan_sip.so failed test with a total of %d errors\n", res);
 	return RESULT_SUCCESS;
 }
+
+/* Create SIP messages for testing. Number indicates which test packet */
+static struct sip_request *create_sip_message(int number)
+{
+	struct sip_request *req;
+	char *demo_packet[3];
+	
+	/* 1. OPTIONS packet */
+	demo_packet[0] = 
+		"OPTIONS sip:3000 at 192.168.236.49 SIP/2.0\n"
+		"Via: SIP/2.0/UDP 192.168.11.11:5060;branch=z9hG4bK193148bb\n"
+		"From: \"asterisk\" <sip:asterisk at 192.168.94.55>;tag=as2b0e6ece\n"
+		"To: <sip:3000 at 192.168.236.49>\n"
+		"Contact: <sip:asterisk at 194.168.94.55>\n"
+		"Call-ID: 3f66e2987339aee36b54cc2f5e371b46 at 194.168.94.55\n"
+		"CSeq: 102 OPTIONS\n"
+		"User-Agent: Asterisk 1.0\n"
+		"Date: Fri, 23 Dec 2005 05:19:48 GMT\n"
+		"Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER\n"
+		"Content-Length: 0\n";
+
+	/* 2. Asterisk reply to options (without SDP) , fromtag and totag*/
+	demo_packet[1] = 
+		"SIP/2.0 200 OK\n"
+		"Via: SIP/2.0/UDP 192.168.94.55:5060;branch=z9hG4bK193148bb;received=194.168.94.55\n"
+		"From: \"asterisk\" <sip:asterisk at 194.168.94.55>;tag=as2b0e6ece\n"
+		"To: <sip:3000 at 192.168.236.49>;tag=as220106ec\n"
+		"Call-ID: 3f66e2987339aee36b54cc2f5e371b46 at 192.168.94.55\n"
+		"CSeq: 102 OPTIONS\n"
+		"User-Agent: Asterisk 1.2\n"
+		"Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY\n"
+		"Max-Forwards: 70\n"
+		"Contact: <sip:192.168.236.49>\n"
+		"Accept: application/sdp\n"
+		"Content-Length: 0\n";
+
+	/* 3. Registration request without auth and no white space (WiSIP phone) */
+	demo_packet[2] = 
+		"REGISTER sip:jarl.digium.com:5060 SIP/2.0\n"
+		"Via:SIP/2.0/UDP 192.168.123.149:5060;branch=z9hG4bk723df946284bd7\n"
+		"From:<sip:3300 at jarl.digium.com;user=phone>;tag=B5913DFE66749B9A26B\n"
+		"To:<sip:3300 at jarl.digium.com;user=phone>\n"
+		"Call-ID:8870-D1B9-8CA6-CD71-6061F4366992 at 192.168.123.149\n"
+		"CSeq:86034 REGISTER\n"
+		"User-Agent: WiSIP\n"
+		"Contact: <sip:3300 at 192.168.123.149:5060;transport=udp>\n"
+		"Expires: 120\n"
+		"Content-Length: 0\n";
+
+	req = malloc(sizeof(struct sip_request));
+	if (!req) {
+		ast_log(LOG_DEBUG, "Memory allocation error.\n");
+		return NULL;
+	}
+	memset(req, 0, sizeof(struct sip_request));
+	/* Copy packet into packet if you know what I mean */
+	ast_copy_string(req->data, demo_packet[number], sizeof(req->data));
+	req->len = sizeof(demo_packet[number]);
+
+	/* Fix multiline headers - only done in pedantic mode in chan_sip (sipsock_read) */
+	req->len = lws2sws(req->data, req->len);
+	
+	/* Parse packet */
+	parse_request(req);
+	/* Find method */
+	req->method = find_sip_method(req->rlPart1);
+
+	/* We're done, have a full packet, parsed and ready */
+	return req;
+}
+
+/* Test tag retrieval code */
+static int test_tags(void)
+{
+	struct sip_request *req;
+	char buf[BUFSIZ];
+	char *result;
+	int error = 0;
+
+	/* Test first packet, initial OPTIONS request with from tag and no to tag  */
+	req = create_sip_message(0);
+	result = gettag(req, "To", buf, sizeof(buf));
+	if (option_debug > 3)
+		ast_log(LOG_DEBUG, "Test-tags: To-tag = '%s'\n", result ? result : "<none>");
+	if (result) {
+		error = 1;
+		ast_log(LOG_ERROR, "Wrong to tag in packet one, parse error.");
+	}
+	result = gettag(req, "From", buf, sizeof(buf));
+	if (option_debug > 3)
+		ast_log(LOG_DEBUG, "Test-tags: From-tag = '%s'\n", result ? result : "<none>");
+	if (!result || strcmp(result, "as2b0e6ece")) {
+		error = 1;
+		ast_log(LOG_ERROR, "Wrong From tag in packet one, parse error. Tag = %s\n", result ? result : "<none>");
+	}
+	free(req);
+
+	/* More tests of other packets */
+	/* We need packets with bad syntax and weird syntaxes, examples */
+	/* And packets with UTF8 strings in strange places */
+
+	return error;	
+}
+
+/* Test get header code */
+static int test_get_header()
+{
+	int error = 0;
+
+	/* No op */
+
+	return error;
+}
+
+/* Test call ID generation */
+/* Generate 10.000 call id:s and check if they are identical */
+static int test_callid_uniqueness()
+{
+	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



More information about the asterisk-commits mailing list