mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
tests: Add infrastructure for running certain tests as root.
'[sudo] make check-root' is analogous to 'make check-slow'.
This commit is contained in:
17
Makefile.am
17
Makefile.am
@@ -517,6 +517,20 @@ check-slow: build-test-guests
|
||||
done; \
|
||||
exit $$(( $$errors ? 1 : 0 ))
|
||||
|
||||
check-root: build-test-guests
|
||||
@if test "$$(id -u)" -ne 0; then \
|
||||
echo "***"; \
|
||||
echo "*** error: You must run 'check-root' as root."; \
|
||||
echo "***"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@errors=0; \
|
||||
for f in `grep -l '^$@:' $(SUBDIRS:%=%/Makefile.am)`; do \
|
||||
echo $(MAKE) -C `dirname $$f` $@; \
|
||||
$(MAKE) -C `dirname $$f` $@ || (( errors++ )); \
|
||||
done; \
|
||||
exit $$(( $$errors ? 1 : 0 ))
|
||||
|
||||
build-test-guests:
|
||||
$(MAKE) -C test-data/phony-guests check
|
||||
|
||||
@@ -590,8 +604,9 @@ help:
|
||||
@echo "make check-with-upstream-qemu Test using upstream qemu."
|
||||
@echo "make check-with-upstream-libvirt Test using upstream libvirt."
|
||||
@echo "make check-slow Slow/long-running tests."
|
||||
@echo "sudo make check-root Tests which must be run as root."
|
||||
@echo
|
||||
@echo "make check-all Runs all 'check*' rules."
|
||||
@echo "make check-all Runs all 'check*' rules except check-root."
|
||||
@echo "make check-release Runs 'check*' rules required for release."
|
||||
@echo
|
||||
@echo "make installcheck Test installed libguestfs packages."
|
||||
|
||||
@@ -662,9 +662,44 @@ Add a rule to the F<Makefile.am>:
|
||||
|
||||
=back
|
||||
|
||||
=item C<sudo make check-root>
|
||||
|
||||
Runs some tests which require root privileges. These are supposed to
|
||||
be safe, but take care. You have to run this as root (eg. using
|
||||
L<sudo(8)> explicitly).
|
||||
|
||||
To mark a test as requiring root:
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Add it to the list of C<TESTS> in the F<Makefile.am>, just like a
|
||||
normal test.
|
||||
|
||||
=item *
|
||||
|
||||
Modify the test so it checks if euid == 0, and if I<not> set it skips
|
||||
(ie. returns with exit code 77). If using C<$TEST_FUNCTIONS>, you can
|
||||
call the function C<root_test> for this.
|
||||
|
||||
=item *
|
||||
|
||||
Add a variable C<ROOT_TESTS> to the F<Makefile.am> listing the root
|
||||
tests.
|
||||
|
||||
=item *
|
||||
|
||||
Add a rule to the F<Makefile.am>:
|
||||
|
||||
check-root:
|
||||
$(MAKE) check TESTS="$(ROOT_TESTS)"
|
||||
|
||||
=back
|
||||
|
||||
=item C<make check-all>
|
||||
|
||||
Equivalent to running all C<make check*> rules.
|
||||
Equivalent to running all C<make check*> rules except C<check-root>.
|
||||
|
||||
=item C<make check-release>
|
||||
|
||||
|
||||
@@ -242,6 +242,15 @@ slow_test ()
|
||||
fi
|
||||
}
|
||||
|
||||
# Root tests should always call this function. (See guestfs-hacking(1)).
|
||||
root_test ()
|
||||
{
|
||||
if test "$(id -u)" -ne 0; then
|
||||
echo "$(basename $0): use 'sudo make check-root' to run this test"
|
||||
exit 77
|
||||
fi
|
||||
}
|
||||
|
||||
do_md5 ()
|
||||
{
|
||||
case "$(uname)" in
|
||||
|
||||
Reference in New Issue
Block a user