]> pd.if.org Git - pdclib/commitdiff
Unit tests
authorOwen Shepherd <owen.shepherd@e43.eu>
Mon, 6 Aug 2012 00:18:07 +0000 (01:18 +0100)
committerOwen Shepherd <owen.shepherd@e43.eu>
Mon, 6 Aug 2012 00:18:07 +0000 (01:18 +0100)
21 files changed:
.hgignore [new file with mode: 0644]
opt/dlmalloc/dlmalloc.c
opt/dlmalloc/dlmalloc.h
opt/nothread/call_once.c
opt/nothread/cnd_init.c
opt/nothread/cnd_signal.c
opt/nothread/cnd_wait.c
opt/nothread/mtx_destroy.c
opt/nothread/mtx_init.c
opt/nothread/mtx_lock.c
opt/nothread/mtx_timedlock.c
opt/nothread/mtx_trylock.c
opt/nothread/mtx_unlock.c
opt/nothread/thrd_yield.c
opt/nothread/tss_create.c
opt/nothread/tss_delete.c
opt/nothread/tss_get.c
opt/nothread/tss_set.c
opt/notime/time.c
platform/example/functions/_PDCLIB/freepages.c [new file with mode: 0644]
platform/example/internals/_PDCLIB_config.h

diff --git a/.hgignore b/.hgignore
new file mode 100644 (file)
index 0000000..57af108
--- /dev/null
+++ b/.hgignore
@@ -0,0 +1,10 @@
+syntax: glob\r
+*.o\r
+*.exe\r
+*.d\r
+*.a\r
+*.dll\r
+*.so\r
+*.dylib\r
+*.dso\r
+*~
\ No newline at end of file
index 32c3c35686d582443a7a2f3033936c7e87506207..183f08a59a14559d643b8514587737d0c58931d7 100644 (file)
@@ -516,6 +516,7 @@ MAX_RELEASE_CHECK_RATE   default: 4095 unless not HAVE_MMAP
   improvement at the expense of carrying around more memory.\r
 */\r
 \r
+#ifndef REGTEST\r
 #include "dlmalloc.h"\r
 \r
 /* Version identifier to allow people to support multiple versions */\r
@@ -6251,3 +6252,15 @@ History:
          structure of old version,  but most details differ.)\r
 \r
 */\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+/* TODO: TEST ME */\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index c62029840086fb6a5eca59b55fe26850269b91c9..374fa49310275d745ba5ebd9ce297e899d70d0ba 100644 (file)
@@ -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))\r
 \r
 #undef WIN32\r
+#undef _WIN32\r
 #define DLMALLOC_EXPORT  _PDCLIB_API\r
 #define MALLOC_ALIGNMENT _PDCLIB_MALLOC_ALIGN\r
 #define MSPACES 0\r
index 06de779568c390294955d1c4010f50b188717604..be1ed2e07e4e956ddaa1cd87f1313c2bbd5fcd02 100644 (file)
@@ -6,4 +6,29 @@ void _PDCLIB_call_once(_PDCLIB_once_flag *flag, void (*func)(void))
                func();\r
                *flag = _PDCLIB_ONCE_FLAG_DONE;\r
        }\r
-}
\ No newline at end of file
+}\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+static int count = 0;\r
+once_flag once = ONCE_FLAG_INIT;\r
+\r
+static void do_once(void)\r
+{\r
+    count++;\r
+}\r
+\r
+int main( void )\r
+{\r
+    TESTCASE(count == 0);\r
+    call_once(&once, do_once);\r
+    TESTCASE(count == 1);\r
+    call_once(&once, do_once);\r
+    TESTCASE(count == 1);\r
+    do_once();\r
+    TESTCASE(count == 2);\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif\r
index 1683691b19d6810636b025c6b4348988b5babcdf..379f28ff1d383b2fd8d95cff6e2f013f5319142f 100644 (file)
@@ -5,3 +5,13 @@ int cnd_init(cnd_t *cond)
        /* does nothing */\r
        return thrd_success;\r
 }\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index ca6a7891f06268eb8c5b02ef114e8c5a1e077464..05cbcf6ba0059c0f2fe6ab51826a9aee2fc55af0 100644 (file)
@@ -3,4 +3,14 @@
 int cnd_signal(cnd_t *cond)\r
 {\r
        return thrd_success;\r
-}
\ No newline at end of file
+}\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index 2948d4f2fa27b4711d5104d35472e6da4beb52f8..4c632cc80216eadef4ed7ae8737b2d484b359889 100644 (file)
@@ -3,4 +3,14 @@
 int cnd_wait(cnd_t *cond, mtx_t *mtx)\r
 {\r
        return thrd_error;\r
-}
\ No newline at end of file
+}\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index d9aa748e4bb741dd0907c5d0b3a0b02f9c26b1a0..75baec274ddce20c2c4a15b1d142a85a6e31086d 100644 (file)
@@ -2,3 +2,13 @@
 \r
 void mtx_destroy(mtx_t *mtx)\r
 {}\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index ff506e94e03e5ee67cde2b95fb831c990dea9eab..922c9421f45398231c3bd4619ecc24ee58b1c35e 100644 (file)
