-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from antmicro/rrozak/60812-openocd-tests
Add OpenOCD test
- Loading branch information
Showing
35 changed files
with
6,090 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright 2024 Antmicro <www.antmicro.com> | ||
# | ||
# 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 in background and invokes OpenOCD | ||
# to perform JTAG access test | ||
|
||
SIM_LOG=`realpath sim.log` | ||
OPENOCD_LOG=`realpath openocd.log` | ||
|
||
set +e | ||
|
||
if [ "$#" -lt 1 ]; then | ||
echo "Usage: openocd_test.sh [openocd args ...]" | ||
exit 1 | ||
fi | ||
OPENOCD_ARGS=$@ | ||
|
||
# Utils | ||
source `dirname ${BASH_SOURCE[0]}`/utils.sh | ||
|
||
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}" "VerilatorTB: Start of sim" | ||
if [ $? -ne 0 ]; then | ||
echo -e "${COLOR_RED}Failed to start the simulation!${COLOR_OFF}" | ||
print_logs | ||
terminate ${SIM_PID}; exit -1 | ||
fi | ||
echo -e "Simulation running and ready (pid=${SIM_PID})" | ||
|
||
# Wait a bit | ||
sleep 2s | ||
|
||
# Run the test | ||
echo -e "${COLOR_WHITE}======== Running OpenOCD test '$@' ========${COLOR_OFF}" | ||
cd ${RV_ROOT}/testbench/openocd_scripts && openocd -d2 ${OPENOCD_ARGS} >"${OPENOCD_LOG}" 2>&1 | ||
EXITCODE=$? | ||
|
||
if [ ${EXITCODE} -eq 0 ]; then | ||
echo -e "${COLOR_GREEN}[PASSED]${COLOR_OFF}" | ||
else | ||
echo -e "${COLOR_RED}[FAILED]${COLOR_OFF}" | ||
fi | ||
|
||
# Display logs | ||
print_logs | ||
|
||
wait $SIM_PID | ||
|
||
# Honor the exitcode | ||
exit ${EXITCODE} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright 2024 Antmicro <www.antmicro.com> | ||
# | ||
# 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. | ||
# | ||
|
||
# Colors | ||
COLOR_OFF='\033[0m' | ||
COLOR_RED='\033[31m' | ||
COLOR_GREEN='\033[32m' | ||
COLOR_WHITE='\033[1;37m' | ||
|
||
# Waits until the given phrase appears in a log file (actively written to) | ||
# Usage: wait_for_phrase <log_file> <phrase> | ||
wait_for_phrase () { | ||
|
||
# Check if the log exists | ||
sleep 1s | ||
if ! [ -f "$1" ]; then | ||
echo -e "${COLOR_RED}Log file '$1' not found!${COLOR_OFF}" | ||
return -1 | ||
fi | ||
|
||
# Wait for the phrase | ||
DEADLINE=$((${EPOCHSECONDS} + 30)) | ||
while [ ${EPOCHSECONDS} -lt ${DEADLINE} ] | ||
do | ||
# Check for the phrase | ||
grep "$2" "$1" >/dev/null | ||
if [ $? -eq 0 ]; then | ||
return 0 | ||
fi | ||
|
||
# Sleep and retry | ||
sleep 1s | ||
done | ||
|
||
# Timeout | ||
return -1 | ||
} | ||
|
||
# Terminates a process. First via SIGINT and if this doesn't work after 10s | ||
# retries with SIGKILL | ||
# Usage: terminate <pid> | ||
terminate () { | ||
|
||
local PID=$1 | ||
|
||
# Gently interrupt, wait some time and then kill | ||
/bin/kill -s SIGINT ${PID} || true | ||
sleep 10s | ||
/bin/kill -s SIGKILL ${PID} || true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: OpenOCD Build | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
openOCD: | ||
name: Build OpenOCD | ||
runs-on: ubuntu-latest | ||
env: | ||
# A custom fork is needed to allow bypassing core examination and accessing | ||
# peripherals regardless of core state. | ||
OPENOCD_REPO: https://github.com/antmicro/openocd | ||
OPENOCD_VERSION: riscv-nohalt | ||
|
||
steps: | ||
- name: Setup Cache Metadata | ||
id: cache_metadata | ||
run: | | ||
cache_date=$(date +"%Y_%m_%d") | ||
cache_name=cache_openocd | ||
echo "Cache date: "$cache_date | ||
echo "Cache name: "$cache_name | ||
echo "cache_date=$cache_date" >> "$GITHUB_ENV" | ||
echo "cache_name=$cache_name" >> "$GITHUB_ENV" | ||
- name: Setup cache | ||
uses: actions/cache@v3 | ||
id: cache | ||
timeout-minutes: 60 | ||
with: | ||
path: | | ||
/opt/openocd | ||
/opt/openocd/.cache | ||
key: ${{ env.cache_name }}_${{ env.cache_date }} | ||
restore-keys: ${{ env.cache_name }}_ | ||
|
||
- name: Install prerequisities | ||
if: ${{ steps.cache.outputs.cache-hit != 'true' }} | ||
run: | | ||
sudo apt -qqy update && sudo apt -qqy --no-install-recommends install \ | ||
make libtool pkg-config autoconf automake texinfo | ||
- name: Build and install OpenOCD | ||
if: ${{ steps.cache.outputs.cache-hit != 'true' }} | ||
run: | | ||
git clone -b "${OPENOCD_VERSION}" "${OPENOCD_REPO}" | ||
pushd openocd | ||
./bootstrap | ||
./configure --prefix=/opt/openocd --enable-remote-bitbang \ | ||
CFLAGS="-Wno-error=misleading-indentation -Wno-error=stringop-overflow" | ||
make -j`nproc` | ||
sudo make install | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
name: Test-OpenOCD | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
|
||
tests: | ||
name: Run OpenOCD tests | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
coverage: ["all", "branch", "toggle"] #TODO: add functional coverage | ||
bus: ["axi4", "ahb_lite"] | ||
env: | ||
DEBIAN_FRONTEND: "noninteractive" | ||
CCACHE_DIR: "/opt/openocd-tests/.cache/" | ||
VERILATOR_VERSION: v5.010 | ||
|
||
steps: | ||
- name: Install utils | ||
run: | | ||
sudo apt -qqy update && sudo apt -qqy --no-install-recommends install \ | ||
cpanminus ccache ninja-build gcc-riscv64-unknown-elf | ||
pip3 install meson | ||
sudo cpanm Bit::Vector | ||
- name: Setup Cache Metadata | ||
id: cache_metadata | ||
run: | | ||
date=$(date +"%Y_%m_%d") | ||
time=$(date +"%Y%m%d_%H%M%S_%N") | ||
cache_verilator_restore_key=cache_verilator_ | ||
cache_verilator_key=${cache_verilator_restore_key}${{ env.VERILATOR_VERSION }} | ||
cache_openocd_restore_key=cache_openocd_ | ||
cache_openocd_key=${cache_openocd_restore_key} | ||
cache_test_restore_key=${{ matrix.coverage }}_ | ||
cache_test_key=${cache_test_restore_key}${time} | ||
echo "date=$date" | tee -a "$GITHUB_ENV" | ||
echo "time=$time" | tee -a "$GITHUB_ENV" | ||
echo "cache_verilator_restore_key=$cache_verilator_restore_key" | tee -a "$GITHUB_ENV" | ||
echo "cache_verilator_key=$cache_verilator_key" | tee -a "$GITHUB_ENV" | ||
echo "cache_openocd_restore_key=$cache_openocd_restore_key" | tee -a "$GITHUB_ENV" | ||
echo "cache_openocd_key=$cache_openocd_key" | tee -a "$GITHUB_ENV" | ||
echo "cache_test_restore_key=$cache_test_restore_key" | tee -a "$GITHUB_ENV" | ||
echo "cache_test_key=$cache_test_key" | tee -a "$GITHUB_ENV" | ||
- name: Restore Verilator cache | ||
id: cache-verilator-restore | ||
uses: actions/cache/restore@v3 | ||
with: | ||
path: | | ||
/opt/verilator | ||
/opt/verilator/.cache | ||
key: ${{ env.cache_verilator_key }} | ||
restore-keys: ${{ env.cache_verilator_restore_key }} | ||
|
||
- name: Restore OpenOCD cache | ||
id: cache-openocd-restore | ||
uses: actions/cache/restore@v3 | ||
with: | ||
path: | | ||
/opt/openocd | ||
/opt/openocd/.cache | ||
key: ${{ env.cache_openocd_key }} | ||
restore-keys: ${{ env.cache_openocd_restore_key }} | ||
|
||
- name: Setup repository | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Build verilated simulation | ||
run: | | ||
export PATH=/opt/verilator/bin:/opt/openocd/bin:$PATH | ||
export RV_ROOT=$(pwd) | ||
mkdir run | ||
make -C run -f ${RV_ROOT}/tools/Makefile verilator-build program.hex TEST=infinite_loop \ | ||
CONF_PARAMS="-set build_${{ matrix.bus }} -set openocd_test" COVERAGE=${{ matrix.coverage }} | ||
cd run | ||
${RV_ROOT}/.github/scripts/openocd_test.sh \ | ||
-f ${RV_ROOT}/testbench/openocd_scripts/verilator-rst.cfg \ | ||
-f ${RV_ROOT}/testbench/openocd_scripts/jtag_cg.tcl | ||
- name: Prepare coverage data | ||
run: | | ||
export PATH=/opt/verilator/bin:$PATH | ||
export RV_ROOT=$(pwd) | ||
.github/scripts/convert_coverage_data.sh ${RV_ROOT}/run | ||
echo "convert_coverage_data.sh exited with RET_CODE = "$? | ||
mkdir -p results | ||
mv ${RV_ROOT}/run/coverage.info \ | ||
results/coverage_openocd_${{ matrix.bus }}_${{ matrix.coverage }}.info | ||
- name: Pack artifacts | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: openocd_coverage_data | ||
path: results/*.info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.