2018-11-29 22:11:05 +00:00
|
|
|
# beacon_chain
|
2019-02-27 13:58:07 +00:00
|
|
|
# Copyright (c) 2018-2019 Status Research & Development GmbH
|
2018-11-29 22:11:05 +00:00
|
|
|
# Licensed and distributed under either of
|
2019-11-25 15:30:02 +00:00
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
2018-11-29 22:11:05 +00:00
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
import
|
2020-10-12 20:49:05 +00:00
|
|
|
os, algorithm, strformat, stats, times, tables, std/monotimes, stew/endians2,
|
2020-03-10 04:00:19 +00:00
|
|
|
testutils/markdown_reports, chronicles,
|
2020-07-30 19:18:17 +00:00
|
|
|
../beacon_chain/[beacon_chain_db, extras, ssz],
|
2020-07-07 23:02:14 +00:00
|
|
|
../beacon_chain/spec/[digest, beaconstate, datatypes, presets],
|
2020-07-31 14:49:06 +00:00
|
|
|
../beacon_chain/block_pools/chain_dag,
|
2020-10-12 20:49:05 +00:00
|
|
|
eth/db/[kvstore, kvstore_sqlite3],
|
2019-12-19 13:02:28 +00:00
|
|
|
testblockutil
|
2018-11-29 22:11:05 +00:00
|
|
|
|
2019-12-05 10:27:00 +00:00
|
|
|
type
|
|
|
|
TestDuration = tuple[duration: float, label: string]
|
|
|
|
|
2019-05-27 12:48:13 +00:00
|
|
|
func preset*(): string =
|
|
|
|
" [Preset: " & const_preset & ']'
|
|
|
|
|
2019-12-05 10:27:00 +00:00
|
|
|
# For state_sim
|
2019-12-03 16:45:12 +00:00
|
|
|
template withTimer*(stats: var RunningStat, body: untyped) =
|
|
|
|
let start = getMonoTime()
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2019-12-03 16:45:12 +00:00
|
|
|
block:
|
|
|
|
body
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2019-12-03 16:45:12 +00:00
|
|
|
let stop = getMonoTime()
|
|
|
|
stats.push (stop - start).inMicroseconds.float / 1000000.0
|
2019-07-24 06:19:52 +00:00
|
|
|
|
2019-12-05 10:27:00 +00:00
|
|
|
template withTimer*(duration: var float, body: untyped) =
|
|
|
|
let start = getMonoTime()
|
|
|
|
|
|
|
|
block:
|
|
|
|
body
|
|
|
|
|
|
|
|
duration = (getMonoTime() - start).inMicroseconds.float / 1000000.0
|
|
|
|
|
|
|
|
# For state_sim
|
2019-12-03 16:45:12 +00:00
|
|
|
template withTimerRet*(stats: var RunningStat, body: untyped): untyped =
|
|
|
|
let start = getMonoTime()
|
|
|
|
let tmp = block:
|
|
|
|
body
|
|
|
|
let stop = getMonoTime()
|
|
|
|
stats.push (stop - start).inMicroseconds.float / 1000000.0
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2019-12-03 16:45:12 +00:00
|
|
|
tmp
|
2019-11-27 22:48:12 +00:00
|
|
|
|
2019-12-05 10:27:00 +00:00
|
|
|
var testTimes: seq[TestDuration]
|
2020-03-10 04:00:19 +00:00
|
|
|
var status = initOrderedTable[string, OrderedTable[string, Status]]()
|
|
|
|
var last: string
|
2019-12-05 10:27:00 +00:00
|
|
|
|
2020-03-10 04:00:19 +00:00
|
|
|
proc summarizeLongTests*(name: string) =
|
2019-12-05 10:27:00 +00:00
|
|
|
# TODO clean-up and make machine-readable/storable the output
|
|
|
|
# TODO this is too hard-coded and mostly a demo for using the
|
|
|
|
# timedTest wrapper template for unittest
|
|
|
|
sort(testTimes, system.cmp, SortOrder.Descending)
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "10 longest individual test durations"
|
|
|
|
echo "------------------------------------"
|
|
|
|
for i, item in testTimes:
|
|
|
|
echo &"{item.duration:6.2f}s for {item.label}"
|
|
|
|
if i >= 10:
|
|
|
|
break
|
|
|
|
|
2020-03-10 04:00:19 +00:00
|
|
|
status.sort do (a: (string, OrderedTable[string, Status]),
|
|
|
|
b: (string, OrderedTable[string, Status])) -> int: cmp(a[0], b[0])
|
|
|
|
|
|
|
|
generateReport(name & "-" & const_preset, status, width=90)
|
|
|
|
|
|
|
|
template suiteReport*(name, body) =
|
|
|
|
last = name
|
|
|
|
status[last] = initOrderedTable[string, Status]()
|
2020-05-05 15:02:26 +00:00
|
|
|
block: # namespacing
|
|
|
|
proc runSuite() =
|
|
|
|
suite name:
|
|
|
|
body
|
|
|
|
runSuite()
|
2020-03-10 04:00:19 +00:00
|
|
|
|
2019-12-05 10:27:00 +00:00
|
|
|
template timedTest*(name, body) =
|
|
|
|
var f: float
|
|
|
|
test name:
|
2020-03-10 04:00:19 +00:00
|
|
|
status[last][name] = Status.Fail
|
|
|
|
|
2019-12-05 10:27:00 +00:00
|
|
|
withTimer f:
|
|
|
|
body
|
|
|
|
|
2020-03-10 04:00:19 +00:00
|
|
|
status[last][name] = case testStatusIMPL
|
|
|
|
of OK: Status.OK
|
|
|
|
of FAILED: Status.Fail
|
|
|
|
of SKIPPED: Status.Skip
|
|
|
|
|
2019-12-05 10:27:00 +00:00
|
|
|
# TODO reached for a failed test; maybe defer or similar
|
|
|
|
# TODO noto thread-safe as-is
|
|
|
|
testTimes.add (f, name)
|
|
|
|
|
2020-04-28 08:08:32 +00:00
|
|
|
proc makeTestDB*(tailState: BeaconState, tailBlock: SignedBeaconBlock): BeaconChainDB =
|
2020-10-15 11:49:02 +00:00
|
|
|
result = BeaconChainDB.init(defaultRuntimePreset, "", inMemory = true)
|
2020-09-22 20:42:42 +00:00
|
|
|
ChainDAGRef.preInit(result, tailState, tailState, tailBlock)
|
2019-12-05 10:27:00 +00:00
|
|
|
|
2020-07-13 14:44:58 +00:00
|
|
|
proc makeTestDB*(validators: Natural): BeaconChainDB =
|
2019-12-19 13:02:28 +00:00
|
|
|
let
|
|
|
|
genState = initialize_beacon_state_from_eth1(
|
2020-07-07 23:02:14 +00:00
|
|
|
defaultRuntimePreset, Eth2Digest(), 0,
|
2020-07-13 14:44:58 +00:00
|
|
|
makeInitialDeposits(validators.uint64, flags = {skipBlsValidation}),
|
2020-04-10 13:59:17 +00:00
|
|
|
{skipBlsValidation})
|
2020-04-23 18:58:54 +00:00
|
|
|
genBlock = get_initial_beacon_block(genState[])
|
2020-04-28 08:08:32 +00:00
|
|
|
makeTestDB(genState[], genBlock)
|
2019-12-19 13:02:28 +00:00
|
|
|
|
2019-12-05 10:27:00 +00:00
|
|
|
export inMicroseconds
|