Skip to content

Commit 54efa26

Browse files
committed
Add a disabled builder for riscv64 rva23 emulated tests
This will run all tests for `riscv64a23-unknown-linux-gnu` in a QEMU instance.
1 parent 2a728f1 commit 54efa26

File tree

4 files changed

+189
-1
lines changed

4 files changed

+189
-1
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
FROM ubuntu:24.04
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
RUN apt-get update -y && apt-get install -y --no-install-recommends \
5+
bc \
6+
bzip2 \
7+
ca-certificates \
8+
cmake \
9+
cpio \
10+
curl \
11+
file \
12+
flex \
13+
bison \
14+
g++ \
15+
g++-riscv64-linux-gnu \
16+
git \
17+
libc6-dev \
18+
libc6-dev-riscv64-cross \
19+
libssl-dev \
20+
make \
21+
ninja-build \
22+
python3 \
23+
xz-utils \
24+
opensbi \
25+
u-boot-qemu \
26+
libslirp0 \
27+
build-essential \
28+
pkg-config \
29+
libglib2.0-dev \
30+
libpixman-1-dev \
31+
libsdl2-dev \
32+
libfdt-dev \
33+
python3 \
34+
python3-pip
35+
36+
ENV ARCH=riscv \
37+
CROSS_COMPILE=riscv64-linux-gnu-
38+
39+
WORKDIR /build
40+
41+
# From https://github.com/michaeljclark/busybear-linux/blob/master/conf/linux.config
42+
COPY host-x86_64/riscv64a23-gnu/linux.config /build
43+
44+
# qemu v10.0.2 fully support
45+
RUN curl https://gitlab.com/qemu-project/qemu/-/archive/v10.0.2/qemu-v10.0.2.tar.bz2 | tar xjf - && \
46+
cd qemu-v10.0.2 && \
47+
./configure --target-list=riscv64-softmmu \
48+
--enable-sdl --enable-debug --enable-fdt --enable-slirp && \
49+
make -j && make install
50+
51+
# use the opensbi fw from apt-get install
52+
RUN cp /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.bin /tmp
53+
54+
# Compile the kernel that we're going to be emulating with. This is
55+
# basically just done to be compatible with the QEMU target that we're going
56+
# to be using when running tests.
57+
RUN curl https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.6.97.tar.xz | tar xJf - && \
58+
cp linux.config linux-6.6.97/.config && \
59+
cd /build/linux-6.6.97 && \
60+
make olddefconfig && \
61+
make -j$(nproc) Image && \
62+
cp arch/riscv/boot/Image /tmp && \
63+
rm -rf linux-6.6.97
64+
65+
# Compile an instance of busybox as this provides a lightweight system and init
66+
# binary which we will boot into. Only trick here is configuring busybox to
67+
# build static binaries.
68+
RUN curl https://www.busybox.net/downloads/busybox-1.37.0.tar.bz2 | tar xjf - && \
69+
cd busybox-1.37.0 && \
70+
make defconfig && \
71+
sed -i 's/# CONFIG_STATIC is not set/CONFIG_STATIC=y/' .config && \
72+
sed -i 's/^CONFIG_TC=y$/# CONFIG_TC is not set/' .config && \
73+
sed -i 's/CONFIG_SHA1_HWACCEL=y/# CONFIG_SHA1_HWACCEL is not set/' .config && \
74+
sed -i 's/CONFIG_SHA256_HWACCEL=y/# CONFIG_SHA256_HWACCEL is not set/' .config && \
75+
make -j$(nproc) && \
76+
make install && \
77+
mv _install /tmp/rootfs && \
78+
cd /build && \
79+
rm -rf busybox-1.37.0
80+
81+
# Download the ubuntu rootfs, which we'll use as a chroot for all our tests.
82+
WORKDIR /tmp
83+
RUN mkdir rootfs/ubuntu
84+
RUN curl https://cdimage.ubuntu.com/ubuntu-base/releases/24.04/release/ubuntu-base-24.04.2-base-riscv64.tar.gz | \
85+
tar xzf - -C rootfs/ubuntu && \
86+
cd rootfs && mkdir proc sys dev etc etc/init.d
87+
88+
# Copy over our init script, which starts up our test server and also a few other
89+
# misc tasks
90+
COPY scripts/qemu-bare-bones-rcS rootfs/etc/init.d/rcS
91+
RUN chmod +x rootfs/etc/init.d/rcS
92+
93+
# Helper to quickly fill the entropy pool in the kernel
94+
COPY scripts/qemu-bare-bones-addentropy.c /tmp/addentropy.c
95+
RUN riscv64-linux-gnu-gcc addentropy.c -o rootfs/addentropy -static
96+
97+
COPY scripts/sccache.sh /scripts/
98+
RUN sh /scripts/sccache.sh
99+
100+
# Avoid "fatal: detected dubious ownership in repository at '/checkout'" error
101+
RUN git config --global --add safe.directory "*"
102+
103+
ENV RUST_CONFIGURE_ARGS \
104+
--set target.riscv64a23-unknown-linux-gnu.linker=riscv64-linux-gnu-gcc \
105+
--set target.riscv64a23-unknown-linux-gnu.qemu-rootfs=/tmp/rootfs
106+
ENV SCRIPT python3 ../x.py --stage 2 test --host='' --target riscv64a23-unknown-linux-gnu
107+
108+
ENV NO_CHANGE_USER=1
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
CONFIG_DEFAULT_HOSTNAME="busybear"
2+
CONFIG_SYSVIPC=y
3+
CONFIG_POSIX_MQUEUE=y
4+
CONFIG_IKCONFIG=y
5+
CONFIG_IKCONFIG_PROC=y
6+
CONFIG_CGROUPS=y
7+
CONFIG_CGROUP_SCHED=y
8+
CONFIG_CFS_BANDWIDTH=y
9+
CONFIG_CGROUP_BPF=y
10+
CONFIG_NAMESPACES=y
11+
CONFIG_USER_NS=y
12+
CONFIG_CHECKPOINT_RESTORE=y
13+
CONFIG_BLK_DEV_INITRD=y
14+
CONFIG_EXPERT=y
15+
CONFIG_BPF_SYSCALL=y
16+
CONFIG_SMP=y
17+
CONFIG_MODULES=y
18+
CONFIG_NET=y
19+
CONFIG_PACKET=y
20+
CONFIG_PACKET_DIAG=y
21+
CONFIG_UNIX=y
22+
CONFIG_INET=y
23+
CONFIG_NETLINK_DIAG=y
24+
# CONFIG_WIRELESS is not set
25+
CONFIG_PCI=y
26+
CONFIG_DEVTMPFS=y
27+
CONFIG_BLK_DEV_LOOP=y
28+
CONFIG_VIRTIO_BLK=y
29+
CONFIG_NETDEVICES=y
30+
CONFIG_VIRTIO_NET=y
31+
# CONFIG_ETHERNET is not set
32+
# CONFIG_WLAN is not set
33+
CONFIG_SERIAL_8250=y
34+
CONFIG_SERIAL_8250_CONSOLE=y
35+
CONFIG_SERIAL_OF_PLATFORM=y
36+
CONFIG_HVC_RISCV_SBI=y
37+
# CONFIG_HW_RANDOM is not set
38+
# CONFIG_USB_SUPPORT is not set
39+
CONFIG_VIRTIO_MMIO=y
40+
CONFIG_SIFIVE_PLIC=y
41+
CONFIG_RAS=y
42+
CONFIG_EXT2_FS=y
43+
CONFIG_EXT3_FS=y
44+
CONFIG_EXT4_FS_POSIX_ACL=y
45+
CONFIG_AUTOFS4_FS=y
46+
CONFIG_MSDOS_FS=y
47+
CONFIG_VFAT_FS=y
48+
CONFIG_TMPFS=y
49+
# CONFIG_CRYPTO_ECHAINIV is not set
50+
# CONFIG_CRYPTO_HW is not set
51+
CONFIG_PRINTK_TIME=y

