112 int id1, id2, id3, wait;
116 info->name =
"sched_test_order";
117 info->category =
"/main/sched/";
118 info->summary =
"Test ordering of events in the scheduler API";
120 "This test ensures that events are properly ordered by the "
121 "time they are scheduled to execute in the scheduler API.";
129 "Test failed - could not create scheduler context\n");
138 "ast_sched_wait() should have returned -1, returned '%d'\n",
150 "ast_sched_wait() should have returned <= 100000, returned '%d'\n",
162 "ast_sched_wait() should have returned <= 10000, returned '%d'\n",
174 "ast_sched_wait() should have returned <= 1000, returned '%d'\n",
186 "ast_sched_wait() should have returned > 1000, returned '%d'\n",
198 "ast_sched_wait() should have returned > 10000, returned '%d'\n",
210 "ast_sched_wait() should have returned -1, returned '%d'\n",
220#define DELAYED_SAME_EXPIRE 300
253 "ast_sched_wait() should have returned -1, returned '%d'\n",
269 struct timeval start;
271 int *sched_ids =
NULL;
275 e->
command =
"sched benchmark";
277 "Usage: sched benchmark <num>\n"
284 if (
a->argc != e->
args + 1) {
288 if (sscanf(
a->argv[e->
args],
"%u", &num) != 1) {
293 ast_cli(
a->fd,
"Test failed - could not create scheduler context\n");
297 if (!(sched_ids =
ast_malloc(
sizeof(*sched_ids) * num))) {
298 ast_cli(
a->fd,
"Test failed - memory allocation failure\n");
302 ast_cli(
a->fd,
"Testing ast_sched_add() performance - timing how long it takes "
303 "to add %u entries at random time intervals from 0 to 60 seconds\n", num);
307 for (i = 0; i < num; i++) {
310 ast_cli(
a->fd,
"Test failed - sched_add returned -1\n");
317 ast_cli(
a->fd,
"Testing ast_sched_del() performance - timing how long it takes "
318 "to delete %u entries with random time intervals from 0 to 60 seconds\n", num);
322 for (i = 0; i < num; i++) {
324 ast_cli(
a->fd,
"Test failed - sched_del returned -1\n");
357 struct timespec delay = {3,0};
367 while (nanosleep(&delay, &delay));
385 info->name =
"sched_test_freebird";
386 info->category =
"/main/sched/";
387 info->summary =
"Test deadlock avoidance and double-unref";
389 "This tests a call to AST_SCHED_DEL_UNREF on a running event.";
399 "ao2_alloc() did not return an object\n");
408 "ast_sched_context_create() did not return a context\n");
Asterisk main include file. File version handling, generic pbx functions.
#define ast_malloc(len)
A wrapper for malloc()
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_alloc(data_size, destructor_fn)
Standard Command Line Interface.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
#define AST_CLI_DEFINE(fn, txt,...)
void ast_cli(int fd, const char *fmt,...)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
#define ast_cond_destroy(cond)
#define ast_cond_wait(cond, mutex)
#define ast_mutex_unlock(a)
pthread_cond_t ast_cond_t
#define ast_mutex_destroy(a)
#define ast_mutex_lock(a)
#define ast_cond_signal(cond)
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
Scheduler Routines (derived from cheops)
#define AST_SCHED_DEL_UNREF(sched, id, refcall)
schedule task to get deleted and call unref function
int ast_sched_del(struct ast_sched_context *con, int id) attribute_warn_unused_result
Deletes a scheduled event.
int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
Adds a scheduled event.
void ast_sched_context_destroy(struct ast_sched_context *c)
destroys a schedule context
int ast_sched_start_thread(struct ast_sched_context *con)
Start a thread for processing scheduler entries.
int ast_sched_runq(struct ast_sched_context *con)
Runs the queue.
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
int ast_sched_wait(struct ast_sched_context *con) attribute_warn_unused_result
Determines number of seconds until the next outstanding event to take place.
descriptor for a cli entry.
int args
This gets set in ast_cli_register()
Structure for mutex and tracking information.
#define AST_TEST_REGISTER(cb)
#define ast_test_status_update(a, b, c...)
#define AST_TEST_UNREGISTER(cb)
static struct ast_cli_entry cli_sched[]
AST_TEST_DEFINE(sched_test_order)
static void sched_order_check(struct ast_test *test, int order)
static int sched_order_7_cb(const void *data)
static int lockingcb(const void *data)
#define DELAYED_SAME_EXPIRE
static void test_obj_cleanup(void *data)
static int sched_order_2_cb(const void *data)
static int sched_order_6_cb(const void *data)
static int order_check_failed
static int sched_cb(const void *data)
static int sched_order_5_cb(const void *data)
static int sched_order_8_cb(const void *data)
static char * handle_cli_sched_bench(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int sched_order_3_cb(const void *data)
static int load_module(void)
static int unload_module(void)
static int sched_order_4_cb(const void *data)
static int sched_order_1_cb(const void *data)
int64_t ast_tvdiff_us(struct timeval end, struct timeval start)
Computes the difference (in microseconds) between two struct timeval instances.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
long int ast_random(void)