41 static void *lock_thread(
void *data)
60 enum ast_test_result_state res = AST_TEST_FAIL;
65 struct timeval start_time;
70 info->name =
"named_lock_test";
71 info->category =
"/main/lock/";
72 info->summary =
"Named Lock test";
74 "Tests that named locks operate as expected";
75 return AST_TEST_NOT_RUN;
80 ast_test_status_update(
test,
"This test should take about 3 seconds\n");
83 ast_pthread_create(&thread1, NULL, lock_thread,
"lock_1");
84 ast_pthread_create(&thread2, NULL, lock_thread,
"lock_2");
87 ast_test_validate_cleanup(
test, lock1 != NULL, res, fail);
90 ast_test_validate_cleanup(
test, lock2 != NULL, res, fail);
95 if (!ao2_trylock(lock1)) {
96 ast_test_status_update(
test,
"ao2_trylock on lock1 succeeded when it should have failed\n");
101 if (!ao2_trylock(lock2)) {
102 ast_test_status_update(
test,
"ao2_trylock on lock2 succeeded when it should have failed\n");
110 if (ao2_lock(lock1)) {
111 ast_test_status_update(
test,
"ao2_lock on lock1 failed\n");
116 if (ao2_lock(lock2)) {
117 ast_test_status_update(
test,
"ao2_lock on lock2 failed\n");
123 ast_test_validate_cleanup(
test, duration > 1500 && duration < 3500, res, fail);
132 pthread_join(thread1, NULL);
133 pthread_join(thread2, NULL);
139 static int unload_module(
void)
141 AST_TEST_UNREGISTER(named_lock_test);
145 static int load_module(
void)
147 AST_TEST_REGISTER(named_lock_test);
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
#define AST_TEST_DEFINE(hdr)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define ast_named_lock_get(lock_type, keyspace, key)
Geta named lock handle.
#define ast_named_lock_put(lock)
Put a named lock handle away.