Projects
Wiki     Timeline     Browser     Search     New Ticket     Bug Reports

Changeset 215


Ignore:
Timestamp:
08/08/12 22:09:03 (10 months ago)
Author:
dsteffen@…
Message:

MountainLion? macosforge testsuite

Location:
trunk
Files:
1 added
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile.am

    r214 r215  
    1010        os                                              \ 
    1111        private                                 \ 
    12         src 
     12        src                                             \ 
     13        testing 
    1314 
    1415EXTRA_DIST=                                     \ 
  • trunk/configure.ac

    r214 r215  
    296296# Generate Makefiles. 
    297297# 
    298 AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile os/Makefile private/Makefile src/Makefile]) 
     298AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile os/Makefile private/Makefile src/Makefile testing/Makefile]) 
     299 
     300# 
     301# Generate testsuite links 
     302# 
     303AC_CONFIG_LINKS([testing/dispatch:${x:+}private testing/bench.cc:testing/bench.mm testing/leaks-wrapper:testing/leaks-wrapper.sh]) 
     304 
    299305AC_OUTPUT 
  • trunk/testing/Makefile.am

    r211 r215  
    6363        dispatch_select 
    6464 
    65 dispatch_c99_CFLAGS=-std=c99 
     65dispatch_c99_CFLAGS=$(AM_CFLAGS) -std=c99 
    6666dispatch_plusplus_SOURCES=dispatch_plusplus.cpp 
    6767dispatch_priority2_SOURCES=dispatch_priority.c 
    68 dispatch_priority2_CFLAGS=-DUSE_SET_TARGET_QUEUE=1 
     68dispatch_priority2_CPPFLAGS=$(AM_CPPFLAGS) -DUSE_SET_TARGET_QUEUE=1 
    6969 
    70 INCLUDES=-I$(top_builddir) -I$(top_srcdir) 
     70AM_CPPFLAGS=-I$(top_builddir) -I$(top_srcdir) 
    7171 
    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) 
     72AM_CFLAGS=-Wall $(MARCH_FLAGS) $(CBLOCKS_FLAGS) 
     73AM_OBJCFLAGS=-Wall $(MARCH_FLAGS) $(CBLOCKS_FLAGS) -fobjc-gc 
     74AM_CXXFLAGS=-Wall $(MARCH_FLAGS) $(CXXBLOCKS_FLAGS) 
    7675 
    7776LDADD=libbsdtests.la ../src/libdispatch.la 
     
    8483TESTS+=                                                 \ 
    8584        dispatch_cf_main                        \ 
     85        dispatch_transform                      \ 
    8686        dispatch_sync_on_main           \ 
    8787        cffd 
    8888 
    8989dispatch_cf_main_LDFLAGS=-framework CoreFoundation 
     90dispatch_transform_LDFLAGS=-framework CoreFoundation -framework Security 
    9091dispatch_sync_on_main_LDFLAGS=-framework CoreFoundation 
    9192cffd_LDFLAGS=-framework CoreFoundation 
     
    100101 
    101102dispatch_sync_gc_SOURCES=dispatch_sync_gc.m 
    102 dispatch_sync_gc_OBJCFLAGS=-fobjc-gc 
    103103dispatch_sync_gc_LDFLAGS=-framework Foundation 
    104104dispatch_apply_gc_SOURCES=dispatch_apply_gc.m 
    105 dispatch_apply_gc_OBJCFLAGS=-fobjc-gc 
    106105dispatch_apply_gc_LDFLAGS=-framework Foundation 
    107106nsoperation_SOURCES=nsoperation.m 
    108107nsoperation_LDFLAGS=-framework Foundation 
    109 bench_SOURCES=bench.cc func.c 
     108nodist_bench_SOURCES=bench.cc 
     109bench_SOURCES=func.c 
    110110bench_LDFLAGS=-framework Foundation 
    111111# Workaround missing objcxx support in older autotools 
  • trunk/testing/bench.mm

    r211 r215  
    417417        s = mach_absolute_time(); 
    418418        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--) { 
    419426                unsigned long _clbr; 
    420427#ifdef __LP64__ 
     
    467474#endif 
    468475 
     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 
    469503        s = mach_absolute_time(); 
    470504        for (i = cnt; i; i--) { 
     
    528562        } 
    529563        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        } 
    530595 
    531596        global = 0; 
  • trunk/testing/bsdtestharness.c

    r211 r215  
    1919 */ 
    2020 
    21 #include <mach/clock_types.h> 
    2221#include <dispatch/dispatch.h> 
    2322#include <assert.h> 
     
    2726#include <unistd.h> 
    2827#include <signal.h> 
     28#include <mach/clock_types.h> 
    2929#include <mach-o/arch.h> 
     30#include <sys/resource.h> 
     31#include <sys/time.h> 
    3032 
    3133#include <bsdtests.h> 
     
    3840        dispatch_source_t tmp_ds; 
    3941        int res; 
    40         pid_t pid; 
     42        pid_t pid = 0; 
    4143 
    4244        if (argc < 2) { 
     
    4547        } 
    4648 
     49        short spawnflags = POSIX_SPAWN_START_SUSPENDED; 
     50#if TARGET_OS_EMBEDDED 
     51        spawnflags |= POSIX_SPAWN_SETEXEC; 
     52#endif 
     53 
    4754        posix_spawnattr_t attr; 
    4855        res = posix_spawnattr_init(&attr); 
    4956        assert(res == 0); 
    50         res = posix_spawnattr_setflags(&attr, POSIX_SPAWN_START_SUSPENDED); 
     57        res = posix_spawnattr_setflags(&attr, spawnflags); 
    5158        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        } 
    5266 
    5367        char *arch = getenv("BSDTEST_ARCH"); 
     
    6781        newargv[i-1] = NULL; 
    6882 
    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(); 
    7488        } 
     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 
    7598        //fprintf(stderr, "pid = %d\n", pid); 
    7699        assert(pid > 0); 
     
    82105        dispatch_source_set_event_handler(tmp_ds, ^{ 
    83106                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); 
    85116                assert(res2 != -1); 
    86117                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); 
    87126                exit((WIFEXITED(status) && WEXITSTATUS(status)) || WIFSIGNALED(status)); 
    88127        }); 
    89128        dispatch_resume(tmp_ds); 
    90129 
     130        if (!to) { 
    91131#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; 
    94133#else 
    95         uint64_t timeout = 150LL * NSEC_PER_SEC; 
     134                to = 90LL * NSEC_PER_SEC; 
    96135#endif 
     136        } 
    97137 
    98         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, timeout), main_q, ^{ 
     138        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, to), main_q, ^{ 
    99139                kill(pid, SIGKILL); 
    100                 fprintf(stderr, "Terminating unresponsive process (%0.1lfs)\n", (double)timeout/NSEC_PER_SEC); 
     140                fprintf(stderr, "Terminating unresponsive process (%0.1lfs)\n", (double)to / NSEC_PER_SEC); 
    101141        }); 
    102142 
     
    110150        dispatch_resume(tmp_ds); 
    111151 
     152        if (spawnflags & POSIX_SPAWN_SETEXEC) { 
     153                usleep(USEC_PER_SEC/10); 
     154        } 
    112155        kill(pid, SIGCONT); 
    113156 
  • trunk/testing/bsdtests.c

    r211 r215  
    128128} 
    129129 
     130void _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 
     136void 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 
    130142void 
    131143_test_uint32(const char* file, long line, const char* desc, uint32_t actual, uint32_t expected) 
     
    212224 
    213225void 
     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 
     231void 
     232test_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 
     238void 
    214239_test_long_greater_than_or_equal(const char* file, long line, const char* desc, long actual, long expected_min) 
    215240{ 
     
    248273        GENERATE_DESC 
    249274        _test_double_less_than_or_equal(NULL, 0, desc, val, max_expected); 
     275} 
     276 
     277void 
     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 
     284void 
     285test_double_equal_format(double val, double expected, const char *format, ...) 
     286{ 
     287        GENERATE_DESC 
     288        _test_double_equal(NULL, 0, desc, val, expected); 
    250289} 
    251290 
     
    386425                return; 
    387426        } 
     427 
     428        unsetenv("DYLD_IMAGE_SUFFIX"); 
     429        unsetenv("DYLD_INSERT_LIBRARIES"); 
     430        unsetenv("DYLD_LIBRARY_PATH"); 
    388431 
    389432        unsetenv("MallocStackLogging"); 
  • trunk/testing/bsdtests.h

    r211 r215  
    1919 */ 
    2020 
     21#ifndef __BSD_TEST_H__ 
     22#define __BSD_TEST_H__ 
     23 
    2124#include <errno.h> 
    2225#include <mach/error.h> 
    2326#include <CoreFoundation/CoreFoundation.h> 
     27 
     28static 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__) 
    2435 
    2536__BEGIN_DECLS 
     
    4859 */ 
    4960void _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) 
    5162void test_ptr_null_format(void *ptr, const char *format, ...); 
    5263 
    5364void _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) 
    5566void test_ptr_notnull_format(const void *ptr, const char *format, ...) __printflike(2, 3); 
    5667 
     68void _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) 
     70void test_ptr_not_format(const void* actual, const void* expected, const char *format, ...); 
     71 
    5772void _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) 
    5974void test_ptr_format(const void* actual, const void* expected, const char *format, ...) __printflike(3,4); 
    6075 
    6176void _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) 
    6378void test_uint32_format(long actual, long expected, const char *format, ...) __printflike(3,4); 
    6479 
    6580void _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) 
    6782void test_sint32_format(int32_t actual, int32_t expected, const char* format, ...) __printflike(3,4); 
    6883 
    6984void _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) 
    7186void test_long_format(long actual, long expected, const char *format, ...) __printflike(3,4); 
    7287 
    7388void _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) 
    7590void test_uint64_format(uint64_t actual, uint64_t expected, const char* desc, ...); 
    7691 
    7792void _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) 
    7994void test_int64_format(int64_t actual, int64_t expected, const char* desc, ...); 
    8095 
    8196void _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) 
    8398void test_long_less_than_format(long actual, long max_expected, const char *format, ...) __printflike(3,4); 
    8499 
     100void _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) 
     102void test_long_less_than_or_equal_format(long actual, long max_expected, const char *format, ...) __printflike(3,4); 
     103 
    85104void _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) 
    87106void test_long_greater_than_or_equal_format(long actual, long expected_min, const char *format, ...) __printflike(3,4); 
    88107 
    89108void _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) 
    91110void test_double_less_than_or_equal_format(double val, double max_expected, const char *format, ...) __printflike(3,4); 
    92111 
    93112void _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) 
    95114void test_double_less_than_format(double val, double max_expected, const char *format, ...) __printflike(3,4); 
    96115 
     116void _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) 
     118void test_double_equal_format(double val, double expected, const char *format, ...) __printflike(3,4); 
     119 
    97120void _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) 
    99122void test_errno_format(long actual, long expected, const char *format, ...) __printflike(3,4); 
    100123 
    101124void _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) 
    103126void test_mach_error_format(mach_error_t actual, mach_error_t expected, const char *format, ...) __printflike(3,4); 
    104127 
     
    107130 
    108131void _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) 
    110133#define test_skip2(m) _test_skip("", 0, m) 
    111134void test_skip_format(const char *format, ...) __printflike(1,2); 
    112135 
    113136__END_DECLS 
     137 
     138#endif /* __BSD_TEST_H__ */ 
  • trunk/testing/dispatch_after.c

    r211 r215  
    5151                time_a     = dispatch_time(0,   6*NSEC_PER_SEC); 
    5252                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(), ^{ 
    5454                        dispatch_time_t now_a = dispatch_time(0, 0); 
    5555                        test_long_less_than("can't finish faster than 5.5s", 0, now_a - time_a_min); 
     
    5959                        time_b     = dispatch_time(0,    2*NSEC_PER_SEC); 
    6060                        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(), ^{ 
    6262                                dispatch_time_t now_b = dispatch_time(0, 0); 
    6363                                test_long_less_than("can't finish faster than 1.5s", 0, now_b - time_b_min); 
     
    6767                                time_c     = dispatch_time(0,  0*NSEC_PER_SEC); 
    6868                                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(), ^{ 
    7070                                        dispatch_time_t now_c = dispatch_time(0, 0); 
    7171                                        test_long_less_than("can't finish faster than 0s", 0, now_c - time_c_min); 
    7272                                        test_long_less_than("must finish faster than .5s", 0, time_c_max - now_c); 
    7373 
    74                                         dispatch_async_f(dispatch_get_current_queue(), NULL, done); 
     74                                        dispatch_async_f(dispatch_get_main_queue(), NULL, done); 
    7575                                }); 
    7676                        }); 
  • trunk/testing/dispatch_api.c

    r211 r215  
    3434main(void) 
    3535{ 
     36        dispatch_queue_t q; 
    3637        dispatch_test_start("Dispatch (Public) API"); 
    37         dispatch_queue_t q = dispatch_get_main_queue(); 
     38        q = dispatch_get_main_queue(); 
    3839        test_ptr_notnull("dispatch_get_main_queue", q); 
    3940 
  • trunk/testing/dispatch_apply.c

    r211 r215  
    2525#include <assert.h> 
    2626#include <libkern/OSAtomic.h> 
     27#include <sys/types.h> 
     28#include <sys/sysctl.h> 
    2729 
    2830#include <bsdtests.h> 
    2931#include "dispatch_test.h" 
     32 
     33static 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 */ 
     49static volatile unsigned int busythread_useless; 
     50void 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 */ 
     74void 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} 
    30108 
    31109int 
     
    55133        test_long("nested count", count, final * final * final); 
    56134 
     135        test_apply_contended(queue); 
     136 
    57137        test_stop(); 
    58138 
  • trunk/testing/dispatch_concur.c

    r211 r215  
    148148        if (c > *m) *m = c; 
    149149 
    150         usleep(10000); 
     150        usleep(100000); 
    151151        __sync_sub_and_fetch(&concur, 1); 
    152152} 
  • trunk/testing/dispatch_deadname.c

    r211 r215  
    3333#define test_mach_assume_zero(x) ({kern_return_t _kr = (x); \ 
    3434                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; }) 
     36void 
     37test_mach_debug_port(mach_port_t name, const char *str, unsigned int line) 
    3838{ 
    3939        mach_port_type_t type; 
     
    4141        unsigned int dnreqs = 0, dnrsiz; 
    4242        kern_return_t kr = mach_port_type(mach_task_self(), name, &type); 
    43  
    4443        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); 
    4746                return; 
    4847        } 
     
    5958                                MACH_PORT_RIGHT_DEAD_NAME, &nd)); 
    6059        } 
    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)) { 
    6361                test_mach_assume_zero(mach_port_dnrequest_info(mach_task_self(), name, 
    6462                                &dnrsiz, &dnreqs)); 
     
    7270                                MACH_PORT_RECEIVE_STATUS, (void*)&status, &cnt)); 
    7371                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); 
    8080        } else if (type & (MACH_PORT_TYPE_SEND|MACH_PORT_TYPE_SEND_ONCE| 
    8181                        MACH_PORT_TYPE_DEAD_NAME)) { 
    8282                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); 
    8485        } 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__) 
    9092#else 
    91 #define test_mach_debug_port(x) 
     93#define test_mach_debug_port(x) (void)(x) 
    9294#endif 
    9395 
     
    113115                        test_long("DISPATCH_MACH_SEND_DEAD", 
    114116                                        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); 
    115122                        dispatch_release(ds0); 
    116123                        dispatch_group_leave(g); 
     
    432439        dispatch_release(ds); 
    433440        test_long("DISPATCH_SOURCE_TYPE_MACH_RECV", received, 0); 
     441        dispatch_group_wait(g, DISPATCH_TIME_FOREVER); 
    434442} 
    435443 
  • trunk/testing/dispatch_drift.c

    r211 r215  
    2929#include "dispatch_test.h" 
    3030 
    31 #if TARGET_OS_EMBEDDED 
    32 #define ACCEPTABLE_DRIFT 0.002 
    33 #else 
    3431#define ACCEPTABLE_DRIFT 0.001 
    35 #endif 
    3632 
    3733int 
     
    4036        __block uint32_t count = 0; 
    4137        __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; 
    4441        double interval_d = interval / 1000000000.0; 
    4542        // for 25 seconds 
     
    6865                double jitter = goal - now; 
    6966                double drift = jitter - last_jitter; 
     67                drift_sum += drift; 
    7068 
    7169                printf("%4d: jitter %f, drift %f\n", count, jitter, drift); 
    7270 
    7371                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; 
    7675                        } 
    7776                        double acceptable_drift = ACCEPTABLE_DRIFT; 
    78                         test_double_less_than("drift", drift, acceptable_drift); 
     77                        test_double_less_than("drift", drift_sum, acceptable_drift); 
    7978                        test_stop(); 
    8079                } 
  • trunk/testing/dispatch_group.c

    r211 r215  
    3434#endif 
    3535 
     36#if TARGET_OS_EMBEDDED 
     37#define LOOP_COUNT 50000 
     38#else 
     39#define LOOP_COUNT 200000 
     40#endif 
     41 
     42static void test_group_notify(void*); 
     43 
    3644dispatch_group_t 
    3745create_group(size_t count, int delay) 
     
    5866} 
    5967 
    60 int 
    61 main(void) 
     68static void 
     69test_group(void *ctxt __attribute__((unused))) 
    6270{ 
    6371        long res; 
    64  
    65         dispatch_test_start("Dispatch Group"); 
    66  
    6772        dispatch_group_t group; 
    6873 
     
    96101 
    97102        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); 
    102105        }); 
    103106 
    104107        dispatch_release(group); 
    105108        group = NULL; 
     109} 
    106110 
     111static long completed; 
     112 
     113static void 
     114test_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 
     165static void 
     166test_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 
     187int 
     188main(void) 
     189{ 
     190        dispatch_test_start("Dispatch Group"); 
     191        dispatch_async_f(dispatch_get_main_queue(), NULL, test_group); 
    107192        dispatch_main(); 
    108193 
  • trunk/testing/dispatch_io.c

    r211 r215  
    6666 
    6767static void 
    68 test_io_close(int with_timer) 
     68test_io_close(int with_timer, bool from_path) 
    6969{ 
    7070        #define chunks 4 
     
    8181                test_stop(); 
    8282        } 
    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); 
    8585                test_stop(); 
    8686        } 
     
    9595        dispatch_group_t g = dispatch_group_create(); 
    9696        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) { 
    9998                test_errno("create error", error, 0); 
    10099                dispatch_group_leave(g); 
    101100                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        } 
    103112        dispatch_io_set_high_water(io, READSIZE); 
    104113        if (with_timer == 1) { 
     
    148157                }); 
    149158        } 
    150         dispatch_io_close(io, /* NO STOP */ 0); 
     159        dispatch_io_close(io, 0); 
     160        dispatch_io_close(io, 0); 
    151161        dispatch_io_read(io, 0, 1, dispatch_get_global_queue(0,0), 
    152162                        ^(bool done, dispatch_data_t d, int error) { 
     
    333343        } 
    334344        // 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); 
    337347                test_stop(); 
    338348        } 
     
    477487test_read_many_files(void) 
    478488{ 
    479         char *paths[] = {"/usr/include", NULL}; 
     489        char *paths[] = {"/usr/lib", NULL}; 
    480490        dispatch_group_t g = dispatch_group_create(); 
    481491        dispatch_semaphore_t s = dispatch_semaphore_create(maxopenfiles); 
     
    665675        dispatch_async(dispatch_get_main_queue(), ^{ 
    666676#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); 
    670686                test_io_stop(); 
    671687                test_io_from_io(); 
  • trunk/testing/dispatch_priority.c

    r211 r215  
    3535 
    3636#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 
    4846#endif 
    4947 
    5048#if TARGET_OS_EMBEDDED 
    51 #define LOOP_COUNT 2000000 
     49#define LOOP_COUNT 5000000 
     50const int importance = 24; // priority 55 
    5251#else 
    5352#define LOOP_COUNT 100000000 
    54 #endif 
     53const int importance = 4; // priority 35 
     54#endif 
     55 
     56char *labels[] = { "BACKGROUND", "LOW", "DEFAULT", "HIGH", }; 
     57int 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)) 
    5562 
    5663static union { 
     
    5966} counts[PRIORITIES]; 
    6067 
    61 #define ITERATIONS (long)(PRIORITIES * n_blocks() * 0.50) 
    6268static volatile long iterations; 
     69static long total; 
     70static size_t prio0, priorities = PRIORITIES; 
    6371 
    6472int 
     
    7987histogram(void) 
    8088{ 
    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) { 
    8493                printf("%s: %ld\n", labels[y], counts[y].count); 
    85                 total += counts[y].count; 
     94                completed += counts[y].count; 
    8695 
    8796                double fraction = (double)counts[y].count / (double)n_blocks(); 
     
    93102        } 
    94103 
    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        } 
    98117} 
    99118 
     
    116135                        usleep(100000); 
    117136                        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                        }); 
    120141                } 
    121142        } 
     
    137158{ 
    138159        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; 
    142168 
    143169#if USE_SET_TARGET_QUEUE 
    144170        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 
    149178                q[i] = dispatch_queue_create(labels[i], DISPATCH_QUEUE_CONCURRENT); 
    150 #endif 
    151179                test_ptr_notnull("q[i]", q[i]); 
    152180                assert(q[i]); 
    153181                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++) { 
    167193                submit_work(q[i], &counts[i].count); 
    168194        } 
    169195 
    170 #if USE_SET_TARGET_QUEUE 
    171         for(i = 0; i < PRIORITIES; i++) { 
     196        for (i = prio0; i < prio0 + priorities; i++) { 
    172197                dispatch_resume(q[i]); 
    173198                dispatch_release(q[i]); 
    174199        } 
    175 #endif 
    176200 
    177201        dispatch_main(); 
  • trunk/testing/dispatch_queue_finalizer.c

    r211 r215  
    7070 
    7171        dispatch_set_context(q_null_context, NULL); 
     72        dispatch_set_finalizer_f(q_null_context, never_call); 
    7273        dispatch_release(q_null_context); 
    7374 
  • trunk/testing/dispatch_suspend_timer.c

    r211 r215  
    4646 
    4747        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()); 
    4949 
    5050        __block int i = 0, i_prime = 0; 
  • trunk/testing/dispatch_test.c

    r211 r215  
    2020 
    2121#include "dispatch_test.h" 
     22#include "bsdtests.h" 
    2223 
    2324#ifdef __OBJC_GC__ 
     
    2526#endif 
    2627 
     28#include <stdlib.h> 
     29#include <stdio.h> 
    2730#include <unistd.h> 
    2831#include <sys/event.h> 
    2932#include <assert.h> 
     33 
     34#include <dispatch/dispatch.h> 
    3035 
    3136void test_start(const char* desc); 
     
    5762        return r > 0; 
    5863} 
     64 
     65void 
     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  
    2121#include <sys/cdefs.h> 
    2222#include <stdbool.h> 
     23#include <dispatch/dispatch.h> 
    2324 
    2425#define test_group_wait(g) do { \ 
     
    3536bool dispatch_test_check_evfilt_read_for_fd(int fd); 
    3637 
     38void _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 
    3741__END_DECLS 
  • trunk/testing/dispatch_timer.c

    r211 r215  
    4747 
    4848        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()); 
    5050 
    5151        uint64_t j; 
     
    7474 
    7575        dispatch_source_t s = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, main_q); 
    76         dispatch_debug(s, "fresh timer:"); 
    7776        test_ptr_notnull("dispatch_source_create", s); 
    7877 
     
    8180        dispatch_source_set_cancel_handler(s, ^{ 
    8281                test_ptr_notnull("cancel handler run", s); 
    83                 dispatch_debug(s, "pre release timer:"); 
    8482                dispatch_release(s); 
    85                 dispatch_debug(s, "post release timer:"); 
    8683        }); 
    8784 
  • trunk/testing/dispatch_timer_bit31.c

    r211 r215  
    3535 
    3636        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()); 
    3838 
    3939        struct timeval start_time; 
  • trunk/testing/dispatch_timer_set_time.c

    r211 r215  
    3636 
    3737        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()); 
    3939 
    4040        __block int i = 0; 
  • trunk/testing/dispatch_vm.c

    r211 r215  
    3030 
    3131#include <dispatch/dispatch.h> 
     32#include <dispatch/private.h> 
    3233 
    3334#include <bsdtests.h> 
     
    3738 
    3839#if TARGET_OS_EMBEDDED 
    39 #define ALLOC_SIZE ((size_t)(1024*1024*5ul))    // 5MB 
     40#define ALLOC_SIZE ((size_t)(1024*1024*1ul))    // 1MB 
    4041#define NOTIFICATIONS 1 
    4142#else 
     
    6162#define log_msg(msg, ...) \ 
    6263do { \ 
    63         fprintf(stderr, "[%2ds] " msg, (int)(time(NULL) - initial), ## __VA_ARGS__);\ 
     64        fprintf(stderr, "[%2ds] " msg, (int)(time(NULL) - initial), ##__VA_ARGS__);\ 
    6465} while (0) 
    6566 
     
    103104main(void) 
    104105{ 
    105         dispatch_test_start("Dispatch VM Pressure test"); // <rdar://problem/7000945> 
     106        dispatch_test_start("Dispatch VM Pressure test"); // rdar://problem/7000945 
    106107        if (!dispatch_test_check_evfilt_vm()) { 
    107108                test_skip("EVFILT_VM not supported"); 
     
    143144        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), 
    144145                        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) { 
    146148                        void *p = valloc(ALLOC_SIZE); 
    147149                        if (!p) { 
     
    164166                        return; 
    165167                } 
    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); 
    169174                        cleanup(); 
    170175                }); 
     
    177182main(void) 
    178183{ 
    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"); 
    180186        test_stop(); 
    181187        return 0; 
Note: See TracChangeset for help on using the changeset viewer.