File tree Expand file tree Collapse file tree 4 files changed +110
-4
lines changed
ex02_1_bit_full_adder/test
ex03_4_bit_half_adder/test Expand file tree Collapse file tree 4 files changed +110
-4
lines changed Original file line number Diff line number Diff line change @@ -13,5 +13,11 @@ TOPLEVEL = full_adder
1313# MODULE is the basename of the Python test file
1414MODULE = full_adder_test
1515
16- # include cocotb's make rules to take care of the simulator setup
17- include $(shell cocotb-config --makefiles) /Makefile.sim
16+ ifeq ($(OS ) , Darwin)
17+ include Makefile.Unix
18+ else ifeq ($(OS), Linux)
19+ include Makefile.Unix
20+ else
21+ # include cocotb's make rules to take care of the simulator setup
22+ include $(shell cocotb-config --makefiles)/Makefile.sim
23+ endif
Original file line number Diff line number Diff line change 1+ # Python environment variables
2+ VENV = venv
3+ PYTHON = $(VENV)/bin/python
4+ PIP = $(VENV)/bin/pip
5+ PYTHON_VERSION := $(shell python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
6+
7+ # Explicitly set the path to simulators and cocotb
8+ COCOTB_HOME = $(VENV)/lib/python$(PYTHON_VERSION)/site-packages/cocotb
9+
10+ # Default target
11+ all: check_prereqs test
12+
13+ # Check prerequisites
14+ check_prereqs:
15+ @echo "Checking Cocotb and Simulator Prerequisites:"
16+ @echo "Python Path: $(PYTHON)"
17+ @echo "Cocotb Home: $(COCOTB_HOME)"
18+ @echo "Simulator: $(SIM)"
19+ @which iverilog || (echo "Icarus Verilog (iverilog) not found. Please install it." && exit 1)
20+
21+ # Create Python virtual environment
22+ env:
23+ @python3 -m venv $(VENV)
24+ @$(PIP) install --upgrade pip
25+ @$(PIP) install cocotb
26+
27+ # Run tests with explicit paths
28+ test: env check_prereqs
29+ @echo "Running Cocotb tests..."
30+ @cd $(shell pwd) && \
31+ PYTHONPATH=$(VENV)/lib/python$(PYTHON_VERSION)/site-packages \
32+ PATH=$(VENV)/bin:$(PATH) \
33+ $(MAKE) -f $(COCOTB_HOME)/share/makefiles/Makefile.sim \
34+ VERILOG_SOURCES=$(VERILOG_SOURCES) \
35+ TOPLEVEL=$(TOPLEVEL) \
36+ MODULE=$(MODULE) \
37+ SIM=$(SIM)
38+
39+ # Clean up
40+ clean:
41+ @rm -rf $(VENV)
42+ @rm -rf sim_build
43+ @rm -rf results.tap
44+ @rm -rf *.xml
45+ @rm -rf __pycache__
46+
47+ .PHONY: all env test clean check_prereqs
Original file line number Diff line number Diff line change @@ -13,5 +13,11 @@ TOPLEVEL = half_adder_4
1313# MODULE is the basename of the Python test file
1414MODULE = half_adder_4_test
1515
16- # include cocotb's make rules to take care of the simulator setup
17- include $(shell cocotb-config --makefiles) /Makefile.sim
16+ ifeq ($(OS ) , Darwin)
17+ include Makefile.Unix
18+ else ifeq ($(OS), Linux)
19+ include Makefile.Unix
20+ else
21+ # include cocotb's make rules to take care of the simulator setup
22+ include $(shell cocotb-config --makefiles)/Makefile.sim
23+ endif
Original file line number Diff line number Diff line change 1+ # Python environment variables
2+ VENV = venv
3+ PYTHON = $(VENV)/bin/python
4+ PIP = $(VENV)/bin/pip
5+ PYTHON_VERSION := $(shell python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
6+
7+ # Explicitly set the path to simulators and cocotb
8+ COCOTB_HOME = $(VENV)/lib/python$(PYTHON_VERSION)/site-packages/cocotb
9+
10+ # Default target
11+ all: check_prereqs test
12+
13+ # Check prerequisites
14+ check_prereqs:
15+ @echo "Checking Cocotb and Simulator Prerequisites:"
16+ @echo "Python Path: $(PYTHON)"
17+ @echo "Cocotb Home: $(COCOTB_HOME)"
18+ @echo "Simulator: $(SIM)"
19+ @which iverilog || (echo "Icarus Verilog (iverilog) not found. Please install it." && exit 1)
20+
21+ # Create Python virtual environment
22+ env:
23+ @python3 -m venv $(VENV)
24+ @$(PIP) install --upgrade pip
25+ @$(PIP) install cocotb
26+
27+ # Run tests with explicit paths
28+ test: env check_prereqs
29+ @echo "Running Cocotb tests..."
30+ @cd $(shell pwd) && \
31+ PYTHONPATH=$(VENV)/lib/python$(PYTHON_VERSION)/site-packages \
32+ PATH=$(VENV)/bin:$(PATH) \
33+ $(MAKE) -f $(COCOTB_HOME)/share/makefiles/Makefile.sim \
34+ VERILOG_SOURCES=$(VERILOG_SOURCES) \
35+ TOPLEVEL=$(TOPLEVEL) \
36+ MODULE=$(MODULE) \
37+ SIM=$(SIM)
38+
39+ # Clean up
40+ clean:
41+ @rm -rf $(VENV)
42+ @rm -rf sim_build
43+ @rm -rf results.tap
44+ @rm -rf *.xml
45+ @rm -rf __pycache__
46+
47+ .PHONY: all env test clean check_prereqs
You can’t perform that action at this time.
0 commit comments