Skip to content

Commit

Permalink
more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
billmcspadden-riscv committed Nov 18, 2023
1 parent 44c312d commit 270f33e
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 45 deletions.
70 changes: 65 additions & 5 deletions new_test/TEST_DIR_ROOT/etrace.testdir/br_j_asm.testdir/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,23 @@ $(info TEST_DIR_PATH abspath: $(abspath ${TEST_DIR_PATH}))
include ${TEST_DIR_PATH}/lib/gmsl.git/gmsl

#=========================================================
# A test definition
# List of source files that are the source for a test
C_SRC := $(wildcard *.c)
ASM_SRC := $(wildcard *.S *.s)

C_OBJS := $(subst .s,.o,$(subst .S,.o,${ASM_SRC}))
ASM_OBJS := $(subst .s,.o,$(subst .S,.o,${ASM_SRC}))
OBJS_BASE := ${C_OBJS} ${ASM_OBJS}

#=========================================================
# Per test-instance test definition
# These variables are what make the instance of the test
# unique.

CONFIG_BASE := 0x80000000
MARCH := -march=rv32imc_zicsr -mabi=ilp32

C_SRC := $(wildcard *.c)
C_OBJS := $(subst .s,.o,$(subst .S,.o,${ASM_SRC}))
CC_FLAGS :=
ASM_SRC := $(wildcard *.S *.s)
ASM_OBJS := $(subst .s,.o,$(subst .S,.o,${ASM_SRC}))
OBJS_TMP := ${ASM_OBJS} ${C_OBJS}
ASM_FLAGS := -DCONFIG_BASE=${CONFIG_BASE} ${MARCH}
LD_FILE :=
Expand All @@ -90,6 +97,59 @@ OBJS := $(addprefix ${OBJDIR}/,${OBJS_TMP})

TESTLIST := $(call set_insert,${UNIQ_TESTNAME},${TESTLIST})
TESTLIST_BUILD := $(call set_insert,${OBJDIR}/test.elf,${TESTLIST_BUILD})
OBJDIRS_SET := $(call set_insert,${OBJDIR},${OBJDIRS_SET})

$(call set,C_SRC_AA,${UNIQ_TESTNAME},${C_SRC})
$(call set,CC_FLAGS_AA,${UNIQ_TESTNAME},${CC_FLAGS})
$(call set,ASM_SRC_AA,${UNIQ_TESTNAME},${ASM_SRC})
$(call set,ASM_FLAGS_AA,${UNIQ_TESTNAME},${ASM_FLAGS})
$(call set,RUN_FLAGS_AA,${UNIQ_TESTNAME},${RUN_FLAGS})
$(call set,XLEN_AA,${UNIQ_TESTNAME},${XLEN})
$(call set,OBJDIR_AA,${UNIQ_TESTNAME},${OBJDIR})
$(call set,OBJS_AA,${UNIQ_TESTNAME},${OBJS})
$(call set,LD_FLAGS_AA,${UNIQ_TESTNAME},${LD_FLAGS})

$(info TESTLIST_BUILD: ${TESTLIST_BUILD})
$(info C_SRC: $(call get,C_SRC_AA,${UNIQ_TESTNAME}))
$(info ASM_SRC: $(call get,ASM_SRC_AA,${UNIQ_TESTNAME}))
$(info ASM_FLAGS: $(call get,ASM_FLAGS_AA,${UNIQ_TESTNAME}))
$(info RUN_FLAGS: $(call get,RUN_FLAGS_AA,${UNIQ_TESTNAME}))
$(info XLEN: $(call get,XLEN_AA,${UNIQ_TESTNAME}))
$(info OBJDIR: $(call get,OBJDIR_AA,${UNIQ_TESTNAME}))
$(info OBJS: $(call get,OBJS_AA,${UNIQ_TESTNAME}))
$(info LD_FLAGS: $(call get,LD_FLAGS_AA,${UNIQ_TESTNAME}))
#=========================================================
#=========================================================
# A test definition

CONFIG_BASE := 0x80000000
MARCH := -march=rv64imc_zicsr -mabi=lp64

