Files
systemd/test/units/TEST-62-RESTRICT-IFACES.sh
T
Daan De MeyerandYu Watanabe ee6b3d1aa2 test: Stop using grep -q in integration test
When a TTY is attached to the test unit, grep -q will generate SIGPIPE
for the previous command in the pipeline which in combo with `pipefail`
will cause the command to fail with exit status 141 which will fail the
test.

Replace with >/dev/null to avoid this from happening.

See also https://www.gnu.org/software/grep/manual/html_node/Usage.html
> There is a related problem with Bash’s set -e -o pipefail. Since grep
> does not always read all its input, a command outputting to a pipe read
> by grep can fail when grep exits before reading all its input, and the
> command’s failure can cause Bash to exit.

Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>
2025-12-10 12:09:10 +01:00

53 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -ex
set -o pipefail
setup() {
for i in {0..3};
do
ip netns del "ns${i}" || true
ip link del "veth${i}" || true
ip netns add "ns${i}"
ip link add "veth${i}" type veth peer name "veth${i}_"
ip link set "veth${i}_" netns "ns${i}"
ip -n "ns${i}" link set dev "veth${i}_" up
ip -n "ns${i}" link set dev lo up
ip -n "ns${i}" addr add "192.168.113."$((4*i+1))/30 dev "veth${i}_"
ip link set dev "veth${i}" up
ip link property add dev "veth${i}" altname "veth${i}-altname-with-more-than-15-chars"
ip addr add "192.168.113."$((4*i+2))/30 dev "veth${i}"
done
}
# shellcheck disable=SC2317
teardown() {
set +e
for i in {0..3}; do
ip netns del "ns${i}"
ip link del "veth${i}"
done
}
if systemd-analyze compare-versions "$(uname -r)" lt 5.7; then
echo "kernel is not 5.7+" >>/skipped
exit 77
fi
if systemctl --version | grep -F -- "-BPF_FRAMEWORK" >/dev/null; then
echo "bpf-framework is disabled" >>/skipped
exit 77
fi
trap teardown EXIT
setup
systemctl start --wait TEST-62-RESTRICT-IFACES-1.service
systemctl start --wait TEST-62-RESTRICT-IFACES-2.service
systemctl start --wait TEST-62-RESTRICT-IFACES-3.service
systemctl start --wait TEST-62-RESTRICT-IFACES-4.service
systemctl start --wait TEST-62-RESTRICT-IFACES-5.service
touch /testok