Skip to content

Commit

Permalink
Merge pull request #238 from chipsalliance/main
Browse files Browse the repository at this point in the history
Reintegrate main -> dev-public
  • Loading branch information
calebofearth authored Oct 3, 2023
2 parents 18e8501 + 440a21d commit 5608dfa
Show file tree
Hide file tree
Showing 867 changed files with 73,716 additions and 231,626 deletions.
9 changes: 8 additions & 1 deletion .github/scripts/build_tests_matrix.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
import os
import yaml

def main():
Expand All @@ -8,6 +9,10 @@ def main():
with open(file_name, "r") as fp:
yaml_root = yaml.safe_load(fp)

# Get excluded test list
excluded = os.environ.get("EXCLUDE_TESTS", "")
excluded = [s.strip() for s in excluded.strip().split(",")]

# Get test list
content = yaml_root["contents"][0]
tests = content["tests"]
Expand All @@ -20,7 +25,9 @@ def main():

for i, part in enumerate(parts):
if part == "test_suites" and i + 1 < len(parts):
test_list.append(parts[i+1])
test_name = parts[i+1]
if test_name not in excluded:
test_list.append(test_name)
break

# Output names
Expand Down
87 changes: 87 additions & 0 deletions .github/scripts/gdb_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
#
# 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`

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}
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/Vcaliptra_top_tb >"${SIM_LOG}" 2>&1 &
SIM_PID=$!

# Wait
wait_for_phrase "${SIM_LOG}" "CLP: ROM Flow in progress..."
if [ $? -ne 0 ]; then
echo -e "${COLOR_RED}Failed to start the simulation!${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 ${CALIPTRA_ROOT}/tools/scripts/openocd && openocd -d2 -f 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}

68 changes: 68 additions & 0 deletions .github/scripts/openocd_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash
#
# 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/Vcaliptra_top_tb >"${SIM_LOG}" 2>&1 &
SIM_PID=$!

# Wait
wait_for_phrase "${SIM_LOG}" "CLP: ROM Flow in progress..."
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 5s

# Run the test
echo -e "${COLOR_WHITE}======== Running OpenOCD test '$@' ========${COLOR_OFF}"
cd ${CALIPTRA_ROOT}/tools/scripts/openocd && 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

sleep 1s

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

# Display logs
print_logs

# Honor the exitcode
exit ${EXITCODE}

49 changes: 49 additions & 0 deletions .github/scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# 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
}
36 changes: 7 additions & 29 deletions .github/workflows/build-test-verilator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,18 @@ env:
CARGO_INCREMENTAL: 0
SCCACHE_VERSION: 0.3.3
RISCV_VERSION: v12.1.0
# TODO: To update to 5.006, clean up lint errors
VERILATOR_VERSION: v5.002
VERILATOR_VERSION: v5.012
PKG_CONFIG_PATH: /opt/verilator/share/pkgconfig
SCCACHE_GHA_CACHE_TO: sccache-verilator-10000
SCCACHE_GHA_CACHE_FROM: sccache-verilator-
# Change this to a new random value if you suspect the cache is corrupted
SCCACHE_C_CUSTOM_CACHE_BUSTER: f3e6951f0c1d

jobs:
build_matrix:
name: Build Smoke Test matrix
build_tools:
name: Build Tools
runs-on: ubuntu-22.04
outputs:
test_names: ${{ steps.output-matrix.outputs.test_names }}
steps:
- uses: actions/checkout@v3
- name: Install deps
run: |
sudo apt-get update -qy && sudo apt-get install -qy --no-install-recommends \
python3-minimal python3-yaml
- name: Build matrix
id: output-matrix
run: |
echo "test_names=$(python3 .github/scripts/build_tests_matrix.py)" >> $GITHUB_OUTPUT
build_and_test:
name: Verilator Smoke Test
runs-on: ubuntu-22.04
needs: build_matrix

strategy:
fail-fast: false
matrix:
test_name: ${{fromJSON(needs.build_matrix.outputs.test_names)}}


steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -145,6 +122,8 @@ jobs:
needs: build_tools
outputs:
test_names: ${{ steps.output-matrix.outputs.test_names }}
env:
EXCLUDE_TESTS: "smoke_test_clk_gating, smoke_test_cg_wdt, smoke_test_mbox_cg, smoke_test_kv_cg, smoke_test_doe_cg"
steps:
- uses: actions/checkout@v3
- name: Install deps
Expand All @@ -157,7 +136,7 @@ jobs:
echo "test_names=$(python3 .github/scripts/build_tests_matrix.py)" >> $GITHUB_OUTPUT
build_and_test:
name: Verilator Smoke Test
name: Verilator
runs-on: ubuntu-22.04
needs: build_matrix

Expand Down Expand Up @@ -211,7 +190,6 @@ jobs:
run: |
CALIPTRA_ROOT=$(pwd)
cd tools/scripts
make verilator CALIPTRA_ROOT=$CALIPTRA_ROOT TESTNAME=${{ matrix.test_name }} | tee output.log
# Search the last 30 lines of the output for "TESTCASE PASSED"
tail -n 30 output.log | grep "TESTCASE PASSED"
Expand Down
Loading

0 comments on commit 5608dfa

Please sign in to comment.