CC_FLAGS :=
OBJS_TMP := ${ASM_OBJS} ${C_OBJS}
ASM_FLAGS := -DCONFIG_BASE=${CONFIG_BASE} ${MARCH}
LD_FILE :=
LD_FLAGS := -T riscv_test.ld
RUN_FLAGS :=
XLEN := 64
OBJDIR_TMP := $(strip ${XLEN} ${ASM_FLAGS} ${CC_FLAGS} ${LD_FILE} ${LD_FLAGS} ${RUN_FLAGS})


# Create a unique objdir name for the variations of the test.
# make does not do a good, general job of string processing with
# spaces, so we'll use sed instead with

UNIQ_TESTNAME := $(shell echo ${OBJDIR_TMP} | sed 's/ /__/g' | sed 's/-/_/g' | sed 's/=/_/g')
$(info UNIQ_TESTNAME: ${UNIQ_TESTNAME})

OBJDIR := $(addsuffix .artifactdir,${UNIQ_TESTNAME})
$(info OBJDIR: ${OBJDIR})

OBJS := $(addprefix ${OBJDIR}/,${OBJS_TMP})

TESTLIST := $(call set_insert,${UNIQ_TESTNAME},${TESTLIST})
TESTLIST_BUILD := $(call set_insert,${OBJDIR}/test.elf,${TESTLIST_BUILD})
OBJDIRS_SET := $(call set_insert,${OBJDIR},${OBJDIRS_SET})
$(info TESTLIST_BUILD: ${TESTLIST_BUILD})
$(call set,C_SRC_AA,${UNIQ_TESTNAME},${C_SRC})
$(info C_SRC: $(call get,C_SRC_AA,${UNIQ_TESTNAME}))
Expand Down
126 changes: 86 additions & 40 deletions new_test/TEST_DIR_ROOT/lib/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ endif
$(info TEST_DIR_PATH: ${TEST_DIR_PATH})
$(info TEST_DIR_PATH realpath: $(realpath ${TEST_DIR_PATH}))
$(info TEST_DIR_PATH abspath: $(abspath ${TEST_DIR_PATH}))
$(info UNIQ_TESTNAME: ${UNIQ_TESTNAME})

TESTDIRS := $(wildcard *.testdir)

Expand All @@ -49,6 +50,10 @@ CC := ${RISCV32_TOOL_PATH}/riscv32-unknown-elf-gcc
ASM := ${RISCV32_TOOL_PATH}/riscv32-unknown-elf-gcc
LD := ${RISCV32_TOOL_PATH}/riscv32-unknown-elf-ld

#CC := ${RISCV64_TOOL_PATH}/riscv64-unknown-elf-gcc
#ASM := ${RISCV64_TOOL_PATH}/riscv64-unknown-elf-gcc
#LD := ${RISCV64_TOOL_PATH}/riscv64-unknown-elf-ld



all:
Expand Down Expand Up @@ -79,30 +84,71 @@ build:
fi ; \
fi;

# Convert gmsl assoc arrays into text suitable for bash assoc arrays
ASM_FLAGS_AA_FOR_SH := $(foreach var,${TESTLIST},["$(var)"]="$(call get,ASM_FLAGS_AA,$(var))" )
CC_FLAGS_AA_FOR_SH := $(foreach var,${TESTLIST},["$(var)"]="$(call get,CC_FLAGS_AA,$(var))" )
LD_FLAGS_AA_FOR_SH := $(foreach var,${TESTLIST},["$(var)"]="$(call get,LD_FLAGS_AA,$(var))" )
RUN_FLAGS_AA_FOR_SH := $(foreach var,${TESTLIST},["$(var)"]="$(call get,RUN_FLAGS_AA,$(var))" )

build_tests : ${TESTLIST_BUILD}
#${TESTLIST_BUILD} :
# @echo "making \"$@\" in $$PWD" ;
# @mkdir -p $@.artifactdir || ( echo "unable to create $@.artifactdir" >> test.failed ; exit $$? ; ) ;
# @echo "calling \'make $@\'" ;
# make $@ ; \
# if [ $$? -ne 0 ] ; \
# then \
# echo "\'make $@\' exited with nonzero exit status" >> $@.artifactdir/test.failed ; \
# fi ;
$(info ASM_FLAGS_AA_FOR_SH: ${ASM_FLAGS_AA_FOR_SH})



