Changeset 215
- Timestamp:
- 08/08/12 22:09:03 (10 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 24 edited
-
Makefile.am (modified) (1 diff)
-
configure.ac (modified) (1 diff)
-
testing/Makefile.am (modified) (3 diffs)
-
testing/bench.mm (modified) (3 diffs)
-
testing/bsdtestharness.c (modified) (7 diffs)
-
testing/bsdtests.c (modified) (4 diffs)
-
testing/bsdtests.h (modified) (3 diffs)
-
testing/dispatch_after.c (modified) (3 diffs)
-
testing/dispatch_api.c (modified) (1 diff)
-
testing/dispatch_apply.c (modified) (2 diffs)
-
testing/dispatch_concur.c (modified) (1 diff)
-
testing/dispatch_deadname.c (modified) (6 diffs)
-
testing/dispatch_drift.c (modified) (3 diffs)
-
testing/dispatch_group.c (modified) (3 diffs)
-
testing/dispatch_io.c (modified) (7 diffs)
-
testing/dispatch_priority.c (modified) (6 diffs)
-
testing/dispatch_queue_finalizer.c (modified) (1 diff)
-
testing/dispatch_suspend_timer.c (modified) (1 diff)
-
testing/dispatch_test.c (modified) (3 diffs)
-
testing/dispatch_test.h (modified) (2 diffs)
-
testing/dispatch_timer.c (modified) (3 diffs)
-
testing/dispatch_timer_bit31.c (modified) (1 diff)
-
testing/dispatch_timer_set_time.c (modified) (1 diff)
-
testing/dispatch_transform.c (added)
-
testing/dispatch_vm.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Makefile.am
r214 r215 10 10 os \ 11 11 private \ 12 src 12 src \ 13 testing 13 14 14 15 EXTRA_DIST= \ -
trunk/configure.ac
r214 r215 296 296 # Generate Makefiles. 297 297 # 298 AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile os/Makefile private/Makefile src/Makefile]) 298 AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile os/Makefile private/Makefile src/Makefile testing/Makefile]) 299 300 # 301 # Generate testsuite links 302 # 303 AC_CONFIG_LINKS([testing/dispatch:${x:+}private testing/bench.cc:testing/bench.mm testing/leaks-wrapper:testing/leaks-wrapper.sh]) 304 299 305 AC_OUTPUT -
trunk/testing/Makefile.am
r211 r215 63 63 dispatch_select 64 64 65 dispatch_c99_CFLAGS= -std=c9965 dispatch_c99_CFLAGS=$(AM_CFLAGS) -std=c99 66 66 dispatch_plusplus_SOURCES=dispatch_plusplus.cpp 67 67 dispatch_priority2_SOURCES=dispatch_priority.c 68 dispatch_priority2_C FLAGS=-DUSE_SET_TARGET_QUEUE=168 dispatch_priority2_CPPFLAGS=$(AM_CPPFLAGS) -DUSE_SET_TARGET_QUEUE=1 69 69 70 INCLUDES=-I$(top_builddir) -I$(top_srcdir)70 AM_CPPFLAGS=-I$(top_builddir) -I$(top_srcdir) 71 71 72 CPPFLAGS= 73 CFLAGS=-Wall -g $(MARCH_FLAGS) $(CBLOCKS_FLAGS) 74 OBJCFLAGS=-Wall -g $(MARCH_FLAGS) $(CBLOCKS_FLAGS) 75 CXXFLAGS=-Wall -g $(MARCH_FLAGS) $(CXXBLOCKS_FLAGS) 72 AM_CFLAGS=-Wall $(MARCH_FLAGS) $(CBLOCKS_FLAGS) 73 AM_OBJCFLAGS=-Wall $(MARCH_FLAGS) $(CBLOCKS_FLAGS) -fobjc-gc 74 AM_CXXFLAGS=-Wall $(MARCH_FLAGS) $(CXXBLOCKS_FLAGS) 76 75 77 76 LDADD=libbsdtests.la ../src/libdispatch.la … … 84 83 TESTS+= \ 85 84 dispatch_cf_main \ 85 dispatch_transform \ 86 86 dispatch_sync_on_main \ 87 87 cffd 88 88 89 89 dispatch_cf_main_LDFLAGS=-framework CoreFoundation 90 dispatch_transform_LDFLAGS=-framework CoreFoundation -framework Security 90 91 dispatch_sync_on_main_LDFLAGS=-framework CoreFoundation 91 92 cffd_LDFLAGS=-framework CoreFoundation … … 100 101 101 102 dispatch_sync_gc_SOURCES=dispatch_sync_gc.m 102 dispatch_sync_gc_OBJCFLAGS=-fobjc-gc103 103 dispatch_sync_gc_LDFLAGS=-framework Foundation 104 104 dispatch_apply_gc_SOURCES=dispatch_apply_gc.m 105 dispatch_apply_gc_OBJCFLAGS=-fobjc-gc106 105 dispatch_apply_gc_LDFLAGS=-framework Foundation 107 106 nsoperation_SOURCES=nsoperation.m 108 107 nsoperation_LDFLAGS=-framework Foundation 109 bench_SOURCES=bench.cc func.c 108 nodist_bench_SOURCES=bench.cc 109 bench_SOURCES=func.c 110 110 bench_LDFLAGS=-framework Foundation 111 111 # Workaround missing objcxx support in older autotools -
trunk/testing/bench.mm
r211 r215 417 417 s = mach_absolute_time(); 418 418 for (i = cnt; i; i--) { 419 global = 0; 420 asm volatile("mfence" ::: "memory"); 421 } 422 print_result(s, "Store + mfence:"); 423 424 s = mach_absolute_time(); 425 for (i = cnt; i; i--) { 419 426 unsigned long _clbr; 420 427 #ifdef __LP64__ … … 467 474 #endif 468 475 476 #ifdef _ARM_ARCH_7 477 s = mach_absolute_time(); 478 for (i = cnt; i; i--) { 479 asm volatile("str %[_r], [%[_p], %[_o]]" : 480 : [_p] "p" (&global), [_o] "M" (0), [_r] "r" (0) : "memory"); 481 asm volatile("dmb ishst" : : : "memory"); 482 } 483 print_result(s, "'str + dmb ishst' instructions:"); 484 #endif 485 486 #ifdef _ARM_ARCH_7 487 s = mach_absolute_time(); 488 for (i = cnt; i; i--) { 489 uintptr_t prev; 490 uint32_t t; 491 do { 492 asm volatile("ldrex %[_r], [%[_p], %[_o]]" 493 : [_r] "=&r" (prev) \ 494 : [_p] "p" (&global), [_o] "M" (0) : "memory"); 495 asm volatile("strex %[_t], %[_r], [%[_p], %[_o]]" 496 : [_t] "=&r" (t) \ 497 : [_p] "p" (&global), [_o] "M" (0), [_r] "r" (0) : "memory"); 498 } while (t); 499 } 500 print_result(s, "'ldrex + strex' instructions:"); 501 #endif 502 469 503 s = mach_absolute_time(); 470 504 for (i = cnt; i; i--) { … … 528 562 } 529 563 print_result(s, "Atomic increment:"); 564 565 { 566 global = 0; 567 volatile int32_t *g = &global; 568 569 s = mach_absolute_time(); 570 for (i = cnt; i; i--) { 571 uint32_t result; 572 __sync_and_and_fetch(g, 1); 573 result = *g; 574 if (result) { 575 abort(); 576 } 577 } 578 print_result(s, "Atomic and-and-fetch, reloading result:"); 579 } 580 581 { 582 global = 0; 583 volatile int32_t *g = &global; 584 585 s = mach_absolute_time(); 586 for (i = cnt; i; i--) { 587 uint32_t result; 588 result = __sync_and_and_fetch(g, 1); 589 if (result) { 590 abort(); 591 } 592 } 593 print_result(s, "Atomic and-and-fetch, using result:"); 594 } 530 595 531 596 global = 0; -
trunk/testing/bsdtestharness.c
r211 r215 19 19 */ 20 20 21 #include <mach/clock_types.h>22 21 #include <dispatch/dispatch.h> 23 22 #include <assert.h> … … 27 26 #include <unistd.h> 28 27 #include <signal.h> 28 #include <mach/clock_types.h> 29 29 #include <mach-o/arch.h> 30 #include <sys/resource.h> 31 #include <sys/time.h> 30 32 31 33 #include <bsdtests.h> … … 38 40 dispatch_source_t tmp_ds; 39 41 int res; 40 pid_t pid ;42 pid_t pid = 0; 41 43 42 44 if (argc < 2) { … … 45 47 } 46 48 49 short spawnflags = POSIX_SPAWN_START_SUSPENDED; 50 #if TARGET_OS_EMBEDDED 51 spawnflags |= POSIX_SPAWN_SETEXEC; 52 #endif 53 47 54 posix_spawnattr_t attr; 48 55 res = posix_spawnattr_init(&attr); 49 56 assert(res == 0); 50 res = posix_spawnattr_setflags(&attr, POSIX_SPAWN_START_SUSPENDED);57 res = posix_spawnattr_setflags(&attr, spawnflags); 51 58 assert(res == 0); 59 60 uint64_t to = 0; 61 char *tos = getenv("BSDTEST_TIMEOUT"); 62 if (tos) { 63 to = strtoul(tos, NULL, 0); 64 to *= NSEC_PER_SEC; 65 } 52 66 53 67 char *arch = getenv("BSDTEST_ARCH"); … … 67 81 newargv[i-1] = NULL; 68 82 69 res = posix_spawnp(&pid, newargv[0], NULL, &attr, newargv, environ);70 if (res) {71 errno = res; 72 perror(newargv[0]);73 exit(EXIT_FAILURE);83 struct timeval tv_start; 84 gettimeofday(&tv_start, NULL); 85 86 if (spawnflags & POSIX_SPAWN_SETEXEC) { 87 pid = fork(); 74 88 } 89 if (!pid) { 90 res = posix_spawnp(&pid, newargv[0], NULL, &attr, newargv, environ); 91 if (res) { 92 errno = res; 93 perror(newargv[0]); 94 exit(EXIT_FAILURE); 95 } 96 } 97 75 98 //fprintf(stderr, "pid = %d\n", pid); 76 99 assert(pid > 0); … … 82 105 dispatch_source_set_event_handler(tmp_ds, ^{ 83 106 int status; 84 int res2 = waitpid(pid, &status, 0); 107 struct rusage usage; 108 struct timeval tv_stop, tv_wall; 109 110 gettimeofday(&tv_stop, NULL); 111 tv_wall.tv_sec = tv_stop.tv_sec - tv_start.tv_sec; 112 tv_wall.tv_sec -= (tv_stop.tv_usec < tv_start.tv_usec); 113 tv_wall.tv_usec = abs(tv_stop.tv_usec - tv_start.tv_usec); 114 115 int res2 = wait4(pid, &status, 0, &usage); 85 116 assert(res2 != -1); 86 117 test_long("Process exited", (WIFEXITED(status) && WEXITSTATUS(status) && WEXITSTATUS(status) != 0xff) || WIFSIGNALED(status), 0); 118 printf("[PERF]\twall time: %ld.%06d\n", tv_wall.tv_sec, tv_wall.tv_usec); 119 printf("[PERF]\tuser time: %ld.%06d\n", usage.ru_utime.tv_sec, usage.ru_utime.tv_usec); 120 printf("[PERF]\tsystem time: %ld.%06d\n", usage.ru_stime.tv_sec, usage.ru_stime.tv_usec); 121 printf("[PERF]\tmax resident set size: %ld\n", usage.ru_maxrss); 122 printf("[PERF]\tpage faults: %ld\n", usage.ru_majflt); 123 printf("[PERF]\tswaps: %ld\n", usage.ru_nswap); 124 printf("[PERF]\tvoluntary context switches: %ld\n", usage.ru_nvcsw); 125 printf("[PERF]\tinvoluntary context switches: %ld\n", usage.ru_nivcsw); 87 126 exit((WIFEXITED(status) && WEXITSTATUS(status)) || WIFSIGNALED(status)); 88 127 }); 89 128 dispatch_resume(tmp_ds); 90 129 130 if (!to) { 91 131 #if TARGET_OS_EMBEDDED 92 // Give embedded platforms a little more time. 93 uint64_t timeout = 300LL * NSEC_PER_SEC; 132 to = 180LL * NSEC_PER_SEC; 94 133 #else 95 uint64_t timeout = 150LL * NSEC_PER_SEC;134 to = 90LL * NSEC_PER_SEC; 96 135 #endif 136 } 97 137 98 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, t imeout), main_q, ^{138 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, to), main_q, ^{ 99 139 kill(pid, SIGKILL); 100 fprintf(stderr, "Terminating unresponsive process (%0.1lfs)\n", (double)t imeout/NSEC_PER_SEC);140 fprintf(stderr, "Terminating unresponsive process (%0.1lfs)\n", (double)to / NSEC_PER_SEC); 101 141 }); 102 142 … … 110 150 dispatch_resume(tmp_ds); 111 151 152 if (spawnflags & POSIX_SPAWN_SETEXEC) { 153 usleep(USEC_PER_SEC/10); 154 } 112 155 kill(pid, SIGCONT); 113 156 -
trunk/testing/bsdtests.c
r211 r215 128 128 } 129 129 130 void _test_ptr_not(const char* file, long line, const char* desc, const void* actual, const void* expected) 131 { 132 _test_print(file, line, desc, 133 (actual != expected), "%p", actual, "!%p", expected); 134 } 135 136 void test_ptr_not_format(const void *actual, const void* expected, const char *format, ...) 137 { 138 GENERATE_DESC 139 _test_ptr_not(NULL, 0, desc, actual, expected); 140 } 141 130 142 void 131 143 _test_uint32(const char* file, long line, const char* desc, uint32_t actual, uint32_t expected) … … 212 224 213 225 void 226 _test_long_less_than_or_equal(const char* file, long line, const char* desc, long actual, long expected_max) 227 { 228 _test_print(file, line, desc, (actual <= expected_max), "%ld", actual, "<=%ld", expected_max); 229 } 230 231 void 232 test_long_less_than_or_equal_format(long actual, long expected_max, const char* format, ...) 233 { 234 GENERATE_DESC 235 _test_long_less_than_or_equal(NULL, 0, desc, actual, expected_max); 236 } 237 238 void 214 239 _test_long_greater_than_or_equal(const char* file, long line, const char* desc, long actual, long expected_min) 215 240 { … … 248 273 GENERATE_DESC 249 274 _test_double_less_than_or_equal(NULL, 0, desc, val, max_expected); 275 } 276 277 void 278 _test_double_equal(const char* file, long line, const char* desc, double val, double expected) 279 { 280 _test_print(file, line, desc, (val == expected), "%f", val, "%f", expected); 281 } 282 283 284 void 285 test_double_equal_format(double val, double expected, const char *format, ...) 286 { 287 GENERATE_DESC 288 _test_double_equal(NULL, 0, desc, val, expected); 250 289 } 251 290 … … 386 425 return; 387 426 } 427 428 unsetenv("DYLD_IMAGE_SUFFIX"); 429 unsetenv("DYLD_INSERT_LIBRARIES"); 430 unsetenv("DYLD_LIBRARY_PATH"); 388 431 389 432 unsetenv("MallocStackLogging"); -
trunk/testing/bsdtests.h
r211 r215 19 19 */ 20 20 21 #ifndef __BSD_TEST_H__ 22 #define __BSD_TEST_H__ 23 21 24 #include <errno.h> 22 25 #include <mach/error.h> 23 26 #include <CoreFoundation/CoreFoundation.h> 27 28 static inline const char* 29 __BASENAME__(const char *_str_) 30 { 31 const char *_s_ = strrchr(_str_, '/'); 32 return (_s_ ? _s_ : _str_ - 1) + 1; 33 } 34 #define __SOURCE_FILE__ __BASENAME__(__FILE__) 24 35 25 36 __BEGIN_DECLS … … 48 59 */ 49 60 void _test_ptr_null(const char* file, long line, const char* desc, const void* ptr); 50 #define test_ptr_null(a,b) _test_ptr_null(__ FILE__, __LINE__, a, b)61 #define test_ptr_null(a,b) _test_ptr_null(__SOURCE_FILE__, __LINE__, a, b) 51 62 void test_ptr_null_format(void *ptr, const char *format, ...); 52 63 53 64 void _test_ptr_notnull(const char* file, long line, const char* desc, const void* ptr); 54 #define test_ptr_notnull(a,b) _test_ptr_notnull(__ FILE__, __LINE__, a, b)65 #define test_ptr_notnull(a,b) _test_ptr_notnull(__SOURCE_FILE__, __LINE__, a, b) 55 66 void test_ptr_notnull_format(const void *ptr, const char *format, ...) __printflike(2, 3); 56 67 68 void _test_ptr_not(const char* file, long line, const char* desc, const void* actual, const void* expected); 69 #define test_ptr_not(a, b, c) _test_ptr_not(__SOURCE_FILE__, __LINE__, a, b, c) 70 void test_ptr_not_format(const void* actual, const void* expected, const char *format, ...); 71 57 72 void _test_ptr(const char* file, long line, const char* desc, const void* actual, const void* expected); 58 #define test_ptr(a,b,c) _test_ptr(__ FILE__, __LINE__, a, b, c)73 #define test_ptr(a,b,c) _test_ptr(__SOURCE_FILE__, __LINE__, a, b, c) 59 74 void test_ptr_format(const void* actual, const void* expected, const char *format, ...) __printflike(3,4); 60 75 61 76 void _test_uint32(const char* file, long line, const char* desc, uint32_t actual, uint32_t expected); 62 #define test_uint32(a,b,c) _test_uint32(__ FILE__, __LINE__, a, b, c)77 #define test_uint32(a,b,c) _test_uint32(__SOURCE_FILE__, __LINE__, a, b, c) 63 78 void test_uint32_format(long actual, long expected, const char *format, ...) __printflike(3,4); 64 79 65 80 void _test_int32(const char* file, long line, const char* desc, int32_t actual, int32_t expected); 66 #define test_int32(a,b,c) _test_int32(__ FILE__, __LINE__, a, b, c)81 #define test_int32(a,b,c) _test_int32(__SOURCE_FILE__, __LINE__, a, b, c) 67 82 void test_sint32_format(int32_t actual, int32_t expected, const char* format, ...) __printflike(3,4); 68 83 69 84 void _test_long(const char* file, long line, const char* desc, long actual, long expected); 70 #define test_long(a,b,c) _test_long(__ FILE__, __LINE__, a, b, c)85 #define test_long(a,b,c) _test_long(__SOURCE_FILE__, __LINE__, a, b, c) 71 86 void test_long_format(long actual, long expected, const char *format, ...) __printflike(3,4); 72 87 73 88 void _test_uint64(const char* file, long line, const char* desc, uint64_t actual, uint64_t expected); 74 #define test_uint64(a,b,c) _test_uint64(__ FILE__, __LINE__, a, b, c)89 #define test_uint64(a,b,c) _test_uint64(__SOURCE_FILE__, __LINE__, a, b, c) 75 90 void test_uint64_format(uint64_t actual, uint64_t expected, const char* desc, ...); 76 91 77 92 void _test_int64(const char* file, long line, const char* desc, int64_t actual, int64_t expected); 78 #define test_int64(a,b,c) _test_uint64(__ FILE__, __LINE__, a, b, c)93 #define test_int64(a,b,c) _test_uint64(__SOURCE_FILE__, __LINE__, a, b, c) 79 94 void test_int64_format(int64_t actual, int64_t expected, const char* desc, ...); 80 95 81 96 void _test_long_less_than(const char* file, long line, const char* desc, long actual, long max_expected); 82 #define test_long_less_than(a,b,c) _test_long_less_than(__ FILE__, __LINE__, a, b, c)97 #define test_long_less_than(a,b,c) _test_long_less_than(__SOURCE_FILE__, __LINE__, a, b, c) 83 98 void test_long_less_than_format(long actual, long max_expected, const char *format, ...) __printflike(3,4); 84 99 100 void _test_long_less_than_or_equal(const char* file, long line, const char* desc, long actual, long max_expected); 101 #define test_long_less_than_or_equal(a,b,c) _test_long_less_than_or_equal(__SOURCE_FILE__, __LINE__, a, b, c) 102 void test_long_less_than_or_equal_format(long actual, long max_expected, const char *format, ...) __printflike(3,4); 103 85 104 void _test_long_greater_than_or_equal(const char* file, long line, const char* desc, long actual, long expected_min); 86 #define test_long_greater_than_or_equal(a,b,c) _test_long_greater_than_or_equal(__ FILE__, __LINE__, a, b, c)105 #define test_long_greater_than_or_equal(a,b,c) _test_long_greater_than_or_equal(__SOURCE_FILE__, __LINE__, a, b, c) 87 106 void test_long_greater_than_or_equal_format(long actual, long expected_min, const char *format, ...) __printflike(3,4); 88 107 89 108 void _test_double_less_than_or_equal(const char* file, long line, const char* desc, double val, double max_expected); 90 #define test_double_less_than_or_equal(d, v, m) _test_double_less_than_or_equal(__ FILE__, __LINE__, d, v, m)109 #define test_double_less_than_or_equal(d, v, m) _test_double_less_than_or_equal(__SOURCE_FILE__, __LINE__, d, v, m) 91 110 void test_double_less_than_or_equal_format(double val, double max_expected, const char *format, ...) __printflike(3,4); 92 111 93 112 void _test_double_less_than(const char* file, long line, const char* desc, double val, double max_expected); 94 #define test_double_less_than(d, v, m) _test_double_less_than(__ FILE__, __LINE__, d, v, m)113 #define test_double_less_than(d, v, m) _test_double_less_than(__SOURCE_FILE__, __LINE__, d, v, m) 95 114 void test_double_less_than_format(double val, double max_expected, const char *format, ...) __printflike(3,4); 96 115 116 void _test_double_equal(const char* file, long line, const char* desc, double val, double expected); 117 #define test_double_equal(d, v, m) _test_double_equal(__SOURCE_FILE__, __LINE__, d, v, m) 118 void test_double_equal_format(double val, double expected, const char *format, ...) __printflike(3,4); 119 97 120 void _test_errno(const char* file, long line, const char* desc, long actual, long expected); 98 #define test_errno(a,b,c) _test_errno(__ FILE__, __LINE__, a, b, c)121 #define test_errno(a,b,c) _test_errno(__SOURCE_FILE__, __LINE__, a, b, c) 99 122 void test_errno_format(long actual, long expected, const char *format, ...) __printflike(3,4); 100 123 101 124 void _test_mach_error(const char* file, long line, const char* desc, mach_error_t actual, mach_error_t expected); 102 #define test_mach_error(a,b,c) _test_mach_error(__ FILE__, __LINE__, a, b, c)125 #define test_mach_error(a,b,c) _test_mach_error(__SOURCE_FILE__, __LINE__, a, b, c) 103 126 void test_mach_error_format(mach_error_t actual, mach_error_t expected, const char *format, ...) __printflike(3,4); 104 127 … … 107 130 108 131 void _test_skip(const char* file, long line, const char* desc); 109 #define test_skip(m) _test_skip(__ FILE__, __LINE__, m)132 #define test_skip(m) _test_skip(__SOURCE_FILE__, __LINE__, m) 110 133 #define test_skip2(m) _test_skip("", 0, m) 111 134 void test_skip_format(const char *format, ...) __printflike(1,2); 112 135 113 136 __END_DECLS 137 138 #endif /* __BSD_TEST_H__ */ -
trunk/testing/dispatch_after.c
r211 r215 51 51 time_a = dispatch_time(0, 6*NSEC_PER_SEC); 52 52 time_a_max = dispatch_time(0, 6.5*NSEC_PER_SEC); 53 dispatch_after(time_a, dispatch_get_ current_queue(), ^{53 dispatch_after(time_a, dispatch_get_main_queue(), ^{ 54 54 dispatch_time_t now_a = dispatch_time(0, 0); 55 55 test_long_less_than("can't finish faster than 5.5s", 0, now_a - time_a_min); … … 59 59 time_b = dispatch_time(0, 2*NSEC_PER_SEC); 60 60 time_b_max = dispatch_time(0, 2.5*NSEC_PER_SEC); 61 dispatch_after(time_b, dispatch_get_ current_queue(), ^{61 dispatch_after(time_b, dispatch_get_main_queue(), ^{ 62 62 dispatch_time_t now_b = dispatch_time(0, 0); 63 63 test_long_less_than("can't finish faster than 1.5s", 0, now_b - time_b_min); … … 67 67 time_c = dispatch_time(0, 0*NSEC_PER_SEC); 68 68 time_c_max = dispatch_time(0, .5*NSEC_PER_SEC); 69 dispatch_after(time_c, dispatch_get_ current_queue(), ^{69 dispatch_after(time_c, dispatch_get_main_queue(), ^{ 70 70 dispatch_time_t now_c = dispatch_time(0, 0); 71 71 test_long_less_than("can't finish faster than 0s", 0, now_c - time_c_min); 72 72 test_long_less_than("must finish faster than .5s", 0, time_c_max - now_c); 73 73 74 dispatch_async_f(dispatch_get_ current_queue(), NULL, done);74 dispatch_async_f(dispatch_get_main_queue(), NULL, done); 75 75 }); 76 76 }); -
trunk/testing/dispatch_api.c
r211 r215 34 34 main(void) 35 35 { 36 dispatch_queue_t q; 36 37 dispatch_test_start("Dispatch (Public) API"); 37 dispatch_queue_tq = dispatch_get_main_queue();38 q = dispatch_get_main_queue(); 38 39 test_ptr_notnull("dispatch_get_main_queue", q); 39 40 -
trunk/testing/dispatch_apply.c
r211 r215 25 25 #include <assert.h> 26 26 #include <libkern/OSAtomic.h> 27 #include <sys/types.h> 28 #include <sys/sysctl.h> 27 29 28 30 #include <bsdtests.h> 29 31 #include "dispatch_test.h" 32 33 static volatile int32_t busy_threads_started, busy_threads_finished; 34 35 /* 36 * Keep a thread busy, spinning on the CPU. 37 */ 38 #if TARGET_OS_EMBEDDED 39 // iPhone 4 40 #define ITERS_PER_SECOND 50000000UL 41 #else 42 // On a 2.7 4-core i5 iMac12,2, one thread of this loop runs at ROUGHLY: 43 #define ITERS_PER_SECOND 1000000000UL 44 #endif 45 46 /* Fiddling with j in the middle and hitting this global will hopefully keep 47 * the optimizer from cutting the whole thing out as dead code. 48 */ 49 static volatile unsigned int busythread_useless; 50 void busythread(void *ignored) 51 { 52 (void)ignored; 53 uint64_t i = 0, j = 0; 54 55 OSAtomicIncrement32(&busy_threads_started); 56 57 for(i = 0; i < 2*ITERS_PER_SECOND; i++) 58 { 59 if(i == 500000) { j -= busythread_useless; } 60 j += i; 61 } 62 63 OSAtomicIncrement32(&busy_threads_finished); 64 } 65 66 /* 67 * Test that dispatch_apply can make progress and finish, even if there are 68 * so many other running and unblocked workqueue threads that the apply's 69 * helper threads never get a chance to come up. 70 * 71 * <rdar://problem/10718199> dispatch_apply should not block waiting on other 72 * threads while calling thread is available 73 */ 74 void test_apply_contended(dispatch_queue_t dq) 75 { 76 uint32_t activecpu; 77 size_t s = sizeof(activecpu); 78 sysctlbyname("hw.activecpu", &activecpu, &s, NULL, 0); 79 int tIndex, n_threads = activecpu; 80 dispatch_group_t grp = dispatch_group_create(); 81 82 for(tIndex = 0; tIndex < n_threads; tIndex++) { 83 dispatch_group_async_f(grp, dq, NULL, busythread); 84 } 85 86 // Spin until all the threads have actually started 87 while(busy_threads_started < n_threads) { 88 usleep(1); 89 } 90 91 volatile __block int32_t count = 0; 92 const int32_t final = 32; 93 94 unsigned int before = busy_threads_started; 95 dispatch_apply(final, dq, ^(size_t i __attribute__((unused))) { 96 OSAtomicIncrement32(&count); 97 }); 98 unsigned int after = busy_threads_finished; 99 100 test_long("contended: threads started before apply", before, n_threads); 101 test_long("contended: count", count, final); 102 test_long("contended: threads finished before apply", after, 0); 103 104 dispatch_group_wait(grp, DISPATCH_TIME_FOREVER); 105 dispatch_release(grp); 106 107 } 30 108 31 109 int … … 55 133 test_long("nested count", count, final * final * final); 56 134 135 test_apply_contended(queue); 136 57 137 test_stop(); 58 138 -
trunk/testing/dispatch_concur.c
r211 r215 148 148 if (c > *m) *m = c; 149 149 150 usleep(10000 );150 usleep(100000); 151 151 __sync_sub_and_fetch(&concur, 1); 152 152 } -
trunk/testing/dispatch_deadname.c
r211 r215 33 33 #define test_mach_assume_zero(x) ({kern_return_t _kr = (x); \ 34 34 if (_kr) fprintf(stderr, "mach error 0x%x \"%s\": %s\n", \ 35 _kr, mach_error_string(_kr), #x); _kr; })36 void 37 test_mach_debug_port(mach_port_t name, const char *str )35 _kr, mach_error_string(_kr), #x); (void)kr; }) 36 void 37 test_mach_debug_port(mach_port_t name, const char *str, unsigned int line) 38 38 { 39 39 mach_port_type_t type; … … 41 41 unsigned int dnreqs = 0, dnrsiz; 42 42 kern_return_t kr = mach_port_type(mach_task_self(), name, &type); 43 44 43 if (kr) { 45 fprintf(stderr, "machport[0x%08x] = { error(0x%x) \"%s\" }: %s \n",46 name, kr, mach_error_string(kr), str );44 fprintf(stderr, "machport[0x%08x] = { error(0x%x) \"%s\" }: %s %u\n", 45 name, kr, mach_error_string(kr), str, line); 47 46 return; 48 47 } … … 59 58 MACH_PORT_RIGHT_DEAD_NAME, &nd)); 60 59 } 61 if (type & (MACH_PORT_TYPE_RECEIVE|MACH_PORT_TYPE_SEND| 62 MACH_PORT_TYPE_SEND_ONCE)) { 60 if (type & (MACH_PORT_TYPE_RECEIVE|MACH_PORT_TYPE_SEND)) { 63 61 test_mach_assume_zero(mach_port_dnrequest_info(mach_task_self(), name, 64 62 &dnrsiz, &dnreqs)); … … 72 70 MACH_PORT_RECEIVE_STATUS, (void*)&status, &cnt)); 73 71 fprintf(stderr, "machport[0x%08x] = { R(%03u) S(%03u) SO(%03u) D(%03u) " 74 "dnreqs(%03u) nsreq(%s) pdreq(%s) srights(%s) sorights(%03u) " 75 "qlim(%03u) msgcount(%03u) mkscount(%03u) seqno(%03u) }: %s\n", 76 name, nr, ns, nso, nd, dnreqs, status.mps_nsrequest ? "Y":"N", 77 status.mps_pdrequest ? "Y":"N", status.mps_srights ? "Y":"N", 78 status.mps_sorights, status.mps_qlimit, status.mps_msgcount, 79 status.mps_mscount, status.mps_seqno, str); 72 "dnreqs(%03u) spreq(%s) nsreq(%s) pdreq(%s) srights(%s) " 73 "sorights(%03u) qlim(%03u) msgcount(%03u) mkscount(%03u) " 74 "seqno(%03u) }: %s %u\n", name, nr, ns, nso, nd, dnreqs, 75 type & MACH_PORT_TYPE_SPREQUEST ? "Y":"N", 76 status.mps_nsrequest ? "Y":"N", status.mps_pdrequest ? "Y":"N", 77 status.mps_srights ? "Y":"N", status.mps_sorights, 78 status.mps_qlimit, status.mps_msgcount, status.mps_mscount, 79 status.mps_seqno, str, line); 80 80 } else if (type & (MACH_PORT_TYPE_SEND|MACH_PORT_TYPE_SEND_ONCE| 81 81 MACH_PORT_TYPE_DEAD_NAME)) { 82 82 fprintf(stderr, "machport[0x%08x] = { R(%03u) S(%03u) SO(%03u) D(%03u) " 83 "dnreqs(%03u) }: %s\n", name, nr, ns, nso, nd, dnreqs, str); 83 "dnreqs(%03u) spreq(%s) }: %s %u\n", name, nr, ns, nso, nd, 84 dnreqs, type & MACH_PORT_TYPE_SPREQUEST ? "Y":"N", str, line); 84 85 } else { 85 fprintf(stderr, "machport[0x%08x] = { type(0x%08x) }: %s\n", name, type, 86 str); 87 } 88 } 89 #define test_mach_debug_port(x) test_mach_debug_port(x, __func__) 86 fprintf(stderr, "machport[0x%08x] = { type(0x%08x) }: %s %u\n", name, 87 type, str, line); 88 } 89 fflush(stderr); 90 } 91 #define test_mach_debug_port(x) test_mach_debug_port(x, __func__, __LINE__) 90 92 #else 91 #define test_mach_debug_port(x) 93 #define test_mach_debug_port(x) (void)(x) 92 94 #endif 93 95 … … 113 115 test_long("DISPATCH_MACH_SEND_DEAD", 114 116 dispatch_source_get_handle(ds0), mp); 117 dispatch_source_cancel(ds0); 118 }); 119 dispatch_source_set_cancel_handler(ds0, ^{ 120 kern_return_t kr = mach_port_deallocate(mach_task_self(), mp); 121 test_mach_error("mach_port_deallocate", kr, KERN_SUCCESS); 115 122 dispatch_release(ds0); 116 123 dispatch_group_leave(g); … … 432 439 dispatch_release(ds); 433 440 test_long("DISPATCH_SOURCE_TYPE_MACH_RECV", received, 0); 441 dispatch_group_wait(g, DISPATCH_TIME_FOREVER); 434 442 } 435 443 -
trunk/testing/dispatch_drift.c
r211 r215 29 29 #include "dispatch_test.h" 30 30 31 #if TARGET_OS_EMBEDDED32 #define ACCEPTABLE_DRIFT 0.00233 #else34 31 #define ACCEPTABLE_DRIFT 0.001 35 #endif36 32 37 33 int … … 40 36 __block uint32_t count = 0; 41 37 __block double last_jitter = 0; 42 // 10 times a second 43 uint64_t interval = 1000000000 / 10; 38 __block double drift_sum = 0; 39 // 100 times a second 40 uint64_t interval = 1000000000 / 100; 44 41 double interval_d = interval / 1000000000.0; 45 42 // for 25 seconds … … 68 65 double jitter = goal - now; 69 66 double drift = jitter - last_jitter; 67 drift_sum += drift; 70 68 71 69 printf("%4d: jitter %f, drift %f\n", count, jitter, drift); 72 70 73 71 if (target <= ++count) { 74 if (drift < 0) { 75 drift = -drift; 72 drift_sum /= count - 1; 73 if (drift_sum < 0) { 74 drift_sum = -drift_sum; 76 75 } 77 76 double acceptable_drift = ACCEPTABLE_DRIFT; 78 test_double_less_than("drift", drift , acceptable_drift);77 test_double_less_than("drift", drift_sum, acceptable_drift); 79 78 test_stop(); 80 79 } -
trunk/testing/dispatch_group.c
r211 r215 34 34 #endif 35 35 36 #if TARGET_OS_EMBEDDED 37 #define LOOP_COUNT 50000 38 #else 39 #define LOOP_COUNT 200000 40 #endif 41 42 static void test_group_notify(void*); 43 36 44 dispatch_group_t 37 45 create_group(size_t count, int delay) … … 58 66 } 59 67 60 int 61 main(void)68 static void 69 test_group(void *ctxt __attribute__((unused))) 62 70 { 63 71 long res; 64 65 dispatch_test_start("Dispatch Group");66 67 72 dispatch_group_t group; 68 73 … … 96 101 97 102 dispatch_group_notify(group, dispatch_get_main_queue(), ^{ 98 dispatch_queue_t m = dispatch_get_main_queue(); 99 dispatch_queue_t c = dispatch_get_current_queue(); 100 test_ptr("Notification Received", m, c); 101 test_stop(); 103 dispatch_test_current("Notification Received", dispatch_get_main_queue()); 104 dispatch_async_f(dispatch_get_main_queue(), NULL, test_group_notify); 102 105 }); 103 106 104 107 dispatch_release(group); 105 108 group = NULL; 109 } 106 110 111 static long completed; 112 113 static void 114 test_group_notify2(long cycle, dispatch_group_t tested) 115 { 116 static dispatch_queue_t rq, nq; 117 static dispatch_once_t once; 118 dispatch_once(&once, ^{ 119 rq = dispatch_queue_create("release", 0); 120 dispatch_suspend(rq); 121 nq = dispatch_queue_create("notify", 0); 122 }); 123 dispatch_resume(rq); 124 125 // n=4 works great for a 4CPU Mac Pro, this might work for a wider range of 126 // systems. 127 const int n = 1 + arc4random() % 8; 128 dispatch_group_t group = dispatch_group_create(); 129 dispatch_queue_t qa[n]; 130 131 dispatch_group_enter(group); 132 for (int i = 0; i < n; i++) { 133 char buf[48]; 134 sprintf(buf, "T%ld-%d", cycle, i); 135 qa[i] = dispatch_queue_create(buf, 0); 136 } 137 138 __block float eh = 0; 139 for (int i = 0; i < n; i++) { 140 dispatch_queue_t q = qa[i]; 141 dispatch_group_async(group, q, ^{ 142 // Seems to trigger a little more reliably with some work being 143 // done in this block 144 eh = sin(M_1_PI / cycle); 145 }); 146 } 147 dispatch_group_leave(group); 148 149 dispatch_group_notify(group, nq, ^{ 150 completed = cycle; 151 dispatch_group_leave(tested); 152 }); 153 154 // Releasing qa's queues here seems to avoid the race, so we are arranging 155 // for the current iteration's queues to be released on the next iteration. 156 dispatch_sync(rq, ^{}); 157 dispatch_suspend(rq); 158 for (int i = 0; i < n; i++) { 159 dispatch_queue_t q = qa[i]; 160 dispatch_async(rq, ^{ dispatch_release(q); }); 161 } 162 dispatch_release(group); 163 } 164 165 static void 166 test_group_notify(void *ctxt __attribute__((unused))) 167 { 168 // <rdar://problem/11445820> 169 dispatch_group_t tested = dispatch_group_create(); 170 test_ptr_notnull("dispatch_group_create", tested); 171 long i; 172 for (i = 0; i < LOOP_COUNT; i++) { 173 if (!((i+1) % (LOOP_COUNT/10))) { 174 fprintf(stderr, "#%ld\n", i+1); 175 } 176 dispatch_group_enter(tested); 177 test_group_notify2(i, tested); 178 if (dispatch_group_wait(tested, dispatch_time(DISPATCH_TIME_NOW, 179 NSEC_PER_SEC))) { 180 break; 181 } 182 } 183 test_long("dispatch_group_notify", i, LOOP_COUNT); 184 test_stop(); 185 } 186 187 int 188 main(void) 189 { 190 dispatch_test_start("Dispatch Group"); 191 dispatch_async_f(dispatch_get_main_queue(), NULL, test_group); 107 192 dispatch_main(); 108 193 -
trunk/testing/dispatch_io.c
r211 r215 66 66 67 67 static void 68 test_io_close(int with_timer )68 test_io_close(int with_timer, bool from_path) 69 69 { 70 70 #define chunks 4 … … 81 81 test_stop(); 82 82 } 83 if (fcntl(fd, F_ NOCACHE, 1)) {84 test_errno("fcntl F_ NOCACHE", errno, 0);83 if (fcntl(fd, F_GLOBAL_NOCACHE, 1) == -1) { 84 test_errno("fcntl F_GLOBAL_NOCACHE", errno, 0); 85 85 test_stop(); 86 86 } … … 95 95 dispatch_group_t g = dispatch_group_create(); 96 96 dispatch_group_enter(g); 97 dispatch_io_t io = dispatch_io_create(DISPATCH_IO_RANDOM, fd, 98 dispatch_get_global_queue(0, 0), ^(int error) { 97 void (^cleanup_handler)(int error) = ^(int error) { 99 98 test_errno("create error", error, 0); 100 99 dispatch_group_leave(g); 101 100 close(fd); 102 }); 101 }; 102 dispatch_io_t io; 103 if (!from_path) { 104 io = dispatch_io_create(DISPATCH_IO_RANDOM, fd, 105 dispatch_get_global_queue(0, 0), cleanup_handler); 106 } else { 107 #if DISPATCHTEST_IO_PATH 108 io = dispatch_io_create_with_path(DISPATCH_IO_RANDOM, path, O_RDONLY, 0, 109 dispatch_get_global_queue(0, 0), cleanup_handler); 110 #endif 111 } 103 112 dispatch_io_set_high_water(io, READSIZE); 104 113 if (with_timer == 1) { … … 148 157 }); 149 158 } 150 dispatch_io_close(io, /* NO STOP */ 0); 159 dispatch_io_close(io, 0); 160 dispatch_io_close(io, 0); 151 161 dispatch_io_read(io, 0, 1, dispatch_get_global_queue(0,0), 152 162 ^(bool done, dispatch_data_t d, int error) { … … 333 343 } 334 344 // disable caching also for extra fd opened by dispatch_io_create_with_path 335 if (fcntl(fd, F_GLOBAL_NOCACHE, 1) ) {336 test_errno("fcntl F_GLOBAL_NOCACHE failed", errno, 0);345 if (fcntl(fd, F_GLOBAL_NOCACHE, 1) == -1) { 346 test_errno("fcntl F_GLOBAL_NOCACHE", errno, 0); 337 347 test_stop(); 338 348 } … … 477 487 test_read_many_files(void) 478 488 { 479 char *paths[] = {"/usr/ include", NULL};489 char *paths[] = {"/usr/lib", NULL}; 480 490 dispatch_group_t g = dispatch_group_create(); 481 491 dispatch_semaphore_t s = dispatch_semaphore_create(maxopenfiles); … … 665 675 dispatch_async(dispatch_get_main_queue(), ^{ 666 676 #if DISPATCHTEST_IO 667 test_io_close(0 /* without timer */ ); 668 test_io_close(1 /* with channel interval */); 669 test_io_close(2 /* with external timer */); 677 int i; bool from_path = false; 678 do { 679 for (i = 0; i < 3; i++) { 680 test_io_close(i, from_path); 681 } 682 #if DISPATCHTEST_IO_PATH 683 from_path = !from_path; 684 #endif 685 } while (from_path); 670 686 test_io_stop(); 671 687 test_io_from_io(); -
trunk/testing/dispatch_priority.c
r211 r215 35 35 36 36 #ifdef DISPATCH_QUEUE_PRIORITY_BACKGROUND // <rdar://problem/7439794> 37 38 #define PRIORITIES 4 39 char *labels[PRIORITIES] = { "BACKGROUND", "LOW", "DEFAULT", "HIGH" }; 40 int priorities[PRIORITIES] = { DISPATCH_QUEUE_PRIORITY_BACKGROUND, DISPATCH_QUEUE_PRIORITY_LOW, DISPATCH_QUEUE_PRIORITY_DEFAULT, DISPATCH_QUEUE_PRIORITY_HIGH }; 41 42 #else 43 44 #define PRIORITIES 3 45 char *labels[PRIORITIES] = { "LOW", "DEFAULT", "HIGH" }; 46 int priorities[PRIORITIES] = { DISPATCH_QUEUE_PRIORITY_LOW, DISPATCH_QUEUE_PRIORITY_DEFAULT, DISPATCH_QUEUE_PRIORITY_HIGH }; 47 37 #define USE_BACKGROUND_PRIORITY 1 38 #else 39 #define DISPATCH_QUEUE_PRIORITY_BACKGROUND INT16_MIN 40 #endif 41 42 #define QUEUE_PRIORITY_PTHREAD INT_MAX 43 44 #if DISPATCH_API_VERSION < 20100518 // <rdar://problem/7790099> 45 #define DISPATCH_QUEUE_CONCURRENT NULL 48 46 #endif 49 47 50 48 #if TARGET_OS_EMBEDDED 51 #define LOOP_COUNT 2000000 49 #define LOOP_COUNT 5000000 50 const int importance = 24; // priority 55 52 51 #else 53 52 #define LOOP_COUNT 100000000 54 #endif 53 const int importance = 4; // priority 35 54 #endif 55 56 char *labels[] = { "BACKGROUND", "LOW", "DEFAULT", "HIGH", }; 57 int levels[] = { 58 DISPATCH_QUEUE_PRIORITY_BACKGROUND, DISPATCH_QUEUE_PRIORITY_LOW, 59 DISPATCH_QUEUE_PRIORITY_DEFAULT, DISPATCH_QUEUE_PRIORITY_HIGH, 60 }; 61 #define PRIORITIES (sizeof(levels)/sizeof(*levels)) 55 62 56 63 static union { … … 59 66 } counts[PRIORITIES]; 60 67 61 #define ITERATIONS (long)(PRIORITIES * n_blocks() * 0.50)62 68 static volatile long iterations; 69 static long total; 70 static size_t prio0, priorities = PRIORITIES; 63 71 64 72 int … … 79 87 histogram(void) 80 88 { 81 long total = 0; 82 size_t x,y; 83 for (y = 0; y < PRIORITIES; ++y) { 89 long completed = 0; 90 size_t x, y, i; 91 printf("\n"); 92 for (y = prio0; y < prio0 + priorities; ++y) { 84 93 printf("%s: %ld\n", labels[y], counts[y].count); 85 total+= counts[y].count;94 completed += counts[y].count; 86 95 87 96 double fraction = (double)counts[y].count / (double)n_blocks(); … … 93 102 } 94 103 95 test_long("blocks completed", total, ITERATIONS); 96 test_long_less_than("high priority precedence", counts[0].count, 97 counts[PRIORITIES-1].count); 104 test_long("blocks completed", completed, total); 105 for (i = prio0; i < prio0 + priorities; i++) { 106 if (levels[i] == DISPATCH_QUEUE_PRIORITY_HIGH) { 107 test_long_less_than_or_equal("high priority precedence", 108 counts[i-2].count, counts[i].count); 109 } 110 #if USE_BACKGROUND_PRIORITY 111 if (levels[i] == DISPATCH_QUEUE_PRIORITY_BACKGROUND) { 112 test_long_less_than_or_equal("background priority precedence", 113 counts[i].count, counts[i+2].count); 114 } 115 #endif 116 } 98 117 } 99 118 … … 116 135 usleep(100000); 117 136 histogram(); 118 test_stop(); 119 exit(0); 137 dispatch_time_t delay = DISPATCH_TIME_NOW; 138 dispatch_after(delay, dispatch_get_main_queue(), ^{ 139 test_stop(); 140 }); 120 141 } 121 142 } … … 137 158 { 138 159 dispatch_queue_t q[PRIORITIES]; 139 int i; 140 141 iterations = ITERATIONS; 160 size_t i; 161 162 #if !USE_BACKGROUND_PRIORITY 163 prio0++; 164 priorities--; 165 #endif 166 167 iterations = total = (priorities * n_blocks()) * 0.50; 142 168 143 169 #if USE_SET_TARGET_QUEUE 144 170 dispatch_test_start("Dispatch Priority (Set Target Queue)"); 145 for(i = 0; i < PRIORITIES; i++) { 146 #if DISPATCH_API_VERSION < 20100518 // <rdar://problem/7790099> 147 q[i] = dispatch_queue_create(labels[i], NULL); 148 #else 171 #else 172 dispatch_test_start("Dispatch Priority"); 173 #endif 174 175 for (i = prio0; i < prio0 + priorities; i++) { 176 dispatch_queue_t rq = dispatch_get_global_queue(levels[i], 0); 177 #if USE_SET_TARGET_QUEUE 149 178 q[i] = dispatch_queue_create(labels[i], DISPATCH_QUEUE_CONCURRENT); 150 #endif151 179 test_ptr_notnull("q[i]", q[i]); 152 180 assert(q[i]); 153 181 dispatch_suspend(q[i]); 154 dispatch_set_target_queue(q[i], dispatch_get_global_queue(priorities[i], 0)); 155 #if DISPATCH_API_VERSION < 20100518 // <rdar://problem/7790099> 156 dispatch_queue_set_width(q[i], LONG_MAX); 157 #endif 158 } 159 #else 160 dispatch_test_start("Dispatch Priority"); 161 for(i = 0; i < PRIORITIES; i++) { 162 q[i] = dispatch_get_global_queue(priorities[i], 0); 163 } 164 #endif 165 166 for(i = 0; i < PRIORITIES; i++) { 182 dispatch_set_target_queue(q[i], rq); 183 if (DISPATCH_QUEUE_CONCURRENT != NULL) { 184 dispatch_queue_set_width(q[i], LONG_MAX); 185 } 186 dispatch_release(rq); 187 #else 188 q[i] = rq; 189 #endif 190 } 191 192 for (i = prio0; i < prio0 + priorities; i++) { 167 193 submit_work(q[i], &counts[i].count); 168 194 } 169 195 170 #if USE_SET_TARGET_QUEUE 171 for(i = 0; i < PRIORITIES; i++) { 196 for (i = prio0; i < prio0 + priorities; i++) { 172 197 dispatch_resume(q[i]); 173 198 dispatch_release(q[i]); 174 199 } 175 #endif176 200 177 201 dispatch_main(); -
trunk/testing/dispatch_queue_finalizer.c
r211 r215 70 70 71 71 dispatch_set_context(q_null_context, NULL); 72 dispatch_set_finalizer_f(q_null_context, never_call); 72 73 dispatch_release(q_null_context); 73 74 -
trunk/testing/dispatch_suspend_timer.c
r211 r215 46 46 47 47 dispatch_queue_t main_q = dispatch_get_main_queue(); 48 test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());48 //test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue()); 49 49 50 50 __block int i = 0, i_prime = 0; -
trunk/testing/dispatch_test.c
r211 r215 20 20 21 21 #include "dispatch_test.h" 22 #include "bsdtests.h" 22 23 23 24 #ifdef __OBJC_GC__ … … 25 26 #endif 26 27 28 #include <stdlib.h> 29 #include <stdio.h> 27 30 #include <unistd.h> 28 31 #include <sys/event.h> 29 32 #include <assert.h> 33 34 #include <dispatch/dispatch.h> 30 35 31 36 void test_start(const char* desc); … … 57 62 return r > 0; 58 63 } 64 65 void 66 _dispatch_test_current(const char* file, long line, const char* desc, dispatch_queue_t expected) 67 { 68 dispatch_queue_t actual = dispatch_get_current_queue(); 69 _test_ptr(file, line, desc, actual, expected); 70 } -
trunk/testing/dispatch_test.h
r211 r215 21 21 #include <sys/cdefs.h> 22 22 #include <stdbool.h> 23 #include <dispatch/dispatch.h> 23 24 24 25 #define test_group_wait(g) do { \ … … 35 36 bool dispatch_test_check_evfilt_read_for_fd(int fd); 36 37 38 void _dispatch_test_current(const char* file, long line, const char* desc, dispatch_queue_t expected); 39 #define dispatch_test_current(a,b) _dispatch_test_current(__SOURCE_FILE__, __LINE__, a, b) 40 37 41 __END_DECLS -
trunk/testing/dispatch_timer.c
r211 r215 47 47 48 48 dispatch_queue_t main_q = dispatch_get_main_queue(); 49 test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());49 //test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue()); 50 50 51 51 uint64_t j; … … 74 74 75 75 dispatch_source_t s = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, main_q); 76 dispatch_debug(s, "fresh timer:");77 76 test_ptr_notnull("dispatch_source_create", s); 78 77 … … 81 80 dispatch_source_set_cancel_handler(s, ^{ 82 81 test_ptr_notnull("cancel handler run", s); 83 dispatch_debug(s, "pre release timer:");84 82 dispatch_release(s); 85 dispatch_debug(s, "post release timer:");86 83 }); 87 84 -
trunk/testing/dispatch_timer_bit31.c
r211 r215 35 35 36 36 dispatch_queue_t main_q = dispatch_get_main_queue(); 37 test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());37 //test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue()); 38 38 39 39 struct timeval start_time; -
trunk/testing/dispatch_timer_set_time.c
r211 r215 36 36 37 37 dispatch_queue_t main_q = dispatch_get_main_queue(); 38 test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());38 //test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue()); 39 39 40 40 __block int i = 0; -
trunk/testing/dispatch_vm.c
r211 r215 30 30 31 31 #include <dispatch/dispatch.h> 32 #include <dispatch/private.h> 32 33 33 34 #include <bsdtests.h> … … 37 38 38 39 #if TARGET_OS_EMBEDDED 39 #define ALLOC_SIZE ((size_t)(1024*1024* 5ul)) // 5MB40 #define ALLOC_SIZE ((size_t)(1024*1024*1ul)) // 1MB 40 41 #define NOTIFICATIONS 1 41 42 #else … … 61 62 #define log_msg(msg, ...) \ 62 63 do { \ 63 fprintf(stderr, "[%2ds] " msg, (int)(time(NULL) - initial), ## __VA_ARGS__);\64 fprintf(stderr, "[%2ds] " msg, (int)(time(NULL) - initial), ##__VA_ARGS__);\ 64 65 } while (0) 65 66 … … 103 104 main(void) 104 105 { 105 dispatch_test_start("Dispatch VM Pressure test"); // <rdar://problem/7000945>106 dispatch_test_start("Dispatch VM Pressure test"); // rdar://problem/7000945 106 107 if (!dispatch_test_check_evfilt_vm()) { 107 108 test_skip("EVFILT_VM not supported"); … … 143 144 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), 144 145 dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 145 while (handler_call_count < NOTIFICATIONS && page_count < max_page_count) { 146 while (handler_call_count < NOTIFICATIONS && 147 page_count < max_page_count) { 146 148 void *p = valloc(ALLOC_SIZE); 147 149 if (!p) { … … 164 166 return; 165 167 } 166 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), vm_queue, ^{ 167 test_long_less_than("VM Pressure fired", NOTIFICATIONS - 1, handler_call_count); 168 test_long_less_than("VM Pressure stopped firing", handler_call_count, 4); 168 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), 169 vm_queue, ^{ 170 test_long_greater_than_or_equal("VM Pressure fired", 171 handler_call_count, NOTIFICATIONS); 172 test_long_less_than("VM Pressure stopped firing", 173 handler_call_count, 4); 169 174 cleanup(); 170 175 }); … … 177 182 main(void) 178 183 { 179 dispatch_test_start("Dispatch VM Pressure test - No DISPATCH_SOURCE_TYPE_VM"); 184 dispatch_test_start("Dispatch VM Pressure test" 185 " - No DISPATCH_SOURCE_TYPE_VM"); 180 186 test_stop(); 181 187 return 0;
Note: See TracChangeset
for help on using the changeset viewer.

