Mon May 14 04:44:17 2007

Asterisk developer's documentation


app_test.c File Reference

Applications to test connection and produce report in text file. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "asterisk/channel.h"
#include "asterisk/options.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"

Include dependency graph for app_test.c:

Go to the source code of this file.

Defines

#define HIGHEST_TEST   '2'
#define TEST_VERSION_NUMBER   "8378*"

Functions

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Interface Test Application")
static int load_module (void)
static int measurenoise (struct ast_channel *chan, int ms, char *who)
static int sendnoise (struct ast_channel *chan, int ms)
static int test1_client (int res, struct ast_channel *chan, FILE *f)
static int test1_server (int res, struct ast_channel *chan, FILE *f)
static int test2_client (int res, struct ast_channel *chan, FILE *f)
static int test2_server (int res, struct ast_channel *chan, FILE *f)
static int testclient_exec (struct ast_channel *chan, void *data)
static int testserver_exec (struct ast_channel *chan, void *data)
static int unload_module (void)

Variables

static char * testc_app = "TestClient"
static char * testc_descrip
static char * testc_synopsis = "Execute Interface Test Client"
static char * tests_app = "TestServer"
static char * tests_descrip
static char * tests_synopsis = "Execute Interface Test Server"


Detailed Description

Applications to test connection and produce report in text file.

Author:
Mark Spencer <markster@digium.com>

Russell Bryant <russelb@clemson.edu>

Definition in file app_test.c.


Define Documentation

#define HIGHEST_TEST   '2'

Definition at line 53 of file app_test.c.

Referenced by testclient_exec(), and testserver_exec().

#define TEST_VERSION_NUMBER   "8378*"

Definition at line 51 of file app_test.c.

Referenced by testclient_exec(), and testserver_exec().


Function Documentation

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Interface Test Application"   
)

static int load_module ( void   )  [static]

Definition at line 658 of file app_test.c.

References ast_register_application(), testclient_exec(), and testserver_exec().

00659 {
00660    int res;
00661 
00662    res = ast_register_application(testc_app, testclient_exec, testc_synopsis, testc_descrip);
00663    res |= ast_register_application(tests_app, testserver_exec, tests_synopsis, tests_descrip);
00664 
00665    return res;
00666 }

static int measurenoise ( struct ast_channel chan,
int  ms,
char *  who 
) [static]

Definition at line 72 of file app_test.c.

References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_frfree(), ast_log(), ast_read(), ast_set_read_format(), ast_waitfor(), f, LOG_DEBUG, LOG_NOTICE, and ast_channel::readformat.

Referenced by test1_client(), and test1_server().

00073 {
00074    int res=0;
00075    int mssofar;
00076    int noise=0;
00077    int samples=0;
00078    int x;
00079    short *foo;
00080    struct timeval start;
00081    struct ast_frame *f;
00082    int rformat;
00083    rformat = chan->readformat;
00084    if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) {
00085       ast_log(LOG_NOTICE, "Unable to set to linear mode!\n");
00086       return -1;
00087    }
00088    start = ast_tvnow();
00089    for(;;) {
00090       mssofar = ast_tvdiff_ms(ast_tvnow(), start);
00091       if (mssofar > ms)
00092          break;
00093       res = ast_waitfor(chan, ms - mssofar);
00094       if (res < 1)
00095          break;
00096       f = ast_read(chan);
00097       if (!f) {
00098          res = -1;
00099          break;
00100       }
00101       if ((f->frametype == AST_FRAME_VOICE) && (f->subclass == AST_FORMAT_SLINEAR)) {
00102          foo = (short *)f->data;
00103          for (x=0;x<f->samples;x++) {
00104             noise += abs(foo[x]);
00105             samples++;
00106          }
00107       }
00108       ast_frfree(f);
00109    }
00110 
00111    if (rformat) {
00112       if (ast_set_read_format(chan, rformat)) {
00113          ast_log(LOG_NOTICE, "Unable to restore original format!\n");
00114          return -1;
00115       }
00116    }
00117    if (res < 0)
00118       return res;
00119    if (!samples) {
00120       ast_log(LOG_NOTICE, "No samples were received from the other side!\n");
00121       return -1;
00122    }
00123    ast_log(LOG_DEBUG, "%s: Noise: %d, samples: %d, avg: %d\n", who, noise, samples, noise / samples);
00124    return (noise / samples);
00125 }

