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