diff options
author | Simon Hafner <hafnersimon@gmail.com> | 2015-04-13 22:36:35 -0500 |
---|---|---|
committer | Simon Hafner <hafnersimon@gmail.com> | 2015-04-13 22:36:35 -0500 |
commit | c55f884b5c0ebc0b637138a8de446ba1fd05acdf (patch) | |
tree | 0fe74403843327ac380d3fb8a2775b5b74b93371 /tests/realtimeGC/cmain.c | |
parent | c1d0b2403b3f1c9ca487c362658aefb954ee7d96 (diff) | |
download | Nim-c55f884b5c0ebc0b637138a8de446ba1fd05acdf.tar.gz |
integrated realtimegc stuff into testament
Diffstat (limited to 'tests/realtimeGC/cmain.c')
-rw-r--r-- | tests/realtimeGC/cmain.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/realtimeGC/cmain.c b/tests/realtimeGC/cmain.c new file mode 100644 index 000000000..e9a46d7ce --- /dev/null +++ b/tests/realtimeGC/cmain.c @@ -0,0 +1,67 @@ + +#ifdef WIN +#include <windows.h> +#else +#include <dlfcn.h> +#endif +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <time.h> + +#define RUNTIME (15*60) + + +typedef void (*pFunc)(void); + +int main(int argc, char* argv[]) +{ + int i; + void* hndl; + pFunc status; + pFunc count; + pFunc checkOccupiedMem; + +#ifdef WIN + hndl = (void*) LoadLibrary((char const*)"./tests/realtimeGC/shared.dll"); + status = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"status"); + count = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"count"); + checkOccupiedMem = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"checkOccupiedMem"); +#else /* OSX || NIX */ + hndl = (void*) dlopen((char const*)"./tests/realtimeGC/libshared.so", RTLD_LAZY); + status = (pFunc) dlsym(hndl, (char const*)"status"); + count = (pFunc) dlsym(hndl, (char const*)"count"); + checkOccupiedMem = (pFunc) dlsym(hndl, (char const*)"checkOccupiedMem"); +#endif + + assert(hndl); + assert(status); + assert(count); + assert(checkOccupiedMem); + + time_t startTime = time((time_t*)0); + time_t runTime = (time_t)(RUNTIME); + time_t accumTime = 0; + while (accumTime < runTime) { + for (i = 0; i < 10; i++) + count(); + /* printf("1. sleeping...\n"); */ + sleep(1); + for (i = 0; i < 10; i++) + status(); + /* printf("2. sleeping...\n"); */ + sleep(1); + checkOccupiedMem(); + accumTime = time((time_t*)0) - startTime; + /* printf("--- Minutes left to run: %d\n", (int)(runTime-accumTime)/60); */ + } + printf("Cleaning up the shared object pointer...\n"); +#ifdef WIN + FreeLibrary((HMODULE)hndl); +#else /* OSX || NIX */ + dlclose(hndl); +#endif + printf("Done\n"); + return 0; +} |