static int sendnoise ( struct ast_channel chan,
int  ms 
) [static]

Definition at line 127 of file app_test.c.

References ast_tonepair_start(), ast_tonepair_stop(), and ast_waitfordigit().

Referenced by test1_client(), and test1_server().

00128 {
00129    int res;
00130    res = ast_tonepair_start(chan, 1537, 2195, ms, 8192);
00131    if (!res) {
00132       res = ast_waitfordigit(chan, ms);
00133       ast_tonepair_stop(chan);
00134    }
00135    return res; 
00136 }

static int test1_client ( int  res,
struct ast_channel chan,
FILE *  f 
) [static]

Definition at line 146 of file app_test.c.

References ast_dtmf_stream(), ast_log(), ast_safe_sleep(), ast_waitfordigit(), LOG_DEBUG, measurenoise(), option_debug, and sendnoise().

Referenced by testclient_exec().

00147 {
00148    if (!res) {
00149       /* Step 1: Wait for "1" */
00150       if (option_debug)
00151          ast_log(LOG_DEBUG, "TestClient: 2.  Wait DTMF 1\n");
00152       res = ast_waitfordigit(chan, 3000);
00153       fprintf(f, "WAIT DTMF 1:   %s\n", (res != '1') ? "FAIL" : "PASS");
00154       if (res == '1')
00155          res = 0;
00156       else
00157          res = -1;
00158    }
00159    if (!res)
00160       res = ast_safe_sleep(chan, 1000);
00161 
00162    if (!res) {
00163       /* Step 2: Send "2" */
00164       if (option_debug)
00165          ast_log(LOG_DEBUG, "TestClient: 2.  Send DTMF 2\n");
00166       res = ast_dtmf_stream(chan, NULL, "2", 0);
00167       fprintf(f, "SEND DTMF 2:   %s\n", (res < 0) ? "FAIL" : "PASS");
00168       if (res > 0)
00169          res = 0;
00170    }
00171    if (!res) {
00172       /* Step 3: Wait one second */
00173       if (option_debug)
00174          ast_log(LOG_DEBUG, "TestClient: 3.  Wait one second\n");
00175       res = ast_safe_sleep(chan, 1000);
00176       fprintf(f, "WAIT 1 SEC:    %s\n", (res < 0) ? "FAIL" : "PASS");
00177       if (res > 0)
00178          res = 0;
00179    }        
00180    if (!res) {
00181       /* Step 4: Measure noise */
00182       if (option_debug)
00183          ast_log(LOG_DEBUG, "TestClient: 4.  Measure noise\n");
00184       res = measurenoise(chan, 5000, "TestClient");
00185       fprintf(f, "MEASURENOISE:  %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res);
00186       if (res > 0)
00187          res = 0;
00188    }
00189    if (!res) {
00190       /* Step 5: Wait for "4" */
00191       if (option_debug)
00192          ast_log(LOG_DEBUG, "TestClient: 5.  Wait DTMF 4\n");
00193       res = ast_waitfordigit(chan, 3000);
00194       fprintf(f, "WAIT DTMF 4:   %s\n", (res != '4') ? "FAIL" : "PASS");
00195       if (res == '4')
00196          res = 0;
00197       else
00198          res = -1;
00199    }
00200    if (!res) {
00201       /* Step 6: Transmit tone noise */
00202       if (option_debug)
00203          ast_log(LOG_DEBUG, "TestClient: 6.  Transmit tone\n");
00204       res = sendnoise(chan, 6000);
00205       fprintf(f, "SENDTONE:      %s\n", (res < 0) ? "FAIL" : "PASS");
00206    }
00207    if (!res || (res == '5')) {
00208       /* Step 7: Wait for "5" */
00209       if (option_debug)
00210          ast_log(LOG_DEBUG, "TestClient: 7.  Wait DTMF 5\n");
00211       if (!res)
00212          res = ast_waitfordigit(chan, 3000);
00213       fprintf(f, "WAIT DTMF 5:   %s\n", (res != '5') ? "FAIL" : "PASS");
00214       if (res == '5')
00215          res = 0;
00216       else
00217          res = -1;
00218    }
00219    if (!res) {
00220       /* Step 8: Wait one second */
00221       if (option_debug)
00222          ast_log(LOG_DEBUG, "TestClient: 8.  Wait one second\n");
00223       res = ast_safe_sleep(chan, 1000);
00224       fprintf(f, "WAIT 1 SEC:    %s\n", (res < 0) ? "FAIL" : "PASS");
00225       if (res > 0)
00226          res = 0;
00227    }
00228    if (!res) {
00229       /* Step 9: Measure noise */
00230       if (option_debug)
00231          ast_log(LOG_DEBUG, "TestClient: 6.  Measure tone\n");
00232       res = measurenoise(chan, 4000, "TestClient");
00233       fprintf(f, "MEASURETONE:   %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res);
00234       if (res > 0)
00235          res = 0;
00236    }
00237    if (!res) {
00238       /* Step 10: Send "7" */
00239       if (option_debug)
00240          ast_log(LOG_DEBUG, "TestClient: 7.  Send DTMF 7\n");
00241       res = ast_dtmf_stream(chan, NULL, "7", 0);
00242       fprintf(f, "SEND DTMF 7:   %s\n", (res < 0) ? "FAIL" : "PASS");
00243       if (res > 0)
00244          res =0;
00245    }
00246    if (!res) {
00247       /* Step 11: Wait for "8" */
00248       if (option_debug)
00249          ast_log(LOG_DEBUG, "TestClient: 11.  Wait DTMF 8\n");
00250       res = ast_waitfordigit(chan, 3000);
00251       fprintf(f, "WAIT DTMF 8:   %s\n", (res != '8') ? "FAIL" : "PASS");
00252       if (res == '8')
00253          res = 0;
00254       else
00255          res = -1;
00256    }
00257    if (option_debug && !res ) {
00258       /* Step 12: Hangup! */
00259       ast_log(LOG_DEBUG, "TestClient: 12.  Hangup\n");
00260    }
00261    return res;
00262 }

static int test1_server ( int  res,
struct ast_channel chan,
FILE *  f 
) [static]

Definition at line 264 of file app_test.c.

References ast_dtmf_stream(), ast_log(), ast_safe_sleep(), ast_waitfordigit(), LOG_DEBUG, measurenoise(), option_debug, and sendnoise().

Referenced by testserver_exec().

00265 {
00266    if (!res) {
00267       /* Step 1: Send "1" */
00268       if (option_debug) 
00269          ast_log(LOG_DEBUG, "TestServer: 1.  Send DTMF 1\n");
00270       res = ast_dtmf_stream(chan, NULL, "1", 0);
00271       fprintf(f, "SEND DTMF 1:   %s\n", (res < 0) ? "FAIL" : "PASS");
00272       if (res > 0)
00273          res = 0;
00274    }
00275    if (!res) {
00276       /* Step 2: Wait for "2" */
00277       if (option_debug) 
00278          ast_log(LOG_DEBUG, "TestServer: 2.  Wait DTMF 2\n");
00279       res = ast_waitfordigit(chan, 3000);
00280       fprintf(f, "WAIT DTMF 2:   %s\n", (res != '2') ? "FAIL" : "PASS");
00281       if (res == '2')
00282          res = 0;
00283       else
00284          res = -1;
00285    }
00286    if (!res) {
00287       /* Step 3: Measure noise */
00288       if (option_debug) 
00289          ast_log(LOG_DEBUG, "TestServer: 3.  Measure noise\n");
00290       /* wait a sec for the channel to quieten */
00291       res = ast_safe_sleep(chan, 1000);
00292       if (!res)
00293          res = measurenoise(chan, 5000, "TestServer");
00294       fprintf(f, "MEASURENOISE:  %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res);
00295       if (res > 0)
00296          res = 0;
00297    }
00298    if (!res) {
00299       /* Step 4: Send "4" */
00300       if (option_debug) 
00301          ast_log(LOG_DEBUG, "TestServer: 4.  Send DTMF 4\n");
00302       /* wait a sec to ensure dtmf doesn't get included in  measurement on the other side */
00303       res = ast_safe_sleep(chan, 1000);
00304       /* and then send the 4 (the client should be waiting for it) */
00305       if (!res)
00306          res = ast_dtmf_stream(chan, NULL, "4", 0);
00307       fprintf(f, "SEND DTMF 4:   %s\n", (res < 0) ? "FAIL" : "PASS");
00308       if (res > 0)
00309          res = 0;
00310    }
00311 
00312    if (!res) {
00313       /* Step 5: Wait one second */
00314       if (option_debug) 
00315          ast_log(LOG_DEBUG, "TestServer: 5.  Wait one second\n");
00316       res = ast_safe_sleep(chan, 1000);
00317       fprintf(f, "WAIT 1 SEC:    %s\n", (res < 0) ? "FAIL" : "PASS");
00318       if (res > 0)
00319          res = 0;
00320    }
00321 
00322    if (!res) {
00323       /* Step 6: Measure noise */
00324       if (option_debug) 
00325          ast_log(LOG_DEBUG, "TestServer: 6.  Measure tone\n");
00326       res = measurenoise(chan, 4000, "TestServer");
00327       fprintf(f, "MEASURETONE:   %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res);
00328       if (res > 0)
00329          res = 0;
00330    }
00331 
00332    if (!res) {
00333       /* Step 7: Send "5" */
00334       if (option_debug) 
00335          ast_log(LOG_DEBUG, "TestServer: 7.  Send DTMF 5\n");
00336       /* wait a sec to ensure dtmf doesn't get measured as part of tone */
00337       res = ast_safe_sleep(chan, 1000);
00338       /* and then send the 5 (the client should be waiting for it) */
00339       if (!res)
00340          res = ast_dtmf_stream(chan, NULL, "5", 0);
00341       fprintf(f, "SEND DTMF 5:   %s\n", (res < 0) ? "FAIL" : "PASS");
00342       if (res > 0)
00343          res = 0;
00344    }
00345 
00346    if (!res) {
00347       /* Step 8: Transmit tone noise */
00348       if (option_debug) 
00349          ast_log(LOG_DEBUG, "TestServer: 8.  Transmit tone\n");
00350       res = sendnoise(chan, 6000);
00351       fprintf(f, "SENDTONE:      %s\n", (res < 0) ? "FAIL" : "PASS");
00352    }
00353 
00354    if (!res || (res == '7')) {
00355       /* Step 9: Wait for "7" */
00356       if (option_debug) 
00357          ast_log(LOG_DEBUG, "TestServer: 9.  Wait DTMF 7\n");
00358       if (!res)
00359          res = ast_waitfordigit(chan, 3000);
00360       fprintf(f, "WAIT DTMF 7:   %s\n", (res != '7') ? "FAIL" : "PASS");
00361       if (res == '7')
00362          res = 0;
00363       else
00364          res = -1;
00365    }
00366    if (!res)
00367       res = ast_safe_sleep(chan, 1000);
00368    if (!res) {
00369       /* Step 10: Send "8" */
00370       if (option_debug) 
00371          ast_log(LOG_DEBUG, "TestServer: 10.  Send DTMF 8\n");
00372       res = ast_dtmf_stream(chan, NULL, "8", 0);
00373       fprintf(f, "SEND DTMF 8:   %s\n", (res < 0) ? "FAIL" : "PASS");
00374       if (res > 0)
00375          res = 0;
00376    }
00377    if (!res) {
00378       /* Step 11: Wait for hangup to arrive! */
00379       if (option_debug) 
00380          ast_log(LOG_DEBUG, "TestServer: 11.  Waiting for hangup\n");
00381       res = ast_safe_sleep(chan, 10000);
00382       fprintf(f, "WAIT HANGUP:   %s\n", (res < 0) ? "PASS" : "FAIL");
00383    }
00384    return res;
00385 }

static int test2_client ( int  res,
struct ast_channel chan,
FILE *  f 
) [static]

Definition at line 397 of file app_test.c.

Referenced by testclient_exec().

00398 {
00399    return -1;
00400 }

static int test2_server ( int  res,
struct ast_channel chan,
FILE *  f 
) [static]

Definition at line 402 of file app_test.c.

Referenced by testserver_exec().

00403 {
00404    return -1;
00405 }

static int testclient_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 408 of file app_test.c.

References ast_channel::_state, ast_answer(), ast_app_getdata(), ast_config_AST_LOG_DIR, ast_dtmf_stream(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_safe_sleep(), AST_STATE_UP, ast_strlen_zero(), ast_module_user::chan, f, HIGHEST_TEST, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, option_debug, strsep(), test1_client(), test2_client(), and TEST_VERSION_NUMBER.

Referenced by load_module().

00409 {
00410    struct ast_module_user *u;
00411    int res = 0;
00412    char testid[256], *testnumber, *stringp;
00413    char fn[80];
00414    char serverver[80];
00415    FILE *f;
00416 
00417    /* Parse testid and the optional test number */
00418         strncpy(testid, (char *)data, sizeof(testid)-1);
00419    stringp = testid;
00420    strsep(&stringp, "|");
00421    testnumber = strsep(&stringp, "|");
00422 
00423    /* Default the test number */
00424    if (ast_strlen_zero(testnumber))
00425       testnumber = "1";
00426 
00427    /* Check for test id */
00428    if (ast_strlen_zero(testid)) {
00429       ast_log(LOG_WARNING, "TestClient requires an argument - the test id\n");
00430       return -1;
00431    }
00432    /* Check we know the test number */
00433    if (strlen(testnumber) != 1 || (*testnumber < '1') || (*testnumber > HIGHEST_TEST)) {
00434       ast_log(LOG_WARNING, "TestClient only knows test numbers from 1 to 2\n");
00435       return -1;
00436    }
00437    
00438    u = ast_module_user_add(chan);
00439 
00440    if (chan->_state != AST_STATE_UP)
00441       res = ast_answer(chan);
00442 
00443    /* Wait a few just to be sure things get started */
00444    res = ast_safe_sleep(chan, 3000);
00445 
00446    /* Transmit client version */
00447    if (!res) {
00448       res = ast_dtmf_stream(chan, NULL, TEST_VERSION_NUMBER, 0);
00449       res = ast_dtmf_stream(chan, NULL, testnumber, 0);
00450       res = ast_dtmf_stream(chan, NULL, "#", 0);
00451    }
00452    if (option_debug)
00453       ast_log(LOG_DEBUG, "Transmit client version and test number\n");
00454    
00455    /* Read server version */
00456    if (option_debug)
00457       ast_log(LOG_DEBUG, "Read server version\n");
00458    if (!res) 
00459       res = ast_app_getdata(chan, NULL, serverver, sizeof(serverver) - 1, 0);
00460    if (res > 0)
00461       res = 0;
00462    if (option_debug)
00463       ast_log(LOG_DEBUG, "server version: %s\n", serverver);
00464 
00465    /* Check server supports the test we want to do */
00466    if (!res) {
00467       stringp = strchr(serverver, '*');
00468       if (stringp) {
00469          if (*++stringp != *testnumber) {
00470             ast_log(LOG_WARNING, "TestClient: server doesn't know test \'%s\'\n", testnumber);
00471             ast_module_user_remove(u);
00472             return -1;
00473          }
00474       }
00475       else {
00476          ast_log(LOG_WARNING, "TestClient couldn't find server test number in \'%s\'\n", serverver);
00477          ast_module_user_remove(u);
00478          return -1;
00479       }
00480    }
00481    else {
00482       ast_log(LOG_WARNING, "TestClient failed to read server version\n");
00483       ast_module_user_remove(u);
00484       return -1;
00485    }
00486 
00487    if (res > 0)
00488       res = 0;
00489 
00490    if (!res)
00491       res = ast_safe_sleep(chan, 1000);
00492 
00493    /* Send test id */
00494    if (!res) 
00495       res = ast_dtmf_stream(chan, NULL, testid, 0);      
00496    if (!res) 
00497       res = ast_dtmf_stream(chan, NULL, "#", 0);      
00498    if (option_debug)
00499       ast_log(LOG_DEBUG, "sent test identifier: %s\n", testid);
00500 
00501    if ((res >=0) && (!ast_strlen_zero(testid))) {
00502       /* Make the directory to hold the test results in case it's not there */
00503       snprintf(fn, sizeof(fn), "%s/testresults", ast_config_AST_LOG_DIR);
00504       mkdir(fn, 0777);
00505       snprintf(fn, sizeof(fn), "%s/testresults/%s-client.txt", ast_config_AST_LOG_DIR, testid);
00506       if ((f = fopen(fn, "w+"))) {
00507          setlinebuf(f);
00508          fprintf(f, "CLIENTCHAN:    %s\n", chan->name);
00509          fprintf(f, "CLIENTTEST ID: %s\n", testid);
00510          fprintf(f, "CLIENTTESTNUM: %s\n", testnumber);
00511          fprintf(f, "ANSWER:        PASS\n");
00512 
00513          res = ast_safe_sleep(chan, 1000);  res = 0;
00514          /* and call the appropriate test */
00515          switch (*testnumber) {
00516             case '1':
00517                res = test1_client(res, chan, f);
00518                break;
00519             case '2':
00520                res = test2_client(res, chan, f);
00521                break;
00522          }
00523          
00524          if (option_debug)
00525             ast_log(LOG_DEBUG, "-- TEST COMPLETE--\n");
00526 
00527          fprintf(f, "-- END TEST--\n");
00528          fclose(f);
00529          res = -1;
00530       } else
00531          res = -1;
00532    } else {
00533       ast_log(LOG_NOTICE, "Did not read a test ID on '%s'\n", chan->name);
00534       res = -1;
00535    }
00536    ast_module_user_remove(u);
00537    return res;
00538 }

static int testserver_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 540 of file app_test.c.

References ast_channel::_state, ast_answer(), ast_app_getdata(), ast_config_AST_LOG_DIR, ast_dtmf_stream(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_safe_sleep(), AST_STATE_UP, ast_strlen_zero(), ast_module_user::chan, f, HIGHEST_TEST, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, option_debug, test1_server(), test2_server(), and TEST_VERSION_NUMBER.

Referenced by load_module().

00541 {
00542    struct ast_module_user *u;
00543    int res = 0;
00544    char testid[80]="";
00545    char clientversion[80]="";
00546    char *testnumber;
00547    char fn[80];
00548    FILE *f;
00549    u = ast_module_user_add(chan);
00550 
00551    if (chan->_state != AST_STATE_UP)
00552       res = ast_answer(chan);
00553 
00554    /* Read version */
00555    if (option_debug)
00556       ast_log(LOG_DEBUG, "Read client version\n");
00557    if (!res) 
00558       res = ast_app_getdata(chan, NULL, clientversion, sizeof(clientversion) - 1, 0);
00559    if (res > 0)
00560       res = 0;
00561    if (option_debug)
00562       ast_log(LOG_DEBUG, "client version: %s\n", clientversion);
00563 
00564    /* Check we know the version.  If we do, reply matching it, if we don't, send back * */
00565    testnumber = strchr(clientversion, '*');
00566    if (testnumber) {
00567       ++testnumber;
00568       if (strlen(testnumber) != 1 || (*testnumber < '1') || (*testnumber > HIGHEST_TEST)) {
00569          ast_log(LOG_WARNING, "TestServer: we don\'t know requested test \'%s\'\n", testnumber);
00570          testnumber = "*";
00571       }
00572       else {
00573          ast_log(LOG_WARNING, "TestServer: client requested test \'%s\'\n", testnumber);
00574       }
00575    }
00576    else {
00577       ast_log(LOG_WARNING, "TestServer couldn\'t find desired test number in \'%s\'\n", clientversion);
00578       testnumber = "*";
00579    }
00580 
00581 
00582    ast_log(LOG_DEBUG, "Transmit server version\n");
00583    res = ast_safe_sleep(chan, 1000);
00584    if (!res) {
00585       ast_log(LOG_DEBUG, "testserver replying with %s%s#\n", TEST_VERSION_NUMBER, testnumber);
00586       res = ast_dtmf_stream(chan, NULL, TEST_VERSION_NUMBER, 0);
00587       res = ast_dtmf_stream(chan, NULL, testnumber, 0);
00588       res = ast_dtmf_stream(chan, NULL, "#", 0);
00589    }
00590    if (res > 0)
00591       res = 0;
00592 
00593    /* stop if we don't know the test */
00594    if (*testnumber == '*') {
00595       ast_log(LOG_DEBUG, "TestServer: stopping cos I don't know the test they want\n");
00596       /* but make sure all is sent */
00597       res = ast_safe_sleep(chan, 1000);
00598       ast_module_user_remove(u);
00599       return -1;
00600    }
00601 
00602    if (!res) 
00603       res = ast_app_getdata(chan, NULL, testid, sizeof(testid) - 1, 0);    
00604    if (option_debug) 
00605       ast_log(LOG_DEBUG, "read test identifier: %s\n", testid);
00606    /* Check for sneakyness */
00607    if (strchr(testid, '/'))
00608       res = -1;
00609    if ((res >=0) && (!ast_strlen_zero(testid))) {
00610       /* Got a Test ID!  Whoo hoo! */
00611       /* Make the directory to hold the test results in case it's not there */
00612       snprintf(fn, sizeof(fn), "%s/testresults", ast_config_AST_LOG_DIR);
00613       mkdir(fn, 0777);
00614       snprintf(fn, sizeof(fn), "%s/testresults/%s-server.txt", ast_config_AST_LOG_DIR, testid);
00615       if ((f = fopen(fn, "w+"))) {
00616          setlinebuf(f);
00617          fprintf(f, "SERVERCHAN:    %s\n", chan->name);
00618          fprintf(f, "SERVERTEST ID: %s\n", testid);
00619          fprintf(f, "SERVERTESTNUM: %s\n", testnumber);
00620          fprintf(f, "ANSWER:        PASS\n");
00621          ast_log(LOG_DEBUG, "Processing Test ID '%s'\n", testid);
00622          res = ast_safe_sleep(chan, 1000);  res = 0;
00623          /* call the appropriate test */
00624          switch (*testnumber) {
00625             case '1':
00626                res = test1_server(res, chan, f);
00627                break;
00628             case '2':
00629                res = test2_server(res, chan, f);
00630                break;
00631          }
00632          ast_log(LOG_NOTICE, "-- TEST COMPLETE--\n");
00633          fprintf(f, "-- END TEST--\n");
00634          fclose(f);
00635          res = -1;
00636       } else
00637          res = -1;
00638    } else {
00639       ast_log(LOG_NOTICE, "Did not read a test ID on '%s'\n", chan->name);
00640       res = -1;
00641    }
00642    ast_module_user_remove(u);
00643    return res;
00644 }

static int unload_module ( void   )  [static]

Definition at line 646 of file app_test.c.

References ast_module_user_hangup_all, and ast_unregister_application().

00647 {
00648    int res;
00649 
00650    res = ast_unregister_application(testc_app);
00651    res |= ast_unregister_application(tests_app);
00652 
00653    ast_module_user_hangup_all();
00654 
00655    return res; 
00656 }


Variable Documentation

char* testc_app = "TestClient" [static]

Definition at line 69 of file app_test.c.

char* testc_descrip [static]

Definition at line 61 of file app_test.c.

char* testc_synopsis = "Execute Interface Test Client" [static]

Definition at line 70 of file app_test.c.

char* tests_app = "TestServer" [static]

Definition at line 58 of file app_test.c.

char* tests_descrip [static]

Initial value:

 
    "TestServer(): Perform test server function and write call report.\n"
    "Results stored in /var/log/asterisk/testreports/<testid>-server.txt"

Definition at line 55 of file app_test.c.

char* tests_synopsis = "Execute Interface Test Server" [static]

Definition at line 59 of file app_test.c.


Generated on Mon May 14 04:44:18 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1