test :
arr=(${OBJDIRS_SET}) ; \
echo "arr[]: $${arr[@]}";
testlist=(${TESTLIST}) ; \
echo "testlist[]: $${testlist[@]}";
declare -A asm_flags_aa=( ${ASM_FLAGS_AA_FOR_SH} ) ; \
echo "asm_flags_aa[]: $${asm_flags_aa[@]}"; \
declare -A cc_flags_aa=( ${CC_FLAGS_AA_FOR_SH} ) ; \
echo "cc_flags_aa[]: $${cc_flags_aa[@]}"; \
declare -A ld_flags_aa=( ${LD_FLAGS_AA_FOR_SH} ) ; \
echo "ld_flags_aa[]: $${ld_flags_aa[@]}"; \
declare -A run_flags_aa=( ${run_FLAGS_AA_FOR_SH} ) ; \
echo "run_flags_aa[]: $${runflags_aa[@]}";

.PHONY : ${TESTLIST}
build_tests : ${TESTLIST}
${TESTLIST} :
@echo "making \"$@\" in $$PWD" ;
mkdir -p $@.artifactdir || ( echo "unable to create $@.artifactdir" >> test.failed ; exit $$? ; ) ;
declare -A asm_flags_aa=( ${ASM_FLAGS_AA_FOR_SH} ) ; \
declare -A cc_flags_aa=( ${CC_FLAGS_AA_FOR_SH} ) ; \
declare -A ld_flags_aa=( ${LD_FLAGS_AA_FOR_SH} ) ; \
declare -A run_flags_aa=( ${run_FLAGS_AA_FOR_SH} ) ; \
echo "calling \'make $@\'" ; \
echo "make $@.artifactdir/test.elf ASM_FLAGS_NEXT=$${asm_flags_aa["$@"]} CC_FLAGS_NEXT=$${cc_flags_aa["$@"]} LD_FLAGS_NEXT=$${ld_flags_aa["$@"]}" ; \
make $@.artifactdir/test.elf ASM_FLAGS_NEXT="$${asm_flags_aa[$@]}" CC_FLAGS_NEXT="$${cc_flags_aa[$@]}" LD_FLAGS_NEXT="$${ld_flags_aa[$@]}" ; \
if [ $$? -ne 0 ] ; \
then \
echo "\'make $@\' exited with nonzero exit status" >> $@.artifactdir/test.failed ; \
fi ;

$(info foo: $(call get,OBJS_AA,${UNIQ_TESTNAME}))
$(info goo: $(call get,OBJDIR_AA,${UNIQ_TESTNAME}))
$(info OBJDIRS_SET: ${OBJDIRS_SET})
OBJDIRS_OBJS := $(addsuffix /%.o,${OBJDIRS_SET})
$(info OBJDIRS_OBJS: ${OBJDIRS_OBJS})

#$(call get,OBJDIR_AA,${UNIQ_TESTNAME})/%.o : %.s %.S
$(call get,OBJDIR_AA,${UNIQ_TESTNAME})/%.o : %.S
#$(call get,OBJDIR_AA,${UNIQ_TESTNAME})/%.o : %.S
${OBJDIRS_OBJS} : %.S
@echo "making \"$@\" in $$PWD" ;
@mkdir -p $(call get,OBJDIR_AA,${UNIQ_TESTNAME}) || ( echo "unable to create $@.artifactdir" >> test.failed ; exit $$? ; ) ;
${ASM} -c $(call get,ASM_FLAGS_AA,${UNIQ_TESTNAME}) \
-o $@ \
$(call get,ASM_SRC_AA,${UNIQ_TESTNAME})
@echo "ASM_FLAGS_NEXT: ${ASM_FLAGS_NEXT}" ;
@mkdir -p $(dir $@) || ( echo "unable to create $@.artifactdir" >> test.failed ; exit $$? ; ) ;
${ASM} -c ${ASM_FLAGS_NEXT} -o $@ $<

${OBJDIRS_OBJS} : %.c
@echo "making \"$@\" in $$PWD" ;
@mkdir -p $(dir $@) || ( echo "unable to create $@.artifactdir" >> test.failed ; exit $$? ; ) ;
${CC} -c ${CC_FLAGS_NEXT} -o $@ $<


