From be83a5dc1029795a4e1c1dc39bf13b3d8de4ac80 Mon Sep 17 00:00:00 2001 From: Wojciech Sipak Date: Fri, 29 Nov 2024 13:23:30 +0100 Subject: [PATCH 1/3] use docker container with fixed version --- .github/workflows/test-openocd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-openocd.yml b/.github/workflows/test-openocd.yml index 7091d556f0b..c18094ab9a8 100644 --- a/.github/workflows/test-openocd.yml +++ b/.github/workflows/test-openocd.yml @@ -8,7 +8,7 @@ jobs: tests: name: Run OpenOCD tests runs-on: ubuntu-latest - container: ghcr.io/antmicro/cores-veer-el2:latest + container: ghcr.io/antmicro/cores-veer-el2:20241129 strategy: fail-fast: false matrix: From 8ed5aab887d0ecb5fa84b707709678b94b511541 Mon Sep 17 00:00:00 2001 From: Wojciech Sipak Date: Fri, 29 Nov 2024 11:17:53 +0100 Subject: [PATCH 2/3] shorten openocd test --- .github/scripts/dump_and_compare.sh | 4 +-- .github/scripts/gdb_test.sh | 43 ++++++++++++++-------------- .github/scripts/openocd/veer-el2.cfg | 1 + .github/scripts/test.gdb | 30 ++++--------------- .github/workflows/test-openocd.yml | 3 +- 5 files changed, 32 insertions(+), 49 deletions(-) diff --git a/.github/scripts/dump_and_compare.sh b/.github/scripts/dump_and_compare.sh index 378a298879c..81daf1dbebf 100755 --- a/.github/scripts/dump_and_compare.sh +++ b/.github/scripts/dump_and_compare.sh @@ -16,7 +16,7 @@ set -ex # Invoke GDB and dump core registers -${GCC_PREFIX}-gdb -n --batch -x test.gdb >gdb.log +${GCC_PREFIX}-gdb -n --batch -x $RV_ROOT/.github/scripts/test.gdb >gdb.log # Parse the log, extract register values. Skip those which change as the # program executes since we don't know at which point we tap in. cat gdb.log | grep -E '^ra |^sp |^gp |^tp |^t[01256] |^s[0-9]+ |^a[0-9]+ |^\$[0-9]+' >gdb_test_dump.txt @@ -24,5 +24,5 @@ cat gdb.log | grep -E '^ra |^sp |^gp |^tp |^t[01256] |^s[0-9]+ |^a[0-9]+ |^\$[0- # Compare the dumps # TODO this temporarily exits with success just to allow collecting coverage data # without considering the truthness of register values. -diff -E -y gdb_test_golden.txt gdb_test_dump.txt || true +diff -E -y $RV_ROOT/.github/scripts/gdb_test_golden.txt gdb_test_dump.txt || true diff --git a/.github/scripts/gdb_test.sh b/.github/scripts/gdb_test.sh index 908bfffccb7..6b90822535d 100755 --- a/.github/scripts/gdb_test.sh +++ b/.github/scripts/gdb_test.sh @@ -16,10 +16,13 @@ # This script runs Verilator RTL simulation and OpenOCD in background, invokes # the supplied test command and shuts everything down. -SIM_LOG=`realpath sim.log` -OPENOCD_LOG=`realpath openocd.log` +SIM_LOG=$(realpath sim.log) +OPENOCD_LOG=$(realpath openocd.log) +GDB_LOG=$(realpath gdb.log) GCC_PREFIX=riscv64-unknown-elf +WORKDIR=$PWD + # Ensure that RISC-V toolchain is installed if ! which ${GCC_PREFIX}-gcc >/dev/null; then GCC_PREFIX=riscv32-unknown-elf @@ -32,11 +35,6 @@ export GCC_PREFIX set +e -if [ "$#" -lt 1 ]; then - echo "Usage: gdb_test.sh [args ...]" - exit 1 -fi - # Utils source `dirname ${BASH_SOURCE[0]}`/utils.sh @@ -48,10 +46,12 @@ terminate_all () { } print_logs () { - echo -e "${COLOR_WHITE}======== Simulation log ========${COLOR_OFF}" - cat ${SIM_LOG} || true echo -e "${COLOR_WHITE}======== OpenOCD log ========${COLOR_OFF}" cat ${OPENOCD_LOG} || true + echo -e "${COLOR_WHITE}======== GDB log ========${COLOR_OFF}" + cat ${GDB_LOG} || true + echo -e "${COLOR_WHITE}======== Simulation log ========${COLOR_OFF}" + cat ${SIM_LOG} || true } echo -e "${COLOR_WHITE}======== Launching interactive simulation ========${COLOR_OFF}" @@ -63,9 +63,8 @@ SIM_PID=$! # Wait wait_for_phrase "${SIM_LOG}" "Start of sim" -# TODO handle proper string in the output instead of waiting -sleep 10s retcode=$? +sleep 10s if [ $retcode -ne 0 ]; then echo -e "${COLOR_RED}Failed to start the simulation: $retcode ${COLOR_OFF}" print_logs @@ -77,6 +76,7 @@ echo -e "Simulation running and ready (pid=${SIM_PID})" echo -e "Launching OpenOCD..." cd ${RV_ROOT}/.github/scripts/openocd && openocd -d2 --file board/caliptra-verilator.cfg >"${OPENOCD_LOG}" 2>&1 & OPENOCD_PID=$! +cd $WORKDIR # Wait wait_for_phrase "${OPENOCD_LOG}" "Listening on port 3333 for gdb connections" @@ -91,16 +91,9 @@ echo -e "OpenOCD running and ready (pid=${OPENOCD_PID})" sleep 1s # Run the test -echo -e "${COLOR_WHITE}======== Running test '$@' ========${COLOR_OFF}" - -bash -c "$(printf ' %q' "$@")" -EXITCODE=$? - -if [ ${EXITCODE} -eq 0 ]; then - echo -e "${COLOR_GREEN}[PASSED]${COLOR_OFF}" -else - echo -e "${COLOR_RED}[FAILED]${COLOR_OFF}" -fi +echo -e "${COLOR_WHITE}======== Running test dump_and_compare.sh ========${COLOR_OFF}" +pwd +${RV_ROOT}/.github/scripts/dump_and_compare.sh sleep 1s @@ -111,5 +104,13 @@ terminate_all # Display logs print_logs +if grep -q 'PASSED' $SIM_LOG ; then + echo -e "${COLOR_GREEN}[PASSED]${COLOR_OFF}" + EXITCODE=0 +else + echo -e "${COLOR_RED}[FAILED]${COLOR_OFF}" + EXITCODE=1 +fi + # Honor the exitcode exit ${EXITCODE} diff --git a/.github/scripts/openocd/veer-el2.cfg b/.github/scripts/openocd/veer-el2.cfg index c8472325fb4..b8cc96df770 100644 --- a/.github/scripts/openocd/veer-el2.cfg +++ b/.github/scripts/openocd/veer-el2.cfg @@ -13,6 +13,7 @@ $_TARGETNAME.0 configure -work-area-phys 0x50001000 -work-area-size 0x1000 -work $_TARGETNAME.0 configure -event gdb-detach { resume + shutdown } $_TARGETNAME.0 riscv expose_csrs 1968=dcsr diff --git a/.github/scripts/test.gdb b/.github/scripts/test.gdb index 5c7bc199697..630f7b37a59 100644 --- a/.github/scripts/test.gdb +++ b/.github/scripts/test.gdb @@ -17,9 +17,6 @@ set architecture riscv:rv32 set remotetimeout 360 target extended-remote :3333 -echo Connected, waiting...\n -shell sleep 30s - echo Dumping registers...\n info registers echo Accessing DCCM...\n @@ -121,27 +118,12 @@ set *(0xd0000008) = 0x55555555 set *(0xd000000C) = 0xAAAAAAAA print/x *0xd0000000@4 -echo Setting Breakpoint 1...\n -hbreak *0x1c - -echo Continuing...\n -continue - -delete - -# This causes an error. Let's execute it anyway for coverage. -echo Accessing region at 0xe0000000...\n -set *(0xe0000000) = 0x01234567 -set *(0xe0000004) = 0x89ABCDEF -set *(0xe0000008) = 0x55555555 -set *(0xe000000C) = 0xAAAAAAAA -print/x *0xe0000000@4 -echo Accessing region at 0xf0000000...\n -set *(0xf0000000) = 0x01234567 -set *(0xf0000004) = 0x89ABCDEF -set *(0xf0000008) = 0x55555555 -set *(0xf000000C) = 0xAAAAAAAA -print/x *0xf0000000@4 +# TODO test breakpoint +# echo Setting Breakpoint 1...\n +# hbreak *0x1c +# echo Continuing...\n +# continue +# delete # end the simulation gracefully set *(volatile unsigned char*)0xd0580000 = 0xff diff --git a/.github/workflows/test-openocd.yml b/.github/workflows/test-openocd.yml index c18094ab9a8..f90a50ed308 100644 --- a/.github/workflows/test-openocd.yml +++ b/.github/workflows/test-openocd.yml @@ -77,8 +77,7 @@ jobs: make -C gdb_test -f ${RV_ROOT}/tools/Makefile verilator-build program.hex TEST=infinite_loop \ CONF_PARAMS="-set build_${{ matrix.bus }} -set openocd_test" COVERAGE=${{ matrix.coverage }} -j$(nproc) cd gdb_test - ${RV_ROOT}/.github/scripts/gdb_test.sh \ - /bin/bash -c 'cd ${RV_ROOT}/.github/scripts && ./dump_and_compare.sh' || true + ${RV_ROOT}/.github/scripts/gdb_test.sh pkill openocd || true - name: Prepare coverage data From 3ed889e3d2a794e625720945a80b0c4ae9d8f2e3 Mon Sep 17 00:00:00 2001 From: Wojciech Sipak Date: Mon, 2 Dec 2024 14:32:15 +0100 Subject: [PATCH 3/3] set and delete breakpoint --- .github/scripts/test.gdb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/test.gdb b/.github/scripts/test.gdb index 630f7b37a59..9b8d4629b87 100644 --- a/.github/scripts/test.gdb +++ b/.github/scripts/test.gdb @@ -120,10 +120,10 @@ print/x *0xd0000000@4 # TODO test breakpoint # echo Setting Breakpoint 1...\n -# hbreak *0x1c +hbreak *0x1c # echo Continuing...\n # continue -# delete +delete # end the simulation gracefully set *(volatile unsigned char*)0xd0580000 = 0xff