From 9d17d027343185a2a87f748bec572f54469c0ea7 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 18 Nov 2019 09:10:48 +0100 Subject: [PATCH] attempt to add valgrind support to the CIs and testament (#12646) * attempt to add valgrind support to the CIs and testament * valgrind (currently) works only on 64-bit Linux (cherry picked from commit 223e65e52995d4243c04b5240109d12b6dc95fa2) --- .travis.yml | 2 ++ azure-pipelines.yml | 2 +- testament/specs.nim | 9 +++++++++ testament/testament.nim | 18 +++++++++++------- tests/valgrind/tbasic_valgrind.nim | 6 ++++++ 5 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 tests/valgrind/tbasic_valgrind.nim diff --git a/.travis.yml b/.travis.yml index 4a14d9a237..d62fe20d24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,6 +51,8 @@ addons: - libsdl1.2-dev - libgc-dev - libsfml-dev + - libc6-dbg + - valgrind homebrew: packages: - boehmgc diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d392aa2e34..e9b8c3fab7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -46,7 +46,7 @@ steps: sudo apt-fast update -qq DEBIAN_FRONTEND='noninteractive' \ sudo apt-fast install --no-install-recommends -yq \ - libcurl4-openssl-dev libgc-dev libsdl1.2-dev libsfml-dev + libcurl4-openssl-dev libgc-dev libsdl1.2-dev libsfml-dev valgrind libc6-dbg displayName: 'Install dependencies (amd64 Linux)' condition: and(eq(variables['Agent.OS'], 'Linux'), eq(variables['CPU'], 'amd64')) diff --git a/testament/specs.nim b/testament/specs.nim index 30f2b97d14..53578b3060 100644 --- a/testament/specs.nim +++ b/testament/specs.nim @@ -72,6 +72,7 @@ type nimout*: string parseErrors*: string # when the spec definition is invalid, this is not empty. unjoinable*: bool + useValgrind*: bool timeout*: float # in seconds, fractions possible, # but don't rely on much precision @@ -195,6 +196,14 @@ proc parseSpec*(filename: string): TSpec = result.nimout = e.value of "joinable": result.unjoinable = not parseCfgBool(e.value) + of "valgrind": + when defined(linux) and sizeof(int) == 8: + result.useValgrind = parseCfgBool(e.value) + result.unjoinable = true + else: + # Windows lacks valgrind. Silly OS. + # Valgrind only supports OSX <= 17.x + result.useValgrind = false of "disabled": case e.value.normalize of "y", "yes", "true", "1", "on": result.err = reDisabled diff --git a/testament/testament.nim b/testament/testament.nim index 703515f786..80084b2246 100644 --- a/testament/testament.nim +++ b/testament/testament.nim @@ -100,8 +100,8 @@ proc execCmdEx2(command: string, args: openarray[string]; workingDir, input: str for arg in args: result.cmdLine.add ' ' result.cmdLine.add quoteShell(arg) - - var p = startProcess(command, workingDir=workingDir, args=args, options={poStdErrToStdOut, poUsePath}) + var p = startProcess(command, workingDir=workingDir, args=args, + options={poStdErrToStdOut, poUsePath}) var outp = outputStream(p) # There is no way to provide input for the child process @@ -441,12 +441,16 @@ proc testSpecHelper(r: var TResults, test: TTest, expected: TSpec, target: TTarg if isJsTarget: exeCmd = nodejs args = concat(@[exeFile], args) - elif defined(posix) and not exeFile.contains('/'): - # "security" in Posix is actually just a euphemism - # for "unproductive arbitrary shit" - exeCmd = "./" & exeFile else: - exeCmd = exeFile + if defined(posix) and not exeFile.contains('/'): + # "security" in Posix is actually just a euphemism + # for "unproductive arbitrary shit" + exeCmd = "./" & exeFile + else: + exeCmd = exeFile + if expected.useValgrind: + args = exeCmd & args + exeCmd = "valgrind" var (_, buf, exitCode) = execCmdEx2(exeCmd, args, input = expected.input) # Treat all failure codes from nodejs as 1. Older versions of nodejs used # to return other codes, but for us it is sufficient to know that it's not 0. diff --git a/tests/valgrind/tbasic_valgrind.nim b/tests/valgrind/tbasic_valgrind.nim new file mode 100644 index 0000000000..455b1ff17c --- /dev/null +++ b/tests/valgrind/tbasic_valgrind.nim @@ -0,0 +1,6 @@ +discard """ + valgrind: true + cmd: "nim c --gc:destructors $file" +""" + +echo "hello world"