mirror of
https://github.com/openembedded/meta-openembedded.git
synced 2026-10-21 20:19:33 +00:00
run-ptest has a #!/bin/sh shebang but used two constructs that are not
available in the target /bin/sh (dash), so the suite died immediately
after starting the server and reported no test results at all:
run-ptest: line 54: stdbuf: not found
run-ptest: line 58: syntax error: bad substitution
ERROR: Exit status is 2
${PIPESTATUS[0]} is a bash array reference; dash has no PIPESTATUS and
fails with "bad substitution". stdbuf is coreutils-only and is not
guaranteed to be installed on the target.
Capture pg_regress output to a temporary file and use $? directly
instead of piping live into sed, which removes the need for both
PIPESTATUS and stdbuf while keeping the same PASS:/FAIL: translation.
Signed-off-by: Khem Raj <raj.khem@gmail.com>
73 lines
2.3 KiB
Bash
73 lines
2.3 KiB
Bash
#!/bin/sh
|
|
#
|
|
# PostgreSQL regression test runner for ptest
|
|
#
|
|
# This script initializes a temporary PostgreSQL database cluster,
|
|
# starts a server instance, and executes the standard regression test
|
|
# suite via pg_regress against the installed PostgreSQL binaries.
|
|
#
|
|
|
|
set -e
|
|
|
|
PGDATA=/tmp/ptest_pgdata
|
|
PTEST_PATH=$(dirname "$(readlink -f "$0")")
|
|
TESTDIR="${PTEST_PATH}/test"
|
|
PGBIN=$(pg_config --bindir)
|
|
PKGLIBDIR=$(pg_config --pkglibdir)
|
|
|
|
cleanup() {
|
|
su - postgres -c "pg_ctl -D ${PGDATA} stop -m immediate" 2>/dev/null || true
|
|
rm -rf "${PGDATA}"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
# Initialize the database cluster
|
|
rm -rf "${PGDATA}"
|
|
su - postgres -c "${PGBIN}/initdb -D ${PGDATA} --no-locale" || exit 1
|
|
|
|
# Start the server
|
|
su - postgres -c "pg_ctl -D ${PGDATA} -l ${PGDATA}/logfile start -w -t 120" || exit 1
|
|
|
|
# Ensure the test directory is writable by the postgres user for
|
|
# regression output files (regression.out, regression.diffs, results/).
|
|
chown -R postgres:postgres "${TESTDIR}"
|
|
|
|
# Prepare the tablespace test directory
|
|
mkdir -p "${TESTDIR}/testtablespace"
|
|
chmod 0700 "${TESTDIR}/testtablespace"
|
|
chown postgres:postgres "${TESTDIR}/testtablespace"
|
|
|
|
# Disable set -e so we can capture the regression run's exit status
|
|
set +e
|
|
|
|
# Run the regression tests, capturing output to a plain file instead of
|
|
# piping live into sed: ${PIPESTATUS[0]} is a bashism this script's
|
|
# "#!/bin/sh" shebang can't rely on (target /bin/sh is dash, which has no
|
|
# PIPESTATUS array and fails with "bad substitution"), and batching
|
|
# through a file avoids needing stdbuf, which isn't guaranteed installed.
|
|
# --dlpath points to the standard PostgreSQL package library directory
|
|
# where regress.so and contrib modules (autoinc.so, refint.so, etc.)
|
|
# are installed, so that CREATE FUNCTION ... AS tests can locate them.
|
|
REGRESS_LOG=$(mktemp /tmp/postgresql-ptest.XXXXXX)
|
|
su - postgres -c "cd ${TESTDIR} && \
|
|
${TESTDIR}/pg_regress \
|
|
--inputdir=. \
|
|
--bindir=${PGBIN} \
|
|
--dlpath=${PKGLIBDIR} \
|
|
--max-concurrent-tests=20 \
|
|
--schedule=parallel_schedule" > "${REGRESS_LOG}" 2>&1
|
|
RESULT=$?
|
|
|
|
sed -n \
|
|
-e 's/^ok [0-9]\+\s\+[+* ]\?\s*/PASS: /p' \
|
|
-e 's/^not ok [0-9]\+\s\+[+* ]\?\s*/FAIL: /p' "${REGRESS_LOG}"
|
|
rm -f "${REGRESS_LOG}"
|
|
|
|
if [ "${RESULT}" = "0" ]; then
|
|
echo "PASS: all tests passed"
|
|
else
|
|
echo "FAIL: some tests failed"
|
|
fi
|
|
|
|
exit ${RESULT}
|