Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testament: generic N-fold batching: windows CI 37mn=>16m #14823

Merged
merged 7 commits into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,19 @@ jobs:
vmImage: 'macOS-10.15'
CPU: amd64
NIM_COMPILE_TO_CPP: true
Windows_amd64:
Windows_amd64_batch0_3:
vmImage: 'windows-2019'
CPU: amd64
# see also: `NIM_TEST_PACKAGES`
NIM_TESTAMENT_BATCH: "0_3"
Windows_amd64_batch1_3:
vmImage: 'windows-2019'
CPU: amd64
NIM_TESTAMENT_BATCH: "1_3"
Windows_amd64_batch2_3:
vmImage: 'windows-2019'
CPU: amd64
NIM_TESTAMENT_BATCH: "2_3"

pool:
vmImage: $(vmImage)
Expand Down
7 changes: 6 additions & 1 deletion koch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,12 @@ proc runCI(cmd: string) =
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")
# xxx: even though this is the main bottlneck, we could use same code to batch the other tests
#[
BUG: with initOptParser, `--batch:'' all` interprets `all` as the argument of --batch
]#
execFold("Run tester", "nim c -r -d:nimCoroutines testament/testament --pedantic --batch:$1 all -d:nimCoroutines" % ["NIM_TESTAMENT_BATCH".getEnv("_")])

block CT_FFI:
when defined(posix): # windows can be handled in future PR's
execFold("nimble install -y libffi", "nimble install -y libffi")
Expand Down
4 changes: 4 additions & 0 deletions lib/nimhcr.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
discard """
batchable: false
"""

#
#
# Nim's Runtime Library
Expand Down
4 changes: 4 additions & 0 deletions lib/nimrtl.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
discard """
batchable: false
"""

#
#
# Nim's Runtime Library
Expand Down
5 changes: 3 additions & 2 deletions testament/categories.nim
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,9 @@ proc runJoinedTest(r: var TResults, cat: Category, testsDir: string) =
quit 1
else:
echo "megatest output OK"
removeFile(outputGottenFile)
removeFile(megatestFile)
when false: # no point removing those, always good for debugging
removeFile(outputGottenFile)
removeFile(megatestFile) # keep it around
#testSpec r, makeTest("megatest", options, cat)

# ---------------------------------------------------------------------------
Expand Down
23 changes: 23 additions & 0 deletions testament/specs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
#

import sequtils, parseutils, strutils, os, streams, parsecfg
from hashes import hash

type TestamentData* = ref object
# better to group globals under 1 object; could group the other ones here too
batchArg*: string
testamentNumBatch*: int
testamentBatch*: int

let testamentData0* = TestamentData()

var compilerPrefix* = findExe("nim")

Expand Down Expand Up @@ -68,11 +77,13 @@ type
ccodeCheck*: string
maxCodeSize*: int
err*: TResultEnum
inCurrentBatch*: bool
targets*: set[TTarget]
matrix*: seq[string]
nimout*: string
parseErrors*: string # when the spec definition is invalid, this is not empty.
unjoinable*: bool
unbatchable*: bool
useValgrind*: bool
timeout*: float # in seconds, fractions possible,
# but don't rely on much precision
Expand Down Expand Up @@ -138,6 +149,12 @@ proc addLine*(self: var string; a,b: string) =
proc initSpec*(filename: string): TSpec =
result.file = filename

proc isCurrentBatch(testamentData: TestamentData, filename: string): bool =
if testamentData.testamentNumBatch != 0:
hash(filename) mod testamentData.testamentNumBatch == testamentData.testamentBatch
else:
true

proc parseSpec*(filename: string): TSpec =
result.file = filename
let specStr = extractSpec(filename)
Expand Down Expand Up @@ -203,6 +220,8 @@ proc parseSpec*(filename: string): TSpec =
result.action = actionReject
of "nimout":
result.nimout = e.value
of "batchable":
result.unbatchable = not parseCfgBool(e.value)
of "joinable":
result.unjoinable = not parseCfgBool(e.value)
of "valgrind":
Expand Down Expand Up @@ -297,3 +316,7 @@ proc parseSpec*(filename: string): TSpec =

if skips.anyIt(it in result.file):
result.err = reDisabled

result.inCurrentBatch = isCurrentBatch(testamentData0, filename) or result.unbatchable
if not result.inCurrentBatch:
result.err = reDisabled
18 changes: 15 additions & 3 deletions testament/testament.nim
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,14 @@ proc addResult(r: var TResults, test: TTest, target: TTarget,
expected = expected,
given = given)
r.data.addf("$#\t$#\t$#\t$#", name, expected, given, $success)
template disp(msg) =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick (don't have to change it), I use disp for "dispatch" and there is no conditional here. :-)

maybeStyledEcho styleDim, fgYellow, msg & " ", styleBright, fgCyan, name
if success == reSuccess:
maybeStyledEcho fgGreen, "PASS: ", fgCyan, alignLeft(name, 60), fgBlue, " (", durationStr, " sec)"
elif success == reDisabled:
maybeStyledEcho styleDim, fgYellow, "SKIP: ", styleBright, fgCyan, name
elif success == reJoined:
maybeStyledEcho styleDim, fgYellow, "JOINED: ", styleBright, fgCyan, name
if test.spec.inCurrentBatch: disp("SKIP:")
else: disp("NOTINBATCH:")
elif success == reJoined: disp("JOINED:")
else:
maybeStyledEcho styleBright, fgRed, failString, fgCyan, name
maybeStyledEcho styleBright, fgCyan, "Test \"", test.name, "\"", " in category \"", test.cat.string, "\""
Expand Down Expand Up @@ -645,6 +647,15 @@ proc main() =
useColors = false
else:
quit Usage
of "batch":
testamentData0.batchArg = p.val
if p.val != "_":
let s = p.val.split("_")
doAssert s.len == 2, $(p.val, s)
testamentData0.testamentBatch = s[0].parseInt
testamentData0.testamentNumBatch = s[1].parseInt
doAssert testamentData0.testamentNumBatch > 0
doAssert testamentData0.testamentBatch >= 0 and testamentData0.testamentBatch < testamentData0.testamentNumBatch
of "simulate":
simulate = true
of "megatest":
Expand Down Expand Up @@ -682,6 +693,7 @@ proc main() =
myself &= " " & quoteShell("--targets:" & targetsStr)

myself &= " " & quoteShell("--nim:" & compilerPrefix)
myself &= " --batch:" & testamentData0.batchArg

if skipFrom.len > 0:
myself &= " " & quoteShell("--skipFrom:" & skipFrom)
Expand Down
9 changes: 0 additions & 9 deletions tests/osproc/ta_in.nim

This file was deleted.

33 changes: 0 additions & 33 deletions tests/osproc/ta_out.nim

This file was deleted.

7 changes: 0 additions & 7 deletions tests/osproc/tafalse.nim

This file was deleted.

4 changes: 4 additions & 0 deletions tests/osproc/texecps.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
discard """
joinable: false
"""

import osproc, streams, strutils, os

const NumberOfProcesses = 13
Expand Down
26 changes: 0 additions & 26 deletions tests/osproc/texitcode.nim

This file was deleted.

37 changes: 0 additions & 37 deletions tests/osproc/tstderr.nim

This file was deleted.

17 changes: 0 additions & 17 deletions tests/osproc/tstdin.nim

This file was deleted.

31 changes: 0 additions & 31 deletions tests/osproc/tstdout.nim

This file was deleted.

Loading