src/tools/build-manifest/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static HOSTS: &[&str] = &[
4040
"powerpc64le-unknown-linux-gnu",
4141
"powerpc64le-unknown-linux-musl",
4242
"riscv64gc-unknown-linux-gnu",
43+
"riscv64a23-unknown-linux-gnu",
4344
"s390x-unknown-linux-gnu",
4445
"sparcv9-sun-solaris",
4546
"x86_64-apple-darwin",
@@ -155,6 +156,7 @@ static TARGETS: &[&str] = &[
155156
"riscv64gc-unknown-none-elf",
156157
"riscv64gc-unknown-linux-gnu",
157158
"riscv64gc-unknown-linux-musl",
159+
"riscv64a23-unknown-linux-gnu",
158160
"s390x-unknown-linux-gnu",
159161
"sparc64-unknown-linux-gnu",
160162
"sparcv9-sun-solaris",

src/tools/remote-test-client/src/main.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ fn prepare_rootfs(target: &str, rootfs: &Path, server: &Path, rootfs_img: &Path)
111111
"arm-unknown-linux-gnueabihf" | "aarch64-unknown-linux-gnu" => {
112112
prepare_rootfs_cpio(rootfs, rootfs_img)
113113
}
114-
"riscv64gc-unknown-linux-gnu" => prepare_rootfs_ext4(rootfs, rootfs_img),
114+
"riscv64a23-unknown-linux-gnu" | "riscv64gc-unknown-linux-gnu" => {
115+
prepare_rootfs_ext4(rootfs, rootfs_img)
116+
}
115117
_ => panic!("{} is not supported", target),
116118
}
117119
}
@@ -234,6 +236,31 @@ fn start_qemu_emulator(target: &str, rootfs: &Path, server: &Path, tmpdir: &Path
234236
.arg(&format!("file={},format=raw,id=hd0", &rootfs_img.to_string_lossy()));
235237
t!(cmd.spawn());
236238
}
239+
"riscv64a23-unknown-linux-gnu" => {
240+
let mut cmd = Command::new("qemu-system-riscv64");
241+
cmd.arg("-nographic")
242+
.arg("-machine")
243+
.arg("virt")
244+
.arg("-cpu")
245+
.arg("rva23s64")
246+
.arg("-m")
247+
.arg("1024")
248+
.arg("-bios")
249+
.arg("/tmp/fw_jump.bin")
250+
.arg("-kernel")
251+
.arg("/tmp/Image")
252+
.arg("-append")
253+
.arg("quiet console=ttyS0 root=/dev/vda rw")
254+
.arg("-netdev")
255+
.arg("user,id=net0,hostfwd=tcp::12345-:12345")
256+
.arg("-device")
257+
.arg("virtio-net-device,netdev=net0,mac=00:00:00:00:00:00")
258+
.arg("-device")
259+
.arg("virtio-blk-device,drive=hd0")
260+
.arg("-drive")
261+
.arg(&format!("file={},format=raw,id=hd0,if=none", &rootfs_img.to_string_lossy()));
262+
t!(cmd.spawn());
263+
}
237264
_ => panic!("cannot start emulator for: {}", target),
238265
}
239266
}

0 commit comments

Comments
 (0)