From: Christian Goeschel Ndjomouo Date: Thu, 23 Apr 2026 03:42:22 +0000 (-0400) Subject: tests: (chrt) add --reset-on-fork test X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=572ee7da3f5adca21e41b28023ca4d0004007ee1;p=thirdparty%2Futil-linux.git tests: (chrt) add --reset-on-fork test Signed-off-by: Christian Goeschel Ndjomouo --- diff --git a/tests/expected/chrt/reset-on-fork b/tests/expected/chrt/reset-on-fork new file mode 100644 index 000000000..dca5179fd --- /dev/null +++ b/tests/expected/chrt/reset-on-fork @@ -0,0 +1,4 @@ +pid 's current scheduling policy: SCHED_FIFO|SCHED_RESET_ON_FORK +pid 's current scheduling priority: 33 +pid 's current scheduling policy: SCHED_OTHER +pid 's current scheduling priority: 0 diff --git a/tests/ts/chrt/reset-on-fork b/tests/ts/chrt/reset-on-fork new file mode 100755 index 000000000..a0d7faf30 --- /dev/null +++ b/tests/ts/chrt/reset-on-fork @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +# This file is part of util-linux. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Copyright (C) 2026 Christian Goeschel Ndjomouo + +TS_TOPDIR="${0%/*}/../.." +TS_DESC="reset-on-fork" + +. "$TS_TOPDIR"/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_CHRT" +ts_check_test_command "$TS_HELPER_CHILD_CREATE" +ts_skip_nonroot +ts_skip_docker +ts_skip_qemu_user + +trap 'kill $PARENT_PID 2>/dev/null' EXIT + +# We want immediate feedback from the helper, not upon termination +"$TS_HELPER_CHILD_CREATE" 3 >>"$TS_OUTPUT" 2>>"$TS_ERRLOG" & +PARENT_PID=$! +"$TS_CMD_CHRT" --reset-on-fork --fifo --pid 33 "$PARENT_PID" >>"$TS_OUTPUT" 2>>"$TS_ERRLOG" + +# Let's wait until the helper forked +sleep 1 + +for t in 0.1 0.1 0.1 1; do + CHILD_PID="$(awk -F: '/^Child PID: [0-9]+$/ {print $2}' "$TS_OUTPUT" 2>>"$TS_ERRLOG")" + CHILD_PID="${CHILD_PID// /}" + if [[ "$CHILD_PID" =~ ^[0-9]+$ ]] ; then + break + fi + sleep $t +done + +if [ -z "$CHILD_PID" ]; then + ts_failed "Failed to obtain child PID" +fi + +"$TS_CMD_CHRT" --pid "$PARENT_PID" 2>>"$TS_ERRLOG" | sed -e "s@$PARENT_PID@@g" >>"$TS_OUTPUT" +"$TS_CMD_CHRT" --pid "$CHILD_PID" 2>>"$TS_ERRLOG" | sed -e "s@$CHILD_PID@@g" >>"$TS_OUTPUT" +sed -i -E '/(runtime parameter|(Parent|Child) PID:)/d' "$TS_OUTPUT" + +# We don't need the helper anymore +kill "$PARENT_PID" 2>/dev/null +wait "$PARENT_PID" 2>/dev/null + +ts_finalize