[asterisk-commits] branch group/testframework r16476 - in
/team/group/testframework: ./ channels...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Wed Mar 29 23:14:20 MST 2006
Author: russell
Date: Thu Mar 30 00:14:18 2006
New Revision: 16476
URL: http://svn.digium.com/view/asterisk?rev=16476&view=rev
Log:
add one of oej's old example tests and get things back in working condition
Modified:
team/group/testframework/asterisk.c
team/group/testframework/channels/chan_sip.c
team/group/testframework/codetest.c
team/group/testframework/include/asterisk.h
Modified: team/group/testframework/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/group/testframework/asterisk.c?rev=16476&r1=16475&r2=16476&view=diff
==============================================================================
--- team/group/testframework/asterisk.c (original)
+++ team/group/testframework/asterisk.c Thu Mar 30 00:14:18 2006
@@ -2311,6 +2311,12 @@
srand((unsigned int) getpid() + (unsigned int) time(NULL));
initstate((unsigned int) getpid() * 65536 + (unsigned int) time(NULL), randompool, sizeof(randompool));
+#ifdef ENABLE_CODE_TEST
+ if (codetest_init()) {
+ printf(term_quit());
+ exit(1);
+ }
+#endif
if (init_logger()) {
printf(term_quit());
exit(1);
Modified: team/group/testframework/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/testframework/channels/chan_sip.c?rev=16476&r1=16475&r2=16476&view=diff
==============================================================================
--- team/group/testframework/channels/chan_sip.c (original)
+++ team/group/testframework/channels/chan_sip.c Thu Mar 30 00:14:18 2006
@@ -92,6 +92,7 @@
#include "asterisk/linkedlists.h"
#include "asterisk/stringfields.h"
#include "asterisk/monitor.h"
+#include "asterisk/codetest.h"
#ifdef OSP_SUPPORT
#include "asterisk/astosp.h"
@@ -13419,6 +13420,120 @@
return 0;
}
+#ifdef ENABLE_CODE_TEST
+static int test_tags_func(int fd, int argc, char *argv[]);
+static struct sip_request *create_sip_message(int number);
+#endif
+
+AST_DEFINE_CODE_TEST(test_tags, "tags", test_tags_func);
+
+#ifdef ENABLE_CODE_TEST
+/* 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;
+}
+#endif
+
+#ifdef ENABLE_CODE_TEST
+/*! \brief Test tag retrieval code */
+static int test_tags_func(int fd, int argc, char *argv[])
+{
+ 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;
+}
+#endif
+
/*! \brief reload: Part of Asterisk module interface */
int reload(void)
{
@@ -13502,6 +13617,9 @@
ast_manager_register2("SIPshowpeer", EVENT_FLAG_SYSTEM, manager_sip_show_peer,
"Show SIP peer (text format)", mandescr_show_peer);
+ /* Register code tests */
+ ast_register_codetest(&test_tags);
+
sip_poke_all_peers();
sip_send_all_registers();
@@ -13532,6 +13650,9 @@
ast_manager_unregister("SIPpeers");
ast_manager_unregister("SIPshowpeer");
+
+ /* Unregister Code Tests */
+ ast_unregister_codetest(&test_tags);
if (!ast_mutex_lock(&iflock)) {
/* Hangup all interfaces if they have an owner */
Modified: team/group/testframework/codetest.c
URL: http://svn.digium.com/view/asterisk/team/group/testframework/codetest.c?rev=16476&r1=16475&r2=16476&view=diff
==============================================================================
--- team/group/testframework/codetest.c (original)
+++ team/group/testframework/codetest.c Thu Mar 30 00:14:18 2006
@@ -60,12 +60,12 @@
static int count_tests(struct testfile *tf);
static int handle_cli_show_files(int fd, int argc, char *argv[]);
static int handle_cli_show_file(int fd, int argc, char *argv[]);
-static char *complete_testfiles(char *line, char *word, int pos, int state);
-static char *complete_cli_show_file(char *line, char *word, int pos, int state);
+static char *complete_testfiles(const char *line, const char *word, int pos, int state);
+static char *complete_cli_show_file(const char *line, const char *word, int pos, int state);
static void check_test_result(int fd, struct ast_codetest *test, int res);
static int handle_cli_run(int fd, int argc, char *argv[]);
-static char *complete_tests(char *line, char *word, int pos, int state);
-static char *complete_cli_run(char *line, char *word, int pos, int state);
+static char *complete_tests(const char *line, const char *word, int pos, int state);
+static char *complete_cli_run(const char *line, const char *word, int pos, int state);
/*!
\brief Add a test to the list of tests for a file
@@ -212,7 +212,7 @@
return RESULT_SUCCESS;
}
-static char *complete_testfiles(char *line, char *word, int pos, int state)
+static char *complete_testfiles(const char *line, const char *word, int pos, int state)
{
struct testfile *cur;
int match = 0;
@@ -232,7 +232,7 @@
}
-static char *complete_cli_show_file(char *line, char *word, int pos, int state)
+static char *complete_cli_show_file(const char *line, const char *word, int pos, int state)
{
if (pos != 3)
return NULL;
@@ -309,7 +309,7 @@
return RESULT_SUCCESS;
}
-static char *complete_tests(char *line, char *word, int pos, int state)
+static char *complete_tests(const char *line, const char *word, int pos, int state)
{
char *file;
char *ret = NULL;
@@ -343,13 +343,12 @@
return ret;
}
-static char *complete_cli_run(char *line, char *word, int pos, int state)
+static char *complete_cli_run(const char *line, const char *word, int pos, int state)
{
if (pos == 2)
return complete_testfiles(line, word, pos, state);
- else if (pos == 3)
- /* XXX Why isn't this being executed ?! XXX */
- return complete_tests(line, word, pos, state);
+ /*else if (pos == 3)
+ return complete_tests(line, word, pos, state);*/
return NULL;
}
Modified: team/group/testframework/include/asterisk.h
URL: http://svn.digium.com/view/asterisk/team/group/testframework/include/asterisk.h?rev=16476&r1=16475&r2=16476&view=diff
==============================================================================
--- team/group/testframework/include/asterisk.h (original)
+++ team/group/testframework/include/asterisk.h Thu Mar 30 00:14:18 2006
@@ -70,6 +70,11 @@
int dnsmgr_init(void);
void dnsmgr_start_refresh(void);
int dnsmgr_reload(void);
+#ifdef ENABLE_CODE_TEST
+/* Provided by codetest.c */
+int codetest_init(void);
+#endif
+
/*!
* \brief Register the version of a source code file with the core.
More information about the asterisk-commits
mailing list