Skip to content

Commit

Permalink
[software] Add Makefile targets for the new tests folder
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelRiedel committed Feb 23, 2024
1 parent 246d05e commit faa4888
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 9 deletions.
27 changes: 18 additions & 9 deletions software/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ MEMPOOL_DIR := $(shell git rev-parse --show-toplevel 2>/dev/null || echo $$MEMPO
APPS_DIR := $(ROOT_DIR)/apps
HALIDE_DIR := $(ROOT_DIR)/halide
RUNTIME_DIR := $(ROOT_DIR)/runtime
TESTS_DIR := $(ROOT_DIR)/riscv-tests/isa
TESTS_DIR := $(ROOT_DIR)/tests
RISCV_TESTS_DIR := $(ROOT_DIR)/riscv-tests/isa
TOOLCHAIN_DIR := $(abspath $(ROOT_DIR)/../toolchain)
# This will overwrite the ROOT_DIR variable from the included makefile
include $(RUNTIME_DIR)/runtime.mk
include $(TESTS_DIR)/snitch_isa.mk
include $(RISCV_TESTS_DIR)/snitch_isa.mk

# Applications
.PHONY: apps
apps:
make -C $(APPS_DIR) all

.PHONY: tests
tests:
make -C $(TESTS_DIR) all

.PHONY: halide-apps
halide-apps:
make -C $(HALIDE_DIR) all
Expand All @@ -27,18 +32,22 @@ halide-apps:
clean-apps:
make -C $(APPS_DIR) clean

.PHONY: clean-tests
clean-tests:
make -C $(TESTS_DIR) clean

.PHONY: clean-halide-apps
clean-halide-apps:
make -C $(HALIDE_DIR) clean

# Unit tests
TESTS := $(addprefix bin/,$(rtl_mempool_tests))
RISCV_TESTS := $(addprefix bin/,$(rtl_mempool_tests))

define rtl_mempool_tests_template

TESTS_$(1) := $(addprefix bin/,$($(1)_mempool_tests))
RISCV-TESTS-$(1) := $(addprefix bin/,$($(1)_mempool_tests))

$$(TESTS_$(1)): bin/$(1)-mempool-%: $(TESTS_DIR)/$(1)/%.S $(LINKER_SCRIPT)
$$(RISCV-TESTS-$(1)): bin/$(1)-mempool-%: $(RISCV_TESTS_DIR)/$(1)/%.S $(LINKER_SCRIPT)
mkdir -p $$(shell dirname $$@)
$$(RISCV_CC) $$(RISCV_CCFLAGS_TESTS) -T$$(RUNTIME_DIR)/link.ld $$< -o $$@
$$(RISCV_STRIP) $$@ -g -S -d --strip-debug
Expand All @@ -51,13 +60,13 @@ $(eval $(call rtl_mempool_tests_template,rv32um))
$(eval $(call rtl_mempool_tests_template,rv32ua))
$(eval $(call rtl_mempool_tests_template,rv32uxpulpimg))

test: update_opcodes $(TESTS)
riscv-tests: update_opcodes $(RISCV_TESTS)

clean-test:
clean-riscv-test:
rm -vf $(RUNTIME)
rm -vf $(LINKER_SCRIPT)
rm -vf $(TESTS)
rm -vf $(addsuffix .dump,$(TESTS))
rm -vf $(RISCV_TESTS)
rm -vf $(addsuffix .dump,$(RISCV_TESTS))

# Helper targets
update_opcodes:
Expand Down
46 changes: 46 additions & 0 deletions software/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2021 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

# Author: Samuel Riedel, ETH Zurich

SHELL = /usr/bin/env bash
ROOT_DIR := $(patsubst %/,%, $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
MEMPOOL_DIR := $(shell git rev-parse --show-toplevel 2>/dev/null || echo $$MEMPOOL_DIR)
SOFTWARE_DIR := $(abspath $(ROOT_DIR)/..)
BIN_DIR := $(abspath $(SOFTWARE_DIR)/bin)
DATA_DIR := $(abspath $(SOFTWARE_DIR)/data)
RUNTIME_DIR := $(abspath $(SOFTWARE_DIR)/runtime)
TESTS_DIR := $(ROOT_DIR)
# This will overwrite the ROOT_DIR variable from the included makefile
include $(RUNTIME_DIR)/runtime.mk

TESTS := $(patsubst $(TESTS_DIR)/%/main.c,%,$(shell find $(TESTS_DIR) -name "main.c"))
DATA := $(patsubst %.args,%.h,$(shell find $(TESTS_DIR) -name "data.args"))
ALLPYS := $(patsubst %.py,%.h,$(wildcard $(DATA_DIR)/*.py))
BINARIES := $(addprefix $(BIN_DIR)/,$(TESTS))

# Make all applications
all: $(TESTS)

$(TESTS): % : $(BIN_DIR)/% $(TESTS_DIR)/Makefile $(shell find $(RUNTIME_DIR)/**.{S,c,h,ld} -type f)

.PHONY: $(BINARIES)
$(BINARIES): $(BIN_DIR)/%: %/main.c.o $(RUNTIME) $(LINKER_SCRIPT) $(DATA) $(ALLPYS) update_opcodes
mkdir -p $(dir $@)
$(RISCV_CC) -Iinclude $(RISCV_LDFLAGS) -o $@ $< $(RUNTIME) -T$(RUNTIME_DIR)/link.ld
$(RISCV_OBJDUMP) $(RISCV_OBJDUMP_FLAGS) -D $@ > $@.dump

# Helper targets
update_opcodes:
make -C $(MEMPOOL_DIR) update_opcodes

.PHONY: clean
clean:
rm -vf $(BINARIES)
rm -vf $(addsuffix .dump,$(BINARIES))
rm -vf $(addsuffix /main.c.o,$(TESTS))
rm -vf $(RUNTIME)
rm -vf $(LINKER_SCRIPT)

.INTERMEDIATE: $(addsuffix /main.c.o,$(TESTS))

0 comments on commit faa4888

Please sign in to comment.