1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
/*
The oSIP library implements the Session Initiation Protocol (SIP -rfc2543-)
Copyright (C) 2001 Aymeric MOIZARD jack@atosc.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef ENABLE_MPATROL
#include <mpatrol.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <osip/smsg.h>
#include <osip/port.h>
int test_message (char *msg, int verbose, int clone);
void
usage ()
{
fprintf (stderr, "Usage: ./torture_test torture_file number [-v] [-c]\n");
exit (1);
}
int
main (int argc, char **argv)
{
int i;
int verbose = 0; /* 1: verbose, 0 (or nothing: not verbose) */
int clone = 0; /* 1: verbose, 0 (or nothing: not verbose) */
char *marker;
FILE *torture_file;
char *tmp;
char *msg;
char *tmpmsg;
static int num_test = 0;
if (argc > 3)
{
if (0 == strncmp (argv[3], "-v", 2))
verbose = 1;
else if (0 == strncmp (argv[3], "-c", 2))
clone = 1;
else
usage ();
}
if (argc > 4)
{
if (0 == strncmp (argv[4], "-v", 2))
verbose = 1;
else if (0 == strncmp (argv[4], "-c", 2))
clone = 1;
else
usage ();
}
if (argc < 3)
{
usage ();
}
torture_file = fopen (argv[1], "r");
if (torture_file == NULL)
{
usage ();
}
/* initialize parser */
parser_init ();
i = 0;
tmp = (char *) smalloc (500);
marker = fgets (tmp, 500, torture_file); /* lines are under 500 */
while (marker != NULL && i < atoi (argv[2]))
{
if (0 == strncmp (tmp, "|", 1))
i++;
marker = fgets (tmp, 500, torture_file);
}
num_test++;
msg = (char *) smalloc (50000); /* msg are under 10000 */
if (msg == NULL)
{
fprintf (stderr, "Error! smalloc failed\n");
return -1;
}
tmpmsg = msg;
if (marker == NULL)
{
fprintf (stderr,
"Error! The message's number you specified does not exist\n");
exit (1); /* end of file detected! */
}
/* this part reads an entire message, separator is "|" */
/* (it is unlinkely that it will appear in messages!) */
while (marker != NULL && strncmp (tmp, "|", 1))
{
sstrncpy (tmpmsg, tmp, strlen (tmp));
tmpmsg = tmpmsg + strlen (tmp);
marker = fgets (tmp, 500, torture_file);
}
if (verbose)
{
fprintf (stdout, "test %s : ============================ \n", argv[2]);
fprintf (stdout, "%s", msg);
if (0 == test_message (msg, verbose, clone))
fprintf (stdout, "test %s : ============================ OK\n",
argv[2]);
else
fprintf (stdout, "test %s : ============================ FAILED\n",
argv[2]);
}
else
{
if (0 == test_message (msg, verbose, clone))
fprintf (stdout, "test %s : OK\n", argv[2]);
else
fprintf (stdout, "test %s : FAILED\n", argv[2]);
}
sfree (msg);
sfree (tmp);
fclose (torture_file);
return 0;
}
int
test_message (char *msg, int verbose, int clone)
{
sip_t *sip;
{
char *result;
/* int j=10000; */
int j = 1;
fprintf (stdout,
"Trying %i sequentials calls to msg_init(), msg_parse() and msg_free()\n",
j);
while (j != 0)
{
j--;
msg_init (&sip);
if (msg_parse (sip, msg) != 0)
{
fprintf (stdout, "ERROR: failed while parsing!\n");
msg_free (sip); /* try to free msg, even if it failed! */
sfree (sip);
return -1;
}
msg_free (sip); /* try to free msg, even if it failed! */
sfree (sip);
}
msg_init (&sip);
if (msg_parse (sip, msg) != 0)
{
fprintf (stdout, "ERROR: failed while parsing!\n");
msg_free (sip); /* try to free msg, even if it failed! */
/* this seems dangerous..... */
return -1;
}
else
{
int i;
i = msg_2char (sip, &result);
if (i == -1)
{
fprintf (stdout, "ERROR: failed while printing message!\n");
msg_free (sip);
sfree (sip);
return -1;
}
else
{
if (verbose)
fprintf (stdout, "%s", result);
if (clone)
{
/* create a clone of message */
/* int j = 10000; */
int j = 1;
fprintf (stdout,
"Trying %i sequentials calls to msg_clone() and msg_free()\n",
j);
while (j != 0)
{
sip_t *copy;
j--;
i = msg_clone (sip, ©);
if (i != 0)
{
fprintf (stdout,
"ERROR: failed while creating copy of message!\n");
}
else
{
char *tmp;
msg_force_update (copy);
i = msg_2char (copy, &tmp);
if (i != 0)
{
fprintf (stdout,
"ERROR: failed while printing message!\n");
}
else
{
if (0 == strcmp (result, tmp))
{
if (verbose)
printf
("The msg_clone method works perfectly\n");
}
else
printf
("ERROR: The msg_clone method DOES NOT works\n");
if (verbose)
printf ("Here is the copy: \n%s\n", tmp);
sfree (tmp);
}
msg_free (copy);
sfree (copy);
}
}
fprintf (stdout, "sequentials calls: done\n");
}
sfree (result);
}
msg_free (sip);
sfree (sip);
}
}
return 0;
}
|