mirror of
https://git.kernel.org/pub/scm/libs/libcap/libcap.git
synced 2026-01-27 01:44:26 +00:00
Add some code to automatically exit the kernel test
I occasionally test libcap against a custom kernel using QEMU. Now I have a simple exit binary for exiting with status. From the top level, one can use: make ktest However, for more control: cd kdebug make test If you want to look around after the tests run: make shell Exit the shell & QEMU with ctrl-D (or exit). Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
This commit is contained in:
parent
9ff6454107
commit
b5dcf3aa87
5
Makefile
5
Makefile
@ -8,7 +8,7 @@ include Make.Rules
|
||||
# flags
|
||||
#
|
||||
|
||||
all install clean kdebug: %: %-here
|
||||
all install clean: %: %-here
|
||||
$(MAKE) -C libcap $@
|
||||
ifneq ($(PAM_CAP),no)
|
||||
$(MAKE) -C pam_cap $@
|
||||
@ -52,6 +52,9 @@ ifeq ($(GOLANG),yes)
|
||||
endif
|
||||
$(MAKE) -C progs $@
|
||||
|
||||
ktest: all
|
||||
$(MAKE) -C kdebug test
|
||||
|
||||
sudotest: all
|
||||
$(MAKE) -C tests $@
|
||||
ifneq ($(PAM_CAP),no)
|
||||
|
||||
@ -1,9 +1,17 @@
|
||||
topdir=$(shell pwd)/..
|
||||
include ../Make.Rules
|
||||
|
||||
test:
|
||||
test: exit
|
||||
rm -f interactive
|
||||
./test-kernel.sh
|
||||
|
||||
shell: exit
|
||||
touch interactive
|
||||
./test-kernel.sh
|
||||
|
||||
exit: exit.c
|
||||
$(CC) -O2 $< -o $@ --static
|
||||
|
||||
all:
|
||||
@echo cd to kdebug to test a kernel build
|
||||
|
||||
@ -11,4 +19,4 @@ install:
|
||||
|
||||
clean:
|
||||
$(LOCALCLEAN)
|
||||
rm -f fs.conf initramfs.img
|
||||
rm -f fs.conf initramfs.img exit interactive
|
||||
|
||||
36
kdebug/exit.c
Normal file
36
kdebug/exit.c
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* See https://stackoverflow.com/questions/42208228/how-to-automatically-close-the-execution-of-the-qemu-after-end-of-process
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/io.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SHUTDOWN_PORT 0x604
|
||||
#define EXIT_PORT 0x501
|
||||
|
||||
static void clean_exit(void) {
|
||||
ioperm(SHUTDOWN_PORT, 16, 1);
|
||||
outw(0x2000, SHUTDOWN_PORT);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int status;
|
||||
if (argc != 2) {
|
||||
clean_exit();
|
||||
}
|
||||
status = atoi(argv[1]);
|
||||
printf("exiting with status %d (in three seconds)\n", status);
|
||||
sleep(3);
|
||||
if (!status) {
|
||||
clean_exit();
|
||||
}
|
||||
ioperm(EXIT_PORT, 8, 1);
|
||||
/*
|
||||
* status returned is 1+(2*orig_status)
|
||||
*/
|
||||
outb(status-1, EXIT_PORT);
|
||||
printf("didn't exit.. did you include '-device isa-debug-exit'"
|
||||
" in qemu command?\n");
|
||||
exit(1);
|
||||
}
|
||||
@ -10,5 +10,10 @@ echo done
|
||||
|
||||
echo Hello, World
|
||||
cd /root
|
||||
./quicktest.sh
|
||||
sh -i
|
||||
if [ -f ./interactive ]; then
|
||||
./quicktest.sh
|
||||
sh -i
|
||||
else
|
||||
./quicktest.sh || ./exit 1
|
||||
fi
|
||||
./exit
|
||||
|
||||
@ -47,6 +47,7 @@ file /root/getcap $HERE/../progs/getcap 0755 0 0
|
||||
file /root/capsh $HERE/../progs/capsh 0755 0 0
|
||||
file /root/getpcaps $HERE/../progs/getpcaps 0755 0 0
|
||||
file /root/tcapsh-static $HERE/../progs/tcapsh-static 0755 0 0
|
||||
file /root/exit $HERE/exit 0755 0 0
|
||||
EOF
|
||||
|
||||
# convenience for some local experiments
|
||||
@ -55,6 +56,10 @@ if [ -f "$HERE/extras.sh" ]; then
|
||||
. "$HERE/extras.sh"
|
||||
fi
|
||||
|
||||
if [ -f "$HERE/interactive" ]; then
|
||||
echo "file /root/interactive $HERE/interactive 0755 0 0" >> fs.conf
|
||||
fi
|
||||
|
||||
COMMANDS="awk cat chmod cp dmesg fgrep id less ln ls mkdir mount pwd rm rmdir sh sort umount uniq vi"
|
||||
for f in $COMMANDS; do
|
||||
echo slink /bin/$f /sbin/busybox 0755 0 0 >> fs.conf
|
||||
@ -73,4 +78,5 @@ qemu-system-$(uname -m) -m 1024 \
|
||||
-kernel $KERNEL \
|
||||
-initrd initramfs.img \
|
||||
-append "$APPEND" \
|
||||
-smp sockets=2,dies=1,cores=4
|
||||
-smp sockets=2,dies=1,cores=4 \
|
||||
-device isa-debug-exit
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user