Skip to content

Commit

Permalink
Merge pull request #238 from chipsalliance/wsip/debug_coverage
Browse files Browse the repository at this point in the history
Collective PR to combine tests increasing coverage
  • Loading branch information
tmichalak authored Oct 11, 2024
2 parents 795eb58 + b7d2856 commit 199eae1
Show file tree
Hide file tree
Showing 83 changed files with 2,117 additions and 441 deletions.
29 changes: 29 additions & 0 deletions .github/scripts/breakpoint.gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
echo Connecting to OpenOCD...\n
set architecture riscv:rv32
set remotetimeout 30
target extended-remote :3333

echo Connected, waiting...\n
shell sleep 5s

echo Setting Breakpoint 1...\n
hbreak *0x1c

echo Continuing...\n
continue

delete
25 changes: 25 additions & 0 deletions .github/scripts/breakpoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -ex

# Invoke GDB
${GCC_PREFIX}-gdb -n --batch -x breakpoint.gdb >gdb.log
# Parse the log
cat gdb.log | grep 'Breakpoint 1,' >breakpoint.txt

# Compare the dumps
diff -E -y breakpoint.txt breakpoint_golden.txt || true

1 change: 1 addition & 0 deletions .github/scripts/breakpoint_golden.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Breakpoint 1, 0x0000001c in ?? ()
28 changes: 28 additions & 0 deletions .github/scripts/dump_and_compare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -ex

# Invoke GDB and dump core registers
${GCC_PREFIX}-gdb -n --batch -x dump_registers.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]+' >regdump.txt

# 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 regdump_golden.txt regdump.txt || true

24 changes: 24 additions & 0 deletions .github/scripts/dump_registers.gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
echo Connecting to OpenOCD...\n
set architecture riscv:rv32
set remotetimeout 30
target extended-remote :3333

echo Connected, waiting...\n
shell sleep 30s

echo Dumping registers...\n
info registers
115 changes: 115 additions & 0 deletions .github/scripts/gdb_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# 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`
GCC_PREFIX=riscv64-unknown-elf

# Ensure that RISC-V toolchain is installed
if ! which ${GCC_PREFIX}-gcc >/dev/null; then
GCC_PREFIX=riscv32-unknown-elf
fi
if ! which ${GCC_PREFIX}-gcc >/dev/null; then
echo "RISC-V toolchain not found, please refer to https://github.com/chipsalliance/caliptra-rtl?tab=readme-ov-file#riscv-toolchain-installation for more details."
exit 1
fi
export GCC_PREFIX

set +e

if [ "$#" -lt 1 ]; then
echo "Usage: gdb_test.sh <command> [args ...]"
exit 1
fi

# Utils
source `dirname ${BASH_SOURCE[0]}`/utils.sh

terminate_all () {
terminate ${OPENOCD_PID}
echo "waiting for the simulation to end: $SIM_PID"
wait ${SIM_PID}
# terminate ${SIM_PID}
}

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}======== Launching interactive simulation ========${COLOR_OFF}"

# Start the simulation
echo -e "Starting simulation..."
./obj_dir/Vtb_top >"${SIM_LOG}" 2>&1 &
SIM_PID=$!

# Wait
wait_for_phrase "${SIM_LOG}" "Start of sim"
# TODO handle proper string in the output instead of waiting
sleep 10s
retcode=$?
if [ $retcode -ne 0 ]; then
echo -e "${COLOR_RED}Failed to start the simulation: $retcode ${COLOR_OFF}"
print_logs
terminate_all; exit -1
fi
echo -e "Simulation running and ready (pid=${SIM_PID})"

# Launch OpenOCD
echo -e "Launching OpenOCD..."
cd ${RV_ROOT}/.github/scripts/openocd && openocd --debug --file board/caliptra-verilator.cfg >"${OPENOCD_LOG}" 2>&1 &
OPENOCD_PID=$!

# Wait
wait_for_phrase "${OPENOCD_LOG}" "Listening on port 3333 for gdb connections"
if [ $? -ne 0 ]; then
echo -e "${COLOR_RED}Failed to start OpenOCD!${COLOR_OFF}"
print_logs
terminate_all; exit -1
fi
echo -e "OpenOCD running and ready (pid=${OPENOCD_PID})"

# Wait a bit
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

sleep 1s

# Terminate
echo -e "${COLOR_WHITE}Terminating...${COLOR_OFF}"
terminate_all

# Display logs
print_logs

# Honor the exitcode
exit ${EXITCODE}
135 changes: 135 additions & 0 deletions .github/scripts/mem_access.gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
echo Connecting to OpenOCD...\n
set architecture riscv:rv32
set remotetimeout 30
target extended-remote :3333

echo Connected, waiting...\n
shell sleep 5s

