#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 515 of file app_test.c. References tdesc. 00516 { 00517 return tdesc; 00518 }
|
|
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 527 of file app_test.c. References ASTERISK_GPL_KEY. 00528 { 00529 return ASTERISK_GPL_KEY; 00530 }
|
|
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 505 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(). 00506 { 00507 int res; 00508 00509 res = ast_register_application(testc_app, testclient_exec, testc_synopsis, testc_descrip); 00510 res |= ast_register_application(tests_app, testserver_exec, tests_synopsis, tests_descrip); 00511 00512 return res; 00513 }
|
|
Definition at line 67 of file app_test.c. References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_frfree(), ast_log(), ast_read(), ast_set_read_format(), ast_waitfor(), ast_frame::data, ast_frame::frametype, LOG_DEBUG, LOG_NOTICE, ast_channel::readformat, 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 ast_frfree(f); 00104 } 00105 00106 if (rformat) { 00107 if (ast_set_read_format(chan, rformat)) { 00108 ast_log(LOG_NOTICE, "Unable to restore original format!\n"); 00109 return -1; 00110 } 00111 } 00112 if (res < 0) 00113 return res; 00114 if (!samples) { 00115 ast_log(LOG_NOTICE, "No samples were received from the other side!\n"); 00116 return -1; 00117 } 00118 ast_log(LOG_DEBUG, "%s: Noise: %d, samples: %d, avg: %d\n", who, noise, samples, noise / samples); 00119 return (noise / samples); 00120 }
|
|
Definition at line 122 of file app_test.c. References ast_tonepair_start(), ast_tonepair_stop(), and ast_waitfordigit(). Referenced by testclient_exec(), and testserver_exec(). 00123 { 00124 int res; 00125 res = ast_tonepair_start(chan, 1537, 2195, ms, 8192); 00126 if (!res) { 00127 res = ast_waitfordigit(chan, ms); 00128 ast_tonepair_stop(chan); 00129 } 00130 return res; 00131 }
|
|
Definition at line 133 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(), LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, measurenoise(), option_debug, and sendnoise(). Referenced by load_module(). 00134 { 00135 struct localuser *u; 00136 int res = 0; 00137 char *testid=data; 00138 char fn[80]; 00139 char serverver[80]; 00140 FILE *f; 00141 00142 /* Check for test id */ 00143 if (ast_strlen_zero(testid)) { 00144 ast_log(LOG_WARNING, "TestClient requires an argument - the test id\n"); 00145 return -1; 00146 } 00147 00148 LOCAL_USER_ADD(u); 00149 00150 if (chan->_state != AST_STATE_UP) 00151 res = ast_answer(chan); 00152 00153 /* Wait a few just to be sure things get started */ 00154 res = ast_safe_sleep(chan, 3000); 00155 /* Transmit client version */ 00156 if (!res) 00157 res = ast_dtmf_stream(chan, NULL, "8378*1#", 0); 00158 if (option_debug) 00159 ast_log(LOG_DEBUG, "Transmit client version\n"); 00160 00161 /* Read server version */ 00162 if (option_debug) 00163 ast_log(LOG_DEBUG, "Read server version\n"); 00164 if (!res) 00165 res = ast_app_getdata(chan, NULL, serverver, sizeof(serverver) - 1, 0); 00166 if (res > 0) 00167 res = 0; 00168 if (option_debug) 00169 ast_log(LOG_DEBUG, "server version: %s\n", serverver); 00170 00171 if (res > 0) 00172 res = 0; 00173 00174 if (!res) 00175 res = ast_safe_sleep(chan, 1000); 00176 /* Send test id */ 00177 if (!res) 00178 res = ast_dtmf_stream(chan, NULL, testid, 0); 00179 if (!res) 00180 res = ast_dtmf_stream(chan, NULL, "#", 0); 00181 if (option_debug) 00182 ast_log(LOG_DEBUG, "send test identifier: %s\n", testid); 00183 00184 if ((res >=0) && (!ast_strlen_zero(testid))) { 00185 /* Make the directory to hold the test results in case it's not there */ 00186 snprintf(fn, sizeof(fn), "%s/testresults", ast_config_AST_LOG_DIR); 00187 mkdir(fn, 0777); 00188 snprintf(fn, sizeof(fn), "%s/testresults/%s-client.txt", ast_config_AST_LOG_DIR, testid); 00189 if ((f = fopen(fn, "w+"))) { 00190 setlinebuf(f); 00191 fprintf(f, "CLIENTCHAN: %s\n", chan->name); 00192 fprintf(f, "CLIENTTEST ID: %s\n", testid); 00193 fprintf(f, "ANSWER: PASS\n"); 00194 res = 0; 00195 00196 if (!res) { 00197 /* Step 1: Wait for "1" */ 00198 if (option_debug) 00199 ast_log(LOG_DEBUG, "TestClient: 2. Wait DTMF 1\n"); 00200 res = ast_waitfordigit(chan, 3000); 00201 fprintf(f, "WAIT DTMF 1: %s\n", (res != '1') ? "FAIL" : "PASS"); 00202 if (res == '1') 00203 res = 0; 00204 else 00205 res = -1; 00206 } 00207 if (!res) 00208 res = ast_safe_sleep(chan, 1000); 00209 if (!res) { 00210 /* Step 2: Send "2" */ 00211 if (option_debug) 00212 ast_log(LOG_DEBUG, "TestClient: 2. Send DTMF 2\n"); 00213 res = ast_dtmf_stream(chan, NULL, "2", 0); 00214 fprintf(f, "SEND DTMF 2: %s\n", (res < 0) ? "FAIL" : "PASS"); 00215 if (res > 0) 00216 res = 0; 00217 } 00218 if (!res) { 00219 /* Step 3: Wait one second */ 00220 if (option_debug) 00221 ast_log(LOG_DEBUG, "TestClient: 3. Wait one second\n"); 00222 res = ast_safe_sleep(chan, 1000); 00223 fprintf(f, "WAIT 1 SEC: %s\n", (res < 0) ? "FAIL" : "PASS"); 00224 if (res > 0) 00225 res = 0; 00226 } 00227 if (!res) { 00228 /* Step 4: Measure noise */ 00229 if (option_debug) 00230 ast_log(LOG_DEBUG, "TestClient: 4. Measure noise\n"); 00231 res = measurenoise(chan, 5000, "TestClient"); 00232 fprintf(f, "MEASURENOISE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res); 00233 if (res > 0) 00234 res = 0; 00235 } 00236 if (!res) { 00237 /* Step 5: Wait for "4" */ 00238 if (option_debug) 00239 ast_log(LOG_DEBUG, "TestClient: 5. Wait DTMF 4\n"); 00240 res = ast_waitfordigit(chan, 3000); 00241 fprintf(f, "WAIT DTMF 4: %s\n", (res != '4') ? "FAIL" : "PASS"); 00242 if (res == '4') 00243 res = 0; 00244 else 00245 res = -1; 00246 } 00247 if (!res) { 00248 /* Step 6: Transmit tone noise */ 00249 if (option_debug) 00250 ast_log(LOG_DEBUG, "TestClient: 6. Transmit tone\n"); 00251 res = sendnoise(chan, 6000); 00252 fprintf(f, "SENDTONE: %s\n", (res < 0) ? "FAIL" : "PASS"); 00253 } 00254 if (!res || (res == '5')) { 00255 /* Step 7: Wait for "5" */ 00256 if (option_debug) 00257 ast_log(LOG_DEBUG, "TestClient: 7. Wait DTMF 5\n"); 00258 if (!res) 00259 res = ast_waitfordigit(chan, 3000); 00260 fprintf(f, "WAIT DTMF 5: %s\n", (res != '5') ? "FAIL" : "PASS"); 00261 if (res == '5') 00262 res = 0; 00263 else 00264 res = -1; 00265 } 00266 if (!res) { 00267 /* Step 8: Wait one second */ 00268 if (option_debug) 00269 ast_log(LOG_DEBUG, "TestClient: 8. Wait one second\n"); 00270 res = ast_safe_sleep(chan, 1000); 00271 fprintf(f, "WAIT 1 SEC: %s\n", (res < 0) ? "FAIL" : "PASS"); 00272 if (res > 0) 00273 res = 0; 00274 } 00275 if (!res) { 00276 /* Step 9: Measure noise */ 00277 if (option_debug) 00278 ast_log(LOG_DEBUG, "TestClient: 6. Measure tone\n"); 00279 res = measurenoise(chan, 4000, "TestClient"); 00280 fprintf(f, "MEASURETONE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res); 00281 if (res > 0) 00282 res = 0; 00283 } 00284 if (!res) { 00285 /* Step 10: Send "7" */ 00286 if (option_debug) 00287 ast_log(LOG_DEBUG, "TestClient: 7. Send DTMF 7\n"); 00288 res = ast_dtmf_stream(chan, NULL, "7", 0); 00289 fprintf(f, "SEND DTMF 7: %s\n", (res < 0) ? "FAIL" : "PASS"); 00290 if (res > 0) 00291 res =0; 00292 } 00293 if (!res) { 00294 /* Step 11: Wait for "8" */ 00295 if (option_debug) 00296 ast_log(LOG_DEBUG, "TestClient: 11. Wait DTMF 8\n"); 00297 res = ast_waitfordigit(chan, 3000); 00298 fprintf(f, "WAIT DTMF 8: %s\n", (res != '8') ? "FAIL" : "PASS"); 00299 if (res == '8') 00300 res = 0; 00301 else 00302 res = -1; 00303 } 00304 if (option_debug && !res ) { 00305 /* Step 12: Hangup! */ 00306 ast_log(LOG_DEBUG, "TestClient: 12. Hangup\n"); 00307 } 00308 00309 if (option_debug) 00310 ast_log(LOG_DEBUG, "-- TEST COMPLETE--\n"); 00311 fprintf(f, "-- END TEST--\n"); 00312 fclose(f); 00313 res = -1; 00314 } else 00315 res = -1; 00316 } else { 00317 ast_log(LOG_NOTICE, "Did not read a test ID on '%s'\n", chan->name); 00318 res = -1; 00319 } 00320 LOCAL_USER_REMOVE(u); 00321 return res; 00322 }
|
|
Definition at line 324 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(), LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_DEBUG, LOG_NOTICE, measurenoise(), option_debug, and sendnoise(). Referenced by load_module(). 00325 { 00326 struct localuser *u; 00327 int res = 0; 00328 char testid[80]=""; 00329 char fn[80]; 00330 FILE *f; 00331 LOCAL_USER_ADD(u); 00332 if (chan->_state != AST_STATE_UP) 00333 res = ast_answer(chan); 00334 /* Read version */ 00335 if (option_debug) 00336 ast_log(LOG_DEBUG, "Read client version\n"); 00337 if (!res) 00338 res = ast_app_getdata(chan, NULL, testid, sizeof(testid) - 1, 0); 00339 if (res > 0) 00340 res = 0; 00341 if (option_debug) { 00342 ast_log(LOG_DEBUG, "client version: %s\n", testid); 00343 ast_log(LOG_DEBUG, "Transmit server version\n"); 00344 } 00345 res = ast_safe_sleep(chan, 1000); 00346 if (!res) 00347 res = ast_dtmf_stream(chan, NULL, "8378*1#", 0); 00348 if (res > 0) 00349 res = 0; 00350 00351 if (!res) 00352 res = ast_app_getdata(chan, NULL, testid, sizeof(testid) - 1, 0); 00353 if (option_debug) 00354 ast_log(LOG_DEBUG, "read test identifier: %s\n", testid); 00355 /* Check for sneakyness */ 00356 if (strchr(testid, '/')) 00357 res = -1; 00358 if ((res >=0) && (!ast_strlen_zero(testid))) { 00359 /* Got a Test ID! Whoo hoo! */ 00360 /* Make the directory to hold the test results in case it's not there */ 00361 snprintf(fn, sizeof(fn), "%s/testresults", ast_config_AST_LOG_DIR); 00362 mkdir(fn, 0777); 00363 snprintf(fn, sizeof(fn), "%s/testresults/%s-server.txt", ast_config_AST_LOG_DIR, testid); 00364 if ((f = fopen(fn, "w+"))) { 00365 setlinebuf(f); 00366 fprintf(f, "SERVERCHAN: %s\n", chan->name); 00367 fprintf(f, "SERVERTEST ID: %s\n", testid); 00368 fprintf(f, "ANSWER: PASS\n"); 00369 ast_log(LOG_DEBUG, "Processing Test ID '%s'\n", testid); 00370 res = ast_safe_sleep(chan, 1000); 00371 if (!res) { 00372 /* Step 1: Send "1" */ 00373 if (option_debug) 00374 ast_log(LOG_DEBUG, "TestServer: 1. Send DTMF 1\n"); 00375 res = ast_dtmf_stream(chan, NULL, "1", 0); 00376 fprintf(f, "SEND DTMF 1: %s\n", (res < 0) ? "FAIL" : "PASS"); 00377 if (res > 0) 00378 res = 0; 00379 } 00380 if (!res) { 00381 /* Step 2: Wait for "2" */ 00382 if (option_debug) 00383 ast_log(LOG_DEBUG, "TestServer: 2. Wait DTMF 2\n"); 00384 res = ast_waitfordigit(chan, 3000); 00385 fprintf(f, "WAIT DTMF 2: %s\n", (res != '2') ? "FAIL" : "PASS"); 00386 if (res == '2') 00387 res = 0; 00388 else 00389 res = -1; 00390 } 00391 if (!res) { 00392 /* Step 3: Measure noise */ 00393 if (option_debug) 00394 ast_log(LOG_DEBUG, "TestServer: 3. Measure noise\n"); 00395 res = measurenoise(chan, 6000, "TestServer"); 00396 fprintf(f, "MEASURENOISE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res); 00397 if (res > 0) 00398 res = 0; 00399 } 00400 if (!res) { 00401 /* Step 4: Send "4" */ 00402 if (option_debug) 00403 ast_log(LOG_DEBUG, "TestServer: 4. Send DTMF 4\n"); 00404 res = ast_dtmf_stream(chan, NULL, "4", 0); 00405 fprintf(f, "SEND DTMF 4: %s\n", (res < 0) ? "FAIL" : "PASS"); 00406 if (res > 0) 00407 res = 0; 00408 } 00409 00410 if (!res) { 00411 /* Step 5: Wait one second */ 00412 if (option_debug) 00413 ast_log(LOG_DEBUG, "TestServer: 5. Wait one second\n"); 00414 res = ast_safe_sleep(chan, 1000); 00415 fprintf(f, "WAIT 1 SEC: %s\n", (res < 0) ? "FAIL" : "PASS"); 00416 if (res > 0) 00417 res = 0; 00418 } 00419 00420 if (!res) { 00421 /* Step 6: Measure noise */ 00422 if (option_debug) 00423 ast_log(LOG_DEBUG, "TestServer: 6. Measure tone\n"); 00424 res = measurenoise(chan, 4000, "TestServer"); 00425 fprintf(f, "MEASURETONE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res); 00426 if (res > 0) 00427 res = 0; 00428 } 00429 00430 if (!res) { 00431 /* Step 7: Send "5" */ 00432 if (option_debug) 00433 ast_log(LOG_DEBUG, "TestServer: 7. Send DTMF 5\n"); 00434 res = ast_dtmf_stream(chan, NULL, "5", 0); 00435 fprintf(f, "SEND DTMF 5: %s\n", (res < 0) ? "FAIL" : "PASS"); 00436 if (res > 0) 00437 res = 0; 00438 } 00439 00440 if (!res) { 00441 /* Step 8: Transmit tone noise */ 00442 if (option_debug) 00443 ast_log(LOG_DEBUG, "TestServer: 8. Transmit tone\n"); 00444 res = sendnoise(chan, 6000); 00445 fprintf(f, "SENDTONE: %s\n", (res < 0) ? "FAIL" : "PASS"); 00446 } 00447 00448 if (!res || (res == '7')) { 00449 /* Step 9: Wait for "7" */ 00450 if (option_debug) 00451 ast_log(LOG_DEBUG, "TestServer: 9. Wait DTMF 7\n"); 00452 if (!res) 00453 res = ast_waitfordigit(chan, 3000); 00454 fprintf(f, "WAIT DTMF 7: %s\n", (res != '7') ? "FAIL" : "PASS"); 00455 if (res == '7') 00456 res = 0; 00457 else 00458 res = -1; 00459 } 00460 if (!res) 00461 res = ast_safe_sleep(chan, 1000); 00462 if (!res) { 00463 /* Step 10: Send "8" */ 00464 if (option_debug) 00465 ast_log(LOG_DEBUG, "TestServer: 10. Send DTMF 8\n"); 00466 res = ast_dtmf_stream(chan, NULL, "8", 0); 00467 fprintf(f, "SEND DTMF 8: %s\n", (res < 0) ? "FAIL" : "PASS"); 00468 if (res > 0) 00469 res = 0; 00470 } 00471 if (!res) { 00472 /* Step 11: Wait for hangup to arrive! */ 00473 if (option_debug) 00474 ast_log(LOG_DEBUG, "TestServer: 11. Waiting for hangup\n"); 00475 res = ast_safe_sleep(chan, 10000); 00476 fprintf(f, "WAIT HANGUP: %s\n", (res < 0) ? "PASS" : "FAIL"); 00477 } 00478 00479 ast_log(LOG_NOTICE, "-- TEST COMPLETE--\n"); 00480 fprintf(f, "-- END TEST--\n"); 00481 fclose(f); 00482 res = -1; 00483 } else 00484 res = -1; 00485 } else { 00486 ast_log(LOG_NOTICE, "Did not read a test ID on '%s'\n", chan->name); 00487 res = -1; 00488 } 00489 LOCAL_USER_REMOVE(u); 00490 return res; 00491 }
|
|
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 493 of file app_test.c. References ast_unregister_application(), STANDARD_HANGUP_LOCALUSERS, testc_app, and tests_app. 00494 { 00495 int res; 00496 00497 res = ast_unregister_application(testc_app); 00498 res |= ast_unregister_application(tests_app); 00499 00500 STANDARD_HANGUP_LOCALUSERS; 00501 00502 return res; 00503 }
|
|
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 520 of file app_test.c. References STANDARD_USECOUNT. 00521 { 00522 int res; 00523 STANDARD_USECOUNT(res); 00524 return res; 00525 }
|
|
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(). |