mirror of
https://github.com/troglobit/finit.git
synced 2026-10-01 05:22:48 +07:00
WIP: test makefile
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
busybox-x86_64
|
||||
test_root
|
||||
@@ -0,0 +1,70 @@
|
||||
ARCH ?= x86_64
|
||||
|
||||
busybox-ver = 1.31.0
|
||||
busybox-bin = busybox-$(ARCH)
|
||||
|
||||
testroot = test_root
|
||||
testroot_bin = $(testroot)/bin
|
||||
binaries = $(testroot_bin)/cat \
|
||||
$(testroot_bin)/date \
|
||||
$(testroot_bin)/echo \
|
||||
$(testroot_bin)/ls \
|
||||
$(testroot_bin)/mkdir \
|
||||
$(testroot_bin)/mkfifo \
|
||||
$(testroot_bin)/mknod \
|
||||
$(testroot_bin)/mount \
|
||||
$(testroot_bin)/printf \
|
||||
$(testroot_bin)/ps \
|
||||
$(testroot_bin)/sh \
|
||||
$(testroot_bin)/sleep \
|
||||
$(testroot_bin)/top \
|
||||
$(testroot_bin)/touch
|
||||
dirs = $(testroot)/dev \
|
||||
$(testroot)/lib \
|
||||
$(testroot)/proc \
|
||||
$(testroot)/sbin \
|
||||
$(testroot)/sys \
|
||||
$(testroot)/tmp \
|
||||
$(testroot)/usr/local/lib
|
||||
|
||||
$(testroot)/%: $(testroot)
|
||||
mkdir -p $@
|
||||
|
||||
$(busybox-bin):
|
||||
wget 'https://www.busybox.net/downloads/binaries/$(busybox-ver)-defconfig-multiarch-musl/$(busybox-bin)'
|
||||
md5sum -c $(busybox-bin).md5
|
||||
|
||||
$(testroot):
|
||||
mkdir $(testroot)
|
||||
|
||||
$(testroot_bin)/$(busybox-bin): $(testroot_bin) $(busybox-bin)
|
||||
cp $(busybox-bin) $(testroot_bin)/
|
||||
chmod +x $(testroot_bin)/$(busybox-bin)
|
||||
|
||||
$(testroot_bin)/%: $(testroot_bin)/$(busybox-bin)
|
||||
cd $(testroot_bin); \
|
||||
ln -s $(busybox-bin) $(notdir $@)
|
||||
|
||||
$(testroot_bin)/testwrapper.sh:
|
||||
cp testwrapper.sh $@
|
||||
|
||||
$(testroot)/sbin/finit: ../src/finit $(testroot)/lib/ld-musl-x86_64.so.1 $(testroot)/usr/local/lib/libite.so.5 $(testroot)/usr/local/lib/libuev.so.2
|
||||
cp $< $@
|
||||
|
||||
$(testroot)/lib/ld-musl-x86_64.so.1:
|
||||
cp test_root.backup/lib/ld-musl-x86_64.so.1 $@
|
||||
|
||||
$(testroot)/usr/local/lib/libite.so.5:
|
||||
cp test_root.backup/usr/local/lib/libite.so.5 $@
|
||||
|
||||
$(testroot)/usr/local/lib/libuev.so.2:
|
||||
cp test_root.backup/usr/local/lib/libuev.so.2 $@
|
||||
|
||||
.PHONY: test
|
||||
test: $(binaries) $(testroot_bin)/testwrapper.sh $(dirs) $(testroot)/sbin/finit
|
||||
./run.sh finit
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf $(testroot)
|
||||
rm -f $(busybox-bin)
|
||||
@@ -0,0 +1 @@
|
||||
ea7e2353af0067a926d3e021e504290e busybox-x86_64
|
||||
+9
-5
@@ -1,15 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eux
|
||||
set -eu
|
||||
|
||||
TEST_DIR=$(dirname "$0")
|
||||
TESTS_ROOT="${TEST_DIR}/test_root"
|
||||
TESTS_ROOT="$(pwd)/${TEST_DIR}/test_root"
|
||||
|
||||
cp "${TEST_DIR}/testwrapper.sh" "${TESTS_ROOT}/usr/local/bin/"
|
||||
echo "Hint: Execute './test/testenter.sh \$(pgrep -P $$) /bin/sh; reset' to enter the test namespace"
|
||||
|
||||
unshare \
|
||||
# Not supported by Busybox unshare:
|
||||
# --cgroup --time
|
||||
export PATH=/sbin:/bin
|
||||
exec unshare \
|
||||
--user --map-root-user \
|
||||
--fork --pid --mount-proc \
|
||||
--mount \
|
||||
--mount-proc \
|
||||
chroot "$TESTS_ROOT" /usr/local/bin/testwrapper.sh "$@"
|
||||
--uts --ipc --net \
|
||||
chroot "$TESTS_ROOT" /bin/testwrapper.sh "$@"
|
||||
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
if [ "$#" -lt 2 ]; then
|
||||
echo "Usage:"
|
||||
echo " $0 [target-pid] [command [arguments]]"
|
||||
exit 1
|
||||
fi
|
||||
target="$1"
|
||||
shift
|
||||
|
||||
TEST_DIR=$(dirname "$0")
|
||||
TESTS_ROOT="$(pwd)/${TEST_DIR}/test_root"
|
||||
|
||||
export PATH=/sbin:/bin
|
||||
nsenter \
|
||||
--preserve-credentials \
|
||||
--user \
|
||||
--mount \
|
||||
--uts \
|
||||
--ipc \
|
||||
--net \
|
||||
--pid \
|
||||
-w -t "$target" \
|
||||
chroot "$TESTS_ROOT" "$@"
|
||||
+20
-2
@@ -1,9 +1,27 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eux
|
||||
set -eu
|
||||
|
||||
export PATH=/sbin:/bin
|
||||
mount -n -t tmpfs none /dev
|
||||
# mount -t devtmpfs none /dev
|
||||
|
||||
# mknod -m 622 /dev/console c 5 1
|
||||
# mknod -m 666 /dev/null c 1 3
|
||||
# mknod -m 666 /dev/zero c 1 5
|
||||
# mknod -m 666 /dev/ptmx c 5 2
|
||||
# mknod -m 666 /dev/tty c 5 0
|
||||
# mknod -m 444 /dev/random c 1 8
|
||||
# mknod -m 444 /dev/urandom c 1 9
|
||||
# chown root:tty /dev/{console,ptmx,tty}
|
||||
|
||||
mount -t proc none /proc
|
||||
mount -t sysfs none /sys
|
||||
mount -t tmpfs none /tmp
|
||||
|
||||
# mkdir -p /dev/pts
|
||||
# mount -t devpts none /dev/pts
|
||||
|
||||
tty=/dev/$(cat /sys/class/tty/console/active)
|
||||
mkfifo "$tty"
|
||||
|
||||
exec "$@"
|
||||
|
||||
Reference in New Issue
Block a user