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

CI: test workflow #1

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a5e6db9
Fix incorrect condition in background thread
vacantron Jul 3, 2024
2436ecb
Merge pull request #465 from vacantron/develop
jserv Jul 3, 2024
66dec82
Fix typo and remove outdated comment
henrybear327 Jul 3, 2024
cf69d83
Update dhrystone.elf and coremark.elf
henrybear327 Jun 16, 2024
2ee375b
Add coremark arguments
henrybear327 Jul 8, 2024
0e13f01
Move benchmark run to main.yml file
henrybear327 Jul 9, 2024
9f5c057
Merge pull request #468 from henrybear327/fix/typo
jserv Jul 10, 2024
a2e3aaa
Merge pull request #460 from henrybear327/ci/fix_benchmark_pipeline
jserv Jul 10, 2024
9759ad2
CI: Reintroduce benchmark.yml (#469)
henrybear327 Jul 10, 2024
65fdaef
Improve "JALR" execution with T2C JIT-cache
vacantron Aug 1, 2024
f5d04fb
CI: RISCOF workaround
vacantron Aug 4, 2024
34c3db0
Merge pull request #471 from vacantron/t2c/jalr
jserv Aug 7, 2024
7aebf4e
Add testbenches
vacantron Aug 8, 2024
8cc9bbf
Fix missing header of "spirograph"
vacantron Aug 14, 2024
0f1ad98
Add benchmark scripts
vacantron Aug 14, 2024
f8e2422
Trim executables
vacantron Aug 14, 2024
69dc153
Add GitHub workflow for building executables
vacantron Aug 16, 2024
8a1b74a
Update document for prebuilt executables
vacantron Aug 17, 2024
039574b
Update top-level Makefile
vacantron Aug 17, 2024
2786803
Use wget instead of curl
vacantron Aug 17, 2024
57c80c9
Update toolchain installation
vacantron Aug 18, 2024
e250778
Update CI and prebuilt file destination
vacantron Aug 18, 2024
714c758
Update submodules
vacantron Aug 18, 2024
39bbdd3
Update .gitignore
vacantron Aug 18, 2024
4d4c0e3
Update path
vacantron Aug 18, 2024
cd13e36
Force CI
vacantron Aug 18, 2024
08d3889
Fix typo
vacantron Aug 18, 2024
085e266
Update bash script
vacantron Aug 18, 2024
c981733
Update target name
vacantron Aug 18, 2024
d6a2d93
Fix incorrect tar command
vacantron Aug 18, 2024
bab4834
Force CI
vacantron Aug 18, 2024
64ac255
Update path
vacantron Aug 18, 2024
c954d36
Update submodules
vacantron Aug 18, 2024
3cda162
Fix incorrect CROSS_COMPILE
vacantron Aug 18, 2024
512acf7
Fix incorrect script
vacantron Aug 18, 2024
2fdfa6a
Update mk
vacantron Aug 18, 2024
b69c020
Fix GDB script
vacantron Aug 18, 2024
d226777
Update toolchain path
vacantron Aug 18, 2024
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
12 changes: 6 additions & 6 deletions .ci/gdbstub-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

set -e -u -o pipefail

export PATH=`pwd`/toolchain/riscv/bin:$PATH
export PATH=`pwd`/toolchain/bin:$PATH

GDB=
prefixes=("${CROSS_COMPILE}" "riscv32-unknown-elf" "riscv-none-elf")
prefixes=("${CROSS_COMPILE}" "riscv32-unknown-elf-" "riscv-none-elf-")
for prefix in "${prefixes[@]}"; do
utility=${prefix}-gdb
utility=${prefix}gdb
set +e # temporarily disable exit on error
command -v "${utility}" &> /dev/null
if [[ $? == 0 ]]; then
Expand All @@ -21,7 +21,7 @@ if [ -z ${GDB} ]; then
exit 1
fi

build/rv32emu -g build/puzzle.elf &
build/rv32emu -g build/riscv32/puzzle &
PID=$!

# Before starting GDB, we should ensure rv32emu is still running.
Expand All @@ -31,9 +31,9 @@ fi

OPTS=
tmpfile=/tmp/rv32emu-gdbstub.$PID
breakpoints=(0x10700 0x10800 0x10900)
breakpoints=(0x10500 0x10600 0x10700)
bkpt_count=${#breakpoints[@]}
OPTS+="-ex 'file build/puzzle.elf' "
OPTS+="-ex 'file build/riscv32/puzzle' "
OPTS+="-ex 'target remote :1234' "
for t in ${breakpoints[@]}; do
OPTS+="-ex 'break *$t' "
Expand Down
4 changes: 2 additions & 2 deletions .ci/riscv-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
set -e -u -o pipefail

# Install RISCOF
python3 -m pip install git+https://github.com/riscv/riscof
pip3 install git+https://github.com/riscv/riscof.git@d38859f85fe407bcacddd2efcd355ada4683aee4

set -x

export PATH=`pwd`/toolchain/riscv/bin:$PATH
export PATH=`pwd`/toolchain/bin:$PATH

make clean
make arch-test RISCV_DEVICE=IMAFCZicsrZifencei || exit 1
Expand Down
17 changes: 11 additions & 6 deletions .ci/riscv-toolchain-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ check_platform

mkdir -p toolchain

# GNU Toolchain for RISC-V
GCC_VER=2024.04.12
TOOLCHAIN_REPO=https://github.com/riscv-collab/riscv-gnu-toolchain/releases
if [[ "$#" = 0 ]] || [[ "$1" != "riscv-collab" ]]; then
GCC_VER=14.2.0-1
TOOLCHAIN_REPO=https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack
TOOLCHAIN_URL=${TOOLCHAIN_REPO}/releases/download/v${GCC_VER}/xpack-riscv-none-elf-gcc-${GCC_VER}-linux-x64.tar.gz
else
UBUNTU_VER=`lsb_release -r | cut -f2`
GCC_VER=2024.04.12
TOOLCHAIN_REPO=https://github.com/riscv-collab/riscv-gnu-toolchain
TOOLCHAIN_URL=${TOOLCHAIN_REPO}/releases/download/${GCC_VER}/riscv32-elf-ubuntu-${UBUNTU_VER}-gcc-nightly-${GCC_VER}-nightly.tar.gz
fi

wget -q \
${TOOLCHAIN_REPO}/download/${GCC_VER}/riscv32-elf-ubuntu-22.04-gcc-nightly-${GCC_VER}-nightly.tar.gz -O- \
| tar -C toolchain -xz
wget -q ${TOOLCHAIN_URL} -O- | tar -C toolchain --strip-components=1 -xz
6 changes: 3 additions & 3 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
benchmark:
name: Performance regression check
if: contains(toJSON(github.event.head_commit.message), 'Merge pull request ') == false
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Test changed files
Expand All @@ -23,12 +23,12 @@ jobs:
if: ${{ steps.changed-files.outputs.any_changed == 'true' ||
github.event_name == 'workflow_dispatch'}}
run: |
sudo pip3 install numpy
sudo pip3 install numpy --break-system-packages
shell: bash
- name: default build
if: ${{ steps.changed-files.outputs.any_changed == 'true' ||
github.event_name == 'workflow_dispatch'}}
run: make
run: make ENABLE_SDL=0
- name: Run benchmark
if: ${{ steps.changed-files.outputs.any_changed == 'true' ||
github.event_name == 'workflow_dispatch'}}
Expand Down
68 changes: 68 additions & 0 deletions .github/workflows/build-artifact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Build artifact

on:
push:
branches:
- master
- dev
workflow_dispatch:

jobs:
detect-files-changed:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: 'true'
- name: Test files changed
id: files-changed
uses: tj-actions/changed-files@v44
with:
fetch_additional_submodule_history: 'true'
files: |
tests/ansibench/*
tests/rv8-bench/*
tests/*.c
- name: Set alias
id: has_files_changed
run: |
if [[ ${{ steps.files-changed.outputs.any_changed }} == true ]]; then
echo "has_files_changed=true" >> $GITHUB_OUTPUT
else
echo "has_files_changed=false" >> $GITHUB_OUTPUT
fi
outputs:
has_files_changed: ${{ steps.has_files_changed.outputs.has_files_changed }}

build-artifact:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: 'true'
- name: Install dependencies
run: |
sudo apt-get update -q -y
sudo apt-get upgrade -q -y
sudo apt-get install -q -y gcc-multilib g++-multilib
.ci/riscv-toolchain-install.sh
echo "$PWD/toolchain/bin" >> $GITHUB_PATH
- name: Build binaries
run: |
make build-artifact USE_PREBUILT=0
- name: Create tarball
run: |
tar -C build -zcf rv32emu-prebuilt.tar.gz linux-x64 riscv32
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.RV32EMU_PREBUILT_TOKEN }}
run: |
RELEASE_TAG="2024.08.16"
gh release create $RELEASE_TAG \
--repo sysprog21/rv32emu-prebuilt \
--title "$RELEASE_TAG""-nightly"
gh release upload $RELEASE_TAG \
rv32emu-prebuilt.tar.gz \
--repo sysprog21/rv32emu-prebuilt
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ build/softfloat
build/cache/
build/map/
build/path/
build/linux-x64/
build/riscv32/
*.o
*.o.d
tests/**/*.elf
Expand Down
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@
url = https://github.com/sysprog21/berkeley-softfloat-3
branch = rv32emu
shallow = true
[submodule "tests/ansibench"]
path = tests/ansibench
url = https://github.com/sysprog21/ansibench
shallow = true
[submodule "tests/rv8-bench"]
path = tests/rv8-bench
url = https://github.com/sysprog21/rv8-bench
shallow = true
25 changes: 12 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ $(OUT)/emulate.o: CFLAGS += -foptimize-sibling-calls -fomit-frame-pointer -fno-s
.DEFAULT_GOAL := all

include mk/external.mk

include mk/artifact.mk
include mk/wasm.mk

all: config $(BIN)
Expand Down Expand Up @@ -229,36 +229,35 @@ tool: $(TOOLS_BIN)
include mk/riscv-arch-test.mk
include mk/tests.mk

CHECK_ELF_FILES := \
hello \
puzzle \
fcalc
# the prebuilt executables are built for "rv32im"
CHECK_ELF_FILES :=

ifeq ($(call has, EXT_M), 1)
CHECK_ELF_FILES += \
puzzle \
fcalc \
pi
endif

EXPECTED_hello = Hello World!
EXPECTED_puzzle = success in 2005 trials
EXPECTED_fcalc = Performed 12 tests, 0 failures, 100% success rate.
EXPECTED_pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086

check: $(BIN)
check: $(BIN) build-artifact
$(Q)$(foreach e,$(CHECK_ELF_FILES),\
$(PRINTF) "Running $(e).elf ... "; \
if [ "$(shell $(BIN) $(OUT)/$(e).elf | uniq)" = "$(strip $(EXPECTED_$(e))) inferior exit code 0" ]; then \
$(PRINTF) "Running $(e) ... "; \
if [ "$(shell $(BIN) $(OUT)/riscv32/$(e) | uniq)" = "$(strip $(EXPECTED_$(e))) inferior exit code 0" ]; then \
$(call notice, [OK]); \
else \
$(PRINTF) "Failed.\n"; \
exit 1; \
fi; \
)

EXPECTED_aes_sha1 = 1242a6757c8aef23e50b5264f5941a2f4b4a347e -
misalign: $(BIN)
$(Q)$(PRINTF) "Running aes.elf ... ";
$(Q)if [ "$(shell $(BIN) -m $(OUT)/aes.elf | $(SHA1SUM))" = "$(EXPECTED_aes_sha1)" ]; then \
EXPECTED_aes_sha1 = f9924635666d3d58d5b60c0bde8b986a2a99effb -
misalign: $(BIN) build-artifact
$(Q)$(PRINTF) "Running aes ... ";
$(Q)if [ "$(shell $(BIN) -m $(OUT)/riscv32/aes | $(SHA1SUM))" = "$(EXPECTED_aes_sha1)" ]; then \
$(call notice, [OK]); \
else \
$(PRINTF) "Failed.\n"; \
Expand Down
50 changes: 20 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,46 +327,36 @@ Use of this source code is governed by a MIT license that can be found in the [L

## External sources

In `rv32emu` repository, there are some prebuilt ELF files for testing purpose.
* `aes.elf` : See [tests/aes.c](tests/aes.c)
* `captcha.elf` : See [tests/captcha.c](tests/captcha.c)
There are some prebuilt executables in [rv32emu-prebuilt](https://github.com/sysprog21/rv32emu-prebuilt) for testing and benchmarking purpose.
The prebuilt executables are built from GNU/GCC v9 and [xPack GCC v14.2.0-1](https://github.com/xpack-dev-tools/gcc-xpack) under Ubuntu-20.04.

To fetch the prebuilt executables, run the following command:

```shell
$ make build-artifact
```

Or, to compile the executables from the source, run:

```shell
$ make build-artifact USE_PREBUILT=0
```

Notice that the RISC-V cross-compiler is required to build the binary.

In default, `rv32emu` will download the tarball from GitHub and extract the executables into `build/`.

There are still some prebuilt ELF files for testing purpose under `build/`.
* `cc.elf` : See [tests/cc](tests/cc)
* `chacha20.elf` : See [tests/chacha20](tests/chacha20)
* `coremark.elf` : See [eembc/coremark](https://github.com/eembc/coremark) [RV32M]
* `dhrystone.elf` : See [rv8-bench](https://github.com/michaeljclark/rv8-bench)
* `donut.elf` : See [donut.c](tests/donut.c)
* `doom.elf` : See [sysprog21/doom_riscv](https://github.com/sysprog21/doom_riscv) [RV32M]
* `fcalc.elf` : See [fcalc.c](tests/fcalc.c)
* `hamilton.elf` : See [hamilton.c](tests/hamilton.c)
* `ieee754.elf` : See [tests/ieee754.c](tests/ieee754.c) [RV32F]
* `jit-bf.elf` : See [ezaki-k/xkon_beta](https://github.com/ezaki-k/xkon_beta)
* `lena.elf`: See [tests/lena.c](tests/lena.c)
* `line.elf` : See [tests/line.c](tests/line.c) [RV32M]
* `maj2random.elf` : See [tests/maj2random.c](tests/maj2random.c) [RV32F]
* `mandelbrot.elf` : See [tests/mandelbrot.c](tests/mandelbrot.c)
* `nqueens.elf` : See [tests/nqueens.c](tests/nqueens.c)
* `nyancat.elf` : See [tests/nyancat.c](tests/nyancat.c)
* `pi.elf` : See [tests/pi.c](tests/pi.c) [RV32M]
* `qrcode.elf` : See [tests/qrcode.c](tests/qrcode.c)
* `quake.elf` : See [sysprog21/quake-embedded](https://github.com/sysprog21/quake-embedded) [RV32F]
* `readelf.elf` : See [tests/readelf](tests/readelf)
* `richards.elf` : See [tests/richards.c](tests/richards.c)
* `rvsim.elf` : See [tests/rvsim.c](tests/rvsim.c)
* `scimark2.elf` : See [tests/scimark2](tests/scimark2) [RV32MF]
* `smolnes.elf` : See [tests/smolnes](tests/smolnes.c) [RV32M]
* `spirograph.elf` : See [tests/spirograph.c](tests/spirograph.c)
* `stream.elf` : See [tests/stream](tests/stream.c) [RV32MF]
* `qsort.elf` : See [rv8-bench](https://github.com/michaeljclark/rv8-bench)
* `miniz.elf` : See [rv8-bench](https://github.com/michaeljclark/rv8-bench)
* `primes.elf` : See [rv8-bench](https://github.com/michaeljclark/rv8-bench)
* `sha512.elf` : See [rv8-bench](https://github.com/michaeljclark/rv8-bench)
* `numeric_sort.elf` : See [nbench](https://github.com/nfinit/ansibench/tree/master/nbench)
* `FP_emulation.elf` : See [nbench](https://github.com/nfinit/ansibench/tree/master/nbench)
* `bitfield.elf` : See [nbench](https://github.com/nfinit/ansibench/tree/master/nbench)
* `idea.elf` : See [nbench](https://github.com/nfinit/ansibench/tree/master/nbench)
* `assignment.elf` : See [nbench](https://github.com/nfinit/ansibench/tree/master/nbench)
* `string_sort.elf` : See [nbench](https://github.com/nfinit/ansibench/tree/master/nbench)
* `huffman.elf` : See [nbench](https://github.com/nfinit/ansibench/tree/master/nbench)
## Reference

* [Writing a simple RISC-V emulator in plain C](https://fmash16.github.io/content/posts/riscv-emulator-in-c.html)
Expand Down
Binary file removed build/FP_emulation.elf
Binary file not shown.
Binary file removed build/aes.elf
Binary file not shown.
Binary file removed build/assignment.elf
Binary file not shown.
Binary file removed build/bitfield.elf
Binary file not shown.
Binary file removed build/captcha.elf
Binary file not shown.
Binary file removed build/coremark.elf
Binary file not shown.
Binary file removed build/dhrystone.elf
Binary file not shown.
Binary file removed build/donut.elf
Binary file not shown.
Binary file removed build/fcalc.elf
Binary file not shown.
Binary file added build/fibonacci.elf
Binary file not shown.
Binary file removed build/hamilton.elf
Binary file not shown.
Binary file removed build/huffman.elf
Binary file not shown.
Binary file removed build/idea.elf
Binary file not shown.
Binary file removed build/lena.elf
Binary file not shown.
Binary file removed build/line.elf
Binary file not shown.
Binary file removed build/maj2random.elf
Binary file not shown.
Binary file removed build/mandelbrot.elf
Binary file not shown.
Binary file removed build/miniz.elf
Binary file not shown.
Binary file removed build/nqueens.elf
Binary file not shown.
Binary file removed build/numeric_sort.elf
Binary file not shown.
Binary file removed build/nyancat.elf
Binary file not shown.
Binary file removed build/pi.elf
Binary file not shown.
Binary file removed build/primes.elf
Binary file not shown.
Binary file removed build/puzzle.elf
Binary file not shown.
Binary file removed build/qrcode.elf
Binary file not shown.
Binary file removed build/qsort.elf
Binary file not shown.
Binary file removed build/richards.elf
Binary file not shown.
Binary file removed build/rvsim.elf
Binary file not shown.
Binary file removed build/sha512.elf
Binary file not shown.
Binary file removed build/spirograph.elf
Binary file not shown.
Binary file removed build/stream.elf
Binary file not shown.
Binary file removed build/string_sort.elf
Binary file not shown.
56 changes: 56 additions & 0 deletions mk/artifact.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
USE_PREBUILT ?= 1

CC ?= gcc
CROSS_COMPILE ?= riscv-none-elf-

BINDIR := $(abspath $(OUT))

TEST_SUITES += \
ansibench \
rv8-bench

# "ieee754" needs F extension
# "smolnes", "ticks" have inline assembly and only work in riscv
TESTBENCHES += \
captcha \
donut \
fcalc \
hamilton \
$(ieee754) \
jit \
lena \
line \
maj2random \
mandelbrot \
nqueens \
nyancat \
pi \
puzzle \
qrcode \
richards \
rvsim \
$(smolnes) \
spirograph \
$(ticks)

ifeq ($(USE_PREBUILT),1)
LATEST_RELEASE := $(shell wget -q https://api.github.com/repos/sysprog21/rv32emu-prebuilt/releases/latest -O- | grep -Po '(?<="tag_name": ").+(?=",)')
endif

.PHONY: build-artifact

build-artifact:
ifeq ($(USE_PREBUILT),1)
@echo "Fetching prebuilt executables in \"rv32emu-prebuilt\"..."
@wget -q https://github.com/sysprog21/rv32emu-prebuilt/releases/download/$(LATEST_RELEASE)/rv32emu-prebuilt.tar.gz -O- | tar -C build -xz
else
@$(foreach tb,$(TEST_SUITES), \
git submodule update --init ./tests/$(tb) &&) true
@$(foreach tb,$(TEST_SUITES), \
$(MAKE) -C ./tests/$(tb) all BINDIR=$(BINDIR) &&) true
@$(foreach tb,$(TESTBENCHES), \
$(CC) -m32 -O2 -Wno-unused-result -o $(BINDIR)/linux-x64/$(tb) tests/$(tb).c -lm &&) true
@$(foreach tb,$(TESTBENCHES), \
$(CROSS_COMPILE)gcc -march=rv32im -mabi=ilp32 -O2 -Wno-unused-result -Wno-implicit-function-declaration \
-o $(BINDIR)/riscv32/$(tb) tests/$(tb).c -lm -lsemihost &&) true
endif
2 changes: 1 addition & 1 deletion src/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ RV_EXCEPTION_LIST
return false; \
}

/* get current time in microsecnds and update csr_time register */
/* get current time in microseconds and update csr_time register */
static inline void update_time(riscv_t *rv)
{
struct timeval tv;
Expand Down
1 change: 1 addition & 0 deletions src/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,7 @@ static void code_cache_flush(struct jit_state *state, riscv_t *rv)
state->offset = state->org_size;
state->n_blocks = 0;
set_reset(&state->set);
jit_cache_clear(rv->jit_cache);
clear_cache_hot(rv->block_cache, (clear_func_t) clear_hot);
return;
}
Expand Down
Loading
Loading