Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2013, Digium, Inc.
*
* Kinsey Moore <kmoore@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*!
* \file
* \brief CEL unit tests
*
* \author Kinsey Moore <kmoore@digium.com>
*
*/
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
<support_level>core</support_level>
***/
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <math.h>
#include "asterisk/module.h"
#include "asterisk/test.h"
#include "asterisk/cel.h"
#include "asterisk/channel.h"
#include "asterisk/linkedlists.h"
#include "asterisk/chanvars.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/time.h"
#include "asterisk/bridge_basic.h"
#include "asterisk/pickup.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/stasis_bridges.h"
#include "asterisk/json.h"
#include "asterisk/features.h"
#define TEST_CATEGORY "/main/cel/"
#define CHANNEL_TECH_NAME "CELTestChannel"
#define TEST_BACKEND_NAME "CEL Test Logging"
/*! \brief A placeholder for Asterisk's 'real' CEL configuration */
static struct ast_cel_general_config *saved_config;
/*! \brief The CEL config used for CEL unit tests */
static struct ast_cel_general_config *cel_test_config;
/*! \brief Lock used for synchronizing test execution stages with received events */
ast_mutex_t mid_test_sync_lock;
/*! \brief Lock used with sync_out for checking the end of test execution */
ast_mutex_t sync_lock;
/*! \brief Condition used for checking the end of test execution */
ast_cond_t sync_out;
/*! \brief Flag used to trigger a mid-test synchronization, access controlled by mid_test_sync_lock */
int do_mid_test_sync = 0;
/*! \brief A channel technology used for the unit tests */
static struct ast_channel_tech test_cel_chan_tech = {
.type = CHANNEL_TECH_NAME,
.description = "Mock channel technology for CEL tests",
};
/*! \brief A 1 second sleep */
static struct timespec to_sleep = {1, 0};
static void do_sleep(void)
{
while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
}
#define APPEND_EVENT(chan, ev_type, userevent, extra) do { \
if (append_expected_event(chan, ev_type, userevent, extra, NULL)) { \
return AST_TEST_FAIL; \
} \
} while (0)
#define APPEND_EVENT_PEER(chan, ev_type, userevent, extra, peer) do { \
if (append_expected_event(chan, ev_type, userevent, extra, peer)) { \
return AST_TEST_FAIL; \
} \
} while (0)
#define APPEND_EVENT_SNAPSHOT(snapshot, ev_type, userevent, extra, peer) do { \
if (append_expected_event_snapshot(snapshot, ev_type, userevent, extra, peer)) { \
return AST_TEST_FAIL; \
} \
} while (0)
#define APPEND_DUMMY_EVENT() do { \
if (append_dummy_event()) { \
return AST_TEST_FAIL; \
} \
} while (0)
#define BRIDGE_EXIT(channel, bridge) do { \
ast_test_validate(test, !ast_bridge_depart(channel)); \
BRIDGE_EXIT_EVENT(channel, bridge); \
#define BRIDGE_EXIT_EVENT(channel, bridge) do { \
RAII_VAR(struct ast_str *, peer_str, NULL, ast_free); \
peer_str = test_cel_generate_peer_str(channel, bridge); \
ast_test_validate(test, peer_str != NULL); \
BRIDGE_EXIT_EVENT_PEER(channel, bridge, ast_str_buffer(peer_str)); \
} while (0)
#define BRIDGE_EXIT_EVENT_PEER(channel, bridge, peer) do { \
RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
extra = ast_json_pack("{s: s}", "bridge_id", bridge->uniqueid); \
ast_test_validate(test, extra != NULL); \
APPEND_EVENT_PEER(channel, AST_CEL_BRIDGE_EXIT, NULL, extra, peer); \
#define BRIDGE_EXIT_SNAPSHOT(channel, bridge) do { \
RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
RAII_VAR(struct ast_str *, peer_str, NULL, ast_free); \
peer_str = test_cel_generate_peer_str_snapshot(channel, bridge); \
ast_test_validate(test, peer_str != NULL); \
extra = ast_json_pack("{s: s}", "bridge_id", bridge->uniqueid); \
ast_test_validate(test, extra != NULL); \
APPEND_EVENT_SNAPSHOT(channel, AST_CEL_BRIDGE_EXIT, NULL, extra, ast_str_buffer(peer_str)); \
#define BRIDGE_ENTER(channel, bridge) do { \
ast_test_validate(test, !ast_bridge_impart(bridge, channel, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE)); \
do_sleep(); \
BRIDGE_ENTER_EVENT(channel, bridge); \
mid_test_sync(); \
#define BRIDGE_ENTER_EVENT(channel, bridge) do { \
RAII_VAR(struct ast_str *, peer_str, NULL, ast_free); \
peer_str = test_cel_generate_peer_str(channel, bridge); \
ast_test_validate(test, peer_str != NULL); \
BRIDGE_ENTER_EVENT_PEER(channel, bridge, ast_str_buffer(peer_str)); \
} while (0)
#define BRIDGE_ENTER_EVENT_PEER(channel, bridge, peer) do { \
RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
extra = ast_json_pack("{s: s}", "bridge_id", bridge->uniqueid); \
APPEND_EVENT_PEER(channel, AST_CEL_BRIDGE_ENTER, NULL, extra, peer); \
} while (0)
#define BLINDTRANSFER_EVENT(channel, bridge, extension, context) do { \
RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
extra = ast_json_pack("{s: s, s: s, s: s}", \
"extension", extension, \
"context", context, \
"bridge_id", bridge->uniqueid); \
ast_test_validate(test, extra != NULL); \
APPEND_EVENT(channel, AST_CEL_BLINDTRANSFER, NULL, extra); \
} while (0)
#define ATTENDEDTRANSFER_BRIDGE(channel1, bridge1, channel2, bridge2) do { \
RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
extra = ast_json_pack("{s: s, s: s, s: s}", \
"bridge1_id", bridge1->uniqueid, \
"channel2_name", ast_channel_name(channel2), \
"bridge2_id", bridge2->uniqueid); \
ast_test_validate(test, extra != NULL); \
APPEND_EVENT(channel1, AST_CEL_ATTENDEDTRANSFER, NULL, extra); \
/*! \brief Alice's Caller ID */
#define ALICE_CALLERID { .id.name.str = "Alice", .id.name.valid = 1, .id.number.str = "100", .id.number.valid = 1, }
/*! \brief Bob's Caller ID */
#define BOB_CALLERID { .id.name.str = "Bob", .id.name.valid = 1, .id.number.str = "200", .id.number.valid = 1, }
/*! \brief Charlie's Caller ID */
#define CHARLIE_CALLERID { .id.name.str = "Charlie", .id.name.valid = 1, .id.number.str = "300", .id.number.valid = 1, }
/*! \brief David's Caller ID */
#define DAVID_CALLERID { .id.name.str = "David", .id.name.valid = 1, .id.number.str = "400", .id.number.valid = 1, }
/*! \brief Create a \ref test_cel_chan_tech for Alice. */
#define CREATE_ALICE_CHANNEL(channel_var, caller_id) do { \
(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "100", "100", "default", NULL, 0, CHANNEL_TECH_NAME "/Alice"); \
APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
} while (0)
/*! \brief Create a \ref test_cel_chan_tech for Bob. */
#define CREATE_BOB_CHANNEL(channel_var, caller_id) do { \
(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "200", "200", "default", NULL, 0, CHANNEL_TECH_NAME "/Bob"); \
APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
} while (0)
/*! \brief Create a \ref test_cel_chan_tech for Charlie. */
#define CREATE_CHARLIE_CHANNEL(channel_var, caller_id) do { \
(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "300", "300", "default", NULL, 0, CHANNEL_TECH_NAME "/Charlie"); \
APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
/*! \brief Create a \ref test_cel_chan_tech for David. */
#define CREATE_DAVID_CHANNEL(channel_var, caller_id) do { \
(channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "400", "400", "default", NULL, 0, CHANNEL_TECH_NAME "/David"); \
APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
/*! \brief Emulate a channel entering into an application */
#define EMULATE_APP_DATA(channel, priority, application, data) do { \
if ((priority) > 0) { \
ast_channel_priority_set((channel), (priority)); \
} \
ast_channel_appl_set((channel), (application)); \
ast_channel_data_set((channel), (data)); \
ast_channel_publish_snapshot((channel)); \
} while (0)
#define ANSWER_CHANNEL(chan) do { \
EMULATE_APP_DATA(chan, 1, "Answer", ""); \
ANSWER_NO_APP(chan); \
} while (0)
#define ANSWER_NO_APP(chan) do { \
ast_setstate(chan, AST_STATE_UP); \
APPEND_EVENT(chan, AST_CEL_ANSWER, NULL, NULL); \
} while (0)
/*! \brief Hang up a test channel safely */
#define HANGUP_CHANNEL(channel, cause, dialstatus) do { \
ast_channel_hangupcause_set((channel), (cause)); \
ao2_ref(channel, +1); \
ast_hangup((channel)); \
HANGUP_EVENT(channel, cause, dialstatus); \
APPEND_EVENT(channel, AST_CEL_CHANNEL_END, NULL, NULL); \
ao2_cleanup(stasis_cache_get(ast_channel_cache(), \
ast_channel_snapshot_type(), ast_channel_uniqueid(channel))); \
ao2_cleanup(channel); \
channel = NULL; \
} while (0)
#define HANGUP_EVENT(channel, cause, dialstatus) do { \
RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
extra = ast_json_pack("{s: i, s: s, s: s}", \
"hangupcause", cause, \
"hangupsource", "", \
"dialstatus", dialstatus); \
ast_test_validate(test, extra != NULL); \
APPEND_EVENT(channel, AST_CEL_HANGUP, NULL, extra); \
static void mid_test_sync(void);
static int append_expected_event(
struct ast_channel *chan,
enum ast_cel_event_type type,
const char *userdefevname,
struct ast_json *extra,
const char *peer);
static int append_expected_event_snapshot(
struct ast_channel_snapshot *snapshot,
enum ast_cel_event_type type,
const char *userdefevname,
struct ast_json *extra,
const char *peer);
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
static struct ast_str *__test_cel_generate_peer_str(struct ast_channel_snapshot *chan, struct ast_bridge_snapshot *bridge)
{
struct ast_str *peer_str = ast_str_create(32);
struct ao2_iterator i;
char *current_chan = NULL;
if (!peer_str) {
return NULL;
}
for (i = ao2_iterator_init(bridge->channels, 0);
(current_chan = ao2_iterator_next(&i));
ao2_cleanup(current_chan)) {
RAII_VAR(struct ast_channel_snapshot *, current_snapshot,
NULL,
ao2_cleanup);
/* Don't add the channel for which this message is being generated */
if (!strcmp(current_chan, chan->uniqueid)) {
continue;
}
current_snapshot = ast_channel_snapshot_get_latest(current_chan);
if (!current_snapshot) {
continue;
}
ast_str_append(&peer_str, 0, "%s,", current_snapshot->name);
}
ao2_iterator_destroy(&i);
/* Rip off the trailing comma */
ast_str_truncate(peer_str, -1);
return peer_str;
}
static struct ast_str *test_cel_generate_peer_str_snapshot(struct ast_channel_snapshot *chan, struct ast_bridge *bridge)
{
RAII_VAR(struct ast_bridge_snapshot *, snapshot,
ast_bridge_snapshot_get_latest(bridge->uniqueid),
ao2_cleanup);
if (!snapshot) {
return NULL;
}
return __test_cel_generate_peer_str(chan, snapshot);
}
static struct ast_str *test_cel_generate_peer_str(struct ast_channel *chan, struct ast_bridge *bridge)
{
RAII_VAR(struct ast_channel_snapshot *, snapshot,
ast_channel_snapshot_get_latest(ast_channel_uniqueid(chan)),
ao2_cleanup);
if (!snapshot) {
return NULL;
}
return test_cel_generate_peer_str_snapshot(snapshot, bridge);
}
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
static void safe_channel_release(struct ast_channel *chan)
{
if (!chan) {
return;
}
ast_channel_release(chan);
}
AST_TEST_DEFINE(test_cel_channel_creation)
{
RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
struct ast_party_caller caller = ALICE_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test the CEL records created when a channel is created";
info->description =
"Test the CEL records created when a channel is created";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
CREATE_ALICE_CHANNEL(chan, (&caller));
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_cel_unanswered_inbound_call)
{
RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
struct ast_party_caller caller = ALICE_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test inbound unanswered calls";
info->description =
"Test CEL records for a call that is\n"
"inbound to Asterisk, executes some dialplan, but\n"
"is never answered.\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
CREATE_ALICE_CHANNEL(chan, &caller);
EMULATE_APP_DATA(chan, 1, "Wait", "1");
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_cel_unanswered_outbound_call)
{
RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
struct ast_party_caller caller = {
.id.name.str = "",
.id.name.valid = 1,
.id.number.str = "",
.id.number.valid = 1, };
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test outbound unanswered calls";
info->description =
"Test CEL records for a call that is\n"
"outbound to Asterisk but is never answered.\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
CREATE_ALICE_CHANNEL(chan, &caller);
ast_channel_exten_set(chan, "s");
ast_channel_context_set(chan, "default");
ast_set_flag(ast_channel_flags(chan), AST_FLAG_ORIGINATED);
EMULATE_APP_DATA(chan, 0, "AppDial", "(Outgoing Line)");
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_cel_single_party)
{
RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
struct ast_party_caller caller = ALICE_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test CEL for a single party";
info->description =
"Test CEL records for a call that is\n"
"answered, but only involves a single channel\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
CREATE_ALICE_CHANNEL(chan, &caller);
ANSWER_CHANNEL(chan);
EMULATE_APP_DATA(chan, 2, "VoiceMailMain", "1");
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_cel_single_bridge)
{
RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
struct ast_party_caller caller = ALICE_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test CEL for a single party entering/leaving a bridge";
info->description =
"Test CEL records for a call that is\n"
"answered, enters a bridge, and leaves it.\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
bridge = ast_bridge_basic_new();
ast_test_validate(test, bridge != NULL);
CREATE_ALICE_CHANNEL(chan, &caller);
ANSWER_CHANNEL(chan);
EMULATE_APP_DATA(chan, 2, "Bridge", "");
do_sleep();
BRIDGE_ENTER(chan, bridge);
BRIDGE_EXIT(chan, bridge);
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_cel_single_bridge_continue)
{
RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
struct ast_party_caller caller = ALICE_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test CEL for a single party entering/leaving a bridge";
info->description =
"Test CEL records for a call that is\n"
"answered, enters a bridge, and leaves it.\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
bridge = ast_bridge_basic_new();
ast_test_validate(test, bridge != NULL);
CREATE_ALICE_CHANNEL(chan, &caller);
ANSWER_CHANNEL(chan);
EMULATE_APP_DATA(chan, 2, "Bridge", "");
do_sleep();
BRIDGE_ENTER(chan, bridge);
BRIDGE_EXIT(chan, bridge);
EMULATE_APP_DATA(chan, 3, "Wait", "");
/* And then it hangs up */
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_cel_single_twoparty_bridge_a)
{
RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
struct ast_party_caller caller_alice = ALICE_CALLERID;
struct ast_party_caller caller_bob = BOB_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test CEL for a single party entering/leaving a bridge";
info->description =
"Test CEL records for a call that is\n"
"answered, enters a bridge, and leaves it. In this scenario, the\n"
"Party A should answer the bridge first.\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
bridge = ast_bridge_basic_new();
ast_test_validate(test, bridge != NULL);
CREATE_ALICE_CHANNEL(chan_alice, &caller_alice);
CREATE_BOB_CHANNEL(chan_bob, &caller_bob);
ANSWER_CHANNEL(chan_alice);
EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
BRIDGE_ENTER(chan_alice, bridge);
do_sleep();
ANSWER_CHANNEL(chan_bob);
EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
BRIDGE_ENTER(chan_bob, bridge);
BRIDGE_EXIT(chan_alice, bridge);
BRIDGE_EXIT(chan_bob, bridge);
HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_cel_single_twoparty_bridge_b)
{
RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
struct ast_party_caller caller_alice = ALICE_CALLERID;
struct ast_party_caller caller_bob = BOB_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test CEL for a single party entering/leaving a bridge";
info->description =
"Test CEL records for a call that is\n"
"answered, enters a bridge, and leaves it. In this scenario, the\n"
"Party B should answer the bridge first.\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
bridge = ast_bridge_basic_new();
ast_test_validate(test, bridge != NULL);
CREATE_ALICE_CHANNEL(chan_alice, &caller_alice);
CREATE_BOB_CHANNEL(chan_bob, &caller_bob);
ANSWER_CHANNEL(chan_alice);
EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
ANSWER_CHANNEL(chan_bob);
EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
do_sleep();
BRIDGE_ENTER(chan_bob, bridge);
BRIDGE_ENTER(chan_alice, bridge);
BRIDGE_EXIT(chan_alice, bridge);
BRIDGE_EXIT(chan_bob, bridge);
HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
return AST_TEST_PASS;
}
/* XXX Validation needs to be reworked on a per-channel basis before
* test_cel_single_multiparty_bridge and test_cel_dial_answer_multiparty
* can operate properly. */
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
AST_TEST_DEFINE(test_cel_single_multiparty_bridge)
{
RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
struct ast_party_caller caller_alice = ALICE_CALLERID;
struct ast_party_caller caller_bob = BOB_CALLERID;
struct ast_party_caller caller_charlie = CHARLIE_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test CEL for a single party entering/leaving a multi-party bridge";
info->description =
"Test CEL records for a call that is\n"
"answered, enters a bridge, and leaves it. A total of three\n"
"parties perform this action.\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
bridge = ast_bridge_basic_new();
ast_test_validate(test, bridge != NULL);
CREATE_ALICE_CHANNEL(chan_alice, &caller_alice);
CREATE_BOB_CHANNEL(chan_bob, &caller_bob);
CREATE_CHARLIE_CHANNEL(chan_charlie, &caller_charlie);
ANSWER_CHANNEL(chan_alice);
EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
do_sleep();
BRIDGE_ENTER(chan_alice, bridge);
ANSWER_CHANNEL(chan_bob);
EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
do_sleep();
BRIDGE_ENTER(chan_bob, bridge);
ANSWER_CHANNEL(chan_charlie);
EMULATE_APP_DATA(chan_charlie, 2, "Bridge", "");
BRIDGE_ENTER(chan_charlie, bridge);
BRIDGE_EXIT(chan_alice, bridge);
BRIDGE_EXIT(chan_bob, bridge);
BRIDGE_EXIT(chan_charlie, bridge);
HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "");
#define EMULATE_DIAL(channel, dialstring) do { \
EMULATE_APP_DATA(channel, 1, "Dial", dialstring); \
if (append_expected_event(channel, AST_CEL_APP_START, NULL, NULL, NULL)) { \
return AST_TEST_FAIL; \
} \
} while (0)
#define START_DIALED(caller, callee) \
START_DIALED_FULL(caller, callee, "200", "Bob")
#define START_DIALED_FULL(caller, callee, number, name) do { \
callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, number, NULL, NULL, ast_channel_linkedid(caller), 0, CHANNEL_TECH_NAME "/" name); \
if (append_expected_event(callee, AST_CEL_CHANNEL_START, NULL, NULL, NULL)) { \
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
return AST_TEST_FAIL; \
} \
ast_set_flag(ast_channel_flags(callee), AST_FLAG_OUTGOING); \
EMULATE_APP_DATA(callee, 0, "AppDial", "(Outgoing Line)"); \
ast_channel_publish_dial(caller, callee, name, NULL); \
} while (0)
AST_TEST_DEFINE(test_cel_dial_unanswered)
{
RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
struct ast_party_caller caller = ALICE_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test CEL for a dial that isn't answered";
info->description =
"Test CEL records for a channel that\n"
"performs a dial operation that isn't answered\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
CREATE_ALICE_CHANNEL(chan_caller, &caller);
EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
START_DIALED(chan_caller, chan_callee);
ast_channel_state_set(chan_caller, AST_STATE_RINGING);
ast_channel_publish_dial(chan_caller, chan_callee, NULL, "NOANSWER");
HANGUP_CHANNEL(chan_caller, AST_CAUSE_NO_ANSWER, "NOANSWER");
HANGUP_CHANNEL(chan_callee, AST_CAUSE_NO_ANSWER, "");
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_cel_dial_busy)
{
RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
struct ast_party_caller caller = ALICE_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test CEL for a dial that results in a busy";
info->description =
"Test CEL records for a channel that\n"
"performs a dial operation to an endpoint that's busy\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
CREATE_ALICE_CHANNEL(chan_caller, &caller);
EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
START_DIALED(chan_caller, chan_callee);
ast_channel_state_set(chan_caller, AST_STATE_RINGING);
ast_channel_publish_dial(chan_caller, chan_callee, NULL, "BUSY");
HANGUP_CHANNEL(chan_caller, AST_CAUSE_BUSY, "BUSY");
HANGUP_CHANNEL(chan_callee, AST_CAUSE_BUSY, "");
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_cel_dial_congestion)
{
RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
struct ast_party_caller caller = ALICE_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test CEL for a dial that results in congestion";
info->description =
"Test CEL records for a channel that\n"
"performs a dial operation to an endpoint that's congested\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
CREATE_ALICE_CHANNEL(chan_caller, &caller);
EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
START_DIALED(chan_caller, chan_callee);
ast_channel_state_set(chan_caller, AST_STATE_RINGING);
ast_channel_publish_dial(chan_caller, chan_callee, NULL, "CONGESTION");
HANGUP_CHANNEL(chan_caller, AST_CAUSE_CONGESTION, "CONGESTION");
HANGUP_CHANNEL(chan_callee, AST_CAUSE_CONGESTION, "");
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_cel_dial_unavailable)
{
RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
struct ast_party_caller caller = ALICE_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test CEL for a dial that results in unavailable";
info->description =
"Test CEL records for a channel that\n"
"performs a dial operation to an endpoint that's unavailable\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
CREATE_ALICE_CHANNEL(chan_caller, &caller);
EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
START_DIALED(chan_caller, chan_callee);
ast_channel_state_set(chan_caller, AST_STATE_RINGING);
ast_channel_publish_dial(chan_caller, chan_callee, NULL, "CHANUNAVAIL");
HANGUP_CHANNEL(chan_caller, AST_CAUSE_NO_ROUTE_DESTINATION, "CHANUNAVAIL");
HANGUP_CHANNEL(chan_callee, AST_CAUSE_NO_ROUTE_DESTINATION, "");
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_cel_dial_caller_cancel)
{
RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
struct ast_party_caller caller = ALICE_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test CEL for a dial where the caller cancels";
info->description =
"Test CEL records for a channel that\n"
"performs a dial operation to an endpoint but then decides\n"
"to hang up, cancelling the dial\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
CREATE_ALICE_CHANNEL(chan_caller, &caller);
EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
START_DIALED(chan_caller, chan_callee);
ast_channel_state_set(chan_caller, AST_STATE_RINGING);
ast_channel_publish_dial(chan_caller, chan_callee, NULL, "CANCEL");
HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL, "");
HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "CANCEL");
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_cel_dial_parallel_failed)
{
RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
struct ast_party_caller caller = ALICE_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test a parallel dial where all channels fail to answer";
info->description =
"This tests dialing three parties: Bob, Charlie, David. Charlie\n"
"returns BUSY; David returns CONGESTION; Bob fails to answer and\n"
"Alice hangs up. Three records are created for Alice as a result.\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
CREATE_ALICE_CHANNEL(chan_caller, &caller);
/* Channel enters Dial app */
EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob&" CHANNEL_TECH_NAME "/Charlie&" CHANNEL_TECH_NAME "/David");
/* Outbound channels are created */
START_DIALED_FULL(chan_caller, chan_bob, "200", "Bob");
START_DIALED_FULL(chan_caller, chan_charlie, "300", "Charlie");
START_DIALED_FULL(chan_caller, chan_david, "400", "David");
/* Dial starts */
ast_channel_state_set(chan_caller, AST_STATE_RINGING);
/* Charlie is busy */
ast_channel_publish_dial(chan_caller, chan_charlie, NULL, "BUSY");
HANGUP_CHANNEL(chan_charlie, AST_CAUSE_BUSY, "");
/* David is congested */
ast_channel_publish_dial(chan_caller, chan_david, NULL, "CONGESTION");
HANGUP_CHANNEL(chan_david, AST_CAUSE_CONGESTION, "");
/* Bob is canceled */
ast_channel_publish_dial(chan_caller, chan_bob, NULL, "CANCEL");
HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "BUSY");
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_cel_dial_answer_no_bridge)
{
RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
struct ast_party_caller caller = ALICE_CALLERID;
switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = TEST_CATEGORY;
info->summary = "Test dialing, answering, and not going into a bridge.";
info->description =
"This is a weird one, but theoretically possible. You can perform\n"
"a dial, then bounce both channels to different priorities and\n"
"never have them enter a bridge together. Ew. This makes sure that\n"
"when we answer, we get a CEL, it gets ended at that point, and\n"
"that it gets finalized appropriately.\n";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
CREATE_ALICE_CHANNEL(chan_caller, &caller);
EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
START_DIALED(chan_caller, chan_callee);
ast_channel_state_set(chan_caller, AST_STATE_RINGING);
ast_channel_publish_dial(chan_caller, chan_callee, NULL, "ANSWER");
ANSWER_NO_APP(chan_caller);
ast_clear_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
ANSWER_NO_APP(chan_callee);
EMULATE_APP_DATA(chan_caller, 2, "Wait", "1");
EMULATE_APP_DATA(chan_callee, 1, "Wait", "1");
HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "ANSWER");
HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL, "");
return AST_TEST_PASS;
}
AST_TEST_DEFINE(test_cel_dial_answer_twoparty_bridge_a)
{
RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);