$(call get,OBJDIR_AA,${UNIQ_TESTNAME})/test.elf : $(call get,OBJS_AA,${UNIQ_TESTNAME})
OBJS := $(addprefix %/,${OBJS_BASE})
#$(call get,OBJDIR_AA,${UNIQ_TESTNAME})/test.elf : $(call get,OBJS_AA,${UNIQ_TESTNAME})
%/test.elf : ${OBJS}
@echo "making \"$@\" in $$PWD" ;
${LD} $(call get,LD_FLAGS_AA,${UNIQ_TESTNAME}) -o $@ $<
${LD} ${LD_FLAGS_NEXT} -o $@ $<


install:
Expand Down Expand Up @@ -133,28 +179,28 @@ run:

# Run in parallel (potentially, based on the -j switch to make)
# TODO: also redirect stderr into test.failed
.PHONY: ${TESTLIST}
run_tests : ${TESTLIST}
${TESTLIST} :
@echo "making \"$@\"" ;
@mkdir -p $@.artifactdir || ( echo "unable to create $@.artifactdir" >> test.failed ; exit $$? ; ) ;
@if [ ! -e ${TEST_DIR_PATH}/../../c_emulator/riscv_sim_RV$(call get,XLEN_AA,$@) ] ; \
then \
echo "${TEST_DIR_PATH}/../../c_emulator/riscv_sim_RV$(call get,XLEN_AA,$@) does not exist." >> $@.artifactdir/test.failed ; \
fi ;
${TEST_DIR_PATH}/../../c_emulator/riscv_sim_RV$(call get,XLEN_AA,$@) $(call get,RUN_FLAGS_AA,$@) $(call get,OBJDIR_AA,${UNIQ_TESTNAME})/test.elf > $@.artifactdir/test.run.stdout ; \
if [ $$? -ne 0 ] ; \
then \
echo "riscv_sim_$@.$(call get,XLEN_AA,$@) exited with nonzero exit status" >> $@.artifactdir/test.failed ; \
fi ;
@if [ ! -e $@.artifactdir/test.run.stdout ] ; \
then \
echo "file, \"$@.artifactdir/test.run.stdout\" not found" >> $@.artifactdir/test.failed ; \
fi ;
@if [ ! -e $@.artifactdir/test.failed ] ; \
then \
echo "${PWD} passed" >> $@.artifactdir/test.passed ; \
fi;
#.PHONY: ${TESTLIST}
#run_tests : ${TESTLIST}
#${TESTLIST} :
# @echo "making \"$@\"" ;
# @mkdir -p $@.artifactdir || ( echo "unable to create $@.artifactdir" >> test.failed ; exit $$? ; ) ;
# @if [ ! -e ${TEST_DIR_PATH}/../../c_emulator/riscv_sim_RV$(call get,XLEN_AA,$@) ] ; \
# then \
# echo "${TEST_DIR_PATH}/../../c_emulator/riscv_sim_RV$(call get,XLEN_AA,$@) does not exist." >> $@.artifactdir/test.failed ; \
# fi ;
# ${TEST_DIR_PATH}/../../c_emulator/riscv_sim_RV$(call get,XLEN_AA,$@) $(call get,RUN_FLAGS_AA,$@) $(call get,OBJDIR_AA,${UNIQ_TESTNAME})/test.elf > $@.artifactdir/test.run.stdout ; \
# if [ $$? -ne 0 ] ; \
# then \
# echo "riscv_sim_$@.$(call get,XLEN_AA,$@) exited with nonzero exit status" >> $@.artifactdir/test.failed ; \
# fi ;
# @if [ ! -e $@.artifactdir/test.run.stdout ] ; \
# then \
# echo "file, \"$@.artifactdir/test.run.stdout\" not found" >> $@.artifactdir/test.failed ; \
# fi ;
# @if [ ! -e $@.artifactdir/test.failed ] ; \
# then \
# echo "${PWD} passed" >> $@.artifactdir/test.passed ; \
# fi;


# Gather all the test results from this directory on down.
Expand Down

0 comments on commit 270f33e

Please sign in to comment.