80 static char *tests_app =
"TestServer";
81 static char *testc_app =
"TestClient";
83 static int measurenoise(
struct ast_channel *chan,
int ms,
char *who)
95 rformat =
ao2_bump(ast_channel_readformat(chan));
97 ast_log(LOG_NOTICE,
"Unable to set to linear mode!\n");
116 foo = (
short *)f->
data.ptr;
118 noise += abs(foo[x]);
127 ast_log(LOG_NOTICE,
"Unable to restore original format!\n");
136 ast_log(LOG_NOTICE,
"No samples were received from the other side!\n");
139 ast_debug(1,
"%s: Noise: %d, samples: %d, avg: %d\n", who, noise, samples, noise / samples);
140 return (noise / samples);
143 static int sendnoise(
struct ast_channel *chan,
int ms)
154 static int testclient_exec(
struct ast_channel *chan,
const char *data)
157 const char *testid=data;
163 if (ast_strlen_zero(testid)) {
164 ast_log(LOG_WARNING,
"TestClient requires an argument - the test id\n");
176 ast_debug(1,
"Transmit client version\n");
181 res =
ast_app_getdata(chan, NULL, serverver,
sizeof(serverver) - 1, 0);
184 ast_debug(1,
"server version: %s\n", serverver);
196 ast_debug(1,
"send test identifier: %s\n", testid);
198 if ((res >=0) && (!ast_strlen_zero(testid))) {
200 snprintf(fn,
sizeof(fn),
"%s/testresults", ast_config_AST_LOG_DIR);
202 snprintf(fn,
sizeof(fn),
"%s/testresults/%s-client.txt", ast_config_AST_LOG_DIR, testid);
203 if ((f = fopen(fn,
"w+"))) {
205 fprintf(f,
"CLIENTCHAN: %s\n", ast_channel_name(chan));
206 fprintf(f,
"CLIENTTEST ID: %s\n", testid);
207 fprintf(f,
"ANSWER: PASS\n");
212 ast_debug(1,
"TestClient: 2. Wait DTMF 1\n");
214 fprintf(f,
"WAIT DTMF 1: %s\n", (res !=
'1') ?
"FAIL" :
"PASS");
225 ast_debug(1,
"TestClient: 2. Send DTMF 2\n");
227 fprintf(f,
"SEND DTMF 2: %s\n", (res < 0) ?
"FAIL" :
"PASS");
233 ast_debug(1,
"TestClient: 3. Wait one second\n");
235 fprintf(f,
"WAIT 1 SEC: %s\n", (res < 0) ?
"FAIL" :
"PASS");
241 ast_debug(1,
"TestClient: 4. Measure noise\n");
242 res = measurenoise(chan, 5000,
"TestClient");
243 fprintf(f,
"MEASURENOISE: %s (%d)\n", (res < 0) ?
"FAIL" :
"PASS", res);
249 ast_debug(1,
"TestClient: 5. Wait DTMF 4\n");
251 fprintf(f,
"WAIT DTMF 4: %s\n", (res !=
'4') ?
"FAIL" :
"PASS");
259 ast_debug(1,
"TestClient: 6. Transmit tone\n");
260 res = sendnoise(chan, 6000);
261 fprintf(f,
"SENDTONE: %s\n", (res < 0) ?
"FAIL" :
"PASS");
263 if (!res || (res ==
'5')) {
265 ast_debug(1,
"TestClient: 7. Wait DTMF 5\n");
268 fprintf(f,
"WAIT DTMF 5: %s\n", (res !=
'5') ?
"FAIL" :
"PASS");
276 ast_debug(1,
"TestClient: 8. Wait one second\n");
278 fprintf(f,
"WAIT 1 SEC: %s\n", (res < 0) ?
"FAIL" :
"PASS");
284 ast_debug(1,
"TestClient: 9. Measure tone\n");
285 res = measurenoise(chan, 4000,
"TestClient");
286 fprintf(f,
"MEASURETONE: %s (%d)\n", (res < 0) ?
"FAIL" :
"PASS", res);
292 ast_debug(1,
"TestClient: 10. Send DTMF 7\n");
294 fprintf(f,
"SEND DTMF 7: %s\n", (res < 0) ?
"FAIL" :
"PASS");
300 ast_debug(1,
"TestClient: 11. Wait DTMF 8\n");
302 fprintf(f,
"WAIT DTMF 8: %s\n", (res !=
'8') ?
"FAIL" :
"PASS");
313 ast_debug(1,
"TestClient: 12. Hangup\n");
317 fprintf(f,
"-- END TEST--\n");
323 ast_log(LOG_NOTICE,
"Did not read a test ID on '%s'\n", ast_channel_name(chan));
329 static int testserver_exec(
struct ast_channel *chan,
const char *data)
343 ast_debug(1,
"client version: %s\n", testid);
344 ast_debug(1,
"Transmit server version\n");
354 ast_debug(1,
"read test identifier: %s\n", testid);
356 if (strchr(testid,
'/'))
358 if ((res >=0) && (!ast_strlen_zero(testid))) {
363 snprintf(fn,
sizeof(fn),
"%s/testresults", ast_config_AST_LOG_DIR);
365 snprintf(fn,
sizeof(fn),
"%s/testresults/%s-server.txt", ast_config_AST_LOG_DIR, testid);
366 if ((f = fopen(fn,
"w+"))) {
368 fprintf(f,
"SERVERCHAN: %s\n", ast_channel_name(chan));
369 fprintf(f,
"SERVERTEST ID: %s\n", testid);
370 fprintf(f,
"ANSWER: PASS\n");
371 ast_debug(1,
"Processing Test ID '%s'\n", testid);
375 ast_debug(1,
"TestServer: 1. Send DTMF 1\n");
377 fprintf(f,
"SEND DTMF 1: %s\n", (res < 0) ?
"FAIL" :
"PASS");
383 ast_debug(1,
"TestServer: 2. Wait DTMF 2\n");
385 fprintf(f,
"WAIT DTMF 2: %s\n", (res !=
'2') ?
"FAIL" :
"PASS");
393 ast_debug(1,
"TestServer: 3. Measure noise\n");
394 res = measurenoise(chan, 6000,
"TestServer");
395 fprintf(f,
"MEASURENOISE: %s (%d)\n", (res < 0) ?
"FAIL" :
"PASS", res);
401 ast_debug(1,
"TestServer: 4. Send DTMF 4\n");
403 fprintf(f,
"SEND DTMF 4: %s\n", (res < 0) ?
"FAIL" :
"PASS");
409 ast_debug(1,
"TestServer: 5. Wait one second\n");
411 fprintf(f,
"WAIT 1 SEC: %s\n", (res < 0) ?
"FAIL" :
"PASS");
417 ast_debug(1,
"TestServer: 6. Measure tone\n");
418 res = measurenoise(chan, 4000,
"TestServer");
419 fprintf(f,
"MEASURETONE: %s (%d)\n", (res < 0) ?
"FAIL" :
"PASS", res);
425 ast_debug(1,
"TestServer: 7. Send DTMF 5\n");
427 fprintf(f,
"SEND DTMF 5: %s\n", (res < 0) ?
"FAIL" :
"PASS");
433 ast_debug(1,
"TestServer: 8. Transmit tone\n");
434 res = sendnoise(chan, 6000);
435 fprintf(f,
"SENDTONE: %s\n", (res < 0) ?
"FAIL" :
"PASS");
438 if (!res || (res ==
'7')) {
440 ast_debug(1,
"TestServer: 9. Wait DTMF 7\n");
443 fprintf(f,
"WAIT DTMF 7: %s\n", (res !=
'7') ?
"FAIL" :
"PASS");
454 ast_debug(1,
"TestServer: 10. Send DTMF 8\n");
456 fprintf(f,
"SEND DTMF 8: %s\n", (res < 0) ?
"FAIL" :
"PASS");
462 ast_debug(1,
"TestServer: 11. Waiting for hangup\n");
464 fprintf(f,
"WAIT HANGUP: %s\n", (res < 0) ?
"PASS" :
"FAIL");
467 ast_log(LOG_NOTICE,
"-- TEST COMPLETE--\n");
468 fprintf(f,
"-- END TEST--\n");
474 ast_log(LOG_NOTICE,
"Did not read a test ID on '%s'\n", ast_channel_name(chan));
480 static int unload_module(
void)
490 static int load_module(
void)
500 AST_MODULE_INFO_STANDARD_EXTENDED(
ASTERISK_GPL_KEY,
"Interface Test Application");
int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration)
Send a string of DTMF digits to a channel.
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Main Channel structure associated with a channel.
enum ast_getdata_result ast_app_getdata(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout)
Plays a stream and gets DTMF data from a channel.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
ast_channel_state
ast_channel states
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
int ast_unregister_application(const char *app)
Unregister an application.
struct ast_frame_subclass subclass
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
General Asterisk PBX channel definitions.
Asterisk file paths, configured in asterisk.conf.
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ast_debug(level,...)
Log a DEBUG message.
Core PBX routines and definitions.
union ast_frame::@224 data
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
void ast_tonepair_stop(struct ast_channel *chan)
int ast_answer(struct ast_channel *chan)
Answer a channel.
Data structure associated with a single frame of data.
int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
enum ast_frame_type frametype
struct ast_format * format
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
int ast_mkdir(const char *path, int mode)
Recursively create directory path.