#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.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.
Functions | |
char * | description (void) |
Provides a description of the module. | |
char * | key (void) |
Returns the ASTERISK_GPL_KEY. | |
int | load_module (void) |
Initialize the module. | |
static int | measurenoise (struct ast_channel *chan, int ms, char *who) |
static int | sendnoise (struct ast_channel *chan, int ms) |
static int | testclient_exec (struct ast_channel *chan, void *data) |
static int | testserver_exec (struct ast_channel *chan, void *data) |
int | unload_module (void) |
Cleanup all module structures, sockets, etc. | |
int | usecount (void) |
Provides a usecount. | |
Variables | |
LOCAL_USER_DECL | |
STANDARD_LOCAL_USER | |
static char * | tdesc = "Interface Test Application" |
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" |
Definition in file app_test.c.
|
Provides a description of the module.
Definition at line 514 of file app_test.c. References tdesc. 00515 { 00516 return tdesc; 00517 }
|
|
Returns the ASTERISK_GPL_KEY. This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:
char *key(void) { return ASTERISK_GPL_KEY; }
Definition at line 526 of file app_test.c. References ASTERISK_GPL_KEY. 00527 { 00528 return ASTERISK_GPL_KEY; 00529 }
|
|
Initialize the module. Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.
Definition at line 504 of file app_test.c. References ast_register_application(), testc_app, testc_descrip, testc_synopsis, testclient_exec(), tests_app, tests_descrip, tests_synopsis, and testserver_exec(). 00505 { 00506 int res; 00507 00508 res = ast_register_application(testc_app, testclient_exec, testc_synopsis, testc_descrip); 00509 res |= ast_register_application(tests_app, testserver_exec, tests_synopsis, tests_descrip); 00510 00511 return res; 00512 }
|
|
Definition at line 67 of file app_test.c. References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), ast_read(), ast_set_read_format(), ast_waitfor(), ast_frame::data, ast_frame::frametype, LOG_NOTICE, ast_channel::readformat, ast_frame::samples, and ast_frame::subclass. Referenced by testclient_exec(), and testserver_exec(). 00068 { 00069 int res=0; 00070 int mssofar; 00071 int noise=0; 00072 int samples=0; 00073 int x; 00074 short *foo; 00075 struct timeval start; 00076 struct ast_frame *f; 00077 int rformat; 00078 rformat = chan->readformat; 00079 if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) { 00080 ast_log(LOG_NOTICE, "Unable to set to linear mode!\n"); 00081 return -1; 00082 } 00083 start = ast_tvnow(); 00084 for(;;) { 00085 mssofar = ast_tvdiff_ms(ast_tvnow(), start); 00086 if (mssofar > ms) 00087 break; 00088 res = ast_waitfor(chan, ms - mssofar); 00089 if (res < 1) 00090 break; 00091 f = ast_read(chan); 00092 if (!f) { 00093 res = -1; 00094 break; 00095 } 00096 if ((f->frametype == AST_FRAME_VOICE) && (f->subclass == AST_FORMAT_SLINEAR)) { 00097 foo = (short *)f->data; 00098 for (x=0;x<f->samples;x++) { 00099 noise += abs(foo[x]); 00100 samples++; 00101 } 00102 } 00103 } 00104 00105 if (rformat) { 00106 if (ast_set_read_format(chan, rformat)) { 00107 ast_log(LOG_NOTICE, "Unable to restore original format!\n"); 00108 return -1; 00109 } 00110 } 00111 if (res < 0) 00112 return res; 00113 if (!samples) { 00114 ast_log(LOG_NOTICE, "No samples were received from the other side!\n"); 00115 return -1; 00116 } 00117 ast_log(LOG_DEBUG, "%s: Noise: %d, samples: %d, avg: %d\n", who, noise, samples, noise / samples); 00118 return (noise / samples); 00119 }
|
|
Definition at line 121 of file app_test.c. References ast_tonepair_start(), ast_tonepair_stop(), and ast_waitfordigit(). Referenced by testclient_exec(), and testserver_exec(). 00122 { 00123 int res; 00124 res = ast_tonepair_start(chan, 1537, 2195, ms, 8192); 00125 if (!res) { 00126 res = ast_waitfordigit(chan, ms); 00127 ast_tonepair_stop(chan); 00128 } 00129 return res; 00130 }
|
|
Definition at line 132 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_safe_sleep(), AST_STATE_UP, ast_strlen_zero(), ast_waitfordigit(), localuser::chan, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, measurenoise(), ast_channel::name, option_debug, and sendnoise(). Referenced by load_module(). 00133 { 00134 struct localuser *u; 00135 int res = 0; 00136 char *testid=data; 00137 char fn[80]; 00138 char serverver[80]; 00139 FILE *f; 00140 00141 /* Check for test id */ 00142 if (ast_strlen_zero(testid)) { 00143 ast_log(LOG_WARNING, "TestClient requires an argument - the test id\n"); 00144 return -1; 00145 } 00146 00147 LOCAL_USER_ADD(u); 00148 00149 if (chan->_state != AST_STATE_UP) 00150 res = ast_answer(chan); 00151 00152 /* Wait a few just to be sure things get started */ 00153 res = ast_safe_sleep(chan, 3000); 00154 /* Transmit client version */ 00155 if (!res) 00156 res = ast_dtmf_stream(chan, NULL, "8378*1#", 0); 00157 if (option_debug) 00158 ast_log(LOG_DEBUG, "Transmit client version\n"); 00159 00160 /* Read server version */ 00161 if (option_debug) 00162 ast_log(LOG_DEBUG, "Read server version\n"); 00163 if (!res) 00164 res = ast_app_getdata(chan, NULL, serverver, sizeof(serverver) - 1, 0); 00165 if (res > 0) 00166 res = 0; 00167 if (option_debug) 00168 ast_log(LOG_DEBUG, "server version: %s\n", serverver); 00169 00170 if (res > 0) 00171 res = 0; 00172 00173 if (!res) 00174 res = ast_safe_sleep(chan, 1000); 00175 /* Send test id */ 00176 if (!res) 00177 res = ast_dtmf_stream(chan, NULL, testid, 0); 00178 if (!res) 00179 res = ast_dtmf_stream(chan, NULL, "#", 0); 00180 if (option_debug) 00181 ast_log(LOG_DEBUG, "send test identifier: %s\n", testid); 00182 00183 if ((res >=0) && (!ast_strlen_zero(testid))) { 00184 /* Make the directory to hold the test results in case it's not there */ 00185 snprintf(fn, sizeof(fn), "%s/testresults", ast_config_AST_LOG_DIR); 00186 mkdir(fn, 0777); 00187 snprintf(fn, sizeof(fn), "%s/testresults/%s-client.txt", ast_config_AST_LOG_DIR, testid); 00188 if ((f = fopen(fn, "w+"))) { 00189 setlinebuf(f); 00190 fprintf(f, "CLIENTCHAN: %s\n", chan->name); 00191 fprintf(f, "CLIENTTEST ID: %s\n", testid); 00192 fprintf(f, "ANSWER: PASS\n"); 00193 res = 0; 00194 00195 if (!res) { 00196 /* Step 1: Wait for "1" */ 00197 if (option_debug) 00198 ast_log(LOG_DEBUG, "TestClient: 2. Wait DTMF 1\n"); 00199 res = ast_waitfordigit(chan, 3000); 00200 fprintf(f, "WAIT DTMF 1: %s\n", (res != '1') ? "FAIL" : "PASS"); 00201 if (res == '1') 00202 res = 0; 00203 else 00204 res = -1; 00205 } 00206 if (!res) 00207 res = ast_safe_sleep(chan, 1000); 00208 if (!res) { 00209 /* Step 2: Send "2" */ 00210 if (option_debug) 00211 ast_log(LOG_DEBUG, "TestClient: 2. Send DTMF 2\n"); 00212 res = ast_dtmf_stream(chan, NULL, "2", 0); 00213 fprintf(f, "SEND DTMF 2: %s\n", (res < 0) ? "FAIL" : "PASS"); 00214 if (res > 0) 00215 res = 0; 00216 } 00217 if (!res) { 00218 /* Step 3: Wait one second */ 00219 if (option_debug) 00220 ast_log(LOG_DEBUG, "TestClient: 3. Wait one second\n"); 00221 res = ast_safe_sleep(chan, 1000); 00222 fprintf(f, "WAIT 1 SEC: %s\n", (res < 0) ? "FAIL" : "PASS"); 00223 if (res > 0) 00224 res = 0; 00225 } 00226 if (!res) { 00227 /* Step 4: Measure noise */ 00228 if (option_debug) 00229 ast_log(LOG_DEBUG, "TestClient: 4. Measure noise\n"); 00230 res = measurenoise(chan, 5000, "TestClient"); 00231 fprintf(f, "MEASURENOISE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res); 00232 if (res > 0) 00233 res = 0; 00234 } 00235 if (!res) { 00236 /* Step 5: Wait for "4" */ 00237 if (option_debug) 00238 ast_log(LOG_DEBUG, "TestClient: 5. Wait DTMF 4\n"); 00239 res = ast_waitfordigit(chan, 3000); 00240 fprintf(f, "WAIT DTMF 4: %s\n", (res != '4') ? "FAIL" : "PASS"); 00241 if (res == '4') 00242 res = 0; 00243 else 00244 res = -1; 00245 } 00246 if (!res) { 00247 /* Step 6: Transmit tone noise */ 00248 if (option_debug) 00249 ast_log(LOG_DEBUG, "TestClient: 6. Transmit tone\n"); 00250 res = sendnoise(chan, 6000); 00251 fprintf(f, "SENDTONE: %s\n", (res < 0) ? "FAIL" : "PASS"); 00252 } 00253 if (!res || (res == '5')) { 00254 /* Step 7: Wait for "5" */ 00255 if (option_debug) 00256 ast_log(LOG_DEBUG, "TestClient: 7. Wait DTMF 5\n"); 00257 if (!res) 00258 res = ast_waitfordigit(chan, 3000); 00259 fprintf(f, "WAIT DTMF 5: %s\n", (res != '5') ? "FAIL" : "PASS"); 00260 if (res == '5') 00261 res = 0; 00262 else 00263 res = -1; 00264 } 00265 if (!res) { 00266 /* Step 8: Wait one second */ 00267 if (option_debug) 00268 ast_log(LOG_DEBUG, "TestClient: 8. Wait one second\n"); 00269 res = ast_safe_sleep(chan, 1000); 00270 fprintf(f, "WAIT 1 SEC: %s\n", (res < 0) ? "FAIL" : "PASS"); 00271 if (res > 0) 00272 res = 0; 00273 } 00274 if (!res) { 00275 /* Step 9: Measure noise */ 00276 if (option_debug) 00277 ast_log(LOG_DEBUG, "TestClient: 6. Measure tone\n"); 00278 res = measurenoise(chan, 4000, "TestClient"); 00279 fprintf(f, "MEASURETONE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res); 00280 if (res > 0) 00281 res = 0; 00282 } 00283 if (!res) { 00284 /* Step 10: Send "7" */ 00285 if (option_debug) 00286 ast_log(LOG_DEBUG, "TestClient: 7. Send DTMF 7\n"); 00287 res = ast_dtmf_stream(chan, NULL, "7", 0); 00288 fprintf(f, "SEND DTMF 7: %s\n", (res < 0) ? "FAIL" : "PASS"); 00289 if (res > 0) 00290 res =0; 00291 } 00292 if (!res) { 00293 /* Step 11: Wait for "8" */ 00294 if (option_debug) 00295 ast_log(LOG_DEBUG, "TestClient: 11. Wait DTMF 8\n"); 00296 res = ast_waitfordigit(chan, 3000); 00297 fprintf(f, "WAIT DTMF 8: %s\n", (res != '8') ? "FAIL" : "PASS"); 00298 if (res == '8') 00299 res = 0; 00300 else 00301 res = -1; 00302 } 00303 if (option_debug && !res ) { 00304 /* Step 12: Hangup! */ 00305 ast_log(LOG_DEBUG, "TestClient: 12. Hangup\n"); 00306 } 00307 00308 if (option_debug) 00309 ast_log(LOG_DEBUG, "-- TEST COMPLETE--\n"); 00310 fprintf(f, "-- END TEST--\n"); 00311 fclose(f); 00312 res = -1; 00313 } else 00314 res = -1; 00315 } else { 00316 ast_log(LOG_NOTICE, "Did not read a test ID on '%s'\n", chan->name); 00317 res = -1; 00318 } 00319 LOCAL_USER_REMOVE(u); 00320 return res; 00321 }
|
|
Definition at line 323 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_safe_sleep(), AST_STATE_UP, ast_strlen_zero(), ast_waitfordigit(), localuser::chan, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_DEBUG, LOG_NOTICE, measurenoise(), ast_channel::name, option_debug, and sendnoise(). Referenced by load_module(). 00324 { 00325 struct localuser *u; 00326 int res = 0; 00327 char testid[80]=""; 00328 char fn[80]; 00329 FILE *f; 00330 LOCAL_USER_ADD(u); 00331 if (chan->_state != AST_STATE_UP) 00332 res = ast_answer(chan); 00333 /* Read version */ 00334 if (option_debug) 00335 ast_log(LOG_DEBUG, "Read client version\n"); 00336 if (!res) 00337 res = ast_app_getdata(chan, NULL, testid, sizeof(testid) - 1, 0); 00338 if (res > 0) 00339 res = 0; 00340 if (option_debug) { 00341 ast_log(LOG_DEBUG, "client version: %s\n", testid); 00342 ast_log(LOG_DEBUG, "Transmit server version\n"); 00343 } 00344 res = ast_safe_sleep(chan, 1000); 00345 if (!res) 00346 res = ast_dtmf_stream(chan, NULL, "8378*1#", 0); 00347 if (res > 0) 00348 res = 0; 00349 00350 if (!res) 00351 res = ast_app_getdata(chan, NULL, testid, sizeof(testid) - 1, 0); 00352 if (option_debug) 00353 ast_log(LOG_DEBUG, "read test identifier: %s\n", testid); 00354 /* Check for sneakyness */ 00355 if (strchr(testid, '/')) 00356 res = -1; 00357 if ((res >=0) && (!ast_strlen_zero(testid))) { 00358 /* Got a Test ID! Whoo hoo! */ 00359 /* Make the directory to hold the test results in case it's not there */ 00360 snprintf(fn, sizeof(fn), "%s/testresults", ast_config_AST_LOG_DIR); 00361 mkdir(fn, 0777); 00362 snprintf(fn, sizeof(fn), "%s/testresults/%s-server.txt", ast_config_AST_LOG_DIR, testid); 00363 if ((f = fopen(fn, "w+"))) { 00364 setlinebuf(f); 00365 fprintf(f, "SERVERCHAN: %s\n", chan->name); 00366 fprintf(f, "SERVERTEST ID: %s\n", testid); 00367 fprintf(f, "ANSWER: PASS\n"); 00368 ast_log(LOG_DEBUG, "Processing Test ID '%s'\n", testid); 00369 res = ast_safe_sleep(chan, 1000); 00370 if (!res) { 00371 /* Step 1: Send "1" */ 00372 if (option_debug) 00373 ast_log(LOG_DEBUG, "TestServer: 1. Send DTMF 1\n"); 00374 res = ast_dtmf_stream(chan, NULL, "1", 0); 00375 fprintf(f, "SEND DTMF 1: %s\n", (res < 0) ? "FAIL" : "PASS"); 00376 if (res > 0) 00377 res = 0; 00378 } 00379 if (!res) { 00380 /* Step 2: Wait for "2" */ 00381 if (option_debug) 00382 ast_log(LOG_DEBUG, "TestServer: 2. Wait DTMF 2\n"); 00383 res = ast_waitfordigit(chan, 3000); 00384 fprintf(f, "WAIT DTMF 2: %s\n", (res != '2') ? "FAIL" : "PASS"); 00385 if (res == '2') 00386 res = 0; 00387 else 00388 res = -1; 00389 } 00390 if (!res) { 00391 /* Step 3: Measure noise */ 00392 if (option_debug) 00393 ast_log(LOG_DEBUG, "TestServer: 3. Measure noise\n"); 00394 res = measurenoise(chan, 6000, "TestServer"); 00395 fprintf(f, "MEASURENOISE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res); 00396 if (res > 0) 00397 res = 0; 00398 } 00399 if (!res) { 00400 /* Step 4: Send "4" */ 00401 if (option_debug) 00402 ast_log(LOG_DEBUG, "TestServer: 4. Send DTMF 4\n"); 00403 res = ast_dtmf_stream(chan, NULL, "4", 0); 00404 fprintf(f, "SEND DTMF 4: %s\n", (res < 0) ? "FAIL" : "PASS"); 00405 if (res > 0) 00406 res = 0; 00407 } 00408 00409 if (!res) { 00410 /* Step 5: Wait one second */ 00411 if (option_debug) 00412 ast_log(LOG_DEBUG, "TestServer: 5. Wait one second\n"); 00413 res = ast_safe_sleep(chan, 1000); 00414 fprintf(f, "WAIT 1 SEC: %s\n", (res < 0) ? "FAIL" : "PASS"); 00415 if (res > 0) 00416 res = 0; 00417 } 00418 00419 if (!res) { 00420 /* Step 6: Measure noise */ 00421 if (option_debug) 00422 ast_log(LOG_DEBUG, "TestServer: 6. Measure tone\n"); 00423 res = measurenoise(chan, 4000, "TestServer"); 00424 fprintf(f, "MEASURETONE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res); 00425 if (res > 0) 00426 res = 0; 00427 } 00428 00429 if (!res) { 00430 /* Step 7: Send "5" */ 00431 if (option_debug) 00432 ast_log(LOG_DEBUG, "TestServer: 7. Send DTMF 5\n"); 00433 res = ast_dtmf_stream(chan, NULL, "5", 0); 00434 fprintf(f, "SEND DTMF 5: %s\n", (res < 0) ? "FAIL" : "PASS"); 00435 if (res > 0) 00436 res = 0; 00437 } 00438 00439 if (!res) { 00440 /* Step 8: Transmit tone noise */ 00441 if (option_debug) 00442 ast_log(LOG_DEBUG, "TestServer: 8. Transmit tone\n"); 00443 res = sendnoise(chan, 6000); 00444 fprintf(f, "SENDTONE: %s\n", (res < 0) ? "FAIL" : "PASS"); 00445 } 00446 00447 if (!res || (res == '7')) { 00448 /* Step 9: Wait for "7" */ 00449 if (option_debug) 00450 ast_log(LOG_DEBUG, "TestServer: 9. Wait DTMF 7\n"); 00451 if (!res) 00452 res = ast_waitfordigit(chan, 3000); 00453 fprintf(f, "WAIT DTMF 7: %s\n", (res != '7') ? "FAIL" : "PASS"); 00454 if (res == '7') 00455 res = 0; 00456 else 00457 res = -1; 00458 } 00459 if (!res) 00460 res = ast_safe_sleep(chan, 1000); 00461 if (!res) { 00462 /* Step 10: Send "8" */ 00463 if (option_debug) 00464 ast_log(LOG_DEBUG, "TestServer: 10. Send DTMF 8\n"); 00465 res = ast_dtmf_stream(chan, NULL, "8", 0); 00466 fprintf(f, "SEND DTMF 8: %s\n", (res < 0) ? "FAIL" : "PASS"); 00467 if (res > 0) 00468 res = 0; 00469 } 00470 if (!res) { 00471 /* Step 11: Wait for hangup to arrive! */ 00472 if (option_debug) 00473 ast_log(LOG_DEBUG, "TestServer: 11. Waiting for hangup\n"); 00474 res = ast_safe_sleep(chan, 10000); 00475 fprintf(f, "WAIT HANGUP: %s\n", (res < 0) ? "PASS" : "FAIL"); 00476 } 00477 00478 ast_log(LOG_NOTICE, "-- TEST COMPLETE--\n"); 00479 fprintf(f, "-- END TEST--\n"); 00480 fclose(f); 00481 res = -1; 00482 } else 00483 res = -1; 00484 } else { 00485 ast_log(LOG_NOTICE, "Did not read a test ID on '%s'\n", chan->name); 00486 res = -1; 00487 } 00488 LOCAL_USER_REMOVE(u); 00489 return res; 00490 }
|
|
Cleanup all module structures, sockets, etc. This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).
Definition at line 492 of file app_test.c. References ast_unregister_application(), STANDARD_HANGUP_LOCALUSERS, testc_app, and tests_app. 00493 { 00494 int res; 00495 00496 res = ast_unregister_application(testc_app); 00497 res |= ast_unregister_application(tests_app); 00498 00499 STANDARD_HANGUP_LOCALUSERS; 00500 00501 return res; 00502 }
|
|
Provides a usecount. This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.
Definition at line 519 of file app_test.c. References STANDARD_USECOUNT. 00520 { 00521 int res; 00522 STANDARD_USECOUNT(res); 00523 return res; 00524 }
|
|
Definition at line 50 of file app_test.c. |
|
Definition at line 48 of file app_test.c. |
|
Definition at line 52 of file app_test.c. |
|
Definition at line 64 of file app_test.c. Referenced by load_module(), and unload_module(). |
|
Initial value: "TestClient(testid): Executes test client with given testid.\n" "Results stored in /var/log/asterisk/testreports/<testid>-client.txt" Definition at line 60 of file app_test.c. Referenced by load_module(). |
|
Definition at line 65 of file app_test.c. Referenced by load_module(). |
|
Definition at line 57 of file app_test.c. Referenced by load_module(), and unload_module(). |
|
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 54 of file app_test.c. Referenced by load_module(). |
|
Definition at line 58 of file app_test.c. Referenced by load_module(). |