2019-03-18 16:18:57 +00:00
|
|
|
SPEC_DIR = ./specs
|
|
|
|
SCRIPT_DIR = ./scripts
|
2019-03-27 16:35:46 +00:00
|
|
|
TEST_LIBS_DIR = ./test_libs
|
|
|
|
PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec
|
|
|
|
YAML_TEST_DIR = ./yaml_tests
|
|
|
|
GENERATOR_DIR = ./test_generators
|
2019-04-11 09:25:00 +00:00
|
|
|
CONFIGS_DIR = ./configs
|
2019-03-18 16:18:57 +00:00
|
|
|
|
2019-03-27 16:35:46 +00:00
|
|
|
# Collect a list of generator names
|
|
|
|
GENERATORS = $(sort $(dir $(wildcard $(GENERATOR_DIR)/*/)))
|
|
|
|
# Map this list of generator paths to a list of test output paths
|
|
|
|
YAML_TEST_TARGETS = $(patsubst $(GENERATOR_DIR)/%, $(YAML_TEST_DIR)/%, $(GENERATORS))
|
2019-03-28 16:16:18 +00:00
|
|
|
GENERATOR_VENVS = $(patsubst $(GENERATOR_DIR)/%, $(GENERATOR_DIR)/%venv, $(GENERATORS))
|
2019-03-18 22:20:24 +00:00
|
|
|
|
2019-04-03 03:18:17 +00:00
|
|
|
PY_SPEC_PHASE_0_TARGETS = $(PY_SPEC_DIR)/eth2spec/phase0/spec.py
|
2019-03-27 17:21:07 +00:00
|
|
|
PY_SPEC_ALL_TARGETS = $(PY_SPEC_PHASE_0_TARGETS)
|
2019-03-18 22:20:24 +00:00
|
|
|
|
|
|
|
|
2019-03-28 16:16:18 +00:00
|
|
|
.PHONY: clean all test gen_yaml_tests pyspec phase0
|
2019-03-27 16:35:46 +00:00
|
|
|
|
2019-03-29 16:24:04 +00:00
|
|
|
all: $(PY_SPEC_ALL_TARGETS) $(YAML_TEST_DIR) $(YAML_TEST_TARGETS)
|
2019-03-18 22:20:24 +00:00
|
|
|
|
|
|
|
clean:
|
2019-03-27 16:35:46 +00:00
|
|
|
rm -rf $(YAML_TEST_DIR)
|
2019-03-28 16:05:40 +00:00
|
|
|
rm -rf $(GENERATOR_VENVS)
|
2019-04-17 07:47:56 +00:00
|
|
|
rm -rf $(PY_SPEC_DIR)/venv $(PY_SPEC_DIR)/.pytest_cache
|
2019-03-27 16:35:46 +00:00
|
|
|
rm -rf $(PY_SPEC_ALL_TARGETS)
|
2019-03-18 22:20:24 +00:00
|
|
|
|
2019-03-28 16:05:40 +00:00
|
|
|
# "make gen_yaml_tests" to run generators
|
2019-04-20 02:23:10 +00:00
|
|
|
gen_yaml_tests: $(YAML_TEST_TARGETS)
|
2019-03-18 22:20:24 +00:00
|
|
|
|
2019-03-18 22:30:16 +00:00
|
|
|
# runs a limited set of tests against a minimal config
|
2019-03-28 16:16:18 +00:00
|
|
|
test: $(PY_SPEC_ALL_TARGETS)
|
2019-04-17 07:47:56 +00:00
|
|
|
cd $(PY_SPEC_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements.txt; python -m pytest -m minimal_config .
|
2019-03-18 16:18:57 +00:00
|
|
|
|
2019-03-27 16:35:46 +00:00
|
|
|
# "make pyspec" to create the pyspec for all phases.
|
2019-03-28 16:16:18 +00:00
|
|
|
pyspec: $(PY_SPEC_ALL_TARGETS)
|
2019-03-18 22:30:16 +00:00
|
|
|
|
2019-03-27 16:35:46 +00:00
|
|
|
# "make phase0" to create pyspec for phase0
|
2019-03-27 17:21:07 +00:00
|
|
|
phase0: $(PY_SPEC_PHASE_0_TARGETS)
|
2019-03-27 16:35:46 +00:00
|
|
|
|
|
|
|
|
2019-04-03 03:18:17 +00:00
|
|
|
$(PY_SPEC_DIR)/eth2spec/phase0/spec.py:
|
2019-03-27 17:21:07 +00:00
|
|
|
python3 $(SCRIPT_DIR)/phase0/build_spec.py $(SPEC_DIR)/core/0_beacon-chain.md $@
|
2019-03-27 16:35:46 +00:00
|
|
|
|
|
|
|
|
2019-03-28 16:05:40 +00:00
|
|
|
CURRENT_DIR = ${CURDIR}
|
2019-03-27 16:35:46 +00:00
|
|
|
|
|
|
|
# The function that builds a set of suite files, by calling a generator for the given type (param 1)
|
|
|
|
define build_yaml_tests
|
2019-04-20 02:23:10 +00:00
|
|
|
# Started!
|
|
|
|
# Create output directory
|
|
|
|
# Navigate to the generator
|
|
|
|
# Create a virtual environment, if it does not exist already
|
|
|
|
# Activate the venv, this is where dependencies are installed for the generator
|
|
|
|
# Install all the necessary requirements
|
|
|
|
# Run the generator. The generator is assumed to have an "main.py" file.
|
|
|
|
# We output to the tests dir (generator program should accept a "-o <filepath>" argument.
|
|
|
|
echo "generator $(1) started"; \
|
|
|
|
mkdir -p $(YAML_TEST_DIR)$(1); \
|
|
|
|
cd $(GENERATOR_DIR)$(1); \
|
|
|
|
if test -d venv; then python3 -m venv venv; fi; \
|
|
|
|
. venv/bin/activate; \
|
|
|
|
pip3 install -r requirements.txt; \
|
|
|
|
python3 main.py -o $(CURRENT_DIR)/$(YAML_TEST_DIR)$(1) -c $(CURRENT_DIR)/$(CONFIGS_DIR); \
|
|
|
|
echo "generator $(1) finished"
|
2019-03-27 16:35:46 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
# The tests dir itself is simply build by creating the directory (recursively creating deeper directories if necessary)
|
|
|
|
$(YAML_TEST_DIR):
|
2019-03-28 16:05:40 +00:00
|
|
|
$(info creating directory, to output yaml targets to: ${YAML_TEST_TARGETS})
|
2019-03-27 16:35:46 +00:00
|
|
|
mkdir -p $@
|
2019-04-20 02:23:10 +00:00
|
|
|
$(YAML_TEST_DIR)/:
|
|
|
|
$(info ignoring duplicate yaml tests dir)
|
2019-03-27 16:35:46 +00:00
|
|
|
|
|
|
|
# For any target within the tests dir, build it using the build_yaml_tests function.
|
2019-03-28 16:24:18 +00:00
|
|
|
# (creation of output dir is a dependency)
|
|
|
|
$(YAML_TEST_DIR)%: $(YAML_TEST_DIR)
|
2019-03-27 16:35:46 +00:00
|
|
|
$(call build_yaml_tests,$*)
|