-
Notifications
You must be signed in to change notification settings - Fork 426
Expand file tree
/
Copy pathtest-freebsd.bash
More file actions
60 lines (46 loc) · 1.58 KB
/
Copy pathtest-freebsd.bash
File metadata and controls
60 lines (46 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
set -eux
CACHE_DIR=$HOME/.cache/go-fuse-freebsd/
TMP=$(mktemp -d $CACHE_DIR/tmp.XXXXXXXXX)
FREEBSD_VERSION=${FREEBSD_VERSION:-15.0}
IMAGE_NAME=FreeBSD-${FREEBSD_VERSION}-RELEASE-amd64-ufs.raw
FREEBSD_IMAGE_URL=${FREEBSD_IMAGE_URL:-https://download.freebsd.org/releases/VM-IMAGES/${FREEBSD_VERSION}-RELEASE/amd64/Latest/${IMAGE_NAME}.xz}
IMAGE_RAW=$CACHE_DIR/$IMAGE_NAME
# 1. Download and convert to raw, once. Pristine base, never modified.
mkdir -p "$CACHE_DIR"
if [[ ! -f "$IMAGE_RAW" ]]; then
curl -fL --output "$IMAGE_RAW.xz" "$FREEBSD_IMAGE_URL"
xz -d "$IMAGE_RAW.xz"
fi
cp $CACHE_DIR/$IMAGE_NAME $TMP/image.raw
DEV=$(sudo losetup --show --find -P $TMP/image.raw)
mkdir -p $TMP/mnt
UFS=$HOME/bin/fuse-ufs-bin
sudo $UFS -o rw ${DEV}p4 $TMP/mnt
GOOS=freebsd GOARCH=amd64 CGO_ENABLED=0 go test -c -o $TMP ./posixtest
GOOS=freebsd GOARCH=amd64 CGO_ENABLED=0 go test -c -o $TMP ./fs
cat << EOF | sudo tee -a $TMP/mnt/boot/loader.conf
autoboot_delay="0"
console="comconsole"
EOF
sudo cp $TMP/posixtest.test $TMP/fs.test $TMP/mnt/
cat << EOF | sudo tee $TMP/mnt/etc/rc.local
#!/bin/sh
kldload fusefs
/posixtest.test -posixdir /tmp > /posixtest.log 2>&1
/fs.test -test.v > /fs.log 2>&1
sync
shutdown -p now
EOF
sudo umount $TMP/mnt
qemu-system-x86_64 \
-enable-kvm -cpu host \
-m 2G -smp 2 -nographic \
-drive file=$TMP/image.raw,format=raw,if=virtio \
-netdev user,id=net0,hostfwd=tcp::2222-:22 \
-device virtio-net-pci,netdev=net0 \
-nographic
sudo $UFS -o rw ${DEV}p4 $TMP/mnt
sudo cp $TMP/mnt/posixtest.log $TMP/posixtest.log
sudo cp $TMP/mnt/fs.log $TMP/
sudo umount $TMP/mnt