CEL: Fix incorrect/missing extra field information
[asterisk/asterisk.git] / tests / test_cel.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2013, Digium, Inc.
5  *
6  * Kinsey Moore <kmoore@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*!
20  * \file
21  * \brief CEL unit tests
22  *
23  * \author Kinsey Moore <kmoore@digium.com>
24  *
25  */
26
27 /*** MODULEINFO
28         <depend>TEST_FRAMEWORK</depend>
29         <support_level>core</support_level>
30  ***/
31
32 #include "asterisk.h"
33
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
35
36 #include <math.h>
37 #include "asterisk/module.h"
38 #include "asterisk/test.h"
39 #include "asterisk/cel.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/linkedlists.h"
42 #include "asterisk/chanvars.h"
43 #include "asterisk/utils.h"
44 #include "asterisk/causes.h"
45 #include "asterisk/time.h"
46 #include "asterisk/bridge.h"
47 #include "asterisk/bridge_basic.h"
48 #include "asterisk/pickup.h"
49 #include "asterisk/stasis_channels.h"
50 #include "asterisk/stasis_bridges.h"
51 #include "asterisk/json.h"
52 #include "asterisk/features.h"
53 #include "asterisk/core_local.h"
54
55 #define TEST_CATEGORY "/main/cel/"
56
57 #define CHANNEL_TECH_NAME "CELTestChannel"
58
59 #define TEST_BACKEND_NAME "CEL Test Logging"
60
61 /*! \brief A placeholder for Asterisk's 'real' CEL configuration */
62 static struct ast_cel_general_config *saved_config;
63
64 /*! \brief The CEL config used for CEL unit tests */
65 static struct ast_cel_general_config *cel_test_config;
66
67 /*! \brief Lock used for synchronizing test execution stages with received events */
68 ast_mutex_t mid_test_sync_lock;
69
70 /*! \brief Lock used with sync_out for checking the end of test execution */
71 ast_mutex_t sync_lock;
72
73 /*! \brief Condition used for checking the end of test execution */
74 ast_cond_t sync_out;
75
76 /*! \brief Flag used to trigger a mid-test synchronization, access controlled by mid_test_sync_lock */
77 int do_mid_test_sync = 0;
78
79 /*! \brief A channel technology used for the unit tests */
80 static struct ast_channel_tech test_cel_chan_tech = {
81         .type = CHANNEL_TECH_NAME,
82         .description = "Mock channel technology for CEL tests",
83 };
84
85 /*! \brief A 1 second sleep */
86 static struct timespec to_sleep = {1, 0};
87
88 static void do_sleep(void)
89 {
90         while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
91         }
92 }
93
94 #define APPEND_EVENT(chan, ev_type, userevent, extra) do { \
95         if (append_expected_event(chan, ev_type, userevent, extra, NULL)) { \
96                 return AST_TEST_FAIL; \
97         } \
98         } while (0)
99
100 #define APPEND_EVENT_PEER(chan, ev_type, userevent, extra, peer) do { \
101         if (append_expected_event(chan, ev_type, userevent, extra, peer)) { \
102                 return AST_TEST_FAIL; \
103         } \
104         } while (0)
105
106 #define APPEND_EVENT_SNAPSHOT(snapshot, ev_type, userevent, extra, peer) do { \
107         if (append_expected_event_snapshot(snapshot, ev_type, userevent, extra, peer)) { \
108                 return AST_TEST_FAIL; \
109         } \
110         } while (0)
111
112 #define APPEND_DUMMY_EVENT() do { \
113         if (append_dummy_event()) { \
114                 return AST_TEST_FAIL; \
115         } \
116         } while (0)
117
118 #define BRIDGE_EXIT(channel, bridge) do { \
119         ast_test_validate(test, !ast_bridge_depart(channel)); \
120         BRIDGE_EXIT_EVENT(channel, bridge); \
121         mid_test_sync(); \
122         } while (0)
123
124 #define BRIDGE_EXIT_EVENT(channel, bridge) do { \
125         RAII_VAR(struct ast_str *, peer_str, NULL, ast_free); \
126         peer_str = test_cel_generate_peer_str(channel, bridge); \
127         ast_test_validate(test, peer_str != NULL); \
128         BRIDGE_EXIT_EVENT_PEER(channel, bridge, ast_str_buffer(peer_str)); \
129         } while (0)
130
131 #define BRIDGE_EXIT_EVENT_PEER(channel, bridge, peer) do { \
132         RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
133         extra = ast_json_pack("{s: s, s: s}", "bridge_id", bridge->uniqueid, "bridge_technology", bridge->technology->name); \
134         ast_test_validate(test, extra != NULL); \
135         APPEND_EVENT_PEER(channel, AST_CEL_BRIDGE_EXIT, NULL, extra, peer); \
136         } while (0)
137
138 #define BRIDGE_EXIT_SNAPSHOT(channel, bridge) do { \
139         RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
140         RAII_VAR(struct ast_str *, peer_str, NULL, ast_free); \
141         peer_str = test_cel_generate_peer_str_snapshot(channel, bridge); \
142         ast_test_validate(test, peer_str != NULL); \
143         extra = ast_json_pack("{s: s, s: s}", "bridge_id", bridge->uniqueid, "bridge_technology", bridge->technology->name); \
144         ast_test_validate(test, extra != NULL); \
145         APPEND_EVENT_SNAPSHOT(channel, AST_CEL_BRIDGE_EXIT, NULL, extra, ast_str_buffer(peer_str)); \
146         } while (0)
147
148 #define BRIDGE_ENTER(channel, bridge) do { \
149         ast_test_validate(test, !ast_bridge_impart(bridge, channel, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE)); \
150         do_sleep(); \
151         BRIDGE_ENTER_EVENT(channel, bridge); \
152         mid_test_sync(); \
153         } while (0)
154
155 #define BRIDGE_ENTER_EVENT(channel, bridge) do { \
156         RAII_VAR(struct ast_str *, peer_str, NULL, ast_free); \
157         peer_str = test_cel_generate_peer_str(channel, bridge); \
158         ast_test_validate(test, peer_str != NULL); \
159         BRIDGE_ENTER_EVENT_PEER(channel, bridge, ast_str_buffer(peer_str)); \
160         } while (0)
161
162 #define BRIDGE_ENTER_EVENT_PEER(channel, bridge, peer) do { \
163         RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
164         extra = ast_json_pack("{s: s, s: s}", "bridge_id", bridge->uniqueid, "bridge_technology", bridge->technology->name); \
165         ast_test_validate(test, extra != NULL); \
166         APPEND_EVENT_PEER(channel, AST_CEL_BRIDGE_ENTER, NULL, extra, peer); \
167         } while (0)
168
169 #define BLINDTRANSFER_EVENT(channel, bridge, extension, context) do { \
170         RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
171         extra = ast_json_pack("{s: s, s: s, s: s}", \
172                 "extension", extension, \
173                 "context", context, \
174                 "bridge_id", bridge->uniqueid); \
175         ast_test_validate(test, extra != NULL); \
176         APPEND_EVENT(channel, AST_CEL_BLINDTRANSFER, NULL, extra); \
177         } while (0)
178
179 #define ATTENDEDTRANSFER_BRIDGE(channel1, bridge1, channel2, bridge2) do { \
180         RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
181         extra = ast_json_pack("{s: s, s: s, s: s}", \
182                 "bridge1_id", bridge1->uniqueid, \
183                 "channel2_name", ast_channel_name(channel2), \
184                 "bridge2_id", bridge2->uniqueid); \
185         ast_test_validate(test, extra != NULL); \
186         APPEND_EVENT(channel1, AST_CEL_ATTENDEDTRANSFER, NULL, extra); \
187         } while (0)
188
189 /*! \brief Alice's Caller ID */
190 #define ALICE_CALLERID { .id.name.str = "Alice", .id.name.valid = 1, .id.number.str = "100", .id.number.valid = 1, }
191
192 /*! \brief Bob's Caller ID */
193 #define BOB_CALLERID { .id.name.str = "Bob", .id.name.valid = 1, .id.number.str = "200", .id.number.valid = 1, }
194
195 /*! \brief Charlie's Caller ID */
196 #define CHARLIE_CALLERID { .id.name.str = "Charlie", .id.name.valid = 1, .id.number.str = "300", .id.number.valid = 1, }
197
198 /*! \brief David's Caller ID */
199 #define DAVID_CALLERID { .id.name.str = "David", .id.name.valid = 1, .id.number.str = "400", .id.number.valid = 1, }
200
201 /*! \brief Create a \ref test_cel_chan_tech for Alice. */
202 #define CREATE_ALICE_CHANNEL(channel_var, caller_id) do { \
203         (channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "100", "100", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/Alice"); \
204         APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
205         ast_channel_unlock((channel_var)); \
206         } while (0)
207
208 /*! \brief Create a \ref test_cel_chan_tech for Bob. */
209 #define CREATE_BOB_CHANNEL(channel_var, caller_id) do { \
210         (channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "200", "200", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/Bob"); \
211         APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
212         ast_channel_unlock((channel_var)); \
213         } while (0)
214
215 /*! \brief Create a \ref test_cel_chan_tech for Charlie. */
216 #define CREATE_CHARLIE_CHANNEL(channel_var, caller_id) do { \
217         (channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "300", "300", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/Charlie"); \
218         APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
219         ast_channel_unlock((channel_var)); \
220         } while (0)
221
222 /*! \brief Create a \ref test_cel_chan_tech for David. */
223 #define CREATE_DAVID_CHANNEL(channel_var, caller_id) do { \
224         (channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "400", "400", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/David"); \
225         APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
226         ast_channel_unlock((channel_var)); \
227         } while (0)
228
229 /*! \brief Emulate a channel entering into an application */
230 #define EMULATE_APP_DATA(channel, priority, application, data) do { \
231         if ((priority) > 0) { \
232                 ast_channel_priority_set((channel), (priority)); \
233         } \
234         ast_channel_appl_set((channel), (application)); \
235         ast_channel_data_set((channel), (data)); \
236         ast_channel_publish_snapshot((channel)); \
237         } while (0)
238
239 #define ANSWER_CHANNEL(chan) do { \
240         EMULATE_APP_DATA(chan, 1, "Answer", ""); \
241         ANSWER_NO_APP(chan); \
242         } while (0)
243
244 #define ANSWER_NO_APP(chan) do { \
245         ast_setstate(chan, AST_STATE_UP); \
246         APPEND_EVENT(chan, AST_CEL_ANSWER, NULL, NULL); \
247         } while (0)
248
249 /*! \brief Hang up a test channel safely */
250 #define HANGUP_CHANNEL(channel, cause, dialstatus) do { \
251         ast_channel_hangupcause_set((channel), (cause)); \
252         ao2_ref(channel, +1); \
253         ast_hangup((channel)); \
254         HANGUP_EVENT(channel, cause, dialstatus); \
255         APPEND_EVENT(channel, AST_CEL_CHANNEL_END, NULL, NULL); \
256         ao2_cleanup(stasis_cache_get(ast_channel_cache(), \
257                 ast_channel_snapshot_type(), ast_channel_uniqueid(channel))); \
258         ao2_cleanup(channel); \
259         channel = NULL; \
260         } while (0)
261
262 #define HANGUP_EVENT(channel, cause, dialstatus) do { \
263         RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
264         extra = ast_json_pack("{s: i, s: s, s: s}", \
265                 "hangupcause", cause, \
266                 "hangupsource", "", \
267                 "dialstatus", dialstatus); \
268         ast_test_validate(test, extra != NULL); \
269         APPEND_EVENT(channel, AST_CEL_HANGUP, NULL, extra); \
270         } while (0)
271
272 static void mid_test_sync(void);
273
274 static int append_expected_event(
275         struct ast_channel *chan,
276         enum ast_cel_event_type type,
277         const char *userdefevname,
278         struct ast_json *extra,
279         const char *peer);
280
281 static int append_expected_event_snapshot(
282         struct ast_channel_snapshot *snapshot,
283         enum ast_cel_event_type type,
284         const char *userdefevname,
285         struct ast_json *extra,
286         const char *peer);
287
288 static int append_dummy_event(void);
289
290 static struct ast_str *__test_cel_generate_peer_str(struct ast_channel_snapshot *chan, struct ast_bridge_snapshot *bridge)
291 {
292         struct ast_str *peer_str = ast_str_create(32);
293         struct ao2_iterator i;
294         char *current_chan = NULL;
295
296         if (!peer_str) {
297                 return NULL;
298         }
299
300         for (i = ao2_iterator_init(bridge->channels, 0);
301                 (current_chan = ao2_iterator_next(&i));
302                 ao2_cleanup(current_chan)) {
303                 RAII_VAR(struct ast_channel_snapshot *, current_snapshot,
304                         NULL,
305                         ao2_cleanup);
306
307                 /* Don't add the channel for which this message is being generated */
308                 if (!strcmp(current_chan, chan->uniqueid)) {
309                         continue;
310                 }
311
312                 current_snapshot = ast_channel_snapshot_get_latest(current_chan);
313                 if (!current_snapshot) {
314                         continue;
315                 }
316
317                 ast_str_append(&peer_str, 0, "%s,", current_snapshot->name);
318         }
319         ao2_iterator_destroy(&i);
320
321         /* Rip off the trailing comma */
322         ast_str_truncate(peer_str, -1);
323
324         return peer_str;
325 }
326
327 static struct ast_str *test_cel_generate_peer_str_snapshot(struct ast_channel_snapshot *chan, struct ast_bridge *bridge)
328 {
329         RAII_VAR(struct ast_bridge_snapshot *, snapshot,
330                 ast_bridge_snapshot_get_latest(bridge->uniqueid),
331                 ao2_cleanup);
332
333         if (!snapshot) {
334                 return NULL;
335         }
336
337         return __test_cel_generate_peer_str(chan, snapshot);
338 }
339
340 static struct ast_str *test_cel_generate_peer_str(struct ast_channel *chan, struct ast_bridge *bridge)
341 {
342         RAII_VAR(struct ast_channel_snapshot *, snapshot,
343                 ast_channel_snapshot_get_latest(ast_channel_uniqueid(chan)),
344                 ao2_cleanup);
345
346         if (!snapshot) {
347                 return NULL;
348         }
349
350         return test_cel_generate_peer_str_snapshot(snapshot, bridge);
351 }
352
353 static void safe_channel_release(struct ast_channel *chan)
354 {
355         if (!chan) {
356                 return;
357         }
358         ast_channel_release(chan);
359 }
360
361 static void safe_bridge_destroy(struct ast_bridge *bridge)
362 {
363         if (!bridge) {
364                 return;
365         }
366         ast_bridge_destroy(bridge, 0);
367 }
368
369 AST_TEST_DEFINE(test_cel_channel_creation)
370 {
371         RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
372         struct ast_party_caller caller = ALICE_CALLERID;
373
374         switch (cmd) {
375         case TEST_INIT:
376                 info->name = __func__;
377                 info->category = TEST_CATEGORY;
378                 info->summary = "Test the CEL records created when a channel is created";
379                 info->description =
380                         "Test the CEL records created when a channel is created";
381                 return AST_TEST_NOT_RUN;
382         case TEST_EXECUTE:
383                 break;
384         }
385
386         CREATE_ALICE_CHANNEL(chan, (&caller));
387
388         HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL, "");
389
390         return AST_TEST_PASS;
391 }
392
393 AST_TEST_DEFINE(test_cel_unanswered_inbound_call)
394 {
395         RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
396         struct ast_party_caller caller = ALICE_CALLERID;
397
398         switch (cmd) {
399         case TEST_INIT:
400                 info->name = __func__;
401                 info->category = TEST_CATEGORY;
402                 info->summary = "Test inbound unanswered calls";
403                 info->description =
404                         "Test CEL records for a call that is\n"
405                         "inbound to Asterisk, executes some dialplan, but\n"
406                         "is never answered.\n";
407                 return AST_TEST_NOT_RUN;
408         case TEST_EXECUTE:
409                 break;
410         }
411
412         CREATE_ALICE_CHANNEL(chan, &caller);
413
414         EMULATE_APP_DATA(chan, 1, "Wait", "1");
415
416         HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL, "");
417
418         return AST_TEST_PASS;
419 }
420
421 AST_TEST_DEFINE(test_cel_unanswered_outbound_call)
422 {
423         RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
424         struct ast_party_caller caller = {
425                         .id.name.str = "",
426                         .id.name.valid = 1,
427                         .id.number.str = "",
428                         .id.number.valid = 1, };
429
430         switch (cmd) {
431         case TEST_INIT:
432                 info->name = __func__;
433                 info->category = TEST_CATEGORY;
434                 info->summary = "Test outbound unanswered calls";
435                 info->description =
436                         "Test CEL records for a call that is\n"
437                         "outbound to Asterisk but is never answered.\n";
438                 return AST_TEST_NOT_RUN;
439         case TEST_EXECUTE:
440                 break;
441         }
442
443         CREATE_ALICE_CHANNEL(chan, &caller);
444
445         ast_channel_exten_set(chan, "s");
446         ast_channel_context_set(chan, "default");
447         ast_set_flag(ast_channel_flags(chan), AST_FLAG_ORIGINATED);
448         EMULATE_APP_DATA(chan, 0, "AppDial", "(Outgoing Line)");
449         HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL, "");
450
451         return AST_TEST_PASS;
452 }
453
454 AST_TEST_DEFINE(test_cel_single_party)
455 {
456         RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
457         struct ast_party_caller caller = ALICE_CALLERID;
458
459         switch (cmd) {
460         case TEST_INIT:
461                 info->name = __func__;
462                 info->category = TEST_CATEGORY;
463                 info->summary = "Test CEL for a single party";
464                 info->description =
465                         "Test CEL records for a call that is\n"
466                         "answered, but only involves a single channel\n";
467                 return AST_TEST_NOT_RUN;
468         case TEST_EXECUTE:
469                 break;
470         }
471         CREATE_ALICE_CHANNEL(chan, &caller);
472
473         ANSWER_CHANNEL(chan);
474         EMULATE_APP_DATA(chan, 2, "VoiceMailMain", "1");
475
476         HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL, "");
477
478         return AST_TEST_PASS;
479 }
480
481 AST_TEST_DEFINE(test_cel_single_bridge)
482 {
483         RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
484         RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
485
486         struct ast_party_caller caller = ALICE_CALLERID;
487
488         switch (cmd) {
489         case TEST_INIT:
490                 info->name = __func__;
491                 info->category = TEST_CATEGORY;
492                 info->summary = "Test CEL for a single party entering/leaving a bridge";
493                 info->description =
494                         "Test CEL records for a call that is\n"
495                         "answered, enters a bridge, and leaves it.\n";
496                 return AST_TEST_NOT_RUN;
497         case TEST_EXECUTE:
498                 break;
499         }
500         bridge = ast_bridge_basic_new();
501         ast_test_validate(test, bridge != NULL);
502
503         CREATE_ALICE_CHANNEL(chan, &caller);
504
505         ANSWER_CHANNEL(chan);
506         EMULATE_APP_DATA(chan, 2, "Bridge", "");
507
508         do_sleep();
509         BRIDGE_ENTER(chan, bridge);
510
511         do_sleep();
512
513         BRIDGE_EXIT(chan, bridge);
514
515         HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL, "");
516
517         return AST_TEST_PASS;
518 }
519
520 AST_TEST_DEFINE(test_cel_single_bridge_continue)
521 {
522         RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
523         RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
524         struct ast_party_caller caller = ALICE_CALLERID;
525
526         switch (cmd) {
527         case TEST_INIT:
528                 info->name = __func__;
529                 info->category = TEST_CATEGORY;
530                 info->summary = "Test CEL for a single party entering/leaving a bridge";
531                 info->description =
532                         "Test CEL records for a call that is\n"
533                         "answered, enters a bridge, and leaves it.\n";
534                 return AST_TEST_NOT_RUN;
535         case TEST_EXECUTE:
536                 break;
537         }
538         bridge = ast_bridge_basic_new();
539         ast_test_validate(test, bridge != NULL);
540
541         CREATE_ALICE_CHANNEL(chan, &caller);
542
543         ANSWER_CHANNEL(chan);
544         EMULATE_APP_DATA(chan, 2, "Bridge", "");
545
546         do_sleep();
547         BRIDGE_ENTER(chan, bridge);
548
549         do_sleep();
550
551         BRIDGE_EXIT(chan, bridge);
552
553         EMULATE_APP_DATA(chan, 3, "Wait", "");
554
555         /* And then it hangs up */
556         HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL, "");
557
558         return AST_TEST_PASS;
559 }
560
561 AST_TEST_DEFINE(test_cel_single_twoparty_bridge_a)
562 {
563         RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
564         RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
565         RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
566         struct ast_party_caller caller_alice = ALICE_CALLERID;
567         struct ast_party_caller caller_bob = BOB_CALLERID;
568
569         switch (cmd) {
570         case TEST_INIT:
571                 info->name = __func__;
572                 info->category = TEST_CATEGORY;
573                 info->summary = "Test CEL for a single party entering/leaving a bridge";
574                 info->description =
575                         "Test CEL records for a call that is\n"
576                         "answered, enters a bridge, and leaves it. In this scenario, the\n"
577                         "Party A should answer the bridge first.\n";
578                 return AST_TEST_NOT_RUN;
579         case TEST_EXECUTE:
580                 break;
581         }
582         bridge = ast_bridge_basic_new();
583         ast_test_validate(test, bridge != NULL);
584
585         CREATE_ALICE_CHANNEL(chan_alice, &caller_alice);
586
587         CREATE_BOB_CHANNEL(chan_bob, &caller_bob);
588
589         ANSWER_CHANNEL(chan_alice);
590         EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
591
592         BRIDGE_ENTER(chan_alice, bridge);
593         do_sleep();
594
595         ANSWER_CHANNEL(chan_bob);
596         EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
597
598         BRIDGE_ENTER(chan_bob, bridge);
599
600         BRIDGE_EXIT(chan_alice, bridge);
601         BRIDGE_EXIT(chan_bob, bridge);
602
603         HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
604         HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
605
606         return AST_TEST_PASS;
607 }
608
609 AST_TEST_DEFINE(test_cel_single_twoparty_bridge_b)
610 {
611         RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
612         RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
613         RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
614         struct ast_party_caller caller_alice = ALICE_CALLERID;
615         struct ast_party_caller caller_bob = BOB_CALLERID;
616
617         switch (cmd) {
618         case TEST_INIT:
619                 info->name = __func__;
620                 info->category = TEST_CATEGORY;
621                 info->summary = "Test CEL for a single party entering/leaving a bridge";
622                 info->description =
623                         "Test CEL records for a call that is\n"
624                         "answered, enters a bridge, and leaves it. In this scenario, the\n"
625                         "Party B should answer the bridge first.\n";
626                 return AST_TEST_NOT_RUN;
627         case TEST_EXECUTE:
628                 break;
629         }
630         bridge = ast_bridge_basic_new();
631         ast_test_validate(test, bridge != NULL);
632
633         CREATE_ALICE_CHANNEL(chan_alice, &caller_alice);
634
635         CREATE_BOB_CHANNEL(chan_bob, &caller_bob);
636
637         ANSWER_CHANNEL(chan_alice);
638         EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
639
640         ANSWER_CHANNEL(chan_bob);
641         EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
642         do_sleep();
643
644         BRIDGE_ENTER(chan_bob, bridge);
645
646         BRIDGE_ENTER(chan_alice, bridge);
647
648         BRIDGE_EXIT(chan_alice, bridge);
649         BRIDGE_EXIT(chan_bob, bridge);
650
651         HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
652         HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
653
654         return AST_TEST_PASS;
655 }
656
657 /* XXX Validation needs to be reworked on a per-channel basis before
658  * test_cel_single_multiparty_bridge and test_cel_dial_answer_multiparty
659  * can operate properly. */
660 #ifdef RACEY_TESTS
661 AST_TEST_DEFINE(test_cel_single_multiparty_bridge)
662 {
663         RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
664         RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
665         RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
666         RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
667         struct ast_party_caller caller_alice = ALICE_CALLERID;
668         struct ast_party_caller caller_bob = BOB_CALLERID;
669         struct ast_party_caller caller_charlie = CHARLIE_CALLERID;
670
671         switch (cmd) {
672         case TEST_INIT:
673                 info->name = __func__;
674                 info->category = TEST_CATEGORY;
675                 info->summary = "Test CEL for a single party entering/leaving a multi-party bridge";
676                 info->description =
677                         "Test CEL records for a call that is\n"
678                         "answered, enters a bridge, and leaves it. A total of three\n"
679                         "parties perform this action.\n";
680                 return AST_TEST_NOT_RUN;
681         case TEST_EXECUTE:
682                 break;
683         }
684         bridge = ast_bridge_basic_new();
685         ast_test_validate(test, bridge != NULL);
686
687         CREATE_ALICE_CHANNEL(chan_alice, &caller_alice);
688         CREATE_BOB_CHANNEL(chan_bob, &caller_bob);
689         CREATE_CHARLIE_CHANNEL(chan_charlie, &caller_charlie);
690
691         ANSWER_CHANNEL(chan_alice);
692         EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
693
694         do_sleep();
695
696         BRIDGE_ENTER(chan_alice, bridge);
697
698         ANSWER_CHANNEL(chan_bob);
699         EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
700         do_sleep();
701
702         BRIDGE_ENTER(chan_bob, bridge);
703
704         ANSWER_CHANNEL(chan_charlie);
705         EMULATE_APP_DATA(chan_charlie, 2, "Bridge", "");
706         do_sleep();
707         BRIDGE_ENTER(chan_charlie, bridge);
708
709         BRIDGE_EXIT(chan_alice, bridge);
710         BRIDGE_EXIT(chan_bob, bridge);
711         BRIDGE_EXIT(chan_charlie, bridge);
712
713         HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
714         HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
715         HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "");
716
717         return AST_TEST_PASS;
718 }
719 #endif
720
721 #define EMULATE_DIAL(channel, dialstring) do { \
722         EMULATE_APP_DATA(channel, 1, "Dial", dialstring); \
723         if (append_expected_event(channel, AST_CEL_APP_START, NULL, NULL, NULL)) { \
724                 return AST_TEST_FAIL; \
725         } \
726         } while (0)
727
728 #define START_DIALED(caller, callee) \
729         START_DIALED_FULL(caller, callee, "200", "Bob")
730
731 #define START_DIALED_FULL(caller, callee, number, name) do { \
732         callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, number, NULL, NULL, NULL, caller, 0, CHANNEL_TECH_NAME "/" name); \
733         ast_channel_unlock(callee); \
734         if (append_expected_event(callee, AST_CEL_CHANNEL_START, NULL, NULL, NULL)) { \
735                 return AST_TEST_FAIL; \
736         } \
737         ast_set_flag(ast_channel_flags(callee), AST_FLAG_OUTGOING); \
738         EMULATE_APP_DATA(callee, 0, "AppDial", "(Outgoing Line)"); \
739         ast_channel_publish_dial(caller, callee, name, NULL); \
740         } while (0)
741
742 AST_TEST_DEFINE(test_cel_dial_unanswered)
743 {
744         RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
745         RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
746         struct ast_party_caller caller = ALICE_CALLERID;
747
748         switch (cmd) {
749         case TEST_INIT:
750                 info->name = __func__;
751                 info->category = TEST_CATEGORY;
752                 info->summary = "Test CEL for a dial that isn't answered";
753                 info->description =
754                         "Test CEL records for a channel that\n"
755                         "performs a dial operation that isn't answered\n";
756                 return AST_TEST_NOT_RUN;
757         case TEST_EXECUTE:
758                 break;
759         }
760
761         CREATE_ALICE_CHANNEL(chan_caller, &caller);
762
763         EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
764
765         START_DIALED(chan_caller, chan_callee);
766
767         ast_channel_state_set(chan_caller, AST_STATE_RINGING);
768         ast_channel_publish_dial(chan_caller, chan_callee, NULL, "NOANSWER");
769
770         HANGUP_CHANNEL(chan_caller, AST_CAUSE_NO_ANSWER, "NOANSWER");
771         HANGUP_CHANNEL(chan_callee, AST_CAUSE_NO_ANSWER, "");
772
773         return AST_TEST_PASS;
774 }
775
776 AST_TEST_DEFINE(test_cel_dial_unanswered_filter)
777 {
778         RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
779         RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
780         struct ast_party_caller caller = ALICE_CALLERID;
781
782         switch (cmd) {
783         case TEST_INIT:
784                 info->name = __func__;
785                 info->category = TEST_CATEGORY;
786                 info->summary = "Test CEL for a dial that isn't answered";
787                 info->description =
788                         "Test CEL records for a channel that\n"
789                         "performs a dial operation that isn't answered\n";
790                 return AST_TEST_NOT_RUN;
791         case TEST_EXECUTE:
792                 break;
793         }
794
795         CREATE_ALICE_CHANNEL(chan_caller, &caller);
796
797         EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
798
799         START_DIALED(chan_caller, chan_callee);
800
801         ast_channel_state_set(chan_caller, AST_STATE_RINGING);
802         ast_channel_publish_dial(chan_caller, chan_callee, NULL, "NOT A VALID DIAL STATUS");
803         ast_channel_publish_dial(chan_caller, chan_callee, NULL, "NOANSWER");
804
805         HANGUP_CHANNEL(chan_caller, AST_CAUSE_NO_ANSWER, "NOANSWER");
806         HANGUP_CHANNEL(chan_callee, AST_CAUSE_NO_ANSWER, "");
807
808         return AST_TEST_PASS;
809 }
810
811 AST_TEST_DEFINE(test_cel_dial_busy)
812 {
813         RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
814         RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
815         struct ast_party_caller caller = ALICE_CALLERID;
816
817         switch (cmd) {
818         case TEST_INIT:
819                 info->name = __func__;
820                 info->category = TEST_CATEGORY;
821                 info->summary = "Test CEL for a dial that results in a busy";
822                 info->description =
823                         "Test CEL records for a channel that\n"
824                         "performs a dial operation to an endpoint that's busy\n";
825                 return AST_TEST_NOT_RUN;
826         case TEST_EXECUTE:
827                 break;
828         }
829
830         CREATE_ALICE_CHANNEL(chan_caller, &caller);
831
832         EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
833
834         START_DIALED(chan_caller, chan_callee);
835
836         ast_channel_state_set(chan_caller, AST_STATE_RINGING);
837         ast_channel_publish_dial(chan_caller, chan_callee, NULL, "BUSY");
838
839         HANGUP_CHANNEL(chan_caller, AST_CAUSE_BUSY, "BUSY");
840         HANGUP_CHANNEL(chan_callee, AST_CAUSE_BUSY, "");
841
842         return AST_TEST_PASS;
843 }
844
845 AST_TEST_DEFINE(test_cel_dial_congestion)
846 {
847         RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
848         RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
849         struct ast_party_caller caller = ALICE_CALLERID;
850
851         switch (cmd) {
852         case TEST_INIT:
853                 info->name = __func__;
854                 info->category = TEST_CATEGORY;
855                 info->summary = "Test CEL for a dial that results in congestion";
856                 info->description =
857                         "Test CEL records for a channel that\n"
858                         "performs a dial operation to an endpoint that's congested\n";
859                 return AST_TEST_NOT_RUN;
860         case TEST_EXECUTE:
861                 break;
862         }
863
864         CREATE_ALICE_CHANNEL(chan_caller, &caller);
865
866         EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
867
868         START_DIALED(chan_caller, chan_callee);
869
870         ast_channel_state_set(chan_caller, AST_STATE_RINGING);
871         ast_channel_publish_dial(chan_caller, chan_callee, NULL, "CONGESTION");
872
873         HANGUP_CHANNEL(chan_caller, AST_CAUSE_CONGESTION, "CONGESTION");
874         HANGUP_CHANNEL(chan_callee, AST_CAUSE_CONGESTION, "");
875
876         return AST_TEST_PASS;
877 }
878
879 AST_TEST_DEFINE(test_cel_dial_unavailable)
880 {
881         RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
882         RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
883         struct ast_party_caller caller = ALICE_CALLERID;
884
885         switch (cmd) {
886         case TEST_INIT:
887                 info->name = __func__;
888                 info->category = TEST_CATEGORY;
889                 info->summary = "Test CEL for a dial that results in unavailable";
890                 info->description =
891                         "Test CEL records for a channel that\n"
892                         "performs a dial operation to an endpoint that's unavailable\n";
893                 return AST_TEST_NOT_RUN;
894         case TEST_EXECUTE:
895                 break;
896         }
897
898         CREATE_ALICE_CHANNEL(chan_caller, &caller);
899
900         EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
901
902         START_DIALED(chan_caller, chan_callee);
903
904         ast_channel_state_set(chan_caller, AST_STATE_RINGING);
905         ast_channel_publish_dial(chan_caller, chan_callee, NULL, "CHANUNAVAIL");
906
907         HANGUP_CHANNEL(chan_caller, AST_CAUSE_NO_ROUTE_DESTINATION, "CHANUNAVAIL");
908         HANGUP_CHANNEL(chan_callee, AST_CAUSE_NO_ROUTE_DESTINATION, "");
909
910         return AST_TEST_PASS;
911 }
912
913 AST_TEST_DEFINE(test_cel_dial_caller_cancel)
914 {
915         RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
916         RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
917         struct ast_party_caller caller = ALICE_CALLERID;
918
919         switch (cmd) {
920         case TEST_INIT:
921                 info->name = __func__;
922                 info->category = TEST_CATEGORY;
923                 info->summary = "Test CEL for a dial where the caller cancels";
924                 info->description =
925                         "Test CEL records for a channel that\n"
926                         "performs a dial operation to an endpoint but then decides\n"
927                         "to hang up, cancelling the dial\n";
928                 return AST_TEST_NOT_RUN;
929         case TEST_EXECUTE:
930                 break;
931         }
932
933         CREATE_ALICE_CHANNEL(chan_caller, &caller);
934
935         EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
936
937         START_DIALED(chan_caller, chan_callee);
938
939         ast_channel_state_set(chan_caller, AST_STATE_RINGING);
940         ast_channel_publish_dial(chan_caller, chan_callee, NULL, "CANCEL");
941
942         HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL, "");
943         HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "CANCEL");
944
945         return AST_TEST_PASS;
946 }
947
948 AST_TEST_DEFINE(test_cel_dial_parallel_failed)
949 {
950         RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
951         RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
952         RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
953         RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
954         struct ast_party_caller caller = ALICE_CALLERID;
955
956         switch (cmd) {
957         case TEST_INIT:
958                 info->name = __func__;
959                 info->category = TEST_CATEGORY;
960                 info->summary = "Test a parallel dial where all channels fail to answer";
961                 info->description =
962                         "This tests dialing three parties: Bob, Charlie, David. Charlie\n"
963                         "returns BUSY; David returns CONGESTION; Bob fails to answer and\n"
964                         "Alice hangs up. Three records are created for Alice as a result.\n";
965                 return AST_TEST_NOT_RUN;
966         case TEST_EXECUTE:
967                 break;
968         }
969
970         CREATE_ALICE_CHANNEL(chan_caller, &caller);
971
972         /* Channel enters Dial app */
973         EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob&" CHANNEL_TECH_NAME "/Charlie&" CHANNEL_TECH_NAME "/David");
974
975         /* Outbound channels are created */
976         START_DIALED_FULL(chan_caller, chan_bob, "200", "Bob");
977         START_DIALED_FULL(chan_caller, chan_charlie, "300", "Charlie");
978         START_DIALED_FULL(chan_caller, chan_david, "400", "David");
979
980         /* Dial starts */
981         ast_channel_state_set(chan_caller, AST_STATE_RINGING);
982
983         /* Charlie is busy */
984         ast_channel_publish_dial(chan_caller, chan_charlie, NULL, "BUSY");
985         HANGUP_CHANNEL(chan_charlie, AST_CAUSE_BUSY, "");
986
987         /* David is congested */
988         ast_channel_publish_dial(chan_caller, chan_david, NULL, "CONGESTION");
989         HANGUP_CHANNEL(chan_david, AST_CAUSE_CONGESTION, "");
990
991         /* Bob is canceled */
992         ast_channel_publish_dial(chan_caller, chan_bob, NULL, "CANCEL");
993         HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
994
995         /* Alice hangs up */
996         HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "BUSY");
997
998         return AST_TEST_PASS;
999 }
1000
1001 AST_TEST_DEFINE(test_cel_dial_answer_no_bridge)
1002 {
1003         RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
1004         RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
1005         struct ast_party_caller caller = ALICE_CALLERID;
1006
1007         switch (cmd) {
1008         case TEST_INIT:
1009                 info->name = __func__;
1010                 info->category = TEST_CATEGORY;
1011                 info->summary = "Test dialing, answering, and not going into a bridge.";
1012                 info->description =
1013                         "This is a weird one, but theoretically possible. You can perform\n"
1014                         "a dial, then bounce both channels to different priorities and\n"
1015                         "never have them enter a bridge together. Ew. This makes sure that\n"
1016                         "when we answer, we get a CEL, it gets ended at that point, and\n"
1017                         "that it gets finalized appropriately.\n";
1018                 return AST_TEST_NOT_RUN;
1019         case TEST_EXECUTE:
1020                 break;
1021         }
1022
1023         CREATE_ALICE_CHANNEL(chan_caller, &caller);
1024
1025         EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
1026
1027         START_DIALED(chan_caller, chan_callee);
1028
1029         ast_channel_state_set(chan_caller, AST_STATE_RINGING);
1030         ast_channel_publish_dial(chan_caller, chan_callee, NULL, "ANSWER");
1031
1032         ANSWER_NO_APP(chan_caller);
1033         ast_clear_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
1034         ANSWER_NO_APP(chan_callee);
1035
1036         EMULATE_APP_DATA(chan_caller, 2, "Wait", "1");
1037         EMULATE_APP_DATA(chan_callee, 1, "Wait", "1");
1038
1039         HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "ANSWER");
1040         HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL, "");
1041
1042         return AST_TEST_PASS;
1043 }
1044
1045 AST_TEST_DEFINE(test_cel_dial_answer_twoparty_bridge_a)
1046 {
1047         RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
1048         RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
1049         RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
1050         struct ast_party_caller caller = ALICE_CALLERID;
1051
1052         switch (cmd) {
1053         case TEST_INIT:
1054                 info->name = __func__;
1055                 info->category = TEST_CATEGORY;
1056                 info->summary = "Test dialing, answering, and going into a 2-party bridge";
1057                 info->description =
1058                         "The most 'basic' of scenarios\n";
1059                 return AST_TEST_NOT_RUN;
1060         case TEST_EXECUTE:
1061                 break;
1062         }
1063         bridge = ast_bridge_basic_new();
1064         ast_test_validate(test, bridge != NULL);
1065
1066         CREATE_ALICE_CHANNEL(chan_caller, &caller);
1067
1068         EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
1069
1070         START_DIALED(chan_caller, chan_callee);
1071
1072         ast_channel_state_set(chan_caller, AST_STATE_RINGING);
1073         ast_channel_publish_dial(chan_caller, chan_callee, NULL, "ANSWER");
1074
1075         ANSWER_NO_APP(chan_caller);
1076         ANSWER_NO_APP(chan_callee);
1077
1078         do_sleep();
1079
1080         BRIDGE_ENTER(chan_caller, bridge);
1081         BRIDGE_ENTER(chan_callee, bridge);
1082
1083         BRIDGE_EXIT(chan_caller, bridge);
1084         BRIDGE_EXIT(chan_callee, bridge);
1085
1086         HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "ANSWER");
1087         HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL, "");
1088
1089         return AST_TEST_PASS;
1090 }
1091
1092 AST_TEST_DEFINE(test_cel_dial_answer_twoparty_bridge_b)
1093 {
1094         RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
1095         RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
1096         RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
1097         struct ast_party_caller caller = ALICE_CALLERID;
1098
1099         switch (cmd) {
1100         case TEST_INIT:
1101                 info->name = __func__;
1102                 info->category = TEST_CATEGORY;
1103                 info->summary = "Test dialing, answering, and going into a 2-party bridge";
1104                 info->description =
1105                         "The most 'basic' of scenarios\n";
1106                 return AST_TEST_NOT_RUN;
1107         case TEST_EXECUTE:
1108                 break;
1109         }
1110         bridge = ast_bridge_basic_new();
1111         ast_test_validate(test, bridge != NULL);
1112
1113         CREATE_ALICE_CHANNEL(chan_caller, &caller);
1114
1115         EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
1116
1117         START_DIALED(chan_caller, chan_callee);
1118
1119         ast_channel_state_set(chan_caller, AST_STATE_RINGING);
1120         ast_channel_publish_dial(chan_caller, chan_callee, NULL, "ANSWER");
1121
1122         ANSWER_NO_APP(chan_caller);
1123         ANSWER_NO_APP(chan_callee);
1124
1125         do_sleep();
1126         BRIDGE_ENTER(chan_callee, bridge);
1127         BRIDGE_ENTER(chan_caller, bridge);
1128
1129         BRIDGE_EXIT(chan_caller, bridge);
1130         BRIDGE_EXIT(chan_callee, bridge);
1131
1132         HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "ANSWER");
1133         HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL, "");
1134
1135         return AST_TEST_PASS;
1136 }
1137
1138 #ifdef RACEY_TESTS
1139 AST_TEST_DEFINE(test_cel_dial_answer_multiparty)
1140 {
1141         RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
1142         RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
1143         RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
1144         RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
1145         RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
1146         struct ast_party_caller alice_caller = ALICE_CALLERID;
1147         struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
1148
1149         switch (cmd) {
1150         case TEST_INIT:
1151                 info->name = __func__;
1152                 info->category = TEST_CATEGORY;
1153                 info->summary = "Test dialing, answering, and going into a multi-party bridge";
1154                 info->description =
1155                         "A little tricky to get to do, but possible with some redirects.\n";
1156                 return AST_TEST_NOT_RUN;
1157         case TEST_EXECUTE:
1158                 break;
1159         }
1160         bridge = ast_bridge_basic_new();
1161         ast_test_validate(test, bridge != NULL);
1162
1163         CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
1164
1165         EMULATE_DIAL(chan_alice, CHANNEL_TECH_NAME "/Bob");
1166
1167         START_DIALED(chan_alice, chan_bob);
1168         do_sleep();
1169
1170         CREATE_CHARLIE_CHANNEL(chan_charlie, &charlie_caller);
1171         do_sleep();
1172         EMULATE_DIAL(chan_charlie, CHANNEL_TECH_NAME "/Bob");
1173         do_sleep();
1174
1175         START_DIALED_FULL(chan_charlie, chan_david, "400", "David");
1176
1177         ast_channel_state_set(chan_alice, AST_STATE_RINGING);
1178         do_sleep();
1179         ast_channel_state_set(chan_charlie, AST_STATE_RINGING);
1180         do_sleep();
1181         ast_channel_publish_dial(chan_alice, chan_bob, NULL, "ANSWER");
1182         do_sleep();
1183         ast_channel_publish_dial(chan_charlie, chan_david, NULL, "ANSWER");
1184         do_sleep();
1185
1186         ANSWER_NO_APP(chan_alice);
1187         do_sleep();
1188         ANSWER_NO_APP(chan_bob);
1189         do_sleep();
1190         ANSWER_NO_APP(chan_charlie);
1191         do_sleep();
1192         ANSWER_NO_APP(chan_david);
1193         do_sleep();
1194
1195         do_sleep();
1196         BRIDGE_ENTER(chan_charlie, bridge);
1197         BRIDGE_ENTER(chan_david, bridge);
1198         BRIDGE_ENTER(chan_bob, bridge);
1199         BRIDGE_ENTER(chan_alice, bridge);
1200
1201         BRIDGE_EXIT(chan_alice, bridge);
1202         BRIDGE_EXIT(chan_bob, bridge);
1203         BRIDGE_EXIT(chan_charlie, bridge);
1204         BRIDGE_EXIT(chan_david, bridge);
1205
1206         HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "ANSWER");
1207         HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
1208         HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "ANSWER");
1209         HANGUP_CHANNEL(chan_david, AST_CAUSE_NORMAL, "");
1210
1211         return AST_TEST_PASS;
1212 }
1213 #endif
1214
1215 AST_TEST_DEFINE(test_cel_blind_transfer)
1216 {
1217         RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
1218         RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
1219         RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
1220         struct ast_party_caller alice_caller = ALICE_CALLERID;
1221         struct ast_party_caller bob_caller = BOB_CALLERID;
1222         struct ast_bridge_channel_pair pair;
1223
1224         switch (cmd) {
1225         case TEST_INIT:
1226                 info->name = __func__;
1227                 info->category = TEST_CATEGORY;
1228                 info->summary = "Test blind transfers to an extension";
1229                 info->description =
1230                         "This test creates two channels, bridges them, and then"
1231                         " blind transfers the bridge to an extension.\n";
1232                 return AST_TEST_NOT_RUN;
1233         case TEST_EXECUTE:
1234                 break;
1235         }
1236         bridge = ast_bridge_basic_new();
1237         ast_test_validate(test, bridge != NULL);
1238
1239         CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
1240         CREATE_BOB_CHANNEL(chan_bob, &bob_caller);
1241
1242         ANSWER_NO_APP(chan_alice);
1243         ANSWER_NO_APP(chan_bob);
1244
1245         BRIDGE_ENTER(chan_bob, bridge);
1246         BRIDGE_ENTER(chan_alice, bridge);
1247
1248         pair.bridge = bridge;
1249         pair.channel = chan_alice;
1250         ast_bridge_lock(bridge);
1251         ast_bridge_publish_blind_transfer(1, AST_BRIDGE_TRANSFER_SUCCESS,
1252                 &pair, "transfer_context", "transfer_extension");
1253         ast_bridge_unlock(bridge);
1254         BLINDTRANSFER_EVENT(chan_alice, bridge, "transfer_extension", "transfer_context");
1255
1256         BRIDGE_EXIT(chan_alice, bridge);
1257         BRIDGE_EXIT(chan_bob, bridge);
1258
1259         HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
1260         do_sleep();
1261         HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
1262
1263         return AST_TEST_PASS;
1264 }
1265
1266 AST_TEST_DEFINE(test_cel_attended_transfer_bridges_swap)
1267 {
1268         RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
1269         RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
1270         RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
1271         RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
1272         RAII_VAR(struct ast_bridge *, bridge1, NULL, safe_bridge_destroy);
1273         RAII_VAR(struct ast_bridge *, bridge2, NULL, safe_bridge_destroy);
1274         struct ast_party_caller alice_caller = ALICE_CALLERID;
1275         struct ast_party_caller bob_caller = BOB_CALLERID;
1276         struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
1277         struct ast_party_caller david_caller = ALICE_CALLERID;
1278
1279         switch (cmd) {
1280         case TEST_INIT:
1281                 info->name = __func__;
1282                 info->category = TEST_CATEGORY;
1283                 info->summary = "Test attended transfers between two pairs of bridged parties";
1284                 info->description =
1285                         "This test creates four channels, places each pair in"
1286                         " a bridge, and then attended transfers the bridges"
1287                         " together.\n";
1288                 return AST_TEST_NOT_RUN;
1289         case TEST_EXECUTE:
1290                 break;
1291         }
1292         /* Create first set of bridged parties */
1293         bridge1 = ast_bridge_basic_new();
1294         ast_test_validate(test, bridge1 != NULL);
1295
1296         CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
1297         CREATE_BOB_CHANNEL(chan_bob, &bob_caller);
1298         ANSWER_NO_APP(chan_alice);
1299         ANSWER_NO_APP(chan_bob);
1300
1301         BRIDGE_ENTER(chan_bob, bridge1);
1302         BRIDGE_ENTER(chan_alice, bridge1);
1303
1304         /* Create second set of bridged parties */
1305         bridge2 = ast_bridge_basic_new();
1306         ast_test_validate(test, bridge2 != NULL);
1307
1308         CREATE_DAVID_CHANNEL(chan_david, &david_caller);
1309         CREATE_CHARLIE_CHANNEL(chan_charlie, &charlie_caller);
1310         ANSWER_NO_APP(chan_david);
1311         ANSWER_NO_APP(chan_charlie);
1312
1313         BRIDGE_ENTER(chan_charlie, bridge2);
1314
1315         BRIDGE_ENTER(chan_david, bridge2);
1316         BRIDGE_EXIT_EVENT(chan_bob, bridge1);
1317         do_sleep();
1318
1319         /* Perform attended transfer */
1320         ast_bridge_transfer_attended(chan_alice, chan_david);
1321         do_sleep();
1322         BRIDGE_ENTER_EVENT_PEER(chan_bob, bridge2, "CELTestChannel/David,CELTestChannel/Charlie");
1323
1324         BRIDGE_EXIT_EVENT(chan_david, bridge2);
1325         ATTENDEDTRANSFER_BRIDGE(chan_alice, bridge1, chan_david, bridge2);
1326         BRIDGE_EXIT_EVENT(chan_alice, bridge1);
1327
1328         do_sleep();
1329         BRIDGE_EXIT(chan_bob, bridge2);
1330         BRIDGE_EXIT(chan_charlie, bridge2);
1331
1332         HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
1333         do_sleep();
1334         HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
1335         do_sleep();
1336         HANGUP_CHANNEL(chan_david, AST_CAUSE_NORMAL, "");
1337         do_sleep();
1338         HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "");
1339
1340         return AST_TEST_PASS;
1341 }
1342
1343 AST_TEST_DEFINE(test_cel_attended_transfer_bridges_merge)
1344 {
1345         RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
1346         RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
1347         RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
1348         RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
1349         RAII_VAR(struct ast_bridge *, bridge1, NULL, safe_bridge_destroy);
1350         RAII_VAR(struct ast_bridge *, bridge2, NULL, safe_bridge_destroy);
1351         struct ast_party_caller alice_caller = ALICE_CALLERID;
1352         struct ast_party_caller bob_caller = BOB_CALLERID;
1353         struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
1354         struct ast_party_caller david_caller = ALICE_CALLERID;
1355
1356         switch (cmd) {
1357         case TEST_INIT:
1358                 info->name = __func__;
1359                 info->category = TEST_CATEGORY;
1360                 info->summary = "Test attended transfers between two pairs of"
1361                         " bridged parties that results in a bridge merge";
1362                 info->description =
1363                         "This test creates four channels, places each pair"
1364                         " in a bridge, and then attended transfers the bridges"
1365                         " together causing a bridge merge.\n";
1366                 return AST_TEST_NOT_RUN;
1367         case TEST_EXECUTE:
1368                 break;
1369         }
1370         /* Create first set of bridged parties */
1371         bridge1 = ast_bridge_base_new(AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_NATIVE | AST_BRIDGE_CAPABILITY_MULTIMIX,
1372                 AST_BRIDGE_FLAG_SWAP_INHIBIT_FROM | AST_BRIDGE_FLAG_TRANSFER_PROHIBITED | AST_BRIDGE_FLAG_SMART,
1373                 "test_cel", "test_cel_atxfer_bridges_merge_1", NULL);
1374         ast_test_validate(test, bridge1 != NULL);
1375
1376         CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
1377         CREATE_BOB_CHANNEL(chan_bob, &bob_caller);
1378         ANSWER_NO_APP(chan_alice);
1379         ANSWER_NO_APP(chan_bob);
1380
1381         BRIDGE_ENTER(chan_bob, bridge1);
1382         BRIDGE_ENTER(chan_alice, bridge1);
1383
1384         /* Create second set of bridged parties */
1385         bridge2 = ast_bridge_base_new(AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_NATIVE | AST_BRIDGE_CAPABILITY_MULTIMIX,
1386                 AST_BRIDGE_FLAG_SWAP_INHIBIT_FROM | AST_BRIDGE_FLAG_TRANSFER_PROHIBITED | AST_BRIDGE_FLAG_SMART,
1387                 "test_cel", "test_cel_atxfer_bridges_merge_2", NULL);
1388         ast_test_validate(test, bridge2 != NULL);
1389
1390         CREATE_DAVID_CHANNEL(chan_david, &david_caller);
1391         CREATE_CHARLIE_CHANNEL(chan_charlie, &charlie_caller);
1392         ANSWER_NO_APP(chan_david);
1393         ANSWER_NO_APP(chan_charlie);
1394
1395         BRIDGE_ENTER(chan_charlie, bridge2);
1396
1397         BRIDGE_ENTER(chan_david, bridge2);
1398
1399         /* Perform attended transfer */
1400         ast_bridge_transfer_attended(chan_alice, chan_david);
1401         do_sleep();
1402         BRIDGE_EXIT_EVENT_PEER(chan_charlie, bridge2, "CELTestChannel/David");
1403         BRIDGE_ENTER_EVENT_PEER(chan_charlie, bridge1, "CELTestChannel/Bob,CELTestChannel/Alice");
1404         BRIDGE_EXIT_EVENT(chan_david, bridge2);
1405         BRIDGE_EXIT_EVENT(chan_alice, bridge1);
1406
1407         ATTENDEDTRANSFER_BRIDGE(chan_alice, bridge1, chan_david, bridge2);
1408
1409         do_sleep();
1410         BRIDGE_EXIT(chan_bob, bridge1);
1411         BRIDGE_EXIT(chan_charlie, bridge1);
1412
1413         HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
1414         do_sleep();
1415         HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
1416         do_sleep();
1417         HANGUP_CHANNEL(chan_david, AST_CAUSE_NORMAL, "");
1418         do_sleep();
1419         HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "");
1420
1421         return AST_TEST_PASS;
1422 }
1423
1424 AST_TEST_DEFINE(test_cel_attended_transfer_bridges_link)
1425 {
1426         RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
1427         RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
1428         RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
1429         RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
1430         RAII_VAR(struct ast_bridge *, bridge1, NULL, safe_bridge_destroy);
1431         RAII_VAR(struct ast_bridge *, bridge2, NULL, safe_bridge_destroy);
1432         struct ast_party_caller alice_caller = ALICE_CALLERID;
1433         struct ast_party_caller bob_caller = BOB_CALLERID;
1434         struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
1435         struct ast_party_caller david_caller = ALICE_CALLERID;
1436
1437         switch (cmd) {
1438         case TEST_INIT:
1439                 info->name = __func__;
1440                 info->category = TEST_CATEGORY;
1441                 info->summary = "Test attended transfers between two pairs of"
1442                         " bridged parties that results in a bridge merge";
1443                 info->description =
1444                         "This test creates four channels, places each pair"
1445                         " in a bridge, and then attended transfers the bridges"
1446                         " together causing a bridge link.\n";
1447                 return AST_TEST_NOT_RUN;
1448         case TEST_EXECUTE:
1449                 break;
1450         }
1451         /* Create first set of bridged parties */
1452         bridge1 = ast_bridge_base_new(AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_NATIVE | AST_BRIDGE_CAPABILITY_MULTIMIX,
1453                 AST_BRIDGE_FLAG_MERGE_INHIBIT_TO | AST_BRIDGE_FLAG_MERGE_INHIBIT_FROM
1454                 | AST_BRIDGE_FLAG_SWAP_INHIBIT_TO | AST_BRIDGE_FLAG_SWAP_INHIBIT_FROM
1455                 | AST_BRIDGE_FLAG_TRANSFER_PROHIBITED | AST_BRIDGE_FLAG_SMART,
1456                 "test_cel", "test_cel_atxfer_bridges_link_1", NULL);
1457         ast_test_validate(test, bridge1 != NULL);
1458
1459         CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
1460         CREATE_BOB_CHANNEL(chan_bob, &bob_caller);
1461         ANSWER_NO_APP(chan_alice);
1462         ANSWER_NO_APP(chan_bob);
1463
1464         BRIDGE_ENTER(chan_bob, bridge1);
1465         BRIDGE_ENTER(chan_alice, bridge1);
1466
1467         /* Create second set of bridged parties */
1468         bridge2 = ast_bridge_base_new(AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_NATIVE | AST_BRIDGE_CAPABILITY_MULTIMIX,
1469                 AST_BRIDGE_FLAG_MERGE_INHIBIT_TO | AST_BRIDGE_FLAG_MERGE_INHIBIT_FROM
1470                 | AST_BRIDGE_FLAG_SWAP_INHIBIT_TO | AST_BRIDGE_FLAG_SWAP_INHIBIT_FROM
1471                 | AST_BRIDGE_FLAG_TRANSFER_PROHIBITED | AST_BRIDGE_FLAG_SMART,
1472                 "test_cel", "test_cel_atxfer_bridges_link_2", NULL);
1473         ast_test_validate(test, bridge2 != NULL);
1474
1475         CREATE_DAVID_CHANNEL(chan_david, &david_caller);
1476         CREATE_CHARLIE_CHANNEL(chan_charlie, &charlie_caller);
1477         ANSWER_NO_APP(chan_david);
1478         ANSWER_NO_APP(chan_charlie);
1479
1480         BRIDGE_ENTER(chan_charlie, bridge2);
1481         BRIDGE_ENTER(chan_david, bridge2);
1482
1483         /* Perform attended transfer */
1484
1485         /* The following events can not be matched directly since nothing is known
1486          * about the linking local channel.
1487          * ;1 and ;2 CHAN_START and ;2 ANSWER */
1488         APPEND_DUMMY_EVENT();
1489         APPEND_DUMMY_EVENT();
1490         APPEND_DUMMY_EVENT();
1491
1492         ATTENDEDTRANSFER_BRIDGE(chan_alice, bridge1, chan_david, bridge2);
1493
1494         ast_bridge_transfer_attended(chan_alice, chan_david);
1495         do_sleep();
1496
1497         /* ;1 and ;2 BRIDGE_ENTER and ;1 ANSWER */
1498         APPEND_DUMMY_EVENT();
1499         APPEND_DUMMY_EVENT();
1500         APPEND_DUMMY_EVENT();
1501
1502         /* BRIDGE_EXIT alice and david */
1503         APPEND_DUMMY_EVENT();
1504         APPEND_DUMMY_EVENT();
1505
1506         do_sleep();
1507         BRIDGE_EXIT(chan_bob, bridge1);
1508         BRIDGE_EXIT(chan_charlie, bridge2);
1509
1510         HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
1511         do_sleep();
1512         HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
1513         do_sleep();
1514         HANGUP_CHANNEL(chan_david, AST_CAUSE_NORMAL, "");
1515         do_sleep();
1516         HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "");
1517         do_sleep();
1518
1519         /* ;1 and ;2 BRIDGE_EXIT, HANGUP, and CHAN_END */
1520         APPEND_DUMMY_EVENT();
1521         APPEND_DUMMY_EVENT();
1522         APPEND_DUMMY_EVENT();
1523         APPEND_DUMMY_EVENT();
1524         APPEND_DUMMY_EVENT();
1525         APPEND_DUMMY_EVENT();
1526
1527         return AST_TEST_PASS;
1528 }
1529
1530 AST_TEST_DEFINE(test_cel_dial_pickup)
1531 {
1532         RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
1533         RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
1534         RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
1535         struct ast_party_caller caller = ALICE_CALLERID;
1536         struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
1537
1538         switch (cmd) {
1539         case TEST_INIT:
1540                 info->name = __func__;
1541                 info->category = TEST_CATEGORY;
1542                 info->summary = "Test call pickup";
1543                 info->description =
1544                         "Test CEL records for a call that is\n"
1545                         "inbound to Asterisk, executes some dialplan, and\n"
1546                         "is picked up.\n";
1547                 return AST_TEST_NOT_RUN;
1548         case TEST_EXECUTE:
1549                 break;
1550         }
1551
1552         CREATE_ALICE_CHANNEL(chan_caller, &caller);
1553
1554         EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
1555
1556         START_DIALED(chan_caller, chan_callee);
1557
1558         ast_channel_state_set(chan_caller, AST_STATE_RINGING);
1559
1560         CREATE_CHARLIE_CHANNEL(chan_charlie, &charlie_caller);
1561
1562         {
1563                 RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref);
1564                 SCOPED_CHANNELLOCK(lock, chan_callee);
1565
1566                 extra = ast_json_pack("{s: s}", "pickup_channel", ast_channel_name(chan_charlie));
1567                 ast_test_validate(test, extra != NULL);
1568
1569                 APPEND_EVENT(chan_callee, AST_CEL_PICKUP, NULL, extra);
1570                 ast_test_validate(test, !ast_do_pickup(chan_charlie, chan_callee));
1571         }
1572
1573         /* Hang up the masqueraded zombie */
1574         HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "");
1575
1576         ast_channel_publish_dial(chan_caller, chan_callee, NULL, "ANSWER");
1577
1578         HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "ANSWER");
1579         HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL, "");
1580
1581         return AST_TEST_PASS;
1582 }
1583
1584 AST_TEST_DEFINE(test_cel_local_optimize)
1585 {
1586         RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
1587         RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
1588         struct ast_party_caller alice_caller = ALICE_CALLERID;
1589         struct ast_party_caller bob_caller = BOB_CALLERID;
1590         RAII_VAR(struct ast_multi_channel_blob *, mc_blob, NULL, ao2_cleanup);
1591         RAII_VAR(struct ast_channel_snapshot *, alice_snapshot, NULL, ao2_cleanup);
1592         RAII_VAR(struct ast_channel_snapshot *, bob_snapshot, NULL, ao2_cleanup);
1593         RAII_VAR(struct stasis_message *, local_opt_begin, NULL, ao2_cleanup);
1594         RAII_VAR(struct stasis_message *, local_opt_end, NULL, ao2_cleanup);
1595         RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref);
1596
1597         switch (cmd) {
1598         case TEST_INIT:
1599                 info->name = __func__;
1600                 info->category = TEST_CATEGORY;
1601                 info->summary = "Test local channel optimization record generation";
1602                 info->description =
1603                         "Test CEL records for two local channels being optimized\n"
1604                         "out by sending a messages indicating local optimization\n"
1605                         "begin and end\n";
1606                 return AST_TEST_NOT_RUN;
1607         case TEST_EXECUTE:
1608                 break;
1609         }
1610
1611         mc_blob = ast_multi_channel_blob_create(ast_json_null());
1612         ast_test_validate(test, mc_blob != NULL);
1613
1614         CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
1615         CREATE_BOB_CHANNEL(chan_bob, &bob_caller);
1616
1617         ast_channel_lock(chan_alice);
1618         alice_snapshot = ast_channel_snapshot_create(chan_alice);
1619         ast_channel_unlock(chan_alice);
1620         ast_test_validate(test, alice_snapshot != NULL);
1621
1622         ast_channel_lock(chan_bob);
1623         bob_snapshot = ast_channel_snapshot_create(chan_bob);
1624         ast_channel_unlock(chan_bob);
1625         ast_test_validate(test, bob_snapshot != NULL);
1626
1627         ast_multi_channel_blob_add_channel(mc_blob, "1", alice_snapshot);
1628         ast_multi_channel_blob_add_channel(mc_blob, "2", bob_snapshot);
1629
1630         local_opt_begin = stasis_message_create(ast_local_optimization_begin_type(), mc_blob);
1631         ast_test_validate(test, local_opt_begin != NULL);
1632
1633         local_opt_end = stasis_message_create(ast_local_optimization_end_type(), mc_blob);
1634         ast_test_validate(test, local_opt_end != NULL);
1635
1636         stasis_publish(ast_channel_topic(chan_alice), local_opt_begin);
1637         stasis_publish(ast_channel_topic(chan_alice), local_opt_end);
1638
1639         extra = ast_json_pack("{s: s}", "local_two", bob_snapshot->name);
1640         ast_test_validate(test, extra != NULL);
1641
1642         APPEND_EVENT_SNAPSHOT(alice_snapshot, AST_CEL_LOCAL_OPTIMIZE, NULL, extra, NULL);
1643
1644         HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
1645         HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
1646
1647         return AST_TEST_PASS;
1648 }
1649
1650 /*! Container for astobj2 duplicated ast_events */
1651 static struct ao2_container *cel_received_events = NULL;
1652
1653 /*! Container for expected CEL events */
1654 static struct ao2_container *cel_expected_events = NULL;
1655
1656 static struct ast_event *ao2_dup_event(const struct ast_event *event)
1657 {
1658         struct ast_event *event_dup;
1659         uint16_t event_len;
1660
1661         event_len = ast_event_get_size(event);
1662
1663         event_dup = ao2_alloc(event_len, NULL);
1664         if (!event_dup) {
1665                 return NULL;
1666         }
1667
1668         memcpy(event_dup, event, event_len);
1669
1670         return event_dup;
1671 }
1672
1673 static void mid_test_sync(void)
1674 {
1675         ast_mutex_lock(&mid_test_sync_lock);
1676         if (ao2_container_count(cel_expected_events) <= ao2_container_count(cel_received_events)) {
1677                 ast_mutex_unlock(&mid_test_sync_lock);
1678                 return;
1679         }
1680
1681         do_mid_test_sync = 1;
1682         ast_mutex_unlock(&mid_test_sync_lock);
1683
1684         {
1685                 struct timeval start = ast_tvnow();
1686                 struct timespec end = {
1687                         .tv_sec = start.tv_sec + 15,
1688                         .tv_nsec = start.tv_usec * 1000
1689                 };
1690
1691                 SCOPED_MUTEX(lock, &sync_lock);
1692                 ast_cond_timedwait(&sync_out, &sync_lock, &end);
1693         }
1694 }
1695
1696 static int append_event(struct ast_event *ev)
1697 {
1698         RAII_VAR(struct ast_event *, ao2_ev, NULL, ao2_cleanup);
1699         ao2_ev = ao2_dup_event(ev);
1700         if (!ao2_ev) {
1701                 return -1;
1702         }
1703
1704         ao2_link(cel_expected_events, ao2_ev);
1705         return 0;
1706 }
1707
1708 static int append_dummy_event(void)
1709 {
1710         RAII_VAR(struct ast_event *, ev, NULL, ast_free);
1711         RAII_VAR(struct ast_event *, ao2_ev, NULL, ao2_cleanup);
1712
1713         ev = ast_event_new(AST_EVENT_CUSTOM, AST_EVENT_IE_END);
1714         if (!ev) {
1715                 return -1;
1716         }
1717
1718         return append_event(ev);
1719 }
1720
1721 static int append_expected_event_snapshot(
1722         struct ast_channel_snapshot *snapshot,
1723         enum ast_cel_event_type type,
1724         const char *userdefevname,
1725         struct ast_json *extra,
1726         const char *peer)
1727 {
1728         RAII_VAR(struct ast_event *, ev, NULL, ast_free);
1729         ev = ast_cel_create_event(snapshot, type, userdefevname, extra, peer);
1730         if (!ev) {
1731                 return -1;
1732         }
1733
1734         return append_event(ev);
1735 }
1736
1737 static int append_expected_event(
1738         struct ast_channel *chan,
1739         enum ast_cel_event_type type,
1740         const char *userdefevname,
1741         struct ast_json *extra,
1742         const char *peer)
1743 {
1744         RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
1745         ast_channel_lock(chan);
1746         snapshot = ast_channel_snapshot_create(chan);
1747         ast_channel_unlock(chan);
1748         if (!snapshot) {
1749                 return -1;
1750         }
1751
1752         return append_expected_event_snapshot(snapshot, type, userdefevname, extra, peer);
1753 }
1754
1755 static void test_sub(struct ast_event *event)
1756 {
1757         struct ast_event *event_dup = ao2_dup_event(event);
1758         SCOPED_MUTEX(mid_test_lock, &mid_test_sync_lock);
1759
1760         if (!event_dup) {
1761                 return;
1762         }
1763
1764         /* save the event for later processing */
1765         ao2_link(cel_received_events, event_dup);
1766
1767         if (do_mid_test_sync) {
1768                 int expected = ao2_container_count(cel_expected_events);
1769                 int received = ao2_container_count(cel_received_events);
1770                 if (expected <= received) {
1771                         {
1772                         SCOPED_MUTEX(lock, &sync_lock);
1773                         ast_cond_signal(&sync_out);
1774                         do_mid_test_sync = 0;
1775                         }
1776                 }
1777         }
1778 }
1779
1780 /*!
1781  * \internal
1782  * \brief Callback function called before each test executes
1783  */
1784 static int test_cel_init_cb(struct ast_test_info *info, struct ast_test *test)
1785 {
1786         ast_assert(cel_received_events == NULL);
1787         ast_assert(cel_expected_events == NULL);
1788
1789         ast_mutex_init(&mid_test_sync_lock);
1790         ast_mutex_init(&sync_lock);
1791         ast_cond_init(&sync_out, NULL);
1792
1793         /* Back up the real CEL config and insert the test's config */
1794         saved_config = ast_cel_get_config();
1795         ast_cel_set_config(cel_test_config);
1796
1797         /* init CEL event storage (degenerate hash table becomes a linked list) */
1798         cel_received_events = ao2_container_alloc(1, NULL, NULL);
1799         cel_expected_events = ao2_container_alloc(1, NULL, NULL);
1800
1801         /* start the CEL event callback */
1802         if (ast_cel_backend_register(TEST_BACKEND_NAME, test_sub)) {
1803                 return -1;
1804         }
1805         return 0;
1806 }
1807
1808 /*!
1809  * \brief Check two peer strings for equality
1810  *
1811  * \retval zero if the peer strings do not match
1812  * \retval non-zero if the peer strings match
1813  */
1814 static int test_cel_peer_strings_match(const char *str1, const char *str2)
1815 {
1816         struct ao2_container *intersection = ast_str_container_alloc(11);
1817         RAII_VAR(char *, str1_dup, ast_strdup(str1), ast_free);
1818         RAII_VAR(char *, str2_dup, ast_strdup(str2), ast_free);
1819         char *chan;
1820
1821         while ((chan = strsep(&str1_dup, ","))) {
1822                 ast_str_container_add(intersection, chan);
1823         }
1824
1825         while ((chan = strsep(&str2_dup, ","))) {
1826                 RAII_VAR(char *, ao2_chan, ao2_find(intersection, chan, OBJ_SEARCH_KEY), ao2_cleanup);
1827
1828                 /* item in str2 not in str1 */
1829                 if (!ao2_chan) {
1830                         return 0;
1831                 }
1832
1833                 ast_str_container_remove(intersection, chan);
1834         }
1835
1836         /* item in str1 not in str2 */
1837         if (ao2_container_count(intersection)) {
1838                 return 0;
1839         }
1840
1841         return 1;
1842 }
1843
1844 /*!
1845  * \brief Check an IE value from two events
1846  *
1847  * \retval zero if the IEs in the events of the specified type do not match
1848  * \retval non-zero if the IEs in the events of the specified type match
1849  */
1850 static int match_ie_val(
1851         const struct ast_event *event1,
1852         const struct ast_event *event2,
1853         enum ast_event_ie_type type)
1854 {
1855         enum ast_event_ie_pltype pltype = ast_event_get_ie_pltype(type);
1856
1857         /* XXX ignore sec/usec for now */
1858         if (type == AST_EVENT_IE_CEL_EVENT_TIME_USEC) {
1859                 return 1;
1860         }
1861
1862         if (type == AST_EVENT_IE_CEL_EVENT_TIME) {
1863                 return 1;
1864         }
1865
1866         switch (pltype) {
1867         case AST_EVENT_IE_PLTYPE_UINT:
1868         {
1869                 uint32_t val = ast_event_get_ie_uint(event2, type);
1870
1871                 return (val == ast_event_get_ie_uint(event1, type)) ? 1 : 0;
1872         }
1873         case AST_EVENT_IE_PLTYPE_STR:
1874         {
1875                 const char *str1 = ast_event_get_ie_str(event1, type);
1876                 const char *str2 = ast_event_get_ie_str(event2, type);
1877
1878                 if (!str1 && !str2) {
1879                         return 1;
1880                 } else if (!str1) {
1881                         return 0;
1882                 } else if (!str2) {
1883                         return 0;
1884                 }
1885
1886                 /* use special matching for CEL PEER field */
1887                 if (type == AST_EVENT_IE_CEL_PEER) {
1888                         return test_cel_peer_strings_match(str1, str2);
1889                 }
1890
1891                 return !strcmp(str1, str2);
1892         }
1893         case AST_EVENT_IE_PLTYPE_RAW:
1894         case AST_EVENT_IE_PLTYPE_BITFLAGS:
1895                 /* Fall through: just pass on these types */
1896                 return 1;
1897         default:
1898                 break;
1899         }
1900         return 0;
1901 }
1902
1903 static int events_are_equal(struct ast_test *test, struct ast_event *received, struct ast_event *expected)
1904 {
1905         struct ast_event_iterator iterator;
1906         int res;
1907
1908         if (ast_event_get_type(expected) == AST_EVENT_CUSTOM) {
1909                 /* this event is flagged as a wildcard match */
1910                 return 1;
1911         }
1912
1913         for (res = ast_event_iterator_init(&iterator, received); !res; res = ast_event_iterator_next(&iterator)) {
1914                 int ie_type = ast_event_iterator_get_ie_type(&iterator);
1915                 if (!match_ie_val(received, expected, ie_type)) {
1916                         ast_test_status_update(test, "Failed matching on field %s\n", ast_event_get_ie_type_name(ie_type));
1917                         return 0;
1918                 }
1919         }
1920
1921         return 1;
1922 }
1923
1924 static int dump_event(struct ast_test *test, struct ast_event *event)
1925 {
1926         struct ast_event_iterator i;
1927
1928         if (ast_event_iterator_init(&i, event)) {
1929                 ast_test_status_update(test, "Failed to initialize event iterator.  :-(\n");
1930                 return 0;
1931         }
1932
1933         ast_test_status_update(test, "Event: %s\n",
1934                 ast_cel_get_type_name(ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TYPE)));
1935
1936         do {
1937                 enum ast_event_ie_type ie_type;
1938                 enum ast_event_ie_pltype ie_pltype;
1939                 const char *ie_type_name;
1940
1941                 ie_type = ast_event_iterator_get_ie_type(&i);
1942                 ie_type_name = ast_event_get_ie_type_name(ie_type);
1943                 ie_pltype = ast_event_get_ie_pltype(ie_type);
1944
1945                 switch (ie_pltype) {
1946                 case AST_EVENT_IE_PLTYPE_UNKNOWN:
1947                 case AST_EVENT_IE_PLTYPE_STR:
1948                         ast_test_status_update(test, "%.30s: %s\n", ie_type_name,
1949                                         ast_event_iterator_get_ie_str(&i));
1950                         break;
1951                 case AST_EVENT_IE_PLTYPE_UINT:
1952                         ast_test_status_update(test, "%.30s: %u\n", ie_type_name,
1953                                         ast_event_iterator_get_ie_uint(&i));
1954                         break;
1955                 default:
1956                         break;
1957                 }
1958         } while (!ast_event_iterator_next(&i));
1959
1960         ast_test_status_update(test, "\n");
1961
1962         return 0;
1963 }
1964
1965 static int check_events(struct ast_test *test, struct ao2_container *local_expected, struct ao2_container *local_received)
1966 {
1967         struct ao2_iterator received_it;
1968         struct ao2_iterator expected_it;
1969         RAII_VAR(struct ast_event *, rx_event, NULL, ao2_cleanup);
1970         RAII_VAR(struct ast_event *, ex_event, NULL, ao2_cleanup);
1971         int debug = 0;
1972
1973         if (ao2_container_count(local_expected) != ao2_container_count(local_received)) {
1974                 ast_test_status_update(test, "Increasing verbosity since the number of expected events (%d)"
1975                         " did not match number of received events (%d).\n",
1976                         ao2_container_count(local_expected),
1977                         ao2_container_count(local_received));
1978                 debug = 1;
1979         }
1980
1981         received_it = ao2_iterator_init(local_received, 0);
1982         expected_it = ao2_iterator_init(local_expected, 0);
1983         rx_event = ao2_iterator_next(&received_it);
1984         ex_event = ao2_iterator_next(&expected_it);
1985         while (rx_event && ex_event) {
1986                 if (!events_are_equal(test, rx_event, ex_event)) {
1987                         ao2_iterator_destroy(&received_it);
1988                         ao2_iterator_destroy(&expected_it);
1989                         ast_test_status_update(test, "Received event:\n");
1990                         dump_event(test, rx_event);
1991                         ast_test_status_update(test, "Expected event:\n");
1992                         dump_event(test, ex_event);
1993                         return -1;
1994                 }
1995                 if (debug) {
1996                         ast_test_status_update(test, "Compared events successfully%s\n",
1997                                 ast_event_get_type(ex_event) == AST_EVENT_CUSTOM
1998                                         ? " (wildcard match)" : "");
1999                         dump_event(test, rx_event);
2000                 }
2001                 ao2_cleanup(rx_event);
2002                 ao2_cleanup(ex_event);
2003                 rx_event = ao2_iterator_next(&received_it);
2004                 ex_event = ao2_iterator_next(&expected_it);
2005         }
2006         ao2_iterator_destroy(&received_it);
2007         ao2_iterator_destroy(&expected_it);
2008
2009         if (rx_event) {
2010                 ast_test_status_update(test, "Received event:\n");
2011                 dump_event(test, rx_event);
2012                 return -1;
2013         }
2014         if (ex_event) {
2015                 ast_test_status_update(test, "Expected event:\n");
2016                 dump_event(test, ex_event);
2017                 return -1;
2018         }
2019         return 0;
2020 }
2021
2022 /*!
2023  * \internal
2024  * \brief Callback function called after each test executes.
2025  *
2026  * \details
2027  * In addition to cleanup, this function also performs verification
2028  * that the events received during a test match the events that were
2029  * expected to have been generated during the test.
2030  */
2031 static int cel_verify_and_cleanup_cb(struct ast_test_info *info, struct ast_test *test)
2032 {
2033         RAII_VAR(struct ao2_container *, local_expected, cel_expected_events, ao2_cleanup);
2034         RAII_VAR(struct ao2_container *, local_received, cel_received_events, ao2_cleanup);
2035         ast_assert(cel_received_events != NULL);
2036         ast_assert(cel_expected_events != NULL);
2037
2038         do_sleep();
2039
2040         /* stop the CEL event callback and clean up storage structures*/
2041         ast_cel_backend_unregister(TEST_BACKEND_NAME);
2042
2043         /* cleaned up by RAII_VAR's */
2044         cel_expected_events = NULL;
2045         cel_received_events = NULL;
2046
2047         /* check events */
2048         ast_test_validate(test, !check_events(test, local_expected, local_received));
2049
2050         /* Restore the real CEL config */
2051         ast_cel_set_config(saved_config);
2052         ao2_cleanup(saved_config);
2053         saved_config = NULL;
2054
2055         /* clean up the locks */
2056         ast_mutex_destroy(&sync_lock);
2057         ast_mutex_destroy(&mid_test_sync_lock);
2058         ast_cond_destroy(&sync_out);
2059         return 0;
2060 }
2061
2062 static int unload_module(void)
2063 {
2064         AST_TEST_UNREGISTER(test_cel_channel_creation);
2065         AST_TEST_UNREGISTER(test_cel_unanswered_inbound_call);
2066         AST_TEST_UNREGISTER(test_cel_unanswered_outbound_call);
2067         AST_TEST_UNREGISTER(test_cel_single_party);
2068         AST_TEST_UNREGISTER(test_cel_single_bridge);
2069         AST_TEST_UNREGISTER(test_cel_single_bridge_continue);
2070         AST_TEST_UNREGISTER(test_cel_single_twoparty_bridge_a);
2071         AST_TEST_UNREGISTER(test_cel_single_twoparty_bridge_b);
2072 #ifdef RACEY_TESTS
2073         AST_TEST_UNREGISTER(test_cel_single_multiparty_bridge);
2074 #endif
2075
2076         AST_TEST_UNREGISTER(test_cel_dial_unanswered);
2077         AST_TEST_UNREGISTER(test_cel_dial_unanswered_filter);
2078         AST_TEST_UNREGISTER(test_cel_dial_congestion);
2079         AST_TEST_UNREGISTER(test_cel_dial_busy);
2080         AST_TEST_UNREGISTER(test_cel_dial_unavailable);
2081         AST_TEST_UNREGISTER(test_cel_dial_caller_cancel);
2082         AST_TEST_UNREGISTER(test_cel_dial_parallel_failed);
2083         AST_TEST_UNREGISTER(test_cel_dial_answer_no_bridge);
2084         AST_TEST_UNREGISTER(test_cel_dial_answer_twoparty_bridge_a);
2085         AST_TEST_UNREGISTER(test_cel_dial_answer_twoparty_bridge_b);
2086 #ifdef RACEY_TESTS
2087         AST_TEST_UNREGISTER(test_cel_dial_answer_multiparty);
2088 #endif
2089
2090         AST_TEST_UNREGISTER(test_cel_blind_transfer);
2091         AST_TEST_UNREGISTER(test_cel_attended_transfer_bridges_swap);
2092         AST_TEST_UNREGISTER(test_cel_attended_transfer_bridges_merge);
2093         AST_TEST_UNREGISTER(test_cel_attended_transfer_bridges_link);
2094
2095         AST_TEST_UNREGISTER(test_cel_dial_pickup);
2096
2097         AST_TEST_UNREGISTER(test_cel_local_optimize);
2098
2099         ast_channel_unregister(&test_cel_chan_tech);
2100
2101         ao2_cleanup(cel_test_config);
2102         cel_test_config = NULL;
2103
2104         return 0;
2105 }
2106
2107 static int load_module(void)
2108 {
2109         /* build the test config */
2110         cel_test_config = ast_cel_general_config_alloc();
2111         if (!cel_test_config) {
2112                 return -1;
2113         }
2114         cel_test_config->enable = 1;
2115         if (ast_str_container_add(cel_test_config->apps, "dial")) {
2116                 return -1;
2117         }
2118         if (ast_str_container_add(cel_test_config->apps, "park")) {
2119                 return -1;
2120         }
2121         if (ast_str_container_add(cel_test_config->apps, "queue")) {
2122                 return -1;
2123         }
2124         cel_test_config->events |= 1<<AST_CEL_APP_START;
2125         cel_test_config->events |= 1<<AST_CEL_CHANNEL_START;
2126         cel_test_config->events |= 1<<AST_CEL_CHANNEL_END;
2127         cel_test_config->events |= 1<<AST_CEL_ANSWER;
2128         cel_test_config->events |= 1<<AST_CEL_HANGUP;
2129         cel_test_config->events |= 1<<AST_CEL_BRIDGE_ENTER;
2130         cel_test_config->events |= 1<<AST_CEL_BRIDGE_EXIT;
2131         cel_test_config->events |= 1<<AST_CEL_BLINDTRANSFER;
2132         cel_test_config->events |= 1<<AST_CEL_ATTENDEDTRANSFER;
2133         cel_test_config->events |= 1<<AST_CEL_PICKUP;
2134         cel_test_config->events |= 1<<AST_CEL_LOCAL_OPTIMIZE;
2135
2136         ast_channel_register(&test_cel_chan_tech);
2137
2138         AST_TEST_REGISTER(test_cel_channel_creation);
2139         AST_TEST_REGISTER(test_cel_unanswered_inbound_call);
2140         AST_TEST_REGISTER(test_cel_unanswered_outbound_call);
2141
2142         AST_TEST_REGISTER(test_cel_single_party);
2143         AST_TEST_REGISTER(test_cel_single_bridge);
2144         AST_TEST_REGISTER(test_cel_single_bridge_continue);
2145         AST_TEST_REGISTER(test_cel_single_twoparty_bridge_a);
2146         AST_TEST_REGISTER(test_cel_single_twoparty_bridge_b);
2147 #ifdef RACEY_TESTS
2148         AST_TEST_REGISTER(test_cel_single_multiparty_bridge);
2149 #endif
2150
2151         AST_TEST_REGISTER(test_cel_dial_unanswered);
2152         AST_TEST_REGISTER(test_cel_dial_unanswered_filter);
2153         AST_TEST_REGISTER(test_cel_dial_congestion);
2154         AST_TEST_REGISTER(test_cel_dial_busy);
2155         AST_TEST_REGISTER(test_cel_dial_unavailable);
2156         AST_TEST_REGISTER(test_cel_dial_caller_cancel);
2157         AST_TEST_REGISTER(test_cel_dial_parallel_failed);
2158         AST_TEST_REGISTER(test_cel_dial_answer_no_bridge);
2159         AST_TEST_REGISTER(test_cel_dial_answer_twoparty_bridge_a);
2160         AST_TEST_REGISTER(test_cel_dial_answer_twoparty_bridge_b);
2161 #ifdef RACEY_TESTS
2162         AST_TEST_REGISTER(test_cel_dial_answer_multiparty);
2163 #endif
2164
2165         AST_TEST_REGISTER(test_cel_blind_transfer);
2166         AST_TEST_REGISTER(test_cel_attended_transfer_bridges_swap);
2167         AST_TEST_REGISTER(test_cel_attended_transfer_bridges_merge);
2168         AST_TEST_REGISTER(test_cel_attended_transfer_bridges_link);
2169
2170         AST_TEST_REGISTER(test_cel_dial_pickup);
2171
2172         AST_TEST_REGISTER(test_cel_local_optimize);
2173
2174         /* ast_test_register_* has to happen after AST_TEST_REGISTER */
2175         /* Verify received vs expected events and clean things up after every test */
2176         ast_test_register_init(TEST_CATEGORY, test_cel_init_cb);
2177         ast_test_register_cleanup(TEST_CATEGORY, cel_verify_and_cleanup_cb);
2178
2179         return AST_MODULE_LOAD_SUCCESS;
2180 }
2181
2182 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "CEL unit tests");