Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Macros | Functions | Variables
test_aeap_transaction.c File Reference
#include "asterisk.h"
#include <pthread.h>
#include "asterisk/lock.h"
#include "asterisk/test.h"
#include "asterisk/module.h"
#include "asterisk/res_aeap.h"
#include "asterisk/res_aeap_message.h"
#include "../res/res_aeap/general.h"
#include "../res/res_aeap/transaction.h"
Include dependency graph for test_aeap_transaction.c:

Go to the source code of this file.

Macros

#define AEAP_TRANSACTION_ID   "foo"
 
#define CATEGORY   "/res/aeap/transaction/"
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (transaction_exec)
 
 AST_TEST_DEFINE (transaction_exec_timeout)
 
static void * end_transaction (void *data)
 
static enum ast_test_result_state exec (struct ast_test *test, struct ast_aeap_tsx_params *params)
 
static void handle_timeout (struct ast_aeap *aeap, struct ast_aeap_message *msg, void *obj)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Asterisk External Application Protocol Transaction Tests" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_aeap", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Macro Definition Documentation

◆ AEAP_TRANSACTION_ID

#define AEAP_TRANSACTION_ID   "foo"

Definition at line 40 of file test_aeap_transaction.c.

◆ CATEGORY

#define CATEGORY   "/res/aeap/transaction/"

Definition at line 38 of file test_aeap_transaction.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 179 of file test_aeap_transaction.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 179 of file test_aeap_transaction.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 179 of file test_aeap_transaction.c.

◆ AST_TEST_DEFINE() [1/2]

AST_TEST_DEFINE ( transaction_exec  )

Definition at line 115 of file test_aeap_transaction.c.

116{
117 struct ast_aeap_tsx_params params = {
118 .timeout = 5000, /* Give plenty of time for test thread to end */
119 };
120
121 switch (cmd) {
122 case TEST_INIT:
123 info->name = __func__;
124 info->explicit_only = 0;
125 info->category = CATEGORY;
126 info->summary = "test creating a basic AEAP transaction request";
127 info->description = info->summary;
128 return AST_TEST_NOT_RUN;
129 case TEST_EXECUTE:
130 break;
131 }
132
133 return exec(test, &params);
134}
def info(msg)
Parameters to be used when sending a transaction based message.
Definition: res_aeap.h:331
@ TEST_INIT
Definition: test.h:200
@ TEST_EXECUTE
Definition: test.h:201
@ AST_TEST_NOT_RUN
Definition: test.h:194
#define CATEGORY
static enum ast_test_result_state exec(struct ast_test *test, struct ast_aeap_tsx_params *params)

References AST_TEST_NOT_RUN, CATEGORY, exec(), sip_to_pjsip::info(), TEST_EXECUTE, TEST_INIT, and ast_aeap_tsx_params::timeout.

◆ AST_TEST_DEFINE() [2/2]

AST_TEST_DEFINE ( transaction_exec_timeout  )

Definition at line 136 of file test_aeap_transaction.c.

137{
138 struct ast_aeap_tsx_params params = {
139 .timeout = 100, /* Ensure timeout occurs before test thread ends */
140 .on_timeout = handle_timeout,
141 };
142
143 switch (cmd) {
144 case TEST_INIT:
145 info->name = __func__;
146 info->explicit_only = 0;
147 info->category = CATEGORY;
148 info->summary = "test creating a AEAP transaction request that times out";
149 info->description = info->summary;
150 return AST_TEST_NOT_RUN;
151 case TEST_EXECUTE:
152 break;
153 }
154
155 return exec(test, &params);
156}
static void handle_timeout(struct ast_aeap *aeap, struct ast_aeap_message *msg, void *obj)

References AST_TEST_NOT_RUN, CATEGORY, exec(), handle_timeout(), sip_to_pjsip::info(), TEST_EXECUTE, TEST_INIT, and ast_aeap_tsx_params::timeout.

◆ end_transaction()

static void * end_transaction ( void *  data)
static

Definition at line 49 of file test_aeap_transaction.c.

50{
51 /* Delay a second before ending transaction */
52 struct timespec delay = { 1, 0 };
53 int *passed = aeap_transaction_user_obj(data);
54
55 while (nanosleep(&delay, &delay));
56
57 ++*passed;
58 aeap_transaction_end(data, 0);
59
60 return NULL;
61}
#define NULL
Definition: resample.c:96
void * aeap_transaction_user_obj(struct aeap_transaction *tsx)
Retrieve the user object associated with the transaction.
Definition: transaction.c:227
void aeap_transaction_end(struct aeap_transaction *tsx, int result)
End a transaction, and remove it from the given container.
Definition: transaction.c:217

