Skip to content
Permalink
Browse files
MountainLion macosforge testsuite
git-svn-id: https://svn.macosforge.org/repository/libdispatch/trunk@215 5710d607-3af0-45f8-8f96-4508d4f60227
  • Loading branch information
das committed Aug 9, 2012
1 parent 425520e commit 1c5faf74e8828d550a3f534ef745bfde8c2284b6
Show file tree
Hide file tree
Showing 25 changed files with 1,440 additions and 149 deletions.
@@ -9,7 +9,8 @@ SUBDIRS= \
man \
os \
private \
src
src \
testing

EXTRA_DIST= \
LICENSE \
@@ -295,5 +295,11 @@ AC_COMPILE_IFELSE(
#
# Generate Makefiles.
#
AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile os/Makefile private/Makefile src/Makefile])
AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile os/Makefile private/Makefile src/Makefile testing/Makefile])

#
# Generate testsuite links
#
AC_CONFIG_LINKS([testing/dispatch:${x:+}private testing/bench.cc:testing/bench.mm testing/leaks-wrapper:testing/leaks-wrapper.sh])

AC_OUTPUT
@@ -62,17 +62,16 @@ TESTS= \
dispatch_vnode \
dispatch_select

dispatch_c99_CFLAGS=-std=c99
dispatch_c99_CFLAGS=$(AM_CFLAGS) -std=c99
dispatch_plusplus_SOURCES=dispatch_plusplus.cpp
dispatch_priority2_SOURCES=dispatch_priority.c
dispatch_priority2_CFLAGS=-DUSE_SET_TARGET_QUEUE=1
dispatch_priority2_CPPFLAGS=$(AM_CPPFLAGS) -DUSE_SET_TARGET_QUEUE=1

INCLUDES=-I$(top_builddir) -I$(top_srcdir)
AM_CPPFLAGS=-I$(top_builddir) -I$(top_srcdir)

CPPFLAGS=
CFLAGS=-Wall -g $(MARCH_FLAGS) $(CBLOCKS_FLAGS)
OBJCFLAGS=-Wall -g $(MARCH_FLAGS) $(CBLOCKS_FLAGS)
CXXFLAGS=-Wall -g $(MARCH_FLAGS) $(CXXBLOCKS_FLAGS)
AM_CFLAGS=-Wall $(MARCH_FLAGS) $(CBLOCKS_FLAGS)
AM_OBJCFLAGS=-Wall $(MARCH_FLAGS) $(CBLOCKS_FLAGS) -fobjc-gc
AM_CXXFLAGS=-Wall $(MARCH_FLAGS) $(CXXBLOCKS_FLAGS)

LDADD=libbsdtests.la ../src/libdispatch.la
libbsdtests_la_LDFLAGS=-avoid-version
@@ -83,10 +82,12 @@ DISTCLEAN=bench.cc
if HAVE_COREFOUNDATION
TESTS+= \
dispatch_cf_main \
dispatch_transform \
dispatch_sync_on_main \
cffd

dispatch_cf_main_LDFLAGS=-framework CoreFoundation
dispatch_transform_LDFLAGS=-framework CoreFoundation -framework Security
dispatch_sync_on_main_LDFLAGS=-framework CoreFoundation
cffd_LDFLAGS=-framework CoreFoundation
endif
@@ -99,14 +100,13 @@ TESTS+= \
bench

dispatch_sync_gc_SOURCES=dispatch_sync_gc.m
dispatch_sync_gc_OBJCFLAGS=-fobjc-gc
dispatch_sync_gc_LDFLAGS=-framework Foundation
dispatch_apply_gc_SOURCES=dispatch_apply_gc.m
dispatch_apply_gc_OBJCFLAGS=-fobjc-gc
dispatch_apply_gc_LDFLAGS=-framework Foundation
nsoperation_SOURCES=nsoperation.m
nsoperation_LDFLAGS=-framework Foundation
bench_SOURCES=bench.cc func.c
nodist_bench_SOURCES=bench.cc
bench_SOURCES=func.c
bench_LDFLAGS=-framework Foundation
# Workaround missing objcxx support in older autotools
bench.o: bench.cc
@@ -414,6 +414,13 @@ asm volatile("cmpxchg %1,%2"
}
print_result(s, "'cmpxchg' without the 'lock' prefix:");

s = mach_absolute_time();
for (i = cnt; i; i--) {
global = 0;
asm volatile("mfence" ::: "memory");
}
print_result(s, "Store + mfence:");

