From a87f3f85be052fb3332358f95079a059cf1daf15 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 4 Feb 2021 19:38:33 -0600 Subject: [PATCH] feat: introduce some changes/additions from test/use-cases branch But without introducing the use cases tests themselves nor their dependencies in vendor. --- .github/workflows/test.yml | 4 ++-- Makefile | 1 + task_runner.nim | 4 ++-- task_runner.nimble | 5 +++-- task_runner/sys.nim | 12 ++++++++++++ test/test_helpers.nim | 12 ++++++++++++ vendor/nimbus-build-system | 2 +- 7 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 task_runner/sys.nim create mode 100644 test/test_helpers.nim diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aea90d3..b8d9a48 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -81,7 +81,7 @@ jobs: run: | make -j${NPROC} NIMFLAGS="--parallelBuild:${NPROC}" V=1 test - - name: Build and run channel_helgrind + - name: Build and run helgrind tasks if: matrix.platform.os == 'ubuntu' run: | - ./env.sh nimble channel_helgrind + ./env.sh nimble achannels_helgrind diff --git a/Makefile b/Makefile index 4575182..f7c2126 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ BUILD_SYSTEM_DIR := vendor/nimbus-build-system .PHONY: \ all \ clean \ + clean-build-dirs \ deps \ test \ update diff --git a/task_runner.nim b/task_runner.nim index 669a60b..4008a29 100644 --- a/task_runner.nim +++ b/task_runner.nim @@ -9,6 +9,6 @@ # Licensed under either of # Apache License, version 2.0, (LICENSE-APACHEv2) # MIT license (LICENSE-MIT) -import ./task_runner/achannels +import ./task_runner/achannels, ./task_runner/sys -export achannels +export achannels, sys diff --git a/task_runner.nimble b/task_runner.nimble index 0bf294b..8781705 100644 --- a/task_runner.nimble +++ b/task_runner.nimble @@ -26,6 +26,7 @@ proc buildAndRunTest(name: string, " --debugger:native" & " --define:chronicles_line_numbers" & " --define:debug" & + " --define:ssl" & " --linetrace:on" & " --nimcache:nimcache/test/" & name & " --out:" & outDir & name & @@ -43,13 +44,13 @@ proc buildAndRunTest(name: string, task tests, "Run all tests": buildAndRunTest "test_all" -task channel_helgrind, "Run channel implementation through helgrind to detect threading or lock errors": +task achannels_helgrind, "Run channel implementation through helgrind to detect threading or lock errors": rmDir "test/build/" mkDir "test/build/" var commands = [ "nim c" & " --define:useMalloc" & - " --nimcache:nimcache/test/channel_helgrind" & + " --nimcache:nimcache/test/achannels_helgrind" & " --out:test/build/test_achannels" & " --threads:on" & " --tlsEmulation:off" & diff --git a/task_runner/sys.nim b/task_runner/sys.nim new file mode 100644 index 0000000..c60b5bc --- /dev/null +++ b/task_runner/sys.nim @@ -0,0 +1,12 @@ +type + ThreadSafeString* = distinct cstring + +proc safe*(input: string): ThreadSafeString = + var res = cast[cstring](allocShared(input.len + 1)) + copyMem(res, input.cstring, input.len) + res[input.len] = '\0' + res.ThreadSafeString + +proc `$`*(input: ThreadSafeString): string = + result = $(input.cstring) + deallocShared input.cstring diff --git a/test/test_helpers.nim b/test/test_helpers.nim new file mode 100644 index 0000000..5a6030d --- /dev/null +++ b/test/test_helpers.nim @@ -0,0 +1,12 @@ +import chronos, unittest + +template asyncTest*(name, body: untyped) = + test name: + proc scenario {.async.} = body + waitFor scenario() + +template procSuite*(name, body: untyped) = + proc suitePayload = + suite name: + body + suitePayload() diff --git a/vendor/nimbus-build-system b/vendor/nimbus-build-system index 53870bc..e7694f1 160000 --- a/vendor/nimbus-build-system +++ b/vendor/nimbus-build-system @@ -1 +1 @@ -Subproject commit 53870bc6bccf0f09f9c50a923d1fa1fb235d2db0 +Subproject commit e7694f16ceccd7c98ecb6870263025018b7d37b3