References aeap_transaction_end(), aeap_transaction_user_obj(), and NULL.

Referenced by exec().

◆ exec()

static enum ast_test_result_state exec ( struct ast_test *  test,
struct ast_aeap_tsx_params params 
)
static

Definition at line 63 of file test_aeap_transaction.c.

65{
66 pthread_t thread_id = AST_PTHREADT_NULL;
67 struct ao2_container *tsxs = NULL;
68 struct aeap_transaction *tsx = NULL;
70 int passed = 0;
71
73 if (!tsxs) {
74 ast_test_status_update(test, "Failed to create transactions object\n");
75 goto exec_cleanup;
76 }
77
78 params->wait = 1;
79 params->obj = &passed;
80
82 if (!tsx) {
83 ast_test_status_update(test, "Failed to create transaction object\n");
84 goto exec_cleanup;
85 }
86
87 if (ast_pthread_create(&thread_id, NULL, end_transaction, ao2_bump(tsx))) {
88 ast_test_status_update(test, "Failed to create response thread\n");
89 ao2_ref(tsx, -1);
90 goto exec_cleanup;
91 }
92
93 if (aeap_transaction_start(tsx)) {
94 ast_test_status_update(test, "Failed to start transaction request\n");
95 goto exec_cleanup;
96 }
97
98 if (passed == 1) {
99 res = AST_TEST_PASS;
100 }
101
102exec_cleanup:
103
104 if (thread_id != AST_PTHREADT_NULL) {
105 pthread_cancel(thread_id);
106 pthread_join(thread_id, NULL);
107 }
108
109 aeap_transaction_end(tsx, 0);
110 ao2_cleanup(tsxs);
111
112 return res;
113}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
#define AST_PTHREADT_NULL
Definition: lock.h:66
struct ast_aeap_tsx_params params
Definition: transaction.c:46
Generic container type.
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
ast_test_result_state
Definition: test.h:193
@ AST_TEST_PASS
Definition: test.h:195
@ AST_TEST_FAIL
Definition: test.h:196
static void * end_transaction(void *data)
#define AEAP_TRANSACTION_ID
struct ao2_container * aeap_transactions_create(void)
Create an Asterisk external application transactions container.
Definition: transaction.c:272
struct aeap_transaction * aeap_transaction_create_and_add(struct ao2_container *transactions, const char *id, struct ast_aeap_tsx_params *params, struct ast_aeap *aeap)
Create a transaction object, and add it to the given container.
Definition: transaction.c:232
int aeap_transaction_start(struct aeap_transaction *tsx)
Start the transaction.
Definition: transaction.c:198
#define ast_pthread_create(a, b, c, d)
Definition: utils.h:584

References aeap_transaction_create_and_add(), aeap_transaction_end(), AEAP_TRANSACTION_ID, aeap_transaction_start(), aeap_transactions_create(), ao2_bump, ao2_cleanup, ao2_ref, ast_pthread_create, AST_PTHREADT_NULL, AST_TEST_FAIL, AST_TEST_PASS, ast_test_status_update, end_transaction(), NULL, ast_aeap_tsx_params::obj, aeap_transaction::params, and ast_aeap_tsx_params::wait.

Referenced by AST_TEST_DEFINE().

◆ handle_timeout()

static void handle_timeout ( struct ast_aeap aeap,
struct ast_aeap_message msg,
void *  obj 
)
static

Definition at line 42 of file test_aeap_transaction.c.

43{
44 int *passed = obj;
45
46 ++*passed;
47}

Referenced by AST_TEST_DEFINE().

◆ load_module()

static int load_module ( void  )
static

Definition at line 158 of file test_aeap_transaction.c.

159{
160 AST_TEST_REGISTER(transaction_exec);
161 AST_TEST_REGISTER(transaction_exec_timeout);
162
164}
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 166 of file test_aeap_transaction.c.

167{
168 AST_TEST_UNREGISTER(transaction_exec_timeout);
169 AST_TEST_UNREGISTER(transaction_exec);
170
171 return 0;
172}
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128

References AST_TEST_UNREGISTER.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Asterisk External Application Protocol Transaction Tests" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_aeap", }
static

Definition at line 179 of file test_aeap_transaction.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 179 of file test_aeap_transaction.c.