2018-04-06 14:52:10 +00:00
|
|
|
# Nimbus
|
2019-01-06 19:19:48 +00:00
|
|
|
# Copyright (c) 2018-2019 Status Research & Development GmbH
|
2018-04-06 14:52:10 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2019-05-30 16:42:55 +00:00
|
|
|
import macros, strutils, os, unittest2, osproc
|
|
|
|
import threadpool
|
|
|
|
|
|
|
|
# AppVeyor may go out of memory with the default of 4
|
|
|
|
setMinPoolSize(2)
|
2019-03-17 00:54:30 +00:00
|
|
|
|
2020-05-20 04:35:27 +00:00
|
|
|
proc executeMyself(numModules: int, names: openArray[string]): int =
|
2019-09-21 05:45:23 +00:00
|
|
|
let appName = getAppFilename()
|
|
|
|
for i in 0..<numModules:
|
2019-10-26 01:23:09 +00:00
|
|
|
let execResult = execCmd(appName & " " & $i)
|
|
|
|
if execResult != 0:
|
2020-05-20 04:35:27 +00:00
|
|
|
stderr.writeLine("subtest no: " & $i & " failed: " & names[i])
|
2019-10-26 01:23:09 +00:00
|
|
|
result = result or execResult
|
2019-09-21 05:45:23 +00:00
|
|
|
|
2019-09-24 03:29:41 +00:00
|
|
|
proc getImportStmt(stmtList: NimNode): NimNode =
|
|
|
|
result = stmtList[0]
|
|
|
|
result.expectKind nnkImportStmt
|
|
|
|
|
|
|
|
proc ofStmt(idx: int, singleModule: NimNode): NimNode =
|
|
|
|
# remove the "test_" prefix
|
|
|
|
let moduleName = normalize(singleModule.toStrLit.strVal).substr(4)
|
|
|
|
let moduleMain = newIdentNode(moduleName & "Main")
|
|
|
|
|
|
|
|
# construct `of` branch
|
|
|
|
# of idx: moduleMain()
|
|
|
|
result = nnkOfBranch.newTree(
|
|
|
|
newLit(idx),
|
|
|
|
newCall(moduleMain)
|
|
|
|
)
|
|
|
|
|
2020-05-20 04:35:27 +00:00
|
|
|
proc toModuleNames(importStmt: NimNode): NimNode =
|
|
|
|
result = nnkBracket.newTree
|
|
|
|
for singleModule in importStmt:
|
|
|
|
let x = normalize(singleModule.toStrLit.strVal)
|
|
|
|
result.add newLit(x)
|
|
|
|
|
2019-09-21 05:45:23 +00:00
|
|
|
macro cliBuilder(stmtList: typed): untyped =
|
2019-09-24 03:29:41 +00:00
|
|
|
let importStmt = stmtList.getImportStmt
|
2019-09-21 05:45:23 +00:00
|
|
|
let moduleCount = importStmt.len
|
2020-05-20 04:35:27 +00:00
|
|
|
let moduleNames = importStmt.toModuleNames
|
2019-09-21 05:45:23 +00:00
|
|
|
|
2019-09-24 03:29:41 +00:00
|
|
|
# case paramStr(1).parseInt
|
|
|
|
var caseStmt = nnkCaseStmt.newTree(
|
|
|
|
quote do: paramStr(1).parseInt
|
|
|
|
)
|
2019-09-21 05:45:23 +00:00
|
|
|
|
2019-09-24 03:29:41 +00:00
|
|
|
# of 0: codeStreamMain()
|
|
|
|
# of 1: gasMeterMain()
|
|
|
|
# of 2: memoryMain()
|
|
|
|
# ...
|
2019-09-21 05:45:23 +00:00
|
|
|
for idx, singleModule in importStmt:
|
2019-09-24 03:29:41 +00:00
|
|
|
caseStmt.add ofStmt(idx, singleModule)
|
|
|
|
|
|
|
|
# else:
|
|
|
|
# echo "invalid argument"
|
|
|
|
caseStmt.add nnkElse.newTree(
|
|
|
|
quote do: echo "invalid argument"
|
|
|
|
)
|
2019-09-21 05:45:23 +00:00
|
|
|
|
|
|
|
result = quote do:
|
|
|
|
if paramCount() == 0:
|
2020-05-20 04:43:46 +00:00
|
|
|
const names = `moduleNames`
|
2020-05-20 04:35:27 +00:00
|
|
|
quit(executeMyself(`moduleCount`, names))
|
2019-09-21 05:45:23 +00:00
|
|
|
else:
|
|
|
|
disableParamFiltering()
|
|
|
|
`caseStmt`
|
|
|
|
|
|
|
|
# if you want to add new test module(s)
|
|
|
|
# make sure you define an entry poin
|
|
|
|
# e.g.
|
|
|
|
# proc mytestMain*() =
|
|
|
|
# # put anything you want here
|
|
|
|
# and then give it a name `test_mytest.nim`
|
2019-09-22 09:57:19 +00:00
|
|
|
# the `mytest` part should match between
|
|
|
|
# the proc name and the module name
|
2019-09-21 05:45:23 +00:00
|
|
|
|
|
|
|
# if this executable called without any params
|
2019-09-22 09:57:19 +00:00
|
|
|
# it will execute each of the test by executing itself
|
|
|
|
# repeatedly until all sub-tests are executed.
|
|
|
|
# you can execute the sub-test by a number start from zero.
|
2019-09-21 05:45:23 +00:00
|
|
|
|
2020-07-21 06:15:06 +00:00
|
|
|
{. warning[UnusedImport]:off .}
|
|
|
|
|
2019-09-21 05:45:23 +00:00
|
|
|
cliBuilder:
|
2020-05-20 04:43:46 +00:00
|
|
|
import ./test_code_stream,
|
|
|
|
./test_gas_meter,
|
|
|
|
./test_memory,
|
|
|
|
./test_stack,
|
|
|
|
./test_genesis,
|
|
|
|
./test_vm_json,
|
|
|
|
./test_precompiles,
|
|
|
|
./test_generalstate_json,
|
|
|
|
./test_tracer_json,
|
|
|
|
./test_persistblock_json,
|
2020-05-20 04:49:33 +00:00
|
|
|
#./test_rpc, # it crash if we combine it here
|
2020-05-20 04:43:46 +00:00
|
|
|
./test_op_arith,
|
|
|
|
./test_op_bit,
|
|
|
|
./test_op_env,
|
|
|
|
./test_op_memory,
|
|
|
|
./test_op_misc,
|
|
|
|
./test_op_custom,
|
|
|
|
./test_state_db,
|
|
|
|
./test_difficulty,
|
|
|
|
./test_transaction_json,
|
|
|
|
./test_blockchain_json,
|
2020-07-04 06:23:09 +00:00
|
|
|
./test_forkid,
|
2020-05-05 13:46:17 +00:00
|
|
|
../stateless/test_witness_keys,
|
2020-05-20 04:43:46 +00:00
|
|
|
../stateless/test_block_witness,
|
2020-11-19 06:56:22 +00:00
|
|
|
../stateless/test_witness_json,
|
2021-04-24 04:01:56 +00:00
|
|
|
./test_misc,
|
|
|
|
./test_graphql
|