<commit_before>#!/bin/bash

set -o pipefail
set -eux

export LANG=C.UTF-8

# HACK: Something invoked by our build system is setting stdio to non-blocking.
# Validate that this isn't the surrounding context. See more below.
python3 -c "import fcntl, os; assert fcntl.fcntl(0, fcntl.F_GETFL) & os.O_NONBLOCK == 0; assert fcntl.fcntl(1, fcntl.F_GETFL) & os.O_NONBLOCK == 0; assert fcntl.fcntl(2, fcntl.F_GETFL) & os.O_NONBLOCK == 0"

# copy host's source tree to avoid changing that, and make sure we have a clean tree
if [ ! -e /source/.git ]; then
    echo "This container must be run with --volume <host cockpit source checkout>:/source:ro" >&2
    exit 1
fi
git clone /source /tmp/source
[ ! -d /source/node_modules ] || cp -r /source/node_modules /tmp/source/
cd /tmp/source

# cross-build flags
ARCH=$(cat /arch)
case $ARCH in
    amd64) ;;
    i386)
        export CFLAGS=-m32
        export LDFLAGS=-m32
        ;;
    *)
        echo "Unknown architecture '$ARCH'" >&2
        exit 1
esac

if [ -d bots ]; then
    # Set GITHUB_BASE so that "import task" works without failure.
    # https://github.com/cockpit-project/cockpit/issues/10578
    GITHUB_BASE=unused bots/test-bots
fi

# bots/ is by and large an independent project, and for supporting stable
# ranches, we want build/check/dist to work without it; so run everything
# without bots/ in one run (to make sure this works), and keep it in the
# others (to make sure its existence does not break anything)
if [ "${CC:-}" = clang ]; then
    rm -rf bots
fi

./autogen.sh --prefix=/usr --enable-strict --with-systemdunitdir=/tmp

make V=1 all

# HACK: Before running the tests we need to make sure stdio is in blocking mode. We have
# not yet been able to figure out what is putting it non-blocknig.
python3 -c "import fcntl, os; map(lambda fd: fcntl.fcntl(fd, fcntl.F_SETFL, fcntl.fcntl(fd, fcntl.F_GETFL) &~ os.O_NONBLOCK), [0, 1, 2])"

# only run distcheck on main arch
if [ "$ARCH" = amd64 ]; then
    make -j8 distcheck 2>&1
else
    make -j8 check 2>&1
fi

make -j8 check-memory 2>&1 || {
    cat test-suite.log
    exit 1
}<commit_msg>containers: More reasonable make parallelization in unit tests<commit_after>#!/bin/bash

set -o pipefail
set -eux

export LANG=C.UTF-8
export MAKEFLAGS="-j $(nproc)"

# HACK: Something invoked by our build system is setting stdio to non-blocking.
# Validate that this isn't the surrounding context. See more below.
python3 -c "import fcntl, os; assert fcntl.fcntl(0, fcntl.F_GETFL) & os.O_NONBLOCK == 0; assert fcntl.fcntl(1, fcntl.F_GETFL) & os.O_NONBLOCK == 0; assert fcntl.fcntl(2, fcntl.F_GETFL) & os.O_NONBLOCK == 0"

# copy host's source tree to avoid changing that, and make sure we have a clean tree
if [ ! -e /source/.git ]; then
    echo "This container must be run with --volume <host cockpit source checkout>:/source:ro" >&2
    exit 1
fi
git clone /source /tmp/source
[ ! -d /source/node_modules ] || cp -r /source/node_modules /tmp/source/
cd /tmp/source

# cross-build flags
ARCH=$(cat /arch)
case $ARCH in
    amd64) ;;
    i386)
        export CFLAGS=-m32
        export LDFLAGS=-m32
        ;;
    *)
        echo "Unknown architecture '$ARCH'" >&2
        exit 1
esac

if [ -d bots ]; then
    # Set GITHUB_BASE so that "import task" works without failure.
    # https://github.com/cockpit-project/cockpit/issues/10578
    GITHUB_BASE=unused bots/test-bots
fi

# bots/ is by and large an independent project, and for supporting stable
# ranches, we want build/check/dist to work without it; so run everything
# without bots/ in one run (to make sure this works), and keep it in the
# others (to make sure its existence does not break anything)
if [ "${CC:-}" = clang ]; then
    rm -rf bots
fi

./autogen.sh --prefix=/usr --enable-strict --with-systemdunitdir=/tmp

make V=1 all

# HACK: Before running the tests we need to make sure stdio is in blocking mode. We have
# not yet been able to figure out what is putting it non-blocknig.
python3 -c "import fcntl, os; map(lambda fd: fcntl.fcntl(fd, fcntl.F_SETFL, fcntl.fcntl(fd, fcntl.F_GETFL) &~ os.O_NONBLOCK), [0, 1, 2])"

# only run distcheck on main arch
if [ "$ARCH" = amd64 ]; then
    make distcheck 2>&1
else
    make check 2>&1
fi

make check-memory 2>&1 || {
    cat test-suite.log
    exit 1
}
{'fraction_non_alphanumeric': 0.11524076671341749, 'fraction_numerical': 0.019401589527816735, 'mean_word_length': 3.2033398821218073, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5081556', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1488, 'n_words': 549}