Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI for riscv-openocd. #2

Draft
wants to merge 30 commits into
base: riscv
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cf55ed7
Adding CI for riscv-openocd.
Dec 27, 2020
5a9d287
fix
Dec 30, 2020
3bebecd
fix 2
Dec 30, 2020
a856167
fix 3
Dec 30, 2020
9c69287
fix 4
Dec 30, 2020
f9a7224
fix 5
Dec 30, 2020
a37b822
Use depth=1 for git clone. Show revision after clone.
Jan 16, 2021
4979e1b
test
Jan 16, 2021
febd699
test 2
Jan 16, 2021
57fb88e
test 3
Jan 16, 2021
4bb98d0
test 4
Jan 16, 2021
7729e89
Added gcov-generated files to .gitignore
Mar 15, 2021
9bf770b
Changed toolchain to: xPack GNU RISC-V Embedded GCC v10.1.0-1.1
Mar 15, 2021
b586859
Empty commit to re-trigger the CI, attempt 2
Mar 16, 2021
22ee1b1
Temporary: Run the testing 10 times. Catch intermittent fails with hi…
Jun 8, 2021
21fa9c0
Temporary: extend job timeout for the purpose of experiments
Jun 9, 2021
6bb8b69
Temporary: Reduced the cycle count to 5 to meet Gitlab CI timeouts
Jun 10, 2021
70e082f
Run the tests just once
Nov 5, 2021
a51db61
Testing CI stability, run 1
JanMatCodasip Mar 16, 2022
e04eae7
Testing CI stability, run 2
JanMatCodasip Mar 16, 2022
efda985
Testing CI stability, run 3
JanMatCodasip Mar 16, 2022
b982b89
Testing CI stability, run 4
JanMatCodasip Mar 16, 2022
6b19d4e
Testing CI stability, run 5
JanMatCodasip Mar 16, 2022
7125373
Testing CI stability, run 6
JanMatCodasip Mar 16, 2022
f0aa461
Testing CI stability, run 7
JanMatCodasip Mar 16, 2022
e6b63d9
Testing CI stability, run 8
JanMatCodasip Mar 16, 2022
d621797
Testing CI stability, run 9
JanMatCodasip Mar 16, 2022
81057c1
Testing CI stability, run 10
JanMatCodasip Mar 16, 2022
c30b0b1
Testing CI stability, run 11
JanMatCodasip Mar 16, 2022
cf6a1d5
Testing CI stability, run 12
JanMatCodasip Mar 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/riscv-openocd-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: riscv-openocd-ci
on: [push]

jobs:

run-riscv-tests:
timeout-minutes: 720
runs-on: ubuntu-18.04
steps:

- name: Install required pkgs
run: |
sudo apt-get install libtool pkg-config autoconf automake libusb-1.0 libftdi1 lcov device-tree-compiler pylint3
sudo python3 -m pip install pexpect

- name: Checkout OpenOCD
uses: actions/checkout@v2

- name: Build OpenOCD
run: bash tools/riscv-openocd-ci/build_openocd.sh

- name: Checkout & build Spike
run: bash tools/riscv-openocd-ci/build_spike.sh

- name: Download RISC-V toolchain
run: bash tools/riscv-openocd-ci/download_toolchain.sh

- name: Update env. variables
# Change RISCV and PATH env variables. Needed for the next step.
run: |
echo "`pwd`/tools/riscv-openocd-ci/work/install/bin" >> $GITHUB_PATH
echo "RISCV=`pwd`/tools/riscv-openocd-ci/work/install" >> $GITHUB_ENV

- name: Checkout & run riscv-tests
timeout-minutes: 720
run: bash tools/riscv-openocd-ci/run_tests.sh

- name: Process test results
# If at least one test failed (or ended with an exception), this step fails.
run: |
cd tools/riscv-openocd-ci
python3 process_test_results.py --log-dir work/riscv-tests/debug/logs --output-dir work/results/logs

- name: Store test results
# Run even if there was a failed test
if: ${{ success() || failure() }}
uses: actions/upload-artifact@v2
with:
name: test-results
path: tools/riscv-openocd-ci/work/results/logs

- name: Collect OpenOCD code coverage
# Run even if there was a failed test
if: ${{ success() || failure() }}
run: |
lcov --capture --directory . --output-file tools/riscv-openocd-ci/work/openocd-coverage.info
genhtml tools/riscv-openocd-ci/work/openocd-coverage.info --output-directory tools/riscv-openocd-ci/work/results/openocd-coverage

- name: Store OpenOCD code coverage
# Run even if there was a failed test
if: ${{ success() || failure() }}
uses: actions/upload-artifact@v2
with:
name: openocd-coverage
path: tools/riscv-openocd-ci/work/results/openocd-coverage
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*.la
*.in

# coverage files (gcov)
*.gcda
*.gcno

# generated source files
src/jtag/minidriver_imp.h
src/jtag/jtag_minidriver.h
Expand Down
1 change: 1 addition & 0 deletions tools/riscv-openocd-ci/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
work
21 changes: 21 additions & 0 deletions tools/riscv-openocd-ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# CI for riscv-openocd

