source: mod_gnutls/test/common.bash @ ddf6027

debian/masterdebian/stretch-backportsjessie-backportsupstream
Last change on this file since ddf6027 was cf4e708, checked in by Thomas Klute <thomas2.klute@…>, 4 years ago

Run tests in separate network namespaces

Creating a network namespace for each test avoids port conflicts so
Apache instances can run in parallel, and also isolates the tests from
the host system.

Test namespaces are automatically used if the "unshare" command is
available, and can be disabled by passing "--disable-test-namespaces"
to ./configure.

  • Property mode set to 100644
File size: 988 bytes
Line 
1#!/bin/bash
2
3# Usage: wait_pid_gone ${FILE}
4#
5# Wait until $FILE disappears, but no longer than $TEST_LOCK_WAIT
6# seconds
7function wait_pid_gone
8{
9    local pid_file="${1}"
10    local pid_wait=0
11    while [ -e "${pid_file}" ]; do
12        if [ "$((pid_wait++))" -gt "${TEST_LOCK_WAIT}" ]; then
13            return 1
14        fi
15        sleep 1
16    done
17}
18
19
20
21# Usage: netns_reexec ${@}
22#
23# If USE_TEST_NAMESPACE is set and MGS_NETNS_ACTIVE is not, exec the
24# running command inside a new namespace with active loopback
25# interface and MGS_NETNS_ACTIVE defined. This function can be used to
26# isolate each testcase inside its own network namespace. Since
27# MGS_NETNS_ACTIVE is used to track status, there's no harm in calling
28# it multiple times (e.g. in the test-* script and runtests).
29function netns_reexec
30{
31    if [ -n "${USE_TEST_NAMESPACE}" ] && [ -z "${MGS_NETNS_ACTIVE}" ]; then
32        exec "${UNSHARE}" --net -r /bin/bash -c \
33             "export MGS_NETNS_ACTIVE=1; ip link set up lo; exec ${0} ${@}"
34    fi
35    return 0
36}
Note: See TracBrowser for help on using the repository browser.