mirror of
https://github.com/systemd/systemd.git
synced 2025-03-08 08:58:27 +03:00
Merge pull request #27903 from mrc0mmand/test-followups
test: a couple of systemd-{coredump,pstore,run} followups
This commit is contained in:
commit
e1aacab7d5
@ -20,17 +20,16 @@ static inline _Noreturn void _coverage__exit(int status) {
|
||||
}
|
||||
#define _exit(x) _coverage__exit(x)
|
||||
|
||||
/* gcov provides wrappers for the exec*() calls but there's none for execveat(),
|
||||
* which means we lose all coverage prior to the call. To mitigate this, let's
|
||||
* add a simple execveat() wrapper in gcov's style[0], which dumps and resets
|
||||
* the coverage data when needed.
|
||||
*
|
||||
* This applies only when we're built with -Dfexecve=true.
|
||||
/* gcov provides wrappers for the exec*() calls but there's none for execveat()
|
||||
* and execvpe() which means we lose all coverage prior to such call. To mitigate
|
||||
* this, let's add simple wrappers in gcov's style[0] for these exec*() calls,
|
||||
* which dump and reset the coverage data as needed.
|
||||
*
|
||||
* [0] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/libgcov-interface.c;h=b2ee930864183b78c8826255183ca86e15e21ded;hb=HEAD
|
||||
*/
|
||||
|
||||
extern int execveat(int, const char *, char * const [], char * const [], int);
|
||||
extern int execvpe(const char *, char * const [], char * const []);
|
||||
|
||||
static inline int _coverage_execveat(
|
||||
int dirfd,
|
||||
@ -45,3 +44,15 @@ static inline int _coverage_execveat(
|
||||
return r;
|
||||
}
|
||||
#define execveat(d,p,a,e,f) _coverage_execveat(d, p, a, e, f)
|
||||
|
||||
static inline int _coverage_execvpe(
|
||||
const char *file,
|
||||
char * const argv[],
|
||||
char * const envp[]) {
|
||||
__gcov_dump();
|
||||
int r = execvpe(file, argv, envp);
|
||||
__gcov_reset();
|
||||
|
||||
return r;
|
||||
}
|
||||
#define execvpe(f,a,e) _coverage_execvpe(f, a, e)
|
||||
|
@ -42,7 +42,17 @@ sig="${2:?}"
|
||||
ulimit -c unlimited
|
||||
"$bin" infinity &
|
||||
pid=$!
|
||||
sleep 1
|
||||
# Sync with the "fake" binary, so we kill it once it's fully forked off,
|
||||
# otherwise we might kill it during fork and kernel would then report
|
||||
# "wrong" binary name (i.e. $MAKE_DUMP_SCRIPT instead of $CORE_TEST_BIN).
|
||||
# In this case, wait until the "fake" binary (sleep in this case) enters
|
||||
# the "interruptible sleep" state, at which point it should be ready
|
||||
# to be sacrificed.
|
||||
for _ in {0..9}; do
|
||||
read -ra self_stat <"/proc/$pid/stat"
|
||||
[[ "${self_stat[2]}" == S ]] && break
|
||||
sleep .5
|
||||
done
|
||||
kill -s "$sig" "$pid"
|
||||
# This should always fail
|
||||
! wait "$pid"
|
||||
|
@ -125,6 +125,17 @@ start_pstore() {
|
||||
journalctl --sync
|
||||
}
|
||||
|
||||
at_exit() {
|
||||
set +e
|
||||
|
||||
mountpoint -q /sys/fs/pstore && umount /sys/fs/pstore
|
||||
rm -fr /var/lib/systemd/pstore/*
|
||||
rm -f /run/systemd/system/systemd-pstore.service.d/99-StartLimitInterval.conf
|
||||
rm -f /run/systemd/pstore.conf.d/99-test.conf
|
||||
}
|
||||
|
||||
trap at_exit EXIT
|
||||
|
||||
# To avoid having to depend on the VM providing the pstore, let's simulate
|
||||
# it using a simple bind mount
|
||||
PSTORE_DIR="$(mktemp -d)"
|
||||
|
@ -7,17 +7,10 @@ set -o pipefail
|
||||
# shellcheck source=test/units/util.sh
|
||||
. "$(dirname "$0")"/util.sh
|
||||
|
||||
# FIXME(?):
|
||||
# - empty ExecStart= is always inserted
|
||||
# - weird results with systemd-run --property=ExecStart=false true
|
||||
# - group settings for each section?
|
||||
# - i.e systemd-run --remain-after-exit --on-clock-change
|
||||
# --timer-property=After=systemd-journald.service true
|
||||
# generates a unit that has two [Unit] and two [Timer] sections
|
||||
|
||||
systemd-run --help --no-pager
|
||||
systemd-run --version
|
||||
systemd-run --no-ask-password true
|
||||
systemd-run --no-block --collect true
|
||||
|
||||
export PARENT_FOO=bar
|
||||
touch /tmp/public-marker
|
||||
@ -37,8 +30,9 @@ systemd-run --wait --pipe --slice-inherit --slice=foo \
|
||||
bash -xec '[[ "$(</proc/self/cgroup)" =~ /system\.slice/system-foo\.slice/run-.+\.service$ ]]'
|
||||
# We should not inherit caller's environment
|
||||
systemd-run --wait --pipe bash -xec '[[ -z "$PARENT_FOO" ]]'
|
||||
systemd-run --wait --pipe bash -xec '[[ "$PWD" == / ]]'
|
||||
systemd-run --wait --pipe bash -xec '[[ "$PWD" == / && -n "$INVOCATION_ID" ]]'
|
||||
systemd-run --wait --pipe \
|
||||
--send-sighup \
|
||||
--working-directory="" \
|
||||
--working-directory=/tmp \
|
||||
bash -xec '[[ "$PWD" == /tmp ]]'
|
||||
@ -84,6 +78,13 @@ systemd-run --wait --pipe --user --machine=testuser@ \
|
||||
bash -xec '[[ "$(</proc/self/cgroup)" =~ /user\.slice/.+/run-.+\.service$ ]]'
|
||||
systemd-run --wait --pipe --user --machine=testuser@ \
|
||||
bash -xec '[[ "$(id -nu)" == testuser && "$(id -ng)" == testuser ]]'
|
||||
systemd-run --wait --pipe --user --machine=testuser@ \
|
||||
bash -xec '[[ "$PWD" == /home/testuser && -n "$INVOCATION_ID" ]]'
|
||||
systemd-run --wait --pipe --user --machine=testuser@ \
|
||||
--property=LimitCORE=1M:2M \
|
||||
--property=LimitCORE=16M:32M \
|
||||
--property=PrivateTmp=yes \
|
||||
bash -xec '[[ "$(ulimit -c -S)" -eq 16384 && "$(ulimit -c -H)" -eq 32768 && ! -e /tmp/public-marker ]]'
|
||||
|
||||
: "Transient scope (system daemon)"
|
||||
systemd-run --scope \
|
||||
@ -100,6 +101,10 @@ systemd-run --scope --slice-inherit --slice=foo \
|
||||
bash -xec '[[ "$(</proc/self/cgroup)" =~ /system\.slice/system-foo\.slice/run-.+\.scope$ ]]'
|
||||
# We should inherit caller's environment
|
||||
systemd-run --scope bash -xec '[[ "$PARENT_FOO" == bar ]]'
|
||||
systemd-run --scope \
|
||||
--property=RuntimeMaxSec=10 \
|
||||
--property=RuntimeMaxSec=infinity \
|
||||
true
|
||||
|
||||
: "Transient scope (user daemon)"
|
||||
# FIXME: https://github.com/systemd/systemd/issues/27883
|
||||
@ -190,8 +195,16 @@ grep -q "^SocketMode=0644$" "/run/systemd/transient/$UNIT.socket"
|
||||
grep -qE "^ExecStart=.*/bin/true.*$" "/run/systemd/transient/$UNIT.service"
|
||||
systemctl stop "$UNIT.socket" "$UNIT.service" || :
|
||||
|
||||
: "Interactive options"
|
||||
SHELL=/bin/true systemd-run --shell
|
||||
SHELL=/bin/true systemd-run --scope --shell
|
||||
systemd-run --wait --pty true
|
||||
systemd-run --wait --machine=.host --pty true
|
||||
(! SHELL=/bin/false systemd-run --quiet --shell)
|
||||
|
||||
(! systemd-run)
|
||||
(! systemd-run "")
|
||||
(! systemd-run --foo=bar)
|
||||
(! systemd-run --wait --pipe --slice=foo.service true)
|
||||
|
||||
for opt in nice on-{active,boot,calendar,startup,unit-active,unit-inactive} property service-type setenv; do
|
||||
|
Loading…
x
Reference in New Issue
Block a user