From d60614e3231ad07d63a78d25d69fb2fdfd7cd5f7 Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Sat, 7 Sep 2024 15:56:56 -0700 Subject: [PATCH 01/14] ADD: add CMake build --- tests/CMakeLists.txt | 93 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 tests/CMakeLists.txt diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000000..9ad2e7726a --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,93 @@ +######################################################################################################################## +# file: CMakeLists.txt +# +# usage: +# Edit "VARIABLES"-section to suit project requirements. +# Build instructions: +# cmake . -S ./ -B ./build/ -D CMAKE_BUILD_TYPE=Debug +# cmake --build ./build/ --target all +# Cleaning: +# cmake --build ./build/ --target clean +######################################################################################################################## +cmake_minimum_required(VERSION 3.10) + +project(chipyard-tests LANGUAGES C CXX) + + +################################# +# RISCV Toolchain +################################# + +set(CMAKE_SYSTEM_NAME "Generic" CACHE STRING "") +set(CMAKE_SYSTEM_PROCESSOR "riscv" CACHE STRING "") + +set(TOOLCHAIN_PREFIX "riscv64-unknown-elf-") + +set(CMAKE_AR "${TOOLCHAIN_PREFIX}ar") +set(CMAKE_ASM_COMPILER "${TOOLCHAIN_PREFIX}gcc") +set(CMAKE_C_COMPILER "${TOOLCHAIN_PREFIX}gcc") +set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PREFIX}g++") +set(CMAKE_LINKER "${TOOLCHAIN_PREFIX}ld") +set(CMAKE_OBJCOPY "${TOOLCHAIN_PREFIX}objcopy") +set(CMAKE_OBJDUMP "${TOOLCHAIN_PREFIX}objdump") +set(CMAKE_SIZE "${TOOLCHAIN_PREFIX}size") + + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/..") +set(CMAKE_EXECUTABLE_SUFFIX ".riscv") + + +################################# +# Flags +################################# + +# CPU architecture +set(ARCH "rv64imafdc") +set(ABI "lp64d") +set(CMODEL "medany") +set(ARCH_FLAGS -march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL}) + +# spec +set(SPECS "htif_nano.specs") +set(SPEC_FLAGS -specs=${SPECS}) + +# linker script +set(LINKER_SCRIPT "htif.ld") + +add_compile_options(-std=gnu99) +add_compile_options(-O2 -Wall -Wextra) +add_compile_options(-fno-common -fno-builtin-printf) +add_compile_options(${ARCH_FLAGS}) +add_compile_options(${SPEC_FLAGS}) + +add_link_options(-static) +# add_link_options(${ARCH_FLAGS}) +add_link_options(${SPEC_FLAGS}) +add_link_options(-T ${LINKER_SCRIPT}) + + +################################# +# Build +################################# + +add_executable(pwm pwm.c) +add_executable(blkdev blkdev.c) +add_executable(accum accum.c) +add_executable(charcount charcount.c) +add_executable(nic-loopback nic-loopback.c) +add_executable(big-blkdev big-blkdev.c) +add_executable(pingd pingd.c) +add_executable(streaming-passthrough streaming-passthrough.c) +add_executable(streaming-fir streaming-fir.c) +add_executable(nvdla nvdla.c) +add_executable(spiflashread spiflashread.c) +add_executable(spiflashwrite spiflashwrite.c) +add_executable(fft fft.c) +add_executable(gcd gcd.c) +add_executable(hello hello.c) +add_executable(mt-hello mt-hello.c) +add_executable(symmetric symmetric.c) + + +# spiflash.img: spiflash.py +# python3 $< From 0266a3265bb4287aead652922b77f2b3f3465639 Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Sat, 7 Sep 2024 16:01:06 -0700 Subject: [PATCH 02/14] ADD: add C++ example --- tests/cpp-hello.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/cpp-hello.cpp diff --git a/tests/cpp-hello.cpp b/tests/cpp-hello.cpp new file mode 100644 index 0000000000..f9ad6f154a --- /dev/null +++ b/tests/cpp-hello.cpp @@ -0,0 +1,10 @@ +#include +using namespace std; + +// HACK: This is a workaround for the missing __dso_handle routine in the current toolchain +extern "C" void *__dso_handle = 0; + +int main() { + cout << "Hello World!"; + return 0; +} From 6a1668bf570a0a309f1a4c79ef9c75faeda491e2 Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Sat, 7 Sep 2024 16:01:23 -0700 Subject: [PATCH 03/14] ADD: add C++ example --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9ad2e7726a..537e7cfbe3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -61,7 +61,6 @@ add_compile_options(${ARCH_FLAGS}) add_compile_options(${SPEC_FLAGS}) add_link_options(-static) -# add_link_options(${ARCH_FLAGS}) add_link_options(${SPEC_FLAGS}) add_link_options(-T ${LINKER_SCRIPT}) @@ -74,6 +73,7 @@ add_executable(pwm pwm.c) add_executable(blkdev blkdev.c) add_executable(accum accum.c) add_executable(charcount charcount.c) +add_executable(cpp-hello cpp-hello.cpp) add_executable(nic-loopback nic-loopback.c) add_executable(big-blkdev big-blkdev.c) add_executable(pingd pingd.c) From 00c914c09e372d623f678d4893b22ac53b973d18 Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Sun, 8 Sep 2024 12:58:40 -0700 Subject: [PATCH 04/14] ADD: add SPIFlash build routine --- tests/CMakeLists.txt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 537e7cfbe3..7372e87780 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,7 +34,7 @@ set(CMAKE_SIZE "${TOOLCHAIN_PREFIX}size") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/..") -set(CMAKE_EXECUTABLE_SUFFIX ".riscv") +set(CMAKE_EXECUTABLE_SUFFIX ".riscv") ################################# @@ -42,7 +42,7 @@ set(CMAKE_EXECUTABLE_SUFFIX ".riscv") ################################# # CPU architecture -set(ARCH "rv64imafdc") +set(ARCH "rv64imafd") set(ABI "lp64d") set(CMODEL "medany") set(ARCH_FLAGS -march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL}) @@ -89,5 +89,15 @@ add_executable(mt-hello mt-hello.c) add_executable(symmetric symmetric.c) -# spiflash.img: spiflash.py -# python3 $< +# Add custom command to generate spiflash.img from spiflash.py +add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/spiflash.img + COMMAND python3 ${CMAKE_SOURCE_DIR}/spiflash.py + DEPENDS ${CMAKE_SOURCE_DIR}/spiflash.py + COMMENT "Generating spiflash.img" +) + +# Add a target for spiflash.img +add_custom_target(spiflash_img ALL + DEPENDS ${CMAKE_BINARY_DIR}/spiflash.img +) From 71d211622faf0bf14c3e2213fc5b855fc716e9b2 Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Sun, 8 Sep 2024 12:59:51 -0700 Subject: [PATCH 05/14] REFACTOR: switch to use CMake build --- scripts/build-tests.sh | 2 ++ tests/Makefile | 71 ------------------------------------------ tests/libgloss.mk | 54 -------------------------------- 3 files changed, 2 insertions(+), 125 deletions(-) create mode 100755 scripts/build-tests.sh delete mode 100644 tests/Makefile delete mode 100644 tests/libgloss.mk diff --git a/scripts/build-tests.sh b/scripts/build-tests.sh new file mode 100755 index 0000000000..fb56e88a69 --- /dev/null +++ b/scripts/build-tests.sh @@ -0,0 +1,2 @@ +cmake ./tests/ -S ./tests/ -B ./tests/build/ -D CMAKE_BUILD_TYPE=Debug +cmake --build ./tests/build/ --target all diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index 1c6df31b5c..0000000000 --- a/tests/Makefile +++ /dev/null @@ -1,71 +0,0 @@ -################################# -# RISCV Toolchain -################################# - -TARGET = riscv64-unknown-elf - -GCC = $(TARGET)-gcc -CXX = $(TARGET)-g++ -CP = $(TARGET)-objcopy -OBJDUMP = $(TARGET)-objdump -DG = $(TARGET)-gdb -SIZE = $(TARGET)-size - - -################################# -# Flags -################################# - -# SoC Settings -ARCH = rv64imafdc -ABI = lp64d -ARCHFLAGS = -march=$(ARCH) -mabi=$(ABI) - -CFLAGS = -std=gnu99 -O2 -fno-common -fno-builtin-printf -Wall -CFLAGS += $(ARCHFLAGS) -LDFLAGS = -static - -include libgloss.mk - -PROGRAMS = pwm blkdev accum charcount nic-loopback big-blkdev pingd \ - streaming-passthrough streaming-fir nvdla spiflashread spiflashwrite fft gcd \ - hello mt-hello symmetric - - -.DEFAULT_GOAL := default - - -################################# -# Build -################################# - -spiflash.img: spiflash.py - python3 $< - -%.o: %.S - $(GCC) $(CFLAGS) -D__ASSEMBLY__=1 -c $< -o $@ - -%.o: %.c mmio.h spiflash.h - $(GCC) $(CFLAGS) -c $< -o $@ - -%.riscv: %.o $(libgloss) - $(GCC) $(LDFLAGS) $< -o $@ - -%.dump: %.riscv - $(OBJDUMP) -D $< > $@ - - -################################# -# Recipes -################################# - -.PHONY: clean -clean: - rm -f *.riscv *.o *.dump - $(if $(libgloss),rm -rf $(libgloss_builddir)/) - -.PHONY: default -default: $(addsuffix .riscv, $(PROGRAMS)) spiflash.img - -.PHONY: dumps -dumps: $(addsuffix .dump, $(PROGRAMS)) diff --git a/tests/libgloss.mk b/tests/libgloss.mk deleted file mode 100644 index 5553bdbdd3..0000000000 --- a/tests/libgloss.mk +++ /dev/null @@ -1,54 +0,0 @@ -# Handle libgloss-htif dependency -ifndef libgloss - -ifndef GCC -$(error GCC is not defined) -endif - -ifndef TARGET -$(error TARGET is not defined) -endif - -libgloss_specs := htif_nano.specs - -# Test whether libgloss-htif is globally installed and usable -# Define BUILD_LIBGLOSS=1 to unconditionally force a local build -BUILD_LIBGLOSS ?= $(shell { echo 'int main(void) { return 0; }' | \ - $(GCC) -xc -specs=$(libgloss_specs) -o /dev/null - 2> /dev/null ; } || \ - echo "$$?") - -ifneq ($(BUILD_LIBGLOSS),) -$(info libgloss-htif: Using local build) - -libgloss_srcdir := ../toolchains/libgloss -libgloss_builddir := libgloss -libgloss_specs := $(libgloss_srcdir)/util/$(libgloss_specs) -libgloss_lib := $(libgloss_builddir)/libgloss_htif.a -libgloss := $(libgloss_lib) $(libgloss_specs) htif.ld - -LDFLAGS += -L libgloss - -$(libgloss_builddir)/Makefile: $(libgloss_srcdir)/configure - mkdir -p $(dir $@) - cd $(dir $@) && $(realpath $<) \ - --prefix=$(shell $(GCC) -print-sysroot) \ - --host=$(TARGET) \ - --disable-multilib - -$(libgloss_lib): $(libgloss_builddir)/Makefile - $(MAKE) -C $(dir $^) - -.PHONY: libgloss -libgloss: $(libgloss) - -else - -$(info libgloss-htif: Using global install) -libgloss := # No additional prerequisites - -endif - -CFLAGS += -specs=$(libgloss_specs) -LDFLAGS += -specs=$(libgloss_specs) - -endif # libgloss From 91c545e763204669ff4e628d5d5ae00441eda96b Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Sun, 8 Sep 2024 13:06:27 -0700 Subject: [PATCH 06/14] ADD: ignore tests builds --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d47102810d..b107b6dd83 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ project/project/ .sbt .classpath_cache/ .vscode/ +tests/build/ From c2f1565c3876621149f539ef36f38998dfc7d704 Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Sun, 8 Sep 2024 13:25:02 -0700 Subject: [PATCH 07/14] ADD: update docs for building test programs --- docs/Software/Baremetal.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/Software/Baremetal.rst b/docs/Software/Baremetal.rst index 4bfeaef4bc..96bc2fac13 100644 --- a/docs/Software/Baremetal.rst +++ b/docs/Software/Baremetal.rst @@ -22,6 +22,16 @@ To build baremetal RISC-V programs to run in simulation, we use the riscv64-unkn $ spike hello.riscv Hello, World! -For more examples, look at the `tests/ directory `_ in the chipyard repository. +We have provided a set of example programs in the `tests/ directory `_ in the chipyard repository. + +The tests directory contains a CMakeLists.txt file that can be used to build the programs. To build the programs, you can use the following commands: + +.. code:: bash + + $ cmake . -S ./ -B ./build/ -D CMAKE_BUILD_TYPE=Debug + $ cmake --build ./build/ --target all + $ spike hello.riscv + Hello, World! + For more information about the libgloss port, take a look at `its README `_. From ecd763ab782b26be51af8dd30cb9a93ce5f879d7 Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Sun, 8 Sep 2024 13:25:22 -0700 Subject: [PATCH 08/14] ADD: update CI script for new tests building --- .github/scripts/build-extra-tests.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/scripts/build-extra-tests.sh b/.github/scripts/build-extra-tests.sh index e38b50fe01..d0610d8c62 100755 --- a/.github/scripts/build-extra-tests.sh +++ b/.github/scripts/build-extra-tests.sh @@ -7,5 +7,6 @@ set -ex SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" source $SCRIPT_DIR/defaults.sh -make -C $LOCAL_CHIPYARD_DIR/tests clean -make -C $LOCAL_CHIPYARD_DIR/tests +cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug +cmake --build $LOCAL_CHIPYARD_DIR/build/ --target clean +cmake --build $LOCAL_CHIPYARD_DIR/build/ --target all From a4059d4cdadc7370bb3a8dcf1b41ff3cd3fc9f38 Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Sun, 8 Sep 2024 13:31:04 -0700 Subject: [PATCH 09/14] FIX: fix build path --- .github/scripts/build-extra-tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/build-extra-tests.sh b/.github/scripts/build-extra-tests.sh index d0610d8c62..68ad20493c 100755 --- a/.github/scripts/build-extra-tests.sh +++ b/.github/scripts/build-extra-tests.sh @@ -8,5 +8,5 @@ SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" source $SCRIPT_DIR/defaults.sh cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug -cmake --build $LOCAL_CHIPYARD_DIR/build/ --target clean -cmake --build $LOCAL_CHIPYARD_DIR/build/ --target all +cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target clean +cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all From 7664e59f82bb6ec040ddae729fe995d58c8fba75 Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Sun, 8 Sep 2024 14:33:33 -0700 Subject: [PATCH 10/14] FIX: fix CI --- .github/scripts/run-tests.sh | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/scripts/run-tests.sh b/.github/scripts/run-tests.sh index 8a75285019..e7ae398c7c 100755 --- a/.github/scripts/run-tests.sh +++ b/.github/scripts/run-tests.sh @@ -32,7 +32,9 @@ case $1 in chipyard-rocket) run_bmark LOADMEM=1 run_asm LOADMEM=1 - make -C $LOCAL_CHIPYARD_DIR/tests + cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug + cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + # Test run-binary with and without loadmem run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/hello.riscv LOADMEM=1 run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/hello.riscv @@ -77,7 +79,9 @@ case $1 in run_binary BINARY=$LOCAL_CHIPYARD_DIR/generators/compress-acc/software-zstd/compress/009987_cl0_ws12.riscv LOADMEM=1 ;; chipyard-manymmioaccels) - make -C $LOCAL_CHIPYARD_DIR/tests + cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug + cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + # test streaming-passthrough run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/streaming-passthrough.riscv LOADMEM=1 @@ -89,29 +93,41 @@ case $1 in run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/fft.riscv LOADMEM=1 ;; chipyard-nvdla) - make -C $LOCAL_CHIPYARD_DIR/tests + cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug + cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/nvdla.riscv LOADMEM=1 ;; chipyard-manyperipherals) # SPI Flash read tests - make -C $LOCAL_CHIPYARD_DIR/tests + cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug + cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/spiflashread.riscv ;; chipyard-spiflashwrite) - make -C $LOCAL_CHIPYARD_DIR/tests + cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug + cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/spiflashwrite.riscv LOADMEM=1 [[ "`xxd $LOCAL_CHIPYARD_DIR/tests/spiflash.img | grep 1337\ 00ff\ aa55\ face | wc -l`" == "6" ]] || false ;; chipyard-tethered) - make -C $LOCAL_CHIPYARD_DIR/tests + cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug + cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/hello.riscv LOADMEM=1 EXTRA_SIM_FLAGS="+cflush_addr=0x2010200" ;; chipyard-symmetric) - make -C $LOCAL_CHIPYARD_DIR/tests + cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug + cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/symmetric.riscv LOADMEM=1 ;; chipyard-llcchiplet) - make -C $LOCAL_CHIPYARD_DIR/tests + cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug + cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/hello.riscv LOADMEM=1 ;; chipyard-rerocc) From 94aaf25cb2496494e9e7673ec281643afe13ee92 Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Sun, 8 Sep 2024 15:33:06 -0700 Subject: [PATCH 11/14] FIX: fix Python output file location --- tests/CMakeLists.txt | 2 +- tests/spiflash.py | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7372e87780..34bc236fb0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -92,7 +92,7 @@ add_executable(symmetric symmetric.c) # Add custom command to generate spiflash.img from spiflash.py add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/spiflash.img - COMMAND python3 ${CMAKE_SOURCE_DIR}/spiflash.py + COMMAND python3 ${CMAKE_SOURCE_DIR}/spiflash.py --outfile ${CMAKE_BINARY_DIR}/spiflash.img DEPENDS ${CMAKE_SOURCE_DIR}/spiflash.py COMMENT "Generating spiflash.img" ) diff --git a/tests/spiflash.py b/tests/spiflash.py index af65b64e9a..1bf6a0d235 100755 --- a/tests/spiflash.py +++ b/tests/spiflash.py @@ -1,10 +1,16 @@ #!/usr/bin/env python3 - # Generates a binary file that the SPI test uses -outfile = "spiflash.img" +import argparse + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Generate a binary file for SPI test") + parser.add_argument("--outfile", type=str, default="spiflash.img", help="Output file") + args = parser.parse_args() + + outfile = args.outfile -with open(outfile, 'wb') as f: - for i in range(0,0x100000,4): - check = 0xdeadbeef - i - f.write(check.to_bytes(4,'little')) + with open(outfile, "wb") as f: + for i in range(0,0x100000,4): + check = 0xdeadbeef - i + f.write(check.to_bytes(4, "little")) From f620e48c484d66db524bb9a0fc3069154d7789cb Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Sun, 8 Sep 2024 17:51:53 -0700 Subject: [PATCH 12/14] FIX: fix Python output file location --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 34bc236fb0..ebe8f39404 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -92,7 +92,7 @@ add_executable(symmetric symmetric.c) # Add custom command to generate spiflash.img from spiflash.py add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/spiflash.img - COMMAND python3 ${CMAKE_SOURCE_DIR}/spiflash.py --outfile ${CMAKE_BINARY_DIR}/spiflash.img + COMMAND python3 ${CMAKE_SOURCE_DIR}/spiflash.py --outfile ${CMAKE_SOURCE_DIR}/spiflash.img DEPENDS ${CMAKE_SOURCE_DIR}/spiflash.py COMMENT "Generating spiflash.img" ) From 18de5c919180f48aa31d0c176a7383bedacf96de Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Mon, 9 Sep 2024 09:11:59 -0700 Subject: [PATCH 13/14] ADD: add hint to let *nix shell knows what kind of interpreter to run --- scripts/build-tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/build-tests.sh b/scripts/build-tests.sh index fb56e88a69..3967e982f8 100755 --- a/scripts/build-tests.sh +++ b/scripts/build-tests.sh @@ -1,2 +1,4 @@ +#!/usr/bin/env bash + cmake ./tests/ -S ./tests/ -B ./tests/build/ -D CMAKE_BUILD_TYPE=Debug cmake --build ./tests/build/ --target all From fde5d610e8bd62765722e821e20e4b1a2b5d0b2c Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Mon, 9 Sep 2024 09:23:34 -0700 Subject: [PATCH 14/14] REFACTOR: move cmake lines to a script Co-authored-by: Cursor --- .github/scripts/run-tests.sh | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/.github/scripts/run-tests.sh b/.github/scripts/run-tests.sh index e7ae398c7c..250f26b032 100755 --- a/.github/scripts/run-tests.sh +++ b/.github/scripts/run-tests.sh @@ -28,12 +28,16 @@ run_binary () { make run-binary-fast -C $LOCAL_SIM_DIR $DISABLE_SIM_PREREQ $MAPPING_FLAGS $@ } +build_tests() { + cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug + cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all +} + case $1 in chipyard-rocket) run_bmark LOADMEM=1 run_asm LOADMEM=1 - cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug - cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + build_tests # Test run-binary with and without loadmem run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/hello.riscv LOADMEM=1 @@ -79,9 +83,7 @@ case $1 in run_binary BINARY=$LOCAL_CHIPYARD_DIR/generators/compress-acc/software-zstd/compress/009987_cl0_ws12.riscv LOADMEM=1 ;; chipyard-manymmioaccels) - cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug - cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all - + build_tests # test streaming-passthrough run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/streaming-passthrough.riscv LOADMEM=1 @@ -91,42 +93,36 @@ case $1 in # test fft run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/fft.riscv LOADMEM=1 - ;; + ;; chipyard-nvdla) - cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug - cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + build_tests run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/nvdla.riscv LOADMEM=1 - ;; + ;; chipyard-manyperipherals) - # SPI Flash read tests - cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug - cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + # SPI Flash read tests + build_tests run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/spiflashread.riscv ;; chipyard-spiflashwrite) - cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug - cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + build_tests run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/spiflashwrite.riscv LOADMEM=1 [[ "`xxd $LOCAL_CHIPYARD_DIR/tests/spiflash.img | grep 1337\ 00ff\ aa55\ face | wc -l`" == "6" ]] || false ;; chipyard-tethered) - cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug - cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + build_tests run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/hello.riscv LOADMEM=1 EXTRA_SIM_FLAGS="+cflush_addr=0x2010200" ;; chipyard-symmetric) - cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug - cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + build_tests run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/symmetric.riscv LOADMEM=1 ;; chipyard-llcchiplet) - cmake $LOCAL_CHIPYARD_DIR/tests/ -S $LOCAL_CHIPYARD_DIR/tests/ -B $LOCAL_CHIPYARD_DIR/tests/build/ -D CMAKE_BUILD_TYPE=Debug - cmake --build $LOCAL_CHIPYARD_DIR/tests/build/ --target all + build_tests run_binary BINARY=$LOCAL_CHIPYARD_DIR/tests/hello.riscv LOADMEM=1 ;;