xref: /aosp_15_r20/external/libcap/kdebug/test-kernel.sh (revision 2810ac1b38eead2603277920c78344c84ddf3aff)
1#!/bin/bash
2# The following is a synthesis of info in:
3#
4#  http://vmsplice.net/~stefan/stefanha-kernel-recipes-2015.pdf
5#  http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/README
6#
7KBASE=../../linux
8#APPEND="console=ttyS0"
9
10function die {
11    echo "$*"
12    exit 1
13}
14
15pushd ..
16make LIBCSTATIC=yes all test || die "failed to make all test of libcap tree"
17make LIBCSTATIC=yes -C progs tcapsh-static || die "failed to make progs/tcapsh-static"
18make -C tests uns_test
19popd
20
21# Assumes desired make *config (eg. make defconfig) is already done.
22pushd $KBASE
23pwd
24make V=1 all || die "failed to build kernel: $0"
25popd
26
27HERE=$(/bin/pwd)
28
29cat > fs.conf <<EOF
30file /init test-init.sh 0755 0 0
31dir /etc 0755 0 0
32file /etc/passwd test-passwd 0444 0 0
33dir /lib 0755 0 0
34dir /proc 0755 0 0
35dir /dev 0755 0 0
36dir /sys 0755 0 0
37dir /sbin 0755 0 0
38file /sbin/busybox /usr/sbin/busybox 0755 0 0
39dir /bin 0755 0 0
40file /bin/myprompt test-prompt.sh 0755 0 0
41file /bin/bash test-bash.sh 0755 0 0
42dir /usr 0755 0 0
43dir /usr/bin 0755 0 0
44dir /root 0755 0 0
45file /root/quicktest.sh $HERE/../progs/quicktest.sh 0755 0 0
46file /root/setcap $HERE/../progs/setcap 0755 0 0
47file /root/getcap $HERE/../progs/getcap 0755 0 0
48file /root/capsh $HERE/../progs/capsh 0755 0 0
49file /root/getpcaps $HERE/../progs/getpcaps 0755 0 0
50file /root/tcapsh-static $HERE/../progs/tcapsh-static 0755 0 0
51file /root/exit $HERE/exit 0755 0 0
52file /root/uns_test $HERE/../tests/uns_test 0755 0 0
53EOF
54
55# convenience for some local experiments
56if [ -f "$HERE/extras.sh" ]; then
57    echo "local, uncommitted enhancements to kernel test"
58    . "$HERE/extras.sh"
59fi
60
61if [ -f "$HERE/interactive" ]; then
62    echo "file /root/interactive $HERE/interactive 0755 0 0" >> fs.conf
63fi
64
65COMMANDS="awk cat chmod cp dmesg grep id less ln ls mkdir mount pwd rm rmdir sh sort umount uniq vi"
66for f in $COMMANDS; do
67    echo slink /bin/$f /sbin/busybox 0755 0 0 >> fs.conf
68done
69
70UCOMMANDS="id cut"
71for f in $UCOMMANDS; do
72    echo slink /usr/bin/$f /sbin/busybox 0755 0 0 >> fs.conf
73done
74
75$KBASE/usr/gen_init_cpio fs.conf | gzip -9 > initramfs.img
76
77KERNEL=$KBASE/arch/$(uname -m)/boot/bzImage
78
79qemu-system-$(uname -m) -m 1024 \
80		   -kernel $KERNEL \
81		   -initrd initramfs.img \
82		   -append "$APPEND" \
83		   -smp sockets=2,dies=1,cores=4 \
84		   -device isa-debug-exit
85