Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
    struct timespec start, curr;
    struct timers timers;
    struct list_head expired;
    struct timer t[PER_CONN_TIME];
    unsigned int i, num;
    bool check = false;

    opt_register_noarg("-c|--check", opt_set_bool, &check,
                       "Check timer structure during progress");

    opt_parse(&argc, argv, opt_log_stderr_exit);

    num = argv[1] ? atoi(argv[1]) : (check ? 100000 : 100000000);

    list_head_init(&expired);
    curr = start = time_now();
    timers_init(&timers, start);

    for (i = 0; i < num; i++) {
        curr = time_add(curr, time_from_msec(1));
        if (check)
            timers_check(&timers, NULL);
        timers_expire(&timers, curr, &expired);
        if (check)
            timers_check(&timers, NULL);
        assert(list_empty(&expired));

        if (i >= PER_CONN_TIME) {
            timer_del(&timers, &t[i%PER_CONN_TIME]);
            if (check)
                timers_check(&timers, NULL);
        }
        timer_add(&timers, &t[i%PER_CONN_TIME],
                  time_add(curr, time_from_msec(CONN_TIMEOUT_MS)));
        if (check)
            timers_check(&timers, NULL);
    }
    if (num > PER_CONN_TIME) {
        for (i = 0; i < PER_CONN_TIME; i++)
            timer_del(&timers, &t[i]);
    }

    curr = time_sub(time_now(), start);
    if (check)
        timers_check(&timers, NULL);
    timers_cleanup(&timers);
    opt_free_table();

    for (i = 0; i < ARRAY_SIZE(timers.level); i++)
        if (!timers.level[i])
            break;

    printf("%u in %lu.%09lu (%u levels / %zu)\n",
           num, (long)curr.tv_sec, curr.tv_nsec,
           i, ARRAY_SIZE(timers.level));
    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	struct timeabs when;
	struct timers timers;

	plan_tests(7);
	
	when.ts.tv_sec = 0; when.ts.tv_nsec = 0;
	timers_init(&timers, when);

	/* Add these */
	new_timer(&timers, 35000000);
	new_timer(&timers, 38000000);
	new_timer(&timers, 59000000);
	new_timer(&timers, 65000000);
	new_timer(&timers, 88000000);
	new_timer(&timers, 125000000);
	new_timer(&timers, 130000000);
	new_timer(&timers, 152000000);
	new_timer(&timers, 168000000);
	/* Expire all but the last one. */
	update_and_expire(&timers);
	update_and_expire(&timers);
	update_and_expire(&timers);
	update_and_expire(&timers);
	update_and_expire(&timers);
	update_and_expire(&timers);
	update_and_expire(&timers);
	update_and_expire(&timers);
	/* Add a new one. */
	new_timer(&timers, 169000000);
	ok1(timers_check(&timers, NULL));

	/* Used to get the wrong one... */
	timers_dump(&timers, stdout);
	ok1(timer_earliest(&timers, &when));
	ok1(when.ts.tv_nsec == 168000000);
	free(timers_expire(&timers, when));

	ok1(timer_earliest(&timers, &when));
	ok1(when.ts.tv_nsec == 169000000);
	free(timers_expire(&timers, when));

	ok1(timers_check(&timers, NULL));
	ok1(!timer_earliest(&timers, &when));
	timers_cleanup(&timers);

	return exit_status();
}
Ejemplo n.º 3
0
int main(void)
{
	struct timers timers;
	struct timer t, *expired;

	/* This is how many tests you plan to run */
	plan_tests(3);

	timers_init(&timers, timemono_from_usec(1364726722653919ULL));
	timer_init(&t);
	timer_addmono(&timers, &t, timemono_from_usec(1364726722703919ULL));
	ok1(!timers_expire(&timers, timemono_from_usec(1364726722653920ULL)));
	expired = timers_expire(&timers, timemono_from_usec(1364726725454187ULL));
	ok1(expired == &t);
	ok1(!timers_expire(&timers, timemono_from_usec(1364726725454187ULL)));
	timers_cleanup(&timers);

	/* This exits depending on whether all tests passed */
	return exit_status();
}
Ejemplo n.º 4
0
static int ss7_unload_module(void)
{
  cli_unregister();

#ifdef SCCP
  sccp_cleanup();
#endif
  isup_cleanup();

  cleanup_dump(0, 1, 1);
  if(monitor_running) {
    stop_monitor();
  }
  stop_mtp_thread();
  mtp_cleanup();
  timers_cleanup();


  destroy_config();
  ast_verbose(VERBOSE_PREFIX_3 "SS7 channel unloaded.\n");
  return AST_MODULE_LOAD_SUCCESS;
}
Ejemplo n.º 5
0
Archivo: run-ff.c Proyecto: chr15m/ccan
int main(void)
{
	struct timers timers;
	struct timer t;
	struct list_head expired;

	/* This is how many tests you plan to run */
	plan_tests(3);

	timers_init(&timers, timeabs_from_usec(1364726722653919ULL));
	timer_add(&timers, &t, timeabs_from_usec(1364726722703919ULL));
	timers_expire(&timers, timeabs_from_usec(1364726722653920ULL), &expired);
	ok1(list_empty(&expired));
	timers_expire(&timers, timeabs_from_usec(1364726725454187ULL), &expired);
	ok1(!list_empty(&expired));
	ok1(list_top(&expired, struct timer, list) == &t);

	timers_cleanup(&timers);

	/* This exits depending on whether all tests passed */
	return exit_status();
}
Ejemplo n.º 6
0
int main(void)
{
	struct io_listener *l;
	int fd;
	struct timers timers;
	struct timer timer, *expired;
	struct addrinfo *addrinfo;

	/* This is how many tests you plan to run */
	plan_tests(7);

	fake_time = time_now();

	timers_init(&timers, fake_time);
	timer_init(&timer);
	timer_add(&timers, &timer,
		  timeabs_add(fake_time, time_from_sec(1000)));

	fd = make_listen_fd(PORT, &addrinfo);
	freeaddrinfo(addrinfo);
	ok1(fd >= 0);
	l = io_new_listener(NULL, fd, init_conn, NULL);
	ok1(l);

	fake_time.ts.tv_sec += 1000;
	ok1(io_time_override(get_fake_time) == time_now);
	ok1(io_loop(&timers, &expired) == NULL);

	ok1(expired == &timer);
	ok1(!timers_expire(&timers, fake_time));
	ok1(io_time_override(time_now) == get_fake_time);
	io_close_listener(l);

	timers_cleanup(&timers);

	/* This exits depending on whether all tests passed */
	return exit_status();
}
Ejemplo n.º 7
0
int main(void)
{
	struct timers timers;
	struct timer t;

	/* This is how many tests you plan to run */
	plan_tests(7);

	timers_init(&timers, grains_to_time(1364984760903400ULL));
	ok1(timers.base == 1364984760903400ULL);
	timer_init(&t);
	timer_add(&timers, &t, grains_to_time(1364984761003398ULL));
	ok1(t.time == 1364984761003398ULL);
	ok1(timers.first == 1364984761003398ULL);
	ok1(!timers_expire(&timers, grains_to_time(1364984760903444ULL)));
	ok1(timers_check(&timers, NULL));
	ok1(!timers_expire(&timers, grains_to_time(1364984761002667ULL)));
	ok1(timers_check(&timers, NULL));

	timers_cleanup(&timers);

	/* This exits depending on whether all tests passed */
	return exit_status();
}
Ejemplo n.º 8
0
void timers_init(void) {
  timers_cleanup();
  timers = linked_list_create_root();
  update_handlers = linked_list_create_root();
  highlight_handlers = linked_list_create_root();
}
Ejemplo n.º 9
0
Archivo: run.c Proyecto: chr15m/ccan
int main(void)
{
	struct timers timers;
	struct timer t[64];
	struct list_head expired;
	struct timeabs earliest;
	uint64_t i;
	struct timeabs epoch = { { 0, 0 } };

	/* This is how many tests you plan to run */
	plan_tests(488);

	timers_init(&timers, epoch);
	ok1(timers_check(&timers, NULL));
	ok1(!timer_earliest(&timers, &earliest));

	timer_add(&timers, &t[0], timeabs_from_nsec(1));
	ok1(timers_check(&timers, NULL));
	ok1(timer_earliest(&timers, &earliest));
	ok1(timeabs_eq(earliest, grains_to_time(t[0].time)));
	timer_del(&timers, &t[0]);
	ok1(timers_check(&timers, NULL));
	ok1(!timer_earliest(&timers, &earliest));

	/* Check timer ordering. */
	for (i = 0; i < 32; i++) {
		timer_add(&timers, &t[i*2], timeabs_from_nsec(1ULL << i));
		ok1(timers_check(&timers, NULL));
		timer_add(&timers, &t[i*2+1], timeabs_from_nsec((1ULL << i) + 1));
		ok1(timers_check(&timers, NULL));
	}

	for (i = 0; i < 32; i++) {
		const struct timer *t1, *t2;

		t1 = get_first(&timers);
		ok1(t1 == &t[i*2] || t1 == &t[i*2+1]);
		timer_del(&timers, (struct timer *)t1);
		ok1(timers_check(&timers, NULL));

		t2 = get_first(&timers);
		ok1(t2 != t1 && (t2 == &t[i*2] || t2 == &t[i*2+1]));
		timer_del(&timers, (struct timer *)t2);
		ok1(timers_check(&timers, NULL));
	}

	/* Check expiry. */
	for (i = 0; i < 32; i++) {
		uint64_t exp = (uint64_t)TIMER_GRANULARITY << i;

		timer_add(&timers, &t[i*2], timeabs_from_nsec(exp));
		ok1(timers_check(&timers, NULL));
		timer_add(&timers, &t[i*2+1], timeabs_from_nsec(exp + 1));
		ok1(timers_check(&timers, NULL));
	}

	for (i = 0; i < 32; i++) {
		struct timer *t1, *t2;

		ok1(timer_earliest(&timers, &earliest));
		timers_expire(&timers, earliest, &expired);

		t1 = list_pop(&expired, struct timer, list);
		ok1(t1);
		t2 = list_pop(&expired, struct timer, list);
		ok1(t2);
		ok1(list_empty(&expired));

		ok1(t1 == &t[i*2] || t1 == &t[i*2+1]);
		ok1(t2 != t1 && (t2 == &t[i*2] || t2 == &t[i*2+1]));
		ok1(timers_check(&timers, NULL));
	}

	ok1(!timer_earliest(&timers, &earliest));

	timers_cleanup(&timers);

	/* This exits depending on whether all tests passed */
	return exit_status();
}