echo Accessing DCCM...\n
set *(0x00080000) = 0x01234567
set *(0x00080004) = 0x89ABCDEF
set *(0x00080008) = 0x55555555
set *(0x0008000C) = 0xAAAAAAAA
print/x *0x00080000@4

# TODO why does the default configuration for iccm (0xe000000) differ from the documentation (0x40000)?
echo Accessing ICCM...\n
set *(0x0e000000) = 0x01234567
set *(0x0e000004) = 0x89ABCDEF
set *(0x0e000008) = 0x55555555
set *(0x0e00000C) = 0xAAAAAAAA
print/x *0x00e00000@4

echo Accessing region at 0x20000000...\n
set *(0x20000000) = 0x01234567
set *(0x20000004) = 0x89ABCDEF
set *(0x20000008) = 0x55555555
set *(0x2000000C) = 0xAAAAAAAA
print/x *0x20000000@4

echo Accessing region at 0x30000000...\n
set *(0x30000000) = 0x01234567
set *(0x30000004) = 0x89ABCDEF
set *(0x30000008) = 0x55555555
set *(0x3000000C) = 0xAAAAAAAA
print/x *0x30000000@4

echo Accessing region at 0x40000000...\n
set *(0x40000000) = 0x01234567
set *(0x40000004) = 0x89ABCDEF
set *(0x40000008) = 0x55555555
set *(0x4000000C) = 0xAAAAAAAA
print/x *0x40000000@4

echo Accessing region at 0x50000000...\n
set *(0x50000000) = 0x01234567
set *(0x50000004) = 0x89ABCDEF
set *(0x50000008) = 0x55555555
set *(0x5000000C) = 0xAAAAAAAA
print/x *0x50000000@4

echo Accessing region at 0x60000000...\n
set *(0x60000000) = 0x01234567
set *(0x60000004) = 0x89ABCDEF
set *(0x60000008) = 0x55555555
set *(0x6000000C) = 0xAAAAAAAA
print/x *0x60000000@4

echo Accessing region at 0x70000000...\n
set *(0x70000000) = 0x01234567
set *(0x70000004) = 0x89ABCDEF
set *(0x70000008) = 0x55555555
set *(0x7000000C) = 0xAAAAAAAA
print/x *0x70000000@4

echo Accessing region at 0x80000000...\n
set *(0x80000000) = 0x01234567
set *(0x80000004) = 0x89ABCDEF
set *(0x80000008) = 0x55555555
set *(0x8000000C) = 0xAAAAAAAA
print/x *0x80000000@4

echo Accessing region at 0x90000000...\n
set *(0x90000000) = 0x01234567
set *(0x90000004) = 0x89ABCDEF
set *(0x90000008) = 0x55555555
set *(0x9000000C) = 0xAAAAAAAA
print/x *0x90000000@4

echo Accessing region at 0xa0000000...\n
set *(0xa0000000) = 0x01234567
set *(0xa0000004) = 0x89ABCDEF
set *(0xa0000008) = 0x55555555
set *(0xa000000C) = 0xAAAAAAAA
print/x *0xa0000000@4

echo Accessing region at 0xb0000000...\n
set *(0xb0000000) = 0x01234567
set *(0xb0000004) = 0x89ABCDEF
set *(0xb0000008) = 0x55555555
set *(0xb000000C) = 0xAAAAAAAA
print/x *0xb0000000@4

echo Accessing region at 0xc0000000...\n
set *(0xc0000000) = 0x01234567
set *(0xc0000004) = 0x89ABCDEF
set *(0xc0000008) = 0x55555555
set *(0xc000000C) = 0xAAAAAAAA
print/x *0xc0000000@4

echo Accessing region at 0xd0000000...\n
set *(0xd0000000) = 0x01234567
set *(0xd0000004) = 0x89ABCDEF
set *(0xd0000008) = 0x55555555
set *(0xd000000C) = 0xAAAAAAAA
print/x *0xd0000000@4

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

27 changes: 27 additions & 0 deletions .github/scripts/mem_access.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -ex

# Invoke GDB
${GCC_PREFIX}-gdb -n --batch -x mem_access.gdb >gdb.log
# Parse the log
cat gdb.log | grep -E '^\$[0-9]+' >out.txt

# Compare the dumps
# TODO this temporarily exits with success just to allow collecting coverage data
# without considering the truthness of reported values.
diff -E -y mem_access_golden.txt out.txt || true

3 changes: 3 additions & 0 deletions .github/scripts/mem_access_golden.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$1 = {0xcafebaba, 0xdeadbeef, 0xfeedbaca, 0xa5a5a5a5}
$2 = {0x1234567, 0x89abcdef, 0x55555555, 0xaaaaaaaa}
$3 = {0xaaaab0b7, 0xaaa08093, 0x7c009073, 0x90734191, 0x50b77f91, 0x80931234, 0xf1376780, 0x7111abcd}
Loading

0 comments on commit 199eae1

Please sign in to comment.