From c1adf30c9c5995f2c4e18cb8b52a1392626278e4 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 13 May 2020 21:54:21 -0700 Subject: [PATCH 1/5] _ --- tests/stdlib/tfdleak.nim | 14 ++-- tests/trunner.nim | 146 +++++++++++++++++++++------------------ 2 files changed, 86 insertions(+), 74 deletions(-) diff --git a/tests/stdlib/tfdleak.nim b/tests/stdlib/tfdleak.nim index 08ef06da3d77..fc854664fca1 100644 --- a/tests/stdlib/tfdleak.nim +++ b/tests/stdlib/tfdleak.nim @@ -9,13 +9,16 @@ when defined(windows): import winlean else: import posix +from stdtest/specialpaths import buildDir proc leakCheck(f: int | FileHandle | SocketHandle, msg: string, expectLeak = defined(nimInheritHandles)) = - discard startProcess( + let p = startProcess( getAppFilename(), args = @[$f.int, msg, $expectLeak], options = {poParentStreams} - ).waitForExit -1 + ) + doAssert p.waitForExit == 0 + close p proc isValidHandle(f: int): bool = ## Check if a handle is valid. Requires OS-native handles. @@ -28,12 +31,12 @@ proc isValidHandle(f: int): bool = proc main() = if paramCount() == 0: # Parent process - let f = system.open("__test_fdleak", fmReadWrite) + let f = system.open(buildDir / "__test_fdleak", fmReadWrite) defer: close f leakCheck(f.getOsFileHandle, "system.open()") - doAssert f.reopen("__test_fdleak2", fmReadWrite), "reopen failed" + doAssert f.reopen(buildDir / "__test_fdleak2", fmReadWrite), "reopen failed" leakCheck(f.getOsFileHandle, "reopen") @@ -67,7 +70,7 @@ proc main() = let selector = newSelector[int]() leakCheck(selector.getFd, "selector()", false) - var mf = memfiles.open("__test_fdleak3", fmReadWrite, newFileSize = 1) + var mf = memfiles.open(buildDir / "__test_fdleak3", fmReadWrite, newFileSize = 1) defer: close mf when defined(windows): leakCheck(mf.fHandle, "memfiles.open().fHandle", false) @@ -79,6 +82,7 @@ proc main() = fd = parseInt(paramStr 1) expectLeak = parseBool(paramStr 3) msg = (if expectLeak: "not " else: "") & "leaked " & paramStr 2 + # echo (msg, expectLeak, fd.isValidHandle, fd) if expectLeak xor fd.isValidHandle: echo msg diff --git a/tests/trunner.nim b/tests/trunner.nim index bd74a8405e60..acc684346e95 100644 --- a/tests/trunner.nim +++ b/tests/trunner.nim @@ -59,72 +59,80 @@ ret=[s1:foobar s2:foobar age:25 pi:3.14] doAssert exitCode == 0 else: # don't run twice the same test - import std/[strutils] - template check2(msg) = doAssert msg in output, output - - block: # mstatic_assert - let (output, exitCode) = runCmd("ccgbugs/mstatic_assert.nim", "-d:caseBad") - check2 "sizeof(bool) == 2" - doAssert exitCode != 0 - - block: # ABI checks - let file = "misc/msizeof5.nim" - block: - let (output, exitCode) = runCmd(file, "-d:checkAbi") - doAssert exitCode == 0, output - block: - let (output, exitCode) = runCmd(file, "-d:checkAbi -d:caseBad") - # on platforms that support _StaticAssert natively, errors will show full context, eg: - # error: static_assert failed due to requirement 'sizeof(unsigned char) == 8' - # "backend & Nim disagree on size for: BadImportcType{int64} [declared in mabi_check.nim(1, 6)]" - check2 "sizeof(unsigned char) == 8" - check2 "sizeof(struct Foo2) == 1" - check2 "sizeof(Foo5) == 16" - check2 "sizeof(Foo5) == 3" - check2 "sizeof(struct Foo6) == " - doAssert exitCode != 0 - - import streams - block: # stdin input - let nimcmd = fmt"{nim} r --hints:off - -firstparam '-second param'" - let inputcmd = "import os; echo commandLineParams()" - let expected = """@["-firstparam", "-second param"]""" - block: - let p = startProcess(nimcmd, options = {poEvalCommand}) - p.inputStream.write("import os; echo commandLineParams()") - p.inputStream.close - var output = p.outputStream.readAll - let error = p.errorStream.readAll - doAssert p.waitForExit == 0 - doAssert error.len == 0, $error - output.stripLineEnd - doAssert output == expected - p.errorStream.close - p.outputStream.close - - block: - when defined(posix): - let cmd = fmt"echo 'import os; echo commandLineParams()' | {nimcmd}" - var (output, exitCode) = execCmdEx(cmd) - output.stripLineEnd - doAssert output == expected - - block: # nim doc --backend:$backend --doccmd:$cmd - # test for https://github.com/nim-lang/Nim/issues/13129 - # test for https://github.com/nim-lang/Nim/issues/13891 - let file = testsDir / "nimdoc/m13129.nim" - for backend in fmt"{mode} js".split: - let cmd = fmt"{nim} doc -b:{backend} --nimcache:{nimcache} -d:m13129Foo1 --doccmd:'-d:m13129Foo2 --hints:off' --usenimcache --hints:off {file}" - check execCmdEx(cmd) == (&"ok1:{backend}\nok2: backend: {backend}\n", 0) - # checks that --usenimcache works with `nim doc` - check fileExists(nimcache / "m13129.html") - - block: # mak sure --backend works with `nim r` - let cmd = fmt"{nim} r --backend:{mode} --hints:off --nimcache:{nimcache} {file}" - check execCmdEx(cmd) == ("ok3\n", 0) - - block: # some importc tests - # issue #14314 - let file = testsDir / "misc/mimportc.nim" - let cmd = fmt"{nim} r -b:cpp --hints:off --nimcache:{nimcache} --warningAsError:ProveInit {file}" - check execCmdEx(cmd) == ("witness\n", 0) + # import std/[strutils] + # template check2(msg) = doAssert msg in output, output + + # block: # mstatic_assert + # let (output, exitCode) = runCmd("ccgbugs/mstatic_assert.nim", "-d:caseBad") + # check2 "sizeof(bool) == 2" + # doAssert exitCode != 0 + + # block: # ABI checks + # let file = "misc/msizeof5.nim" + # block: + # let (output, exitCode) = runCmd(file, "-d:checkAbi") + # doAssert exitCode == 0, output + # block: + # let (output, exitCode) = runCmd(file, "-d:checkAbi -d:caseBad") + # # on platforms that support _StaticAssert natively, errors will show full context, eg: + # # error: static_assert failed due to requirement 'sizeof(unsigned char) == 8' + # # "backend & Nim disagree on size for: BadImportcType{int64} [declared in mabi_check.nim(1, 6)]" + # check2 "sizeof(unsigned char) == 8" + # check2 "sizeof(struct Foo2) == 1" + # check2 "sizeof(Foo5) == 16" + # check2 "sizeof(Foo5) == 3" + # check2 "sizeof(struct Foo6) == " + # doAssert exitCode != 0 + + # import streams + # block: # stdin input + # let nimcmd = fmt"{nim} r --hints:off - -firstparam '-second param'" + # let inputcmd = "import os; echo commandLineParams()" + # let expected = """@["-firstparam", "-second param"]""" + # block: + # let p = startProcess(nimcmd, options = {poEvalCommand}) + # p.inputStream.write("import os; echo commandLineParams()") + # p.inputStream.close + # var output = p.outputStream.readAll + # let error = p.errorStream.readAll + # doAssert p.waitForExit == 0 + # doAssert error.len == 0, $error + # output.stripLineEnd + # doAssert output == expected + # p.errorStream.close + # p.outputStream.close + + # block: + # when defined(posix): + # let cmd = fmt"echo 'import os; echo commandLineParams()' | {nimcmd}" + # var (output, exitCode) = execCmdEx(cmd) + # output.stripLineEnd + # doAssert output == expected + + # block: # nim doc --backend:$backend --doccmd:$cmd + # # test for https://github.com/nim-lang/Nim/issues/13129 + # # test for https://github.com/nim-lang/Nim/issues/13891 + # let file = testsDir / "nimdoc/m13129.nim" + # for backend in fmt"{mode} js".split: + # let cmd = fmt"{nim} doc -b:{backend} --nimcache:{nimcache} -d:m13129Foo1 --doccmd:'-d:m13129Foo2 --hints:off' --usenimcache --hints:off {file}" + # check execCmdEx(cmd) == (&"ok1:{backend}\nok2: backend: {backend}\n", 0) + # # checks that --usenimcache works with `nim doc` + # check fileExists(nimcache / "m13129.html") + + # block: # mak sure --backend works with `nim r` + # let cmd = fmt"{nim} r --backend:{mode} --hints:off --nimcache:{nimcache} {file}" + # check execCmdEx(cmd) == ("ok3\n", 0) + + # block: # some importc tests + # # issue #14314 + # let file = testsDir / "misc/mimportc.nim" + # let cmd = fmt"{nim} r -b:cpp --hints:off --nimcache:{nimcache} --warningAsError:ProveInit {file}" + # check execCmdEx(cmd) == ("witness\n", 0) + + block: # PRTEMP + # D20200513T213820 + let file = testsDir / "stdlib/tfdleak.nim" + let cmd = fmt"{nim} r --hints:off --nimcache:{nimcache} {file}" + for i in 0..<1000: + let ret = execCmdEx(cmd) + echo ret From 27c7eab7ab1d40844e947681653961efc490da68 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 13 May 2020 21:55:58 -0700 Subject: [PATCH 2/5] _ --- koch.nim | 65 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/koch.nim b/koch.nim index 3ec40534ba71..2b74a267fe16 100644 --- a/koch.nim +++ b/koch.nim @@ -528,38 +528,39 @@ proc runCI(cmd: string) = echo hostInfo() # boot without -d:nimHasLibFFI to make sure this still works kochExecFold("Boot in release mode", "boot -d:release") - - ## build nimble early on to enable remainder to depend on it if needed - kochExecFold("Build Nimble", "nimble") - - if getEnv("NIM_TEST_PACKAGES", "0") == "1": - execFold("Test selected Nimble packages (1)", "nim c -r testament/testament cat nimble-packages-1") - elif getEnv("NIM_TEST_PACKAGES", "0") == "2": - execFold("Test selected Nimble packages (2)", "nim c -r testament/testament cat nimble-packages-2") - else: - buildTools() - - ## run tests - execFold("Test nimscript", "nim e tests/test_nimscript.nims") - when defined(windows): - # note: will be over-written below - execFold("Compile tester", "nim c -d:nimCoroutines --os:genode -d:posix --compileOnly testament/testament") - - # main bottleneck here - execFold("Run tester", "nim c -r -d:nimCoroutines testament/testament --pedantic all -d:nimCoroutines") - block CT_FFI: - when defined(posix): # windows can be handled in future PR's - execFold("nimble install -y libffi", "nimble install -y libffi") - const nimFFI = "./bin/nim.ctffi" - # no need to bootstrap with koch boot (would be slower) - let backend = if doUseCpp(): "cpp" else: "c" - execFold("build with -d:nimHasLibFFI", "nim $1 -d:release -d:nimHasLibFFI -o:$2 compiler/nim.nim" % [backend, nimFFI]) - execFold("test with -d:nimHasLibFFI", "$1 $2 -r testament/testament --nim:$1 r tests/trunner.nim" % [nimFFI, backend]) - - execFold("Run nimdoc tests", "nim c -r nimdoc/tester") - execFold("Run nimpretty tests", "nim c -r nimpretty/tester.nim") - when defined(posix): - execFold("Run nimsuggest tests", "nim c -r nimsuggest/tester") + execFold("test with -d:nimHasLibFFI", "$1 $2 -r testament/testament --nim:$1 r tests/trunner.nim" % ["nim", "c"]) + + # ## build nimble early on to enable remainder to depend on it if needed + # kochExecFold("Build Nimble", "nimble") + + # if getEnv("NIM_TEST_PACKAGES", "0") == "1": + # execFold("Test selected Nimble packages (1)", "nim c -r testament/testament cat nimble-packages-1") + # elif getEnv("NIM_TEST_PACKAGES", "0") == "2": + # execFold("Test selected Nimble packages (2)", "nim c -r testament/testament cat nimble-packages-2") + # else: + # buildTools() + + # ## run tests + # execFold("Test nimscript", "nim e tests/test_nimscript.nims") + # when defined(windows): + # # note: will be over-written below + # execFold("Compile tester", "nim c -d:nimCoroutines --os:genode -d:posix --compileOnly testament/testament") + + # # main bottleneck here + # execFold("Run tester", "nim c -r -d:nimCoroutines testament/testament --pedantic all -d:nimCoroutines") + # block CT_FFI: + # when defined(posix): # windows can be handled in future PR's + # execFold("nimble install -y libffi", "nimble install -y libffi") + # const nimFFI = "./bin/nim.ctffi" + # # no need to bootstrap with koch boot (would be slower) + # let backend = if doUseCpp(): "cpp" else: "c" + # execFold("build with -d:nimHasLibFFI", "nim $1 -d:release -d:nimHasLibFFI -o:$2 compiler/nim.nim" % [backend, nimFFI]) + # execFold("test with -d:nimHasLibFFI", "$1 $2 -r testament/testament --nim:$1 r tests/trunner.nim" % [nimFFI, backend]) + + # execFold("Run nimdoc tests", "nim c -r nimdoc/tester") + # execFold("Run nimpretty tests", "nim c -r nimpretty/tester.nim") + # when defined(posix): + # execFold("Run nimsuggest tests", "nim c -r nimsuggest/tester") proc pushCsources() = if not dirExists("../csources/.git"): From feed65de013ed3836e9c6ccf8d85c198b7f2bf33 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 13 May 2020 21:58:40 -0700 Subject: [PATCH 3/5] _ --- koch.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koch.nim b/koch.nim index 2b74a267fe16..4403a6d6e770 100644 --- a/koch.nim +++ b/koch.nim @@ -528,7 +528,7 @@ proc runCI(cmd: string) = echo hostInfo() # boot without -d:nimHasLibFFI to make sure this still works kochExecFold("Boot in release mode", "boot -d:release") - execFold("test with -d:nimHasLibFFI", "$1 $2 -r testament/testament --nim:$1 r tests/trunner.nim" % ["nim", "c"]) + execFold("test with -d:nimHasLibFFI", "$1 $2 -r testament/testament --nim:$1 r tests/trunner.nim" % [getCurrentCompilerExe(), "c"]) # ## build nimble early on to enable remainder to depend on it if needed # kochExecFold("Build Nimble", "nimble") From a47e9968be68399f357f4d34b3046053632eb5b3 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 13 May 2020 22:07:41 -0700 Subject: [PATCH 4/5] _ --- tests/stdlib/tfdleak.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/stdlib/tfdleak.nim b/tests/stdlib/tfdleak.nim index fc854664fca1..f7cae2be8929 100644 --- a/tests/stdlib/tfdleak.nim +++ b/tests/stdlib/tfdleak.nim @@ -82,8 +82,8 @@ proc main() = fd = parseInt(paramStr 1) expectLeak = parseBool(paramStr 3) msg = (if expectLeak: "not " else: "") & "leaked " & paramStr 2 - # echo (msg, expectLeak, fd.isValidHandle, fd) if expectLeak xor fd.isValidHandle: - echo msg + echo (msg, expectLeak, fd.isValidHandle, fd) + # echo msg when isMainModule: main() From ff0b2040523046469ed1593c58ed8cd98b92152a Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 13 May 2020 22:28:53 -0700 Subject: [PATCH 5/5] _ --- tests/trunner.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/trunner.nim b/tests/trunner.nim index acc684346e95..0ed1f256a1ef 100644 --- a/tests/trunner.nim +++ b/tests/trunner.nim @@ -133,6 +133,8 @@ else: # don't run twice the same test # D20200513T213820 let file = testsDir / "stdlib/tfdleak.nim" let cmd = fmt"{nim} r --hints:off --nimcache:{nimcache} {file}" - for i in 0..<1000: + echo cmd + doAssert false # PRTEMP + for i in 0..<1000 let ret = execCmdEx(cmd) echo ret