Generate distinct pseudo-random number for each test

Fixes #1161
This commit is contained in:
mpilman 2019-02-15 21:45:26 -08:00 committed by Alex Miller
parent cdb7c721c9
commit e8af6512ec
2 changed files with 15 additions and 1 deletions

View File

@ -99,6 +99,9 @@ function(add_fdb_test)
if (ENABLE_BUGGIFY)
set(BUGGIFY_OPTION "-B")
endif()
math(EXPR test_idx "${CURRENT_TEST_INDEX} + 1")
set(CURRENT_TEST_INDEX "${test_idx}" CACHE INTERNAL "The index used for the last added test" FORCE)
message("Added ${test_name} with idx ${CURRENT_TEST_INDEX}")
list(TRANSFORM ADD_FDB_TEST_TEST_FILES PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/")
add_test(NAME ${test_name}
COMMAND $<TARGET_FILE:Python::Interpreter> ${TestRunner}
@ -110,6 +113,7 @@ function(add_fdb_test)
--keep-logs ${TEST_KEEP_LOGS}
--keep-simdirs ${TEST_KEEP_SIMDIR}
--seed ${SEED}
--test-number ${CURRENT_TEST_INDEX}
${BUGGIFY_OPTION}
${ADD_FDB_TEST_TEST_FILES}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})

View File

@ -15,6 +15,7 @@ import multiprocessing
import re
import shutil
import io
import random
_logger = None
@ -279,7 +280,14 @@ def run_simulation_test(basedir, options):
test_dir = td.get_current_test_dir()
if options.seed is not None:
pargs.append('-s')
pargs.append("{}".format(int(options.seed, 0)))
seed = int(options.seed, 0)
if options.test_number:
idx = int(options.test_number)
random.seed(seed)
for i in range(idx):
# Python does not have a limit for integers
seed = random.randint(0, 2**32 - 1)
pargs.append("{}".format(seed))
wd = os.path.join(test_dir,
'test_{}'.format(options.name.replace('/', '_')))
os.mkdir(wd)
@ -354,6 +362,8 @@ if __name__ == '__main__':
default='INFO')
parser.add_argument('-x', '--seed', required=False, default=None,
help='The seed to use for this test')
parser.add_argument('-N', '--test-number', required=False, default=None,
help='A unique number for this test (for seed generation)')
parser.add_argument('-F', '--log-format', required=False, default='xml',
choices=['xml', 'json'], help='Log format (json or xml)')
parser.add_argument('-O', '--old-binary', required=False, default=None,