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

tes_gen.py driver to generate tests from a single config #4

Merged
merged 1 commit into from
Apr 8, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
GENERATOR_NAME = 'filter_block_tree'


forks = [ALTAIR]
presets = [MINIMAL]


def _load_model_solutions(instance_path: str):
yaml = YAML(typ='safe')
solutions = yaml.load(open(instance_path, 'r'))
Expand Down Expand Up @@ -134,9 +138,6 @@ def make_cases_fn() -> Iterable[TestCase]:


if __name__ == "__main__":
forks = [ALTAIR]
presets = [MINIMAL]

arg_parser = gen_runner.create_arg_parser(GENERATOR_NAME)

arg_parser.add_argument(
Expand Down
7 changes: 4 additions & 3 deletions tests/generators/fork_choice_generated/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
GENERATOR_NAME = 'fork_choice_generated'


forks = [ALTAIR]
presets = [MINIMAL]


def _import_test_fn():
src = import_module('eth2spec.test.phase0.fork_choice.test_sm_links_tree_model')
print("generating test vectors from tests source: %s" % src.__name__)
Expand Down Expand Up @@ -95,9 +99,6 @@ def make_cases_fn() -> Iterable[TestCase]:


if __name__ == "__main__":
forks = [ALTAIR]
presets = [MINIMAL]

arg_parser = gen_runner.create_arg_parser(GENERATOR_NAME)

arg_parser.add_argument(
Expand Down
86 changes: 86 additions & 0 deletions tests/generators/fork_choice_generated/test_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from eth2spec.gen_helpers.gen_base import gen_runner

from filter_block_tree_generator import (
forks as block_cover_forks,
presets as block_cover_presets,
_load_model_solutions as block_cover_load_solutions,
_create_providers as block_cover_create_providers
)
from main import (
forks as block_tree_forks,
presets as block_tree_presets,
_load_sm_link_solutions as block_tree_load_solutions,
_create_providers as block_tree_create_providers
)


GENERATOR_NAME = 'fork_choice_generated'


test_gen_config = {
'block_tree_test': {
'test_type': 'block_tree',
'instances': 'block_tree.yaml',
'seed': 123,
'nr_variations': 3,
},
'block_cover_test': {
'test_type': 'block_cover',
'instances': 'block_cover.yaml',
'seed': 456,
'nr_variations': 3,
}
}

if __name__ == "__main__":
arg_parser = gen_runner.create_arg_parser(GENERATOR_NAME)

arg_parser.add_argument(
'--fc-gen-debug',
dest='fc_gen_debug',
action='store_true',
default=False,
required=False,
help='If set provides debug output and enable additional checks for generated chains',
)
# TODO: load test_gen_config from a yaml file
# arg_parser.add_argument(
# '--fc-gen-config',
# dest='fc_gen_config',
# type=str,
# default=None,
# required=False,
# help='Path to a file with test generator configurations'
# )

args = arg_parser.parse_args()

for test_name, params in test_gen_config.items():
print(test_name)
test_type = params['test_type']
instances_path = params['instances']
initial_seed = params['seed']
nr_variations = params['nr_variations']

if test_type == 'block_tree':
solutions = block_tree_load_solutions(instances_path)
providers = block_tree_create_providers(forks=block_tree_forks,
presets=block_tree_presets,
debug=args.fc_gen_debug,
initial_seed=initial_seed,
solutions=solutions,
number_of_variations=nr_variations)
elif test_type == 'block_cover':
solutions = block_cover_load_solutions(instances_path)
providers = block_cover_create_providers(forks=block_cover_forks,
presets=block_cover_presets,
debug=args.fc_gen_debug,
initial_seed=initial_seed,
solutions=solutions,
number_of_variations=nr_variations)
else:
raise ValueError(f'Unsupported test type: {test_type}')

gen_runner.run_generator(GENERATOR_NAME, providers, arg_parser)


Loading