#include "asterisk.h"
#include <sys/stat.h>
#include "asterisk/paths.h"
#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
Go to the source code of this file.
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
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 | testclient_exec (struct ast_channel *chan, const char *data) |
static int | testserver_exec (struct ast_channel *chan, const char *data) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Interface Test Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static char * | testc_app = "TestClient" |
static char * | tests_app = "TestServer" |
Russell Bryant <russelb@clemson.edu>
Definition in file app_test.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 491 of file app_test.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 491 of file app_test.c.
static int load_module | ( | void | ) | [static] |
Definition at line 481 of file app_test.c.
References ast_register_application_xml, testclient_exec(), and testserver_exec().
00482 { 00483 int res; 00484 00485 res = ast_register_application_xml(testc_app, testclient_exec); 00486 res |= ast_register_application_xml(tests_app, testserver_exec); 00487 00488 return res; 00489 }
static int measurenoise | ( | struct ast_channel * | chan, | |
int | ms, | |||
char * | who | |||
) | [static] |
Definition at line 80 of file app_test.c.
References ast_debug, AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_frfree, ast_log(), ast_read(), ast_set_read_format(), ast_tvdiff_ms(), ast_tvnow(), ast_waitfor(), f, LOG_NOTICE, and ast_channel::readformat.
Referenced by testclient_exec(), and testserver_exec().
00081 { 00082 int res=0; 00083 int mssofar; 00084 int noise=0; 00085 int samples=0; 00086 int x; 00087 short *foo; 00088 struct timeval start; 00089 struct ast_frame *f; 00090 int rformat; 00091 rformat = chan->readformat; 00092 if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) { 00093 ast_log(LOG_NOTICE, "Unable to set to linear mode!\n"); 00094 return -1; 00095 } 00096 start = ast_tvnow(); 00097 for(;;) { 00098 mssofar = ast_tvdiff_ms(ast_tvnow(), start); 00099 if (mssofar > ms) 00100 break; 00101 res = ast_waitfor(chan, ms - mssofar); 00102 if (res < 1) 00103 break; 00104 f = ast_read(chan); 00105 if (!f) { 00106 res = -1; 00107 break; 00108 } 00109 if ((f->frametype == AST_FRAME_VOICE) && (f->subclass.codec == AST_FORMAT_SLINEAR)) { 00110 foo = (short *)f->data.ptr; 00111 for (x=0;x<f->samples;x++) { 00112 noise += abs(foo[x]); 00113 samples++; 00114 } 00115 } 00116 ast_frfree(f); 00117 } 00118 00119 if (rformat) { 00120 if (ast_set_read_format(chan, rformat)) { 00121 ast_log(LOG_NOTICE, "Unable to restore original format!\n"); 00122 return -1; 00123 } 00124 } 00125 if (res < 0) 00126 return res; 00127 if (!samples) { 00128 ast_log(LOG_NOTICE, "No samples were received from the other side!\n"); 00129 return -1; 00130 } 00131 ast_debug(1, "%s: Noise: %d, samples: %d, avg: %d\n", who, noise, samples, noise / samples); 00132 return (noise / samples); 00133 }
static int sendnoise | ( | struct ast_channel * | chan, | |
int | ms | |||
) | [static] |
Definition at line 135 of file app_test.c.
References ast_tonepair_start(), ast_tonepair_stop(), and ast_waitfordigit().
Referenced by testclient_exec(), and testserver_exec().
00136 { 00137 int res; 00138 res = ast_tonepair_start(chan, 1537, 2195, ms, 8192); 00139 if (!res) { 00140 res = ast_waitfordigit(chan, ms); 00141 ast_tonepair_stop(chan); 00142 } 00143 return res; 00144 }
static int testclient_exec | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
Definition at line 146 of file app_test.c.
References ast_channel::_state, ast_answer(), ast_app_getdata(), ast_config_AST_LOG_DIR, ast_debug, ast_dtmf_stream(), ast_log(), ast_mkdir(), ast_safe_sleep(), AST_STATE_UP, ast_strlen_zero(), ast_waitfordigit(), f, LOG_NOTICE, LOG_WARNING, measurenoise(), ast_channel::name, and sendnoise().
Referenced by load_module().
00147 { 00148 int res = 0; 00149 const char *testid=data; 00150 char fn[80]; 00151 char serverver[80]; 00152 FILE *f; 00153 00154 /* Check for test id */ 00155 if (ast_strlen_zero(testid)) { 00156 ast_log(LOG_WARNING, "TestClient requires an argument - the test id\n"); 00157 return -1; 00158 } 00159 00160 if (chan->_state != AST_STATE_UP) 00161 res = ast_answer(chan); 00162 00163 /* Wait a few just to be sure things get started */ 00164 res = ast_safe_sleep(chan, 3000); 00165 /* Transmit client version */ 00166 if (!res) 00167 res = ast_dtmf_stream(chan, NULL, "8378*1#", 0, 0); 00168 ast_debug(1, "Transmit client version\n"); 00169 00170 /* Read server version */ 00171 ast_debug(1, "Read server version\n"); 00172 if (!res) 00173 res = ast_app_getdata(chan, NULL, serverver, sizeof(serverver) - 1, 0); 00174 if (res > 0) 00175 res = 0; 00176 ast_debug(1, "server version: %s\n", serverver); 00177 00178 if (res > 0) 00179 res = 0; 00180 00181 if (!res) 00182 res = ast_safe_sleep(chan, 1000); 00183 /* Send test id */ 00184 if (!res) 00185 res = ast_dtmf_stream(chan, NULL, testid, 0, 0); 00186 if (!res) 00187 res = ast_dtmf_stream(chan, NULL, "#", 0, 0); 00188 ast_debug(1, "send test identifier: %s\n", testid); 00189 00190 if ((res >=0) && (!ast_strlen_zero(testid))) { 00191 /* Make the directory to hold the test results in case it's not there */ 00192 snprintf(fn, sizeof(fn), "%s/testresults", ast_config_AST_LOG_DIR); 00193 ast_mkdir(fn, 0777); 00194 snprintf(fn, sizeof(fn), "%s/testresults/%s-client.txt", ast_config_AST_LOG_DIR, testid); 00195 if ((f = fopen(fn, "w+"))) { 00196 setlinebuf(f); 00197 fprintf(f, "CLIENTCHAN: %s\n", chan->name); 00198 fprintf(f, "CLIENTTEST ID: %s\n", testid); 00199 fprintf(f, "ANSWER: PASS\n"); 00200 res = 0; 00201 00202 if (!res) { 00203 /* Step 1: Wait for "1" */ 00204 ast_debug(1, "TestClient: 2. Wait DTMF 1\n"); 00205 res = ast_waitfordigit(chan, 3000); 00206 fprintf(f, "WAIT DTMF 1: %s\n", (res != '1') ? "FAIL" : "PASS"); 00207 if (res == '1') 00208 res = 0; 00209 else 00210 res = -1; 00211 } 00212 if (!res) { 00213 res = ast_safe_sleep(chan, 1000); 00214 } 00215 if (!res) { 00216 /* Step 2: Send "2" */ 00217 ast_debug(1, "TestClient: 2. Send DTMF 2\n"); 00218 res = ast_dtmf_stream(chan, NULL, "2", 0, 0); 00219 fprintf(f, "SEND DTMF 2: %s\n", (res < 0) ? "FAIL" : "PASS"); 00220 if (res > 0) 00221 res = 0; 00222 } 00223 if (!res) { 00224 /* Step 3: Wait one second */ 00225 ast_debug(1, "TestClient: 3. Wait one second\n"); 00226 res = ast_safe_sleep(chan, 1000); 00227 fprintf(f, "WAIT 1 SEC: %s\n", (res < 0) ? "FAIL" : "PASS"); 00228 if (res > 0) 00229 res = 0; 00230 } 00231 if (!res) { 00232 /* Step 4: Measure noise */ 00233 ast_debug(1, "TestClient: 4. Measure noise\n"); 00234 res = measurenoise(chan, 5000, "TestClient"); 00235 fprintf(f, "MEASURENOISE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res); 00236 if (res > 0) 00237 res = 0; 00238 } 00239 if (!res) { 00240 /* Step 5: Wait for "4" */ 00241 ast_debug(1, "TestClient: 5. Wait DTMF 4\n"); 00242 res = ast_waitfordigit(chan, 3000); 00243 fprintf(f, "WAIT DTMF 4: %s\n", (res != '4') ? "FAIL" : "PASS"); 00244 if (res == '4') 00245 res = 0; 00246 else 00247 res = -1; 00248 } 00249 if (!res) { 00250 /* Step 6: Transmit tone noise */ 00251 ast_debug(1, "TestClient: 6. Transmit tone\n"); 00252 res = sendnoise(chan, 6000); 00253 fprintf(f, "SENDTONE: %s\n", (res < 0) ? "FAIL" : "PASS"); 00254 } 00255 if (!res || (res == '5')) { 00256 /* Step 7: Wait for "5" */ 00257 ast_debug(1, "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 ast_debug(1, "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 ast_debug(1, "TestClient: 9. Measure tone\n"); 00277 res = measurenoise(chan, 4000, "TestClient"); 00278 fprintf(f, "MEASURETONE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res); 00279 if (res > 0) 00280 res = 0; 00281 } 00282 if (!res) { 00283 /* Step 10: Send "7" */ 00284 ast_debug(1, "TestClient: 10. Send DTMF 7\n"); 00285 res = ast_dtmf_stream(chan, NULL, "7", 0, 0); 00286 fprintf(f, "SEND DTMF 7: %s\n", (res < 0) ? "FAIL" : "PASS"); 00287 if (res > 0) 00288 res =0; 00289 } 00290 if (!res) { 00291 /* Step 11: Wait for "8" */ 00292 ast_debug(1, "TestClient: 11. Wait DTMF 8\n"); 00293 res = ast_waitfordigit(chan, 3000); 00294 fprintf(f, "WAIT DTMF 8: %s\n", (res != '8') ? "FAIL" : "PASS"); 00295 if (res == '8') 00296 res = 0; 00297 else 00298 res = -1; 00299 } 00300 if (!res) { 00301 res = ast_safe_sleep(chan, 1000); 00302 } 00303 if (!res) { 00304 /* Step 12: Hangup! */ 00305 ast_debug(1, "TestClient: 12. Hangup\n"); 00306 } 00307 00308 ast_debug(1, "-- TEST COMPLETE--\n"); 00309 fprintf(f, "-- END TEST--\n"); 00310 fclose(f); 00311 res = -1; 00312 } else 00313 res = -1; 00314 } else { 00315 ast_log(LOG_NOTICE, "Did not read a test ID on '%s'\n", chan->name); 00316 res = -1; 00317 } 00318 return res; 00319 }
static int testserver_exec | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
Definition at line 321 of file app_test.c.
References ast_channel::_state, ast_answer(), ast_app_getdata(), ast_config_AST_LOG_DIR, ast_debug, ast_dtmf_stream(), ast_log(), ast_mkdir(), ast_safe_sleep(), AST_STATE_UP, ast_strlen_zero(), ast_waitfordigit(), f, LOG_NOTICE, measurenoise(), ast_channel::name, and sendnoise().
Referenced by load_module().
00322 { 00323 int res = 0; 00324 char testid[80]=""; 00325 char fn[80]; 00326 FILE *f; 00327 if (chan->_state != AST_STATE_UP) 00328 res = ast_answer(chan); 00329 /* Read version */ 00330 ast_debug(1, "Read client version\n"); 00331 if (!res) 00332 res = ast_app_getdata(chan, NULL, testid, sizeof(testid) - 1, 0); 00333 if (res > 0) 00334 res = 0; 00335 00336 ast_debug(1, "client version: %s\n", testid); 00337 ast_debug(1, "Transmit server version\n"); 00338 00339 res = ast_safe_sleep(chan, 1000); 00340 if (!res) 00341 res = ast_dtmf_stream(chan, NULL, "8378*1#", 0, 0); 00342 if (res > 0) 00343 res = 0; 00344 00345 if (!res) 00346 res = ast_app_getdata(chan, NULL, testid, sizeof(testid) - 1, 0); 00347 ast_debug(1, "read test identifier: %s\n", testid); 00348 /* Check for sneakyness */ 00349 if (strchr(testid, '/')) 00350 res = -1; 00351 if ((res >=0) && (!ast_strlen_zero(testid))) { 00352 /* Got a Test ID! Whoo hoo! */ 00353 /* Make the directory to hold the test results in case it's not there */ 00354 snprintf(fn, sizeof(fn), "%s/testresults", ast_config_AST_LOG_DIR); 00355 ast_mkdir(fn, 0777); 00356 snprintf(fn, sizeof(fn), "%s/testresults/%s-server.txt", ast_config_AST_LOG_DIR, testid); 00357 if ((f = fopen(fn, "w+"))) { 00358 setlinebuf(f); 00359 fprintf(f, "SERVERCHAN: %s\n", chan->name); 00360 fprintf(f, "SERVERTEST ID: %s\n", testid); 00361 fprintf(f, "ANSWER: PASS\n"); 00362 ast_debug(1, "Processing Test ID '%s'\n", testid); 00363 res = ast_safe_sleep(chan, 1000); 00364 if (!res) { 00365 /* Step 1: Send "1" */ 00366 ast_debug(1, "TestServer: 1. Send DTMF 1\n"); 00367 res = ast_dtmf_stream(chan, NULL, "1", 0,0 ); 00368 fprintf(f, "SEND DTMF 1: %s\n", (res < 0) ? "FAIL" : "PASS"); 00369 if (res > 0) 00370 res = 0; 00371 } 00372 if (!res) { 00373 /* Step 2: Wait for "2" */ 00374 ast_debug(1, "TestServer: 2. Wait DTMF 2\n"); 00375 res = ast_waitfordigit(chan, 3000); 00376 fprintf(f, "WAIT DTMF 2: %s\n", (res != '2') ? "FAIL" : "PASS"); 00377 if (res == '2') 00378 res = 0; 00379 else 00380 res = -1; 00381 } 00382 if (!res) { 00383 /* Step 3: Measure noise */ 00384 ast_debug(1, "TestServer: 3. Measure noise\n"); 00385 res = measurenoise(chan, 6000, "TestServer"); 00386 fprintf(f, "MEASURENOISE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res); 00387 if (res > 0) 00388 res = 0; 00389 } 00390 if (!res) { 00391 /* Step 4: Send "4" */ 00392 ast_debug(1, "TestServer: 4. Send DTMF 4\n"); 00393 res = ast_dtmf_stream(chan, NULL, "4", 0, 0); 00394 fprintf(f, "SEND DTMF 4: %s\n", (res < 0) ? "FAIL" : "PASS"); 00395 if (res > 0) 00396 res = 0; 00397 } 00398 if (!res) { 00399 /* Step 5: Wait one second */ 00400 ast_debug(1, "TestServer: 5. Wait one second\n"); 00401 res = ast_safe_sleep(chan, 1000); 00402 fprintf(f, "WAIT 1 SEC: %s\n", (res < 0) ? "FAIL" : "PASS"); 00403 if (res > 0) 00404 res = 0; 00405 } 00406 if (!res) { 00407 /* Step 6: Measure noise */ 00408 ast_debug(1, "TestServer: 6. Measure tone\n"); 00409 res = measurenoise(chan, 4000, "TestServer"); 00410 fprintf(f, "MEASURETONE: %s (%d)\n", (res < 0) ? "FAIL" : "PASS", res); 00411 if (res > 0) 00412 res = 0; 00413 } 00414 if (!res) { 00415 /* Step 7: Send "5" */ 00416 ast_debug(1, "TestServer: 7. Send DTMF 5\n"); 00417 res = ast_dtmf_stream(chan, NULL, "5", 0, 0); 00418 fprintf(f, "SEND DTMF 5: %s\n", (res < 0) ? "FAIL" : "PASS"); 00419 if (res > 0) 00420 res = 0; 00421 } 00422 if (!res) { 00423 /* Step 8: Transmit tone noise */ 00424 ast_debug(1, "TestServer: 8. Transmit tone\n"); 00425 res = sendnoise(chan, 6000); 00426 fprintf(f, "SENDTONE: %s\n", (res < 0) ? "FAIL" : "PASS"); 00427 } 00428 00429 if (!res || (res == '7')) { 00430 /* Step 9: Wait for "7" */ 00431 ast_debug(1, "TestServer: 9. Wait DTMF 7\n"); 00432 if (!res) 00433 res = ast_waitfordigit(chan, 3000); 00434 fprintf(f, "WAIT DTMF 7: %s\n", (res != '7') ? "FAIL" : "PASS"); 00435 if (res == '7') 00436 res = 0; 00437 else 00438 res = -1; 00439 } 00440 if (!res) { 00441 res = ast_safe_sleep(chan, 1000); 00442 } 00443 if (!res) { 00444 /* Step 10: Send "8" */ 00445 ast_debug(1, "TestServer: 10. Send DTMF 8\n"); 00446 res = ast_dtmf_stream(chan, NULL, "8", 0, 0); 00447 fprintf(f, "SEND DTMF 8: %s\n", (res < 0) ? "FAIL" : "PASS"); 00448 if (res > 0) 00449 res = 0; 00450 } 00451 if (!res) { 00452 /* Step 11: Wait for hangup to arrive! */ 00453 ast_debug(1, "TestServer: 11. Waiting for hangup\n"); 00454 res = ast_safe_sleep(chan, 10000); 00455 fprintf(f, "WAIT HANGUP: %s\n", (res < 0) ? "PASS" : "FAIL"); 00456 } 00457 00458 ast_log(LOG_NOTICE, "-- TEST COMPLETE--\n"); 00459 fprintf(f, "-- END TEST--\n"); 00460 fclose(f); 00461 res = -1; 00462 } else 00463 res = -1; 00464 } else { 00465 ast_log(LOG_NOTICE, "Did not read a test ID on '%s'\n", chan->name); 00466 res = -1; 00467 } 00468 return res; 00469 }
static int unload_module | ( | void | ) | [static] |
Definition at line 471 of file app_test.c.
References ast_unregister_application().
00472 { 00473 int res; 00474 00475 res = ast_unregister_application(testc_app); 00476 res |= ast_unregister_application(tests_app); 00477 00478 return res; 00479 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Interface Test Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 491 of file app_test.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 491 of file app_test.c.
char* testc_app = "TestClient" [static] |
Definition at line 78 of file app_test.c.
char* tests_app = "TestServer" [static] |
Definition at line 77 of file app_test.c.