Merge branch 'realtimeGCTest' of https://github.com/jpoirier/Nim into jpoirier-realtimeGCTest
This commit is contained in:
commit
06b7892ed0
8 changed files with 219 additions and 1 deletions
|
|
@ -3,8 +3,11 @@ Each test must have a filename of the form: ``t*.nim``
|
||||||
|
|
||||||
Each test can contain a spec in a ``discard """"""`` block.
|
Each test can contain a spec in a ``discard """"""`` block.
|
||||||
|
|
||||||
The folder ``rodfiles`` contains special tests that test incremental
|
The folder ``rodfiles`` contains special tests that test incremental
|
||||||
compilation via symbol files.
|
compilation via symbol files.
|
||||||
|
|
||||||
The folder ``dll`` contains simple DLL tests.
|
The folder ``dll`` contains simple DLL tests.
|
||||||
|
|
||||||
|
The folder ``realtimeGC`` contains a test for validating that the realtime GC
|
||||||
|
can run properly without linking against the nimrtl.dll/so. It includes a C
|
||||||
|
client and platform specific build files for manual compilation.
|
||||||
|
|
|
||||||
71
tests/realtimeGC/main.c
Normal file
71
tests/realtimeGC/main.c
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
|
||||||
|
#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 (35*60)
|
||||||
|
|
||||||
|
|
||||||
|
typedef void (*pFunc)(void);
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
void* hndl;
|
||||||
|
pFunc status;
|
||||||
|
pFunc count;
|
||||||
|
pFunc occupiedMem;
|
||||||
|
|
||||||
|
#ifdef WIN
|
||||||
|
hndl = (void*) LoadLibrary((char const*)"./shared.dll");
|
||||||
|
status = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"status");
|
||||||
|
count = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"count");
|
||||||
|
occupiedMem = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"occupiedMem");
|
||||||
|
#else /* OSX || NIX */
|
||||||
|
hndl = (void*) dlopen((char const*)"./libshared.so", RTLD_LAZY);
|
||||||
|
status = (pFunc) dlsym(hndl, (char const*)"status");
|
||||||
|
count = (pFunc) dlsym(hndl, (char const*)"count");
|
||||||
|
occupiedMem = (pFunc) dlsym(hndl, (char const*)"occupiedMem");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
assert(hndl);
|
||||||
|
assert(status);
|
||||||
|
assert(count);
|
||||||
|
assert(occupiedMem);
|
||||||
|
|
||||||
|
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);
|
||||||
|
occupiedMem();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
40
tests/realtimeGC/main.nim
Normal file
40
tests/realtimeGC/main.nim
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
discard """
|
||||||
|
cmd: "nim $target --debuginfo $options $file"
|
||||||
|
output: "Done"
|
||||||
|
"""
|
||||||
|
|
||||||
|
import times
|
||||||
|
import os
|
||||||
|
|
||||||
|
const RUNTIME = 35 * 60 # 35 minutes
|
||||||
|
|
||||||
|
when defined(windows):
|
||||||
|
const dllname = "./shared.dll"
|
||||||
|
elif defined(macosx):
|
||||||
|
const dllname = "./libshared.dylib"
|
||||||
|
else:
|
||||||
|
const dllname = "./libshared.so"
|
||||||
|
|
||||||
|
proc status() {.importc: "status", dynlib: dllname.}
|
||||||
|
proc count() {.importc: "count", dynlib: dllname.}
|
||||||
|
proc occupiedMem() {.importc: "occupiedMem", dynlib: dllname.}
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
let startTime = getTime()
|
||||||
|
let runTime = cast[Time](RUNTIME) #
|
||||||
|
var accumTime: Time
|
||||||
|
while accumTime < runTime:
|
||||||
|
for i in 0..10:
|
||||||
|
count()
|
||||||
|
#echo("1. sleeping... ")
|
||||||
|
sleep(500)
|
||||||
|
for i in 0..10:
|
||||||
|
status()
|
||||||
|
#echo("2. sleeping... ")
|
||||||
|
sleep(500)
|
||||||
|
occupiedMem()
|
||||||
|
accumTime = cast[Time]((getTime() - startTime))
|
||||||
|
#echo("--- Minutes left to run: ", int(int(runTime-accumTime)/60))
|
||||||
|
echo("Done")
|
||||||
|
|
||||||
|
main()
|
||||||
6
tests/realtimeGC/main.nim.cfg
Normal file
6
tests/realtimeGC/main.nim.cfg
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
--app:console
|
||||||
|
--threads:on
|
||||||
|
|
||||||
|
-d:release
|
||||||
|
-d:useRealtimeGC
|
||||||
10
tests/realtimeGC/make.bat
Executable file
10
tests/realtimeGC/make.bat
Executable file
|
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
set CXX=gcc
|
||||||
|
set LIBS=-ldl
|
||||||
|
set LNFLAGS=
|
||||||
|
set CFLAGS=-DWIN
|
||||||
|
set INC=
|
||||||
|
|
||||||
|
nim c shared.nim
|
||||||
|
nim c -o:nmain main.nim
|
||||||
|
%CXX% %INC% %DEFS% %CFLAGS% -o cmain main.c %LNFLAGS% %LIBS%
|
||||||
21
tests/realtimeGC/readme.txt
Normal file
21
tests/realtimeGC/readme.txt
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
Test the realtime GC without linking nimrtl.dll/so.
|
||||||
|
|
||||||
|
Note, this is a long running test, default is 35 minutes. To change the
|
||||||
|
the run time see RUNTIME in main.nim and main.c.
|
||||||
|
|
||||||
|
You can build shared.nim, main.nim, and main.c by running make (nix systems)
|
||||||
|
or maike.bat (Windows systems). They both assume GCC and that it's in your
|
||||||
|
path. Output: shared.(dll/so), camin(.exe), nmain(.exe).
|
||||||
|
|
||||||
|
To run the test: execute either nmain or cmain in a shell window.
|
||||||
|
|
||||||
|
To build buy hand:
|
||||||
|
|
||||||
|
- build the shared object (shared.nim):
|
||||||
|
|
||||||
|
$ nim c shared.nim
|
||||||
|
|
||||||
|
- build the client executables:
|
||||||
|
|
||||||
|
$ nim c -o:nmain main.nim
|
||||||
|
$ gcc -o cmain main.c -ldl
|
||||||
61
tests/realtimeGC/shared.nim
Normal file
61
tests/realtimeGC/shared.nim
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
discard """
|
||||||
|
cmd: "nim $target --debuginfo --hints:on --app:lib $options $file"
|
||||||
|
"""
|
||||||
|
|
||||||
|
import strutils
|
||||||
|
|
||||||
|
var gCounter: uint64
|
||||||
|
var gTxStatus: bool
|
||||||
|
var gRxStatus: bool
|
||||||
|
var gConnectStatus: bool
|
||||||
|
var gPttStatus: bool
|
||||||
|
var gComm1Status: bool
|
||||||
|
var gComm2Status: bool
|
||||||
|
|
||||||
|
proc getTxStatus(): string =
|
||||||
|
result = if gTxStatus: "On" else: "Off"
|
||||||
|
gTxStatus = not gTxStatus
|
||||||
|
|
||||||
|
proc getRxStatus(): string =
|
||||||
|
result = if gRxStatus: "On" else: "Off"
|
||||||
|
gRxStatus = not gRxStatus
|
||||||
|
|
||||||
|
proc getConnectStatus(): string =
|
||||||
|
result = if gConnectStatus: "Yes" else: "No"
|
||||||
|
gConnectStatus = not gConnectStatus
|
||||||
|
|
||||||
|
proc getPttStatus(): string =
|
||||||
|
result = if gPttStatus: "PTT: On" else: "PTT: Off"
|
||||||
|
gPttStatus = not gPttStatus
|
||||||
|
|
||||||
|
proc getComm1Status(): string =
|
||||||
|
result = if gComm1Status: "On" else: "Off"
|
||||||
|
gComm1Status = not gComm1Status
|
||||||
|
|
||||||
|
proc getComm2Status(): string =
|
||||||
|
result = if gComm2Status: "On" else: "Off"
|
||||||
|
gComm2Status = not gComm2Status
|
||||||
|
|
||||||
|
proc status() {.exportc: "status", dynlib.} =
|
||||||
|
var tx_status = getTxStatus()
|
||||||
|
var rx_status = getRxStatus()
|
||||||
|
var connected = getConnectStatus()
|
||||||
|
var ptt_status = getPttStatus()
|
||||||
|
var str1: string = "[PilotEdge] Connected: $1 TX: $2 RX: $3" % [connected, tx_status, rx_status]
|
||||||
|
var a = getComm1Status()
|
||||||
|
var b = getComm2Status()
|
||||||
|
var str2: string = "$1 COM1: $2 COM2: $3" % [ptt_status, a, b]
|
||||||
|
#echo(str1)
|
||||||
|
#echo(str2)
|
||||||
|
|
||||||
|
proc count() {.exportc: "count", dynlib.} =
|
||||||
|
var temp: uint64
|
||||||
|
for i in 0..100_000:
|
||||||
|
temp += 1
|
||||||
|
gCounter += 1
|
||||||
|
#echo("gCounter: ", gCounter)
|
||||||
|
|
||||||
|
proc occupiedMem() {.exportc: "occupiedMem", dynlib.} =
|
||||||
|
#echo("Occupied Memmory: ", getOccupiedMem())
|
||||||
|
discard
|
||||||
|
|
||||||
6
tests/realtimeGC/shared.nim.cfg
Normal file
6
tests/realtimeGC/shared.nim.cfg
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
--app:lib
|
||||||
|
--threads:on
|
||||||
|
|
||||||
|
-d:release
|
||||||
|
-d:useRealtimeGC
|
||||||
Loading…
Add table
Add a link
Reference in a new issue