@@ -5,3 +5,13 @@ int mtx_init(mtx_t *mtx, int type)
        *mtx = 0;\r
        return thrd_success;\r
 }\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index 0a1afbdc4cdd60bfedf3470d8e0bc2e6f0890c32..121444e4b9a255d344825115c0ece923e512d3d7 100644 (file)
@@ -7,4 +7,14 @@ int mtx_lock(mtx_t *mtx)
                *mtx = 1;\r
                return thrd_success;\r
        } else return thrd_error;\r
-}
\ No newline at end of file
+}\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index b8166b5b97cfee37b74271635a5114db62e19b11..e3cd4fb80b95de29bd41bc13edd978e7d07317e6 100644 (file)
@@ -3,4 +3,14 @@
 int mtx_timedlock(mtx_t *restrict mtx, const struct timespec *restrict ts)\r
 {\r
        return mtx_lock(mtx);\r
-}
\ No newline at end of file
+}\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index ae3275775046114800efb65ddebb12c0a4d752bd..3333a86f2c313071d50055f7b532661f03a003f1 100644 (file)
@@ -9,3 +9,13 @@ int mtx_trylock(mtx_t *mtx)
                return thrd_success;\r
        }\r
 }\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index 02244bbed591b682cc065cf694e72f4a73a7cccb..1c11401f7931788068b98ec49bc0ec625d871a22 100644 (file)
@@ -6,4 +6,14 @@ int mtx_unlock(mtx_t *mtx)
                *mtx = 0;\r
                return thrd_success;\r
        } else return thrd_error;\r
-}
\ No newline at end of file
+}\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index 8c7863f643f27e1e7319c41cbae70cd1cdd5d051..840157bdaf2441cb7f80fff871ecf7f3283139a4 100644 (file)
@@ -3,4 +3,14 @@
 void thrd_yield(void)\r
 {\r
        /* does nothing */\r
-}
\ No newline at end of file
+}\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index 4b8ce168074f5196fc2a32c7e9c42c61813b8737..2a28fcadcf76419396801c441a6baf5236efbde9 100644 (file)
@@ -5,4 +5,15 @@ int tss_create(tss_t *key, tss_dtor_t dtor)
        key->self  = key;\r
        key->value = NULL;\r
        return thrd_success;\r
-}
\ No newline at end of file
+}\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+/* Tested in tss_get.c */\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index fbaae7e8bc1b5cb3cd485ed1bfbf914a9d06a694..5d251f4904a14b6592f694793bb21eadd5caa41e 100644 (file)
@@ -4,3 +4,14 @@ void tss_delete(tss_t key)
 {\r
        key.self->self = NULL;\r
 }\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+/* Tested in tss_get.c */\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index 7077ac68dbe21113ee5b94874d2551f4493123a0..3e9917b83c3b508fee8c211ed9f0e06732f3e154 100644 (file)
@@ -3,4 +3,22 @@
 void *tss_get(tss_t key)\r
 {\r
        return key.value;\r
-}
\ No newline at end of file
+}\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+static tss_t key;\r
+static char v;\r
+\r
+int main( void )\r
+{\r
+    TESTCASE(tss_create(&key, NULL) == thrd_success);\r
+    TESTCASE(tss_get(key) == NULL);\r
+    TESTCASE(tss_set(key, &v) == thrd_success);\r
+    TESTCASE(tss_get(key) == &v);\r
+    tss_delete(key);\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index feea85d345b80857af5e2eb12444d58ac00f5404..7de3ec5b775527d66e84f01174ce661a81b4d94a 100644 (file)
@@ -4,4 +4,15 @@ int tss_set(tss_t key, void *val)
 {\r
        key.self->value = val;\r
        return thrd_success;\r
-}
\ No newline at end of file
+}\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+/* Tested in tss_get.c */\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file
index 8f348196c4f9bbf898efa61ac28f225a4d83d535..8826ee9c3158b466d1919dc293ad74b360c7c1ae 100644 (file)
@@ -4,4 +4,14 @@ time_t time(time_t* t)
 {\r
        if(t) *t = -1;\r
        return -1;\r
-}
\ No newline at end of file
+}\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#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 (file)
index 0000000..c776876
--- /dev/null
@@ -0,0 +1,30 @@
+/* $Id$ */\r
+\r
+/* _PDCLIB_allocpages( int const )\r
+\r
+   This file is part of the Public Domain C Library (PDCLib).\r
+   Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+/* This is a stub implementation of _PDCLIB_allocpages\r
+*/\r
+\r
+#include <stdint.h>\r
+#include <stddef.h>\r
+#include <_PDCLIB_glue.h>\r
+#include <errno.h>\r
+\r
+void _PDCLIB_freepages( void * p, size_t n )\r
+{\r
+    return;\r
+}\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif\r
index 7e66178b96ea124ba029b3651e03dfc8739e976c..ff4349510dd0093b3e2a9f0dc899e0f25147fc25 100644 (file)
@@ -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 ---------------------------------------------------------------------- */