From: Owen Shepherd Date: Mon, 6 Aug 2012 00:18:07 +0000 (+0100) Subject: Unit tests X-Git-Url: https://pd.if.org/git/?p=pdclib;a=commitdiff_plain;h=5155ca96295a12b4857fc0e6a9629cc43a9a85fa Unit tests --- diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..57af108 --- /dev/null +++ b/.hgignore @@ -0,0 +1,10 @@ +syntax: glob +*.o +*.exe +*.d +*.a +*.dll +*.so +*.dylib +*.dso +*~ \ No newline at end of file diff --git a/opt/dlmalloc/dlmalloc.c b/opt/dlmalloc/dlmalloc.c index 32c3c35..183f08a 100644 --- a/opt/dlmalloc/dlmalloc.c +++ b/opt/dlmalloc/dlmalloc.c @@ -516,6 +516,7 @@ MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP improvement at the expense of carrying around more memory. */ +#ifndef REGTEST #include "dlmalloc.h" /* Version identifier to allow people to support multiple versions */ @@ -6251,3 +6252,15 @@ History: structure of old version, but most details differ.) */ +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +/* TODO: TEST ME */ +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/dlmalloc/dlmalloc.h b/opt/dlmalloc/dlmalloc.h index c620298..374fa49 100644 --- a/opt/dlmalloc/dlmalloc.h +++ b/opt/dlmalloc/dlmalloc.h @@ -24,6 +24,7 @@ static void init_malloc_global_mutex(void) #define MREMAP(a, osz, nsz, mv) _PDCLIB_reallocpages((a), (osz)/_PDCLIB_MALLOC_PAGESIZE, (nsz)/_PDCLIB_MALLOC_PAGESIZE, (mv)) #undef WIN32 +#undef _WIN32 #define DLMALLOC_EXPORT _PDCLIB_API #define MALLOC_ALIGNMENT _PDCLIB_MALLOC_ALIGN #define MSPACES 0 diff --git a/opt/nothread/call_once.c b/opt/nothread/call_once.c index 06de779..be1ed2e 100644 --- a/opt/nothread/call_once.c +++ b/opt/nothread/call_once.c @@ -6,4 +6,29 @@ void _PDCLIB_call_once(_PDCLIB_once_flag *flag, void (*func)(void)) func(); *flag = _PDCLIB_ONCE_FLAG_DONE; } -} \ No newline at end of file +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +static int count = 0; +once_flag once = ONCE_FLAG_INIT; + +static void do_once(void) +{ + count++; +} + +int main( void ) +{ + TESTCASE(count == 0); + call_once(&once, do_once); + TESTCASE(count == 1); + call_once(&once, do_once); + TESTCASE(count == 1); + do_once(); + TESTCASE(count == 2); + return TEST_RESULTS; +} + +#endif diff --git a/opt/nothread/cnd_init.c b/opt/nothread/cnd_init.c index 1683691..379f28f 100644 --- a/opt/nothread/cnd_init.c +++ b/opt/nothread/cnd_init.c @@ -5,3 +5,13 @@ int cnd_init(cnd_t *cond) /* does nothing */ return thrd_success; } + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/nothread/cnd_signal.c b/opt/nothread/cnd_signal.c index ca6a789..05cbcf6 100644 --- a/opt/nothread/cnd_signal.c +++ b/opt/nothread/cnd_signal.c @@ -3,4 +3,14 @@ int cnd_signal(cnd_t *cond) { return thrd_success; -} \ No newline at end of file +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/nothread/cnd_wait.c b/opt/nothread/cnd_wait.c index 2948d4f..4c632cc 100644 --- a/opt/nothread/cnd_wait.c +++ b/opt/nothread/cnd_wait.c @@ -3,4 +3,14 @@ int cnd_wait(cnd_t *cond, mtx_t *mtx) { return thrd_error; -} \ No newline at end of file +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/nothread/mtx_destroy.c b/opt/nothread/mtx_destroy.c index d9aa748..75baec2 100644 --- a/opt/nothread/mtx_destroy.c +++ b/opt/nothread/mtx_destroy.c @@ -2,3 +2,13 @@ void mtx_destroy(mtx_t *mtx) {} + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/nothread/mtx_init.c b/opt/nothread/mtx_init.c index ff506e9..922c942 100644 --- a/opt/nothread/mtx_init.c +++ b/opt/nothread/mtx_init.c @@ -5,3 +5,13 @@ int mtx_init(mtx_t *mtx, int type) *mtx = 0; return thrd_success; } + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/nothread/mtx_lock.c b/opt/nothread/mtx_lock.c index 0a1afbd..121444e 100644 --- a/opt/nothread/mtx_lock.c +++ b/opt/nothread/mtx_lock.c @@ -7,4 +7,14 @@ int mtx_lock(mtx_t *mtx) *mtx = 1; return thrd_success; } else return thrd_error; -} \ No newline at end of file +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/nothread/mtx_timedlock.c b/opt/nothread/mtx_timedlock.c index b8166b5..e3cd4fb 100644 --- a/opt/nothread/mtx_timedlock.c +++ b/opt/nothread/mtx_timedlock.c @@ -3,4 +3,14 @@ int mtx_timedlock(mtx_t *restrict mtx, const struct timespec *restrict ts) { return mtx_lock(mtx); -} \ No newline at end of file +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/nothread/mtx_trylock.c b/opt/nothread/mtx_trylock.c index ae32757..3333a86 100644 --- a/opt/nothread/mtx_trylock.c +++ b/opt/nothread/mtx_trylock.c @@ -9,3 +9,13 @@ int mtx_trylock(mtx_t *mtx) return thrd_success; } } + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/nothread/mtx_unlock.c b/opt/nothread/mtx_unlock.c index 02244bb..1c11401 100644 --- a/opt/nothread/mtx_unlock.c +++ b/opt/nothread/mtx_unlock.c @@ -6,4 +6,14 @@ int mtx_unlock(mtx_t *mtx) *mtx = 0; return thrd_success; } else return thrd_error; -} \ No newline at end of file +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/nothread/thrd_yield.c b/opt/nothread/thrd_yield.c index 8c7863f..840157b 100644 --- a/opt/nothread/thrd_yield.c +++ b/opt/nothread/thrd_yield.c @@ -3,4 +3,14 @@ void thrd_yield(void) { /* does nothing */ -} \ No newline at end of file +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/nothread/tss_create.c b/opt/nothread/tss_create.c index 4b8ce16..2a28fca 100644 --- a/opt/nothread/tss_create.c +++ b/opt/nothread/tss_create.c @@ -5,4 +5,15 @@ int tss_create(tss_t *key, tss_dtor_t dtor) key->self = key; key->value = NULL; return thrd_success; -} \ No newline at end of file +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +/* Tested in tss_get.c */ +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/nothread/tss_delete.c b/opt/nothread/tss_delete.c index fbaae7e..5d251f4 100644 --- a/opt/nothread/tss_delete.c +++ b/opt/nothread/tss_delete.c @@ -4,3 +4,14 @@ void tss_delete(tss_t key) { key.self->self = NULL; } + +#ifdef TEST +#include <_PDCLIB_test.h> + +/* Tested in tss_get.c */ +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/nothread/tss_get.c b/opt/nothread/tss_get.c index 7077ac6..3e9917b 100644 --- a/opt/nothread/tss_get.c +++ b/opt/nothread/tss_get.c @@ -3,4 +3,22 @@ void *tss_get(tss_t key) { return key.value; -} \ No newline at end of file +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +static tss_t key; +static char v; + +int main( void ) +{ + TESTCASE(tss_create(&key, NULL) == thrd_success); + TESTCASE(tss_get(key) == NULL); + TESTCASE(tss_set(key, &v) == thrd_success); + TESTCASE(tss_get(key) == &v); + tss_delete(key); + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/nothread/tss_set.c b/opt/nothread/tss_set.c index feea85d..7de3ec5 100644 --- a/opt/nothread/tss_set.c +++ b/opt/nothread/tss_set.c @@ -4,4 +4,15 @@ int tss_set(tss_t key, void *val) { key.self->value = val; return thrd_success; -} \ No newline at end of file +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +/* Tested in tss_get.c */ +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/opt/notime/time.c b/opt/notime/time.c index 8f34819..8826ee9 100644 --- a/opt/notime/time.c +++ b/opt/notime/time.c @@ -4,4 +4,14 @@ time_t time(time_t* t) { if(t) *t = -1; return -1; -} \ No newline at end of file +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif \ No newline at end of file diff --git a/platform/example/functions/_PDCLIB/freepages.c b/platform/example/functions/_PDCLIB/freepages.c new file mode 100644 index 0000000..c776876 --- /dev/null +++ b/platform/example/functions/_PDCLIB/freepages.c @@ -0,0 +1,30 @@ +/* $Id$ */ + +/* _PDCLIB_allocpages( int const ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is a stub implementation of _PDCLIB_allocpages +*/ + +#include +#include +#include <_PDCLIB_glue.h> +#include + +void _PDCLIB_freepages( void * p, size_t n ) +{ + return; +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif diff --git a/platform/example/internals/_PDCLIB_config.h b/platform/example/internals/_PDCLIB_config.h index 7e66178..ff43495 100644 --- a/platform/example/internals/_PDCLIB_config.h +++ b/platform/example/internals/_PDCLIB_config.h @@ -274,13 +274,14 @@ typedef char * _PDCLIB_va_list; to an appropriate value. (Too small, and malloc() will call the kernel too often. Too large, and you will waste memory.) */ -#define _PDCLIB_PAGESIZE 4096 - -/* Set this to the minimum memory node size. Any malloc() for a smaller size - will be satisfied by a malloc() of this size instead (to avoid excessive - fragmentation). -*/ -#define _PDCLIB_MINALLOC 8 +#define _PDCLIB_MALLOC_PAGESIZE 4096 +#define _PDCLIB_MALLOC_ALIGN 16 +#define _PDCLIB_MALLOC_GRANULARITY 64*1024 +#define _PDCLIB_MALLOC_TRIM_THRESHOLD 2*1024*1024 +#define _PDCLIB_MALLOC_MMAP_THRESHOLD 256*1024 +#define _PDCLIB_MALLOC_RELEASE_CHECK_RATE 4095 + +/* TODO: Better document these */ /* I/O ---------------------------------------------------------------------- */