s = mach_absolute_time();
for (i = cnt; i; i--) {
unsigned long _clbr;
@@ -466,6 +473,33 @@ asm volatile("pushl %%ebx\n\tcpuid\n\tpopl %%ebx"
print_result(s, "'dmb ishst' instruction:");
#endif

#ifdef _ARM_ARCH_7
s = mach_absolute_time();
for (i = cnt; i; i--) {
asm volatile("str %[_r], [%[_p], %[_o]]" :
: [_p] "p" (&global), [_o] "M" (0), [_r] "r" (0) : "memory");
asm volatile("dmb ishst" : : : "memory");
}
print_result(s, "'str + dmb ishst' instructions:");
#endif

#ifdef _ARM_ARCH_7
s = mach_absolute_time();
for (i = cnt; i; i--) {
uintptr_t prev;
uint32_t t;
do {
asm volatile("ldrex %[_r], [%[_p], %[_o]]"
: [_r] "=&r" (prev) \
: [_p] "p" (&global), [_o] "M" (0) : "memory");
asm volatile("strex %[_t], %[_r], [%[_p], %[_o]]"
: [_t] "=&r" (t) \
: [_p] "p" (&global), [_o] "M" (0), [_r] "r" (0) : "memory");
} while (t);
}
print_result(s, "'ldrex + strex' instructions:");
#endif

s = mach_absolute_time();
for (i = cnt; i; i--) {
#ifdef _ARM_ARCH_7
@@ -528,6 +562,37 @@ asm volatile("svc 0x80" : "+r" (_r0)
}
print_result(s, "Atomic increment:");

{
global = 0;
volatile int32_t *g = &global;

s = mach_absolute_time();
for (i = cnt; i; i--) {
uint32_t result;
__sync_and_and_fetch(g, 1);
result = *g;
if (result) {
abort();
}
}
print_result(s, "Atomic and-and-fetch, reloading result:");
}

{
global = 0;
volatile int32_t *g = &global;

s = mach_absolute_time();
for (i = cnt; i; i--) {
uint32_t result;
result = __sync_and_and_fetch(g, 1);
if (result) {
abort();
}
}
print_result(s, "Atomic and-and-fetch, using result:");
}

global = 0;

s = mach_absolute_time();
@@ -18,15 +18,17 @@
* @APPLE_APACHE_LICENSE_HEADER_END@
*/

#include <mach/clock_types.h>
#include <dispatch/dispatch.h>
#include <assert.h>
#include <spawn.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <mach/clock_types.h>
#include <mach-o/arch.h>
#include <sys/resource.h>
#include <sys/time.h>

#include <bsdtests.h>

@@ -37,19 +39,31 @@ main(int argc, char *argv[])
{
dispatch_source_t tmp_ds;
int res;
pid_t pid;
pid_t pid = 0;

if (argc < 2) {
fprintf(stderr, "usage: %s [...]\n", argv[0]);
exit(1);
}

short spawnflags = POSIX_SPAWN_START_SUSPENDED;
#if TARGET_OS_EMBEDDED
spawnflags |= POSIX_SPAWN_SETEXEC;
#endif

posix_spawnattr_t attr;
res = posix_spawnattr_init(&attr);
assert(res == 0);
res = posix_spawnattr_setflags(&attr, POSIX_SPAWN_START_SUSPENDED);
res = posix_spawnattr_setflags(&attr, spawnflags);
assert(res == 0);

uint64_t to = 0;
char *tos = getenv("BSDTEST_TIMEOUT");
if (tos) {
to = strtoul(tos, NULL, 0);
to *= NSEC_PER_SEC;
}

char *arch = getenv("BSDTEST_ARCH");
if (arch) {
const NXArchInfo *ai = NXGetArchInfoFromName(arch);
@@ -66,12 +80,21 @@ main(int argc, char *argv[])
}
newargv[i-1] = NULL;

res = posix_spawnp(&pid, newargv[0], NULL, &attr, newargv, environ);
if (res) {
errno = res;
perror(newargv[0]);
exit(EXIT_FAILURE);
struct timeval tv_start;
gettimeofday(&tv_start, NULL);

if (spawnflags & POSIX_SPAWN_SETEXEC) {
pid = fork();
}
if (!pid) {
res = posix_spawnp(&pid, newargv[0], NULL, &attr, newargv, environ);
if (res) {
errno = res;
perror(newargv[0]);
exit(EXIT_FAILURE);
}
}

//fprintf(stderr, "pid = %d\n", pid);
assert(pid > 0);

@@ -81,23 +104,40 @@ main(int argc, char *argv[])
assert(tmp_ds);
dispatch_source_set_event_handler(tmp_ds, ^{
int status;
int res2 = waitpid(pid, &status, 0);
struct rusage usage;
struct timeval tv_stop, tv_wall;

gettimeofday(&tv_stop, NULL);
tv_wall.tv_sec = tv_stop.tv_sec - tv_start.tv_sec;
tv_wall.tv_sec -= (tv_stop.tv_usec < tv_start.tv_usec);
tv_wall.tv_usec = abs(tv_stop.tv_usec - tv_start.tv_usec);

int res2 = wait4(pid, &status, 0, &usage);
assert(res2 != -1);
test_long("Process exited", (WIFEXITED(status) && WEXITSTATUS(status) && WEXITSTATUS(status) != 0xff) || WIFSIGNALED(status), 0);
printf("[PERF]\twall time: %ld.%06d\n", tv_wall.tv_sec, tv_wall.tv_usec);
printf("[PERF]\tuser time: %ld.%06d\n", usage.ru_utime.tv_sec, usage.ru_utime.tv_usec);
printf("[PERF]\tsystem time: %ld.%06d\n", usage.ru_stime.tv_sec, usage.ru_stime.tv_usec);
printf("[PERF]\tmax resident set size: %ld\n", usage.ru_maxrss);
printf("[PERF]\tpage faults: %ld\n", usage.ru_majflt);
printf("[PERF]\tswaps: %ld\n", usage.ru_nswap);
printf("[PERF]\tvoluntary context switches: %ld\n", usage.ru_nvcsw);
printf("[PERF]\tinvoluntary context switches: %ld\n", usage.ru_nivcsw);
exit((WIFEXITED(status) && WEXITSTATUS(status)) || WIFSIGNALED(status));
});
dispatch_resume(tmp_ds);

if (!to) {
#if TARGET_OS_EMBEDDED
// Give embedded platforms a little more time.
uint64_t timeout = 300LL * NSEC_PER_SEC;
to = 180LL * NSEC_PER_SEC;
#else
uint64_t timeout = 150LL * NSEC_PER_SEC;
to = 90LL * NSEC_PER_SEC;
#endif
}

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, timeout), main_q, ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, to), main_q, ^{
kill(pid, SIGKILL);
fprintf(stderr, "Terminating unresponsive process (%0.1lfs)\n", (double)timeout/NSEC_PER_SEC);
fprintf(stderr, "Terminating unresponsive process (%0.1lfs)\n", (double)to / NSEC_PER_SEC);
});

signal(SIGINT, SIG_IGN);
@@ -109,6 +149,9 @@ main(int argc, char *argv[])
});
dispatch_resume(tmp_ds);

if (spawnflags & POSIX_SPAWN_SETEXEC) {
usleep(USEC_PER_SEC/10);
}
kill(pid, SIGCONT);

dispatch_main();
@@ -127,6 +127,18 @@ test_ptr_format(const void* actual, const void* expected, const char* format, ..
_test_ptr(NULL, 0, desc, actual, expected);
}

void _test_ptr_not(const char* file, long line, const char* desc, const void* actual, const void* expected)
{
_test_print(file, line, desc,
(actual != expected), "%p", actual, "!%p", expected);
}

void test_ptr_not_format(const void *actual, const void* expected, const char *format, ...)
{
GENERATE_DESC
_test_ptr_not(NULL, 0, desc, actual, expected);
}

void
_test_uint32(const char* file, long line, const char* desc, uint32_t actual, uint32_t expected)
{
@@ -210,6 +222,19 @@ test_long_less_than_format(long actual, long expected_max, const char* format, .
_test_long_less_than(NULL, 0, desc, actual, expected_max);
}

void
_test_long_less_than_or_equal(const char* file, long line, const char* desc, long actual, long expected_max)
{
_test_print(file, line, desc, (actual <= expected_max), "%ld", actual, "<=%ld", expected_max);
}

void
test_long_less_than_or_equal_format(long actual, long expected_max, const char* format, ...)
{
GENERATE_DESC
_test_long_less_than_or_equal(NULL, 0, desc, actual, expected_max);
}

void
_test_long_greater_than_or_equal(const char* file, long line, const char* desc, long actual, long expected_min)
{
@@ -249,6 +274,20 @@ test_double_less_than_or_equal_format(double val, double max_expected, const cha
_test_double_less_than_or_equal(NULL, 0, desc, val, max_expected);
}

void
_test_double_equal(const char* file, long line, const char* desc, double val, double expected)
{
_test_print(file, line, desc, (val == expected), "%f", val, "%f", expected);
}


void
test_double_equal_format(double val, double expected, const char *format, ...)
{
GENERATE_DESC
_test_double_equal(NULL, 0, desc, val, expected);
}

void
_test_errno(const char* file, long line, const char* desc, long actual, long expected)
{
@@ -386,6 +425,10 @@ test_leaks_pid(const char *name, pid_t pid)
return;
}

unsetenv("DYLD_IMAGE_SUFFIX");
unsetenv("DYLD_INSERT_LIBRARIES");
unsetenv("DYLD_LIBRARY_PATH");

unsetenv("MallocStackLogging");
unsetenv("MallocStackLoggingNoCompact");

0 comments on commit 1c5faf7

Please sign in to comment.