This directory contains a set of scripts that automatically
run [riscv-tests/debug](https://github.com/riscv/riscv-tests/tree/master/debug)
against riscv-openocd.

The scripts are intended to be called automatically by Github
Actions as a means of testing & continuous integration for riscv-openocd.

The scripts perform these actions:

- Build OpenOCD from source
- Checkout and build Spike (RISC-V ISA simulator) from source
- Download a pre-built RISC-V toolchain
- Use these components together to run
[riscv-tests/debug](https://github.com/riscv/riscv-tests/tree/master/debug)
- Process the test results
- Collect code coverage for OpenOCD

See [.github/workflows](../../.github/workflows) for an example of how this is
used in practice.
39 changes: 39 additions & 0 deletions tools/riscv-openocd-ci/build_openocd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

INSTALL_DIR=`pwd`/tools/riscv-openocd-ci/work/install

# Fail on first error.
set -e

# Echo commands.
set -o xtrace

# Assuming OpenOCD source is already checked-out in the current workdir.

# Show revision info
git --no-pager log --no-walk --pretty=short

./bootstrap

# Enable most frequently used JTAG drivers.
# Allow for code coverage collection.
./configure \
--enable-remote-bitbang \
--enable-jtag_vpi \
--enable-ftdi \
--prefix=$INSTALL_DIR \
CFLAGS="-O0 --coverage -fprofile-arcs -ftest-coverage" \
CXXFLAGS="-O0 --coverage -fprofile-arcs -ftest-coverage" \
LDFLAGS="-fprofile-arcs -lgcov"

# Patch OpenOCD so that coverage is recorded also when terminated
# by a signal.
git apply tools/riscv-openocd-ci/patches/openocd_gcov_flush.patch

# Build and install OpenOCD
make clean # safety
make -j`nproc`
make install

# Check that OpenOCD runs
$INSTALL_DIR/bin/openocd --version
29 changes: 29 additions & 0 deletions tools/riscv-openocd-ci/build_spike.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

CHECKOUT_DIR=`pwd`/tools/riscv-openocd-ci/work/riscv-isa-sim
INSTALL_DIR=`pwd`/tools/riscv-openocd-ci/work/install

# Fail on first error.
set -e

# Echo commands.
set -o xtrace

# Checkout Spike.
mkdir -p "$CHECKOUT_DIR"
cd "$CHECKOUT_DIR"
git clone --depth=1 --recursive https://github.com/riscv/riscv-isa-sim.git .

# Show revision info
git --no-pager log --no-walk --pretty=short

# Build Spike
mkdir build
cd build
bash ../configure --prefix=$INSTALL_DIR
make clean # safety
make -j`nproc`
make install

# Check that Spike runs
$INSTALL_DIR/bin/spike --help
48 changes: 48 additions & 0 deletions tools/riscv-openocd-ci/download_toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Toolchain builds provided by Embecosm (buildbot.embecosm.com)
# TOOLCHAIN_URL="https://buildbot.embecosm.com/job/riscv32-gcc-ubuntu1804"
# TOOLCHAIN_URL+="/25/artifact/riscv32-embecosm-gcc-ubuntu1804-20201108.tar.gz"
# TOOLCHAIN_PREFIX=riscv32-unknown-elf-

# Toolchain builds from "The xPack Project"
# (https://xpack.github.io/riscv-none-embed-gcc/)
TOOLCHAIN_URL="https://github.com/xpack-dev-tools/riscv-none-embed-gcc-xpack/"
TOOLCHAIN_URL+="releases/download/v10.1.0-1.1/"
TOOLCHAIN_URL+="xpack-riscv-none-embed-gcc-10.1.0-1.1-linux-x64.tar.gz"
TOOLCHAIN_PREFIX=riscv-none-embed-

ARCHIVE_NAME=${TOOLCHAIN_URL##*/}
DOWNLOAD_DIR=`pwd`/tools/riscv-openocd-ci/work
INSTALL_DIR=`pwd`/tools/riscv-openocd-ci/work/install

# Fail on first error.
set -e

# Echo commands.
set -o xtrace

# Download the toolchain.
# Use a pre-built toolchain binaries provided by Embecosm: https://buildbot.embecosm.com/
mkdir -p "$DOWNLOAD_DIR"
cd "$DOWNLOAD_DIR"
wget --progress dot:mega "$TOOLCHAIN_URL"

# Extract
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
tar xvf "$DOWNLOAD_DIR/$ARCHIVE_NAME" --strip-components=1

cd "$INSTALL_DIR/bin"

# Make symlinks so that the tools are accessible as riscv64-unknown-elf-*
if [ "$TOOLCHAIN_PREFIX" != "riscv64-unknown-elf-" ]; then
find . -name "$TOOLCHAIN_PREFIX*" | while read F; do
ln -s $F $(echo $F | sed -e "s/$TOOLCHAIN_PREFIX/riscv64-unknown-elf-/");
done
fi

# Check that the compiler and debugger can run, show versions
./riscv64-unknown-elf-gcc --version
./riscv64-unknown-elf-gdb --version

15 changes: 15 additions & 0 deletions tools/riscv-openocd-ci/patches/openocd_gcov_flush.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/src/server/server.c b/src/server/server.c
index 4e970fa8f..43bd9fb2e 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -725,6 +725,10 @@ void server_free(void)

void exit_on_signal(int sig)
{
+ /* dump coverage before being killed by the signal
+ * (otherwise gcov's *.gcda files would not be created) */
+ void __gcov_flush(void);
+ __gcov_flush();
#ifndef _WIN32
/* bring back default system handler and kill yourself */
signal(sig, SIG_DFL);
Loading