Skip to content

Commit 77efcab

Browse files
authored
Rollup merge of #73171 - tblah:riscv-qemu-test, r=pietroalbini
RISC-V Emulated Testing Adds a disabled docker image on which to run RISC-V tests. Based on the armhf image. Test using ``` ./src/ci/docker/run.sh riscv64gc-linux ``` cc: @msizanoen1
2 parents 913aac8 + 086eaf8 commit 77efcab

File tree

7 files changed

+322
-17
lines changed

7 files changed

+322
-17
lines changed

src/bootstrap/configure.py

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ def v(*args):
141141
"rootfs in qemu testing, you probably don't want to use this")
142142
v("qemu-aarch64-rootfs", "target.aarch64-unknown-linux-gnu.qemu-rootfs",
143143
"rootfs in qemu testing, you probably don't want to use this")
144+
v("qemu-riscv64-rootfs", "target.riscv64gc-unknown-linux-gnu.qemu-rootfs",
145+
"rootfs in qemu testing, you probably don't want to use this")
144146
v("experimental-targets", "llvm.experimental-targets",
145147
"experimental LLVM targets to build")
146148
v("release-channel", "rust.channel", "the name of the release channel to build")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
From c820da85c65c7f3aa9e9cb3ed71ada69bf9b783e Mon Sep 17 00:00:00 2001
2+
From: Alistair Francis <[email protected]>
3+
Date: Tue, 19 Nov 2019 13:06:40 +0100
4+
Subject: [PATCH] Remove stime() function calls
5+
6+
stime() has been deprecated in glibc 2.31 and replaced with
7+
clock_settime(). Let's replace the stime() function calls with
8+
clock_settime() in preperation.
9+
10+
function old new delta
11+
rdate_main 197 224 +27
12+
clock_settime - 27 +27
13+
date_main 926 941 +15
14+
stime 37 - -37
15+
------------------------------------------------------------------------------
16+
(add/remove: 2/2 grow/shrink: 2/0 up/down: 69/-37) Total: 32 bytes
17+
18+
Signed-off-by: Alistair Francis <[email protected]>
19+
Signed-off-by: Denys Vlasenko <[email protected]>
20+
21+
[Tom Eccles: adjust patch context to apply on top of 1.31.1-stable]
22+
Signed-off-by: Tom Eccles <[email protected]>
23+
---
24+
coreutils/date.c | 6 +++++-
25+
libbb/missing_syscalls.c | 8 --------
26+
util-linux/rdate.c | 8 ++++++--
27+
3 files changed, 11 insertions(+), 11 deletions(-)
28+
29+
diff --git a/coreutils/date.c b/coreutils/date.c
30+
index 3414d38ae..4ade6abb4 100644
31+
--- a/coreutils/date.c
32+
+++ b/coreutils/date.c
33+
@@ -279,6 +279,9 @@ int date_main(int argc UNUSED_PARAM, char **argv)
34+
time(&ts.tv_sec);
35+
#endif
36+
}
37+
+#if !ENABLE_FEATURE_DATE_NANO
38+
+ ts.tv_nsec = 0;
39+
+#endif
40+
localtime_r(&ts.tv_sec, &tm_time);
41+
42+
/* If date string is given, update tm_time, and maybe set date */
43+
@@ -301,9 +304,10 @@ int date_main(int argc UNUSED_PARAM, char **argv)
44+
if (date_str[0] != '@')
45+
tm_time.tm_isdst = -1;
46+
ts.tv_sec = validate_tm_time(date_str, &tm_time);
47+
+ ts.tv_nsec = 0;
48+
49+
/* if setting time, set it */
50+
- if ((opt & OPT_SET) && stime(&ts.tv_sec) < 0) {
51+
+ if ((opt & OPT_SET) && clock_settime(CLOCK_REALTIME, &ts) < 0) {
52+
bb_perror_msg("can't set date");
53+
}
54+
}
55+
diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c
56+
index 87cf59b3d..dc40d9155 100644
57+
--- a/libbb/missing_syscalls.c
58+
+++ b/libbb/missing_syscalls.c
59+
@@ -15,14 +15,6 @@ pid_t getsid(pid_t pid)
60+
return syscall(__NR_getsid, pid);
61+
}
62+
63+
-int stime(const time_t *t)
64+
-{
65+
- struct timeval tv;
66+
- tv.tv_sec = *t;
67+
- tv.tv_usec = 0;
68+
- return settimeofday(&tv, NULL);
69+
-}
70+
-
71+
int sethostname(const char *name, size_t len)
72+
{
73+
return syscall(__NR_sethostname, name, len);
74+
diff --git a/util-linux/rdate.c b/util-linux/rdate.c
75+
index 70f829e7f..878375d78 100644
76+
--- a/util-linux/rdate.c
77+
+++ b/util-linux/rdate.c
78+
@@ -95,9 +95,13 @@ int rdate_main(int argc UNUSED_PARAM, char **argv)
79+
if (!(flags & 2)) { /* no -p (-s may be present) */
80+
if (time(NULL) == remote_time)
81+
bb_error_msg("current time matches remote time");
82+
- else
83+
- if (stime(&remote_time) < 0)
84+
+ else {
85+
+ struct timespec ts;
86+
+ ts.tv_sec = remote_time;
87+
+ ts.tv_nsec = 0;
88+
+ if (clock_settime(CLOCK_REALTIME, &ts) < 0)
89+
bb_perror_msg_and_die("can't set time of day");
90+
+ }
91+
}
92+
93+
if (flags != 1) /* not lone -s */
94+
--
95+
2.25.1
96+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# based on armhf-gnu/Dockerfile
2+
FROM ubuntu:20.04
3+
4+
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
5+
RUN apt-get update -y && apt-get install -y --no-install-recommends \
6+
bc \
7+
bison \
8+
ca-certificates \
9+
cmake \
10+
cpio \
11+
curl \
12+
debian-ports-archive-keyring \
13+
debootstrap \
14+
flex \
15+
gcc \
16+
gcc-riscv64-linux-gnu \
17+
git \
18+
g++-riscv64-linux-gnu \
19+
g++ \
20+
libc6-dev \
21+
libc6-dev-riscv64-cross \
22+
make \
23+
patch \
24+
python3 \
25+
qemu-system-misc \
26+
xz-utils
27+
28+
ENV ARCH=riscv
29+
ENV CROSS_COMPILE=riscv64-linux-gnu-
30+
31+
WORKDIR /build
32+
33+
# From https://github.com/michaeljclark/busybear-linux/blob/master/conf/linux.config
34+
COPY riscv64gc-linux/linux.config /build
35+
36+
# Compile the kernel that we're going to be emulating with. This is
37+
# basically just done to be compatible with the QEMU target that we're going
38+
# to be using when running tests.
39+
RUN curl https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.6.16.tar.xz | tar xJf - && \
40+
cp linux.config linux-5.6.16/.config && \
41+
cd /build/linux-5.6.16 && \
42+
make olddefconfig && \
43+
make -j$(nproc) vmlinux
44+
RUN cp linux-5.6.16/vmlinux /tmp
45+
RUN rm -rf linux-5.6.16
46+
47+
# Compile an instance of busybox as this provides a lightweight system and init
48+
# binary which we will boot into. Only trick here is configuring busybox to
49+
# build static binaries.
50+
RUN curl https://busybox.net/downloads/busybox-1.31.1.tar.bz2 | tar xjf -
51+
COPY riscv64gc-linux/0001-Remove-stime-function-calls.patch /build/busybox-1.31.1/
52+
RUN cd /build/busybox-1.31.1 && \
53+
patch -p1 -i 0001-Remove-stime-function-calls.patch && \
54+
make defconfig && \
55+
sed -i 's/.*CONFIG_STATIC.*/CONFIG_STATIC=y/' .config && \
56+
make -j$(nproc) && \
57+
make install && \
58+
mv _install /tmp/rootfs && \
59+
cd /build && \
60+
rm -rf busybox-1.31.1
61+
62+
# Download the ubuntu rootfs, which we'll use as a chroot for all our tests
63+
# This is only needed to provide /lib/* and /usr/lib/*
64+
WORKDIR /tmp
65+
RUN debootstrap --variant=minbase --arch=riscv64 --foreign focal /tmp/rootfs/ubuntu
66+
RUN cd rootfs && mkdir proc sys dev etc etc/init.d
67+
# rootfs/ubuntu/proc is in a weird state (access fails with ELOOP) until
68+
# rootfs/ubuntu/debootstrap/debootstrap --second-stage is run (under emulation),
69+
# but this takes ages. Instead hack it into a good enough state.
70+
# /proc is used by std::env::current_exe() (which is roughly
71+
# `readlink /proc/self/exe`)
72+
RUN cd rootfs/ubuntu && rm -rf proc && mkdir proc
73+
74+
# Copy over our init script, which starts up our test server and also a few other
75+
# misc tasks
76+
COPY scripts/qemu-bare-bones-rcS rootfs/etc/init.d/rcS
77+
RUN chmod +x rootfs/etc/init.d/rcS
78+
79+
# Helper to quickly fill the entropy pool in the kernel
80+
COPY scripts/qemu-bare-bones-addentropy.c /tmp/addentropy.c
81+
RUN riscv64-linux-gnu-gcc addentropy.c -o rootfs/addentropy -static
82+
83+
# download and build the riscv bootloader
84+
RUN git clone https://github.com/riscv/riscv-pk
85+
WORKDIR /tmp/riscv-pk
86+
# nothing special about this revision: it is just master at the time of writing
87+
# v1.0.0 doesn't build
88+
RUN git checkout 5d9ed238e1cabfbca3c47f50d32894ce94bfc304
89+
RUN mkdir build && cd build && \
90+
../configure --with-payload=/tmp/vmlinux --host=riscv64-linux-gnu && \
91+
make -j$(nproc) && \
92+
cp bbl /tmp
93+
WORKDIR /tmp
94+
RUN rm -rf /tmp/riscv-pk
95+
96+
COPY scripts/sccache.sh /scripts/
97+
RUN sh /scripts/sccache.sh
98+
99+
ENV RUST_CONFIGURE_ARGS --qemu-riscv64-rootfs=/tmp/rootfs
100+
ENV SCRIPT python3 ../x.py test --target riscv64gc-unknown-linux-gnu
101+
102+
ENV NO_CHANGE_USER=1
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/libstd/sys/unix/process/process_common.rs

+1
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ mod tests {
428428
// ignored there.
429429
#[cfg_attr(target_arch = "arm", ignore)]
430430
#[cfg_attr(target_arch = "aarch64", ignore)]
431+
#[cfg_attr(target_arch = "riscv64", ignore)]
431432
fn test_process_mask() {
432433
unsafe {
433434
// Test to make sure that a signal mask does not get inherited.

src/libstd/time.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -811,11 +811,11 @@ mod tests {
811811

812812
// Right now for CI this test is run in an emulator, and apparently the
813813
// aarch64 emulator's sense of time is that we're still living in the
814-
// 70s.
814+
// 70s. This is also true for riscv (also qemu)
815815
//
816816
// Otherwise let's assume that we're all running computers later than
817817
// 2000.
818-
if !cfg!(target_arch = "aarch64") {
818+
if !cfg!(target_arch = "aarch64") && !cfg!(target_arch = "riscv64") {
819819
assert!(a > thirty_years);
820820
}
821821

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

+68-15
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,23 @@ fn start_android_emulator(server: &Path) {
107107
Command::new("adb").arg("shell").arg("/data/tmp/testd").spawn().unwrap();
108108
}
109109

110-
fn start_qemu_emulator(target: &str, rootfs: &Path, server: &Path, tmpdir: &Path) {
110+
fn prepare_rootfs(target: &str, rootfs: &Path, server: &Path, rootfs_img: &Path) {
111+
t!(fs::copy(server, rootfs.join("testd")));
112+
113+
match target {
114+
"arm-unknown-linux-gnueabihf" | "aarch64-unknown-linux-gnu" => {
115+
prepare_rootfs_cpio(rootfs, rootfs_img)
116+
}
117+
"riscv64gc-unknown-linux-gnu" => prepare_rootfs_ext4(rootfs, rootfs_img),
118+
_ => panic!("{} is not supported", target),
119+
}
120+
}
121+
122+
fn prepare_rootfs_cpio(rootfs: &Path, rootfs_img: &Path) {
111123
// Generate a new rootfs image now that we've updated the test server
112124
// executable. This is the equivalent of:
113125
//
114126
// find $rootfs -print 0 | cpio --null -o --format=newc > rootfs.img
115-
t!(fs::copy(server, rootfs.join("testd")));
116-
let rootfs_img = tmpdir.join("rootfs.img");
117127
let mut cmd = Command::new("cpio");
118128
cmd.arg("--null")
119129
.arg("-o")
@@ -128,6 +138,38 @@ fn start_qemu_emulator(target: &str, rootfs: &Path, server: &Path, tmpdir: &Path
128138
t!(io::copy(&mut child.stdout.take().unwrap(), &mut t!(File::create(&rootfs_img))));
129139
assert!(t!(child.wait()).success());
130140

141+
fn add_files(w: &mut dyn Write, root: &Path, cur: &Path) {
142+
for entry in t!(cur.read_dir()) {
143+
let entry = t!(entry);
144+
let path = entry.path();
145+
let to_print = path.strip_prefix(root).unwrap();
146+
t!(write!(w, "{}\u{0}", to_print.to_str().unwrap()));
147+
if t!(entry.file_type()).is_dir() {
148+
add_files(w, root, &path);
149+
}
150+
}
151+
}
152+
}
153+
154+
fn prepare_rootfs_ext4(rootfs: &Path, rootfs_img: &Path) {
155+
let mut dd = Command::new("dd");
156+
dd.arg("if=/dev/zero")
157+
.arg(&format!("of={}", rootfs_img.to_string_lossy()))
158+
.arg("bs=1M")
159+
.arg("count=1024");
160+
let mut dd_child = t!(dd.spawn());
161+
assert!(t!(dd_child.wait()).success());
162+
163+
let mut mkfs = Command::new("mkfs.ext4");
164+
mkfs.arg("-d").arg(rootfs).arg(rootfs_img);
165+
let mut mkfs_child = t!(mkfs.spawn());
166+
assert!(t!(mkfs_child.wait()).success());
167+
}
168+
169+
fn start_qemu_emulator(target: &str, rootfs: &Path, server: &Path, tmpdir: &Path) {
170+
let rootfs_img = &tmpdir.join("rootfs.img");
171+
prepare_rootfs(target, rootfs, server, rootfs_img);
172+
131173
// Start up the emulator, in the background
132174
match target {
133175
"arm-unknown-linux-gnueabihf" => {
@@ -170,19 +212,30 @@ fn start_qemu_emulator(target: &str, rootfs: &Path, server: &Path, tmpdir: &Path
170212
.arg("virtio-net-device,netdev=net0,mac=00:00:00:00:00:00");
171213
t!(cmd.spawn());
172214
}
173-
_ => panic!("cannot start emulator for: {}" < target),
174-
}
175-
176-
fn add_files(w: &mut dyn Write, root: &Path, cur: &Path) {
177-
for entry in t!(cur.read_dir()) {
178-
let entry = t!(entry);
179-
let path = entry.path();
180-
let to_print = path.strip_prefix(root).unwrap();
181-
t!(write!(w, "{}\u{0}", to_print.to_str().unwrap()));
182-
if t!(entry.file_type()).is_dir() {
183-
add_files(w, root, &path);
184-
}
215+
"riscv64gc-unknown-linux-gnu" => {
216+
let mut cmd = Command::new("qemu-system-riscv64");
217+
cmd.arg("-nographic")
218+
.arg("-machine")
219+
.arg("virt")
220+
.arg("-m")
221+
.arg("1024")
222+
.arg("-bios")
223+
.arg("none")
224+
.arg("-kernel")
225+
.arg("/tmp/bbl")
226+
.arg("-append")
227+
.arg("quiet console=ttyS0 root=/dev/vda rw")
228+
.arg("-netdev")
229+
.arg("user,id=net0,hostfwd=tcp::12345-:12345")
230+
.arg("-device")
231+
.arg("virtio-net-device,netdev=net0,mac=00:00:00:00:00:00")
232+
.arg("-device")
233+
.arg("virtio-blk-device,drive=hd0")
234+
.arg("-drive")
235+
.arg(&format!("file={},format=raw,id=hd0", &rootfs_img.to_string_lossy()));
236+
t!(cmd.spawn());
185237
}
238+
_ => panic!("cannot start emulator for: {}", target),
186239
}
187240
}
188241

0 commit comments

Comments
 (0)