40 static struct ast_test *current_test;
41 AST_MUTEX_DEFINE_STATIC(the_lock);
52 ast_mutex_unlock(lock);
57 enum ast_test_result_state res = AST_TEST_PASS;
62 info->name =
"lock_test";
63 info->category =
"/main/lock/";
64 info->summary =
"SCOPED_LOCK test";
66 "Tests that scoped locks are scoped as they are expected to be";
67 return AST_TEST_NOT_RUN;
77 ast_log(LOG_ERROR,
"The lock was not acquired via RAII");
82 ast_log(LOG_ERROR,
"The lock was not released when the variable went out of scope");
86 for (i = 0; i < 10; ++i) {
89 ast_log(LOG_ERROR,
"The lock was not acquired via RAII");
95 ast_log(LOG_ERROR,
"The lock was not released when the variable went out of scope");
117 ast_test_status_update(current_test,
"Lock is occurring\n");
133 ast_test_status_update(current_test,
"Unlock is occurring\n");
149 ast_test_status_update(current_test,
"Ref is occurring\n");
166 ast_test_status_update(current_test,
"Unref is occurring\n");
199 enum ast_test_result_state res = AST_TEST_PASS;
207 info->name =
"cleanup_order_test";
208 info->category =
"/main/lock/";
209 info->summary =
"cleanup order test";
211 "Tests that variables with cleanup attributes are cleaned up\n"
212 "in the reverse order they are declared.";
213 return AST_TEST_NOT_RUN;
220 object = ao2_alloc(
sizeof(*
object), NULL);
223 return AST_TEST_FAIL;
232 if (!object->reffed || !object->locked) {
233 ast_log(LOG_ERROR,
"Test failed due to out of order initializations");
238 if (object->reffed || object->locked) {
239 ast_log(LOG_ERROR,
"Test failed due to out of order cleanups\n");
254 if (!object->reffed || !object->locked) {
255 ast_log(LOG_ERROR,
"Test failed due to out of order initializations");
261 if (object->reffed || object->locked) {
262 ast_log(LOG_ERROR,
"Test failed due to out of order cleanups\n");
269 static int unload_module(
void)
271 AST_TEST_UNREGISTER(lock_test);
272 AST_TEST_UNREGISTER(cleanup_order);
276 static int load_module(
void)
278 AST_TEST_REGISTER(lock_test);
279 AST_TEST_REGISTER(cleanup_order);
Asterisk main include file. File version handling, generic pbx functions.
static void test_lock(struct test_struct *test)
lock callback function
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
static struct test_struct * test_ref(struct test_struct *test)
ref callback function
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define SCOPED_LOCK(varname, lock, lockfunc, unlockfunc)
Scoped Locks.
struct ao2_container * container
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
static void test_unlock(struct test_struct *test)
unlock callback function
static void test_unref(struct test_struct *test)
unref callback function
static struct test_struct * test_iterator_next(struct ao2_iterator *iter)
wrapper for ao2_iterator_next
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
#define AST_TEST_DEFINE(hdr)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
Structure for mutex and tracking information.
#define ao2_link(container, obj)
Add an object to a container.