Esempio n. 1
0
void
histogram(void) {
	long maxcount = BLOCKS;
	intptr_t sc[PRIORITIES];
	
	intptr_t total = 0;
	
	long x,y;
	for (y = 0; y < PRIORITIES; ++y) {
		sc[y] = counts[y].count;
	}

	for (y = 0; y < PRIORITIES; ++y) {
		double fraction;
		double value;
		printf("%s: %ld\n", labels[y], sc[y]);
		total += sc[y];
		
		fraction = (double)sc[y] / (double)maxcount;
		value = fraction * (double)80;
		for (x = 0; x < 80; ++x) {
			printf("%s", (value > x) ? "*" : " ");
		}
		printf("\n");
	}
	
	test_long("blocks completed", (long)total, ITERATIONS);
	test_long_less_than("high priority precedence", (long)sc[0], (long)sc[2]);
}
void
test_timer(void)
{
	dispatch_test_start("Dispatch Update Timer");

	dispatch_queue_t main_q = dispatch_get_main_queue();
	//test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());

	__block int i = 0;
	struct timeval start_time;

	gettimeofday(&start_time, NULL);

	dispatch_source_t s = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, main_q);
	test_ptr_notnull("dispatch_source_create", s);

	dispatch_source_set_timer(s, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC), NSEC_PER_SEC, 0);

	dispatch_source_set_cancel_handler(s, ^{
		struct timeval end_time;
		gettimeofday(&end_time, NULL);
		// Make sure we actually managed to adjust the interval
		// duration.  Seven one second ticks would blow past
		// this.
		test_long_less_than("total duration", end_time.tv_sec - start_time.tv_sec, 3);
		test_stop();

		dispatch_release(s);
	});
static void
cancel_handler(void* context)
{
	struct timeval end_time;
	UNREFERENCED_PARAMETER(context);
	gettimeofday(&end_time, NULL);
	// Make sure we actually managed to adjust the interval
	// duration.  Seven one second ticks would blow past
	// this.
	test_long_less_than("total duration", end_time.tv_sec - start_time.tv_sec, 3);
	test_ptr_notnull("finalizer ran", timer);
	test_stop();
}
int main(void)
{
	test_start("Dispatch Source Timer, bit 31");

	dispatch_queue_t main_q = dispatch_get_main_queue();
	test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());

	__block int i = 0;
	struct timeval start_time;

	gettimeofday(&start_time, NULL);
	dispatch_source_attr_t attr = dispatch_source_attr_create();
	dispatch_source_attr_set_finalizer(attr, ^(dispatch_source_t ds) {
		struct timeval end_time;
		gettimeofday(&end_time, NULL);
		test_ptr_notnull("finalizer ran", ds);
		// XXX: check, s/b 2.0799... seconds, which is <4 seconds
		// when it could end on a bad boundry.
		test_long_less_than("needs to finish faster than 4 seconds", end_time.tv_sec - start_time.tv_sec, 4);
		// And it has to take at least two seconds...
		test_long_less_than("can't finish faster than 2 seconds", 1, end_time.tv_sec - start_time.tv_sec);
		test_stop();
	});
Esempio n. 5
0
void
test_fin(void *cxt)
{
	fprintf(stderr, "Called back every %llu us on average\n",
			(delay/count)/NSEC_PER_USEC);
	test_long_less_than("Frequency", 1, ceil((double)delay/(count*interval)));
	int i;
	for (i = 0; i < N; i++) {
		dispatch_source_cancel(t[i]);
		dispatch_release(t[i]);
	}
	dispatch_resume(q);
	dispatch_release(q);
	dispatch_release(g);
	test_ptr("finalizer ran", cxt, cxt);
	test_stop();
}
Esempio n. 6
0
int main(void)
{
    test_start("Dispatch Update Timer");

    dispatch_queue_t main_q = dispatch_get_main_queue();
    test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());

    __block int i = 0;
    struct timeval start_time;

    gettimeofday(&start_time, NULL);
    dispatch_source_attr_t attr = dispatch_source_attr_create();
    dispatch_source_attr_set_finalizer(attr, ^(dispatch_source_t ds) {
        struct timeval end_time;
        gettimeofday(&end_time, NULL);
        // Make sure we actually managed to adjust the interval
        // duration.  Seven one second ticks would blow past
        // this.
        test_long_less_than("total duration", end_time.tv_sec - start_time.tv_sec, 3);
        test_ptr_notnull("finalizer ran", ds);
        test_stop();
    });
void
test_after(void)
{
	__block dispatch_time_t time_a_min, time_a, time_a_max;
	__block dispatch_time_t time_b_min, time_b, time_b_max;
	__block dispatch_time_t time_c_min, time_c, time_c_max;

	dispatch_test_start("Dispatch After");

	dispatch_async(dispatch_get_main_queue(), ^{
		time_a_min = dispatch_time(0,  5.5*NSEC_PER_SEC);
		time_a     = dispatch_time(0,   6*NSEC_PER_SEC);
		time_a_max = dispatch_time(0,  6.5*NSEC_PER_SEC);
		dispatch_after(time_a, dispatch_get_main_queue(), ^{
			dispatch_time_t now_a = dispatch_time(0, 0);
			test_long_less_than("can't finish faster than 5.5s", 0, now_a - time_a_min);
			test_long_less_than("must finish faster than  6.5s", 0, time_a_max - now_a);

			time_b_min = dispatch_time(0,  1.5*NSEC_PER_SEC);
			time_b     = dispatch_time(0,    2*NSEC_PER_SEC);
			time_b_max = dispatch_time(0,  2.5*NSEC_PER_SEC);
			dispatch_after(time_b, dispatch_get_main_queue(), ^{
				dispatch_time_t now_b = dispatch_time(0, 0);
				test_long_less_than("can't finish faster than 1.5s", 0, now_b - time_b_min);
				test_long_less_than("must finish faster than  2.5s", 0, time_b_max - now_b);

				time_c_min = dispatch_time(0,  0*NSEC_PER_SEC);
				time_c     = dispatch_time(0,  0*NSEC_PER_SEC);
				time_c_max = dispatch_time(0,  .5*NSEC_PER_SEC);
				dispatch_after(time_c, dispatch_get_main_queue(), ^{
					dispatch_time_t now_c = dispatch_time(0, 0);
					test_long_less_than("can't finish faster than 0s", 0, now_c - time_c_min);
					test_long_less_than("must finish faster than .5s", 0, time_c_max - now_c);

					dispatch_async_f(dispatch_get_main_queue(), NULL, done);
				});
			});
		});