From: Babanpreet Singh <bbnpreetsingh@gmail.com>
To: openembedded-devel@lists.openembedded.org
Cc: Khem Raj <raj.khem@gmail.com>,
Babanpreet Singh <bbnpreetsingh@gmail.com>
Subject: [meta-oe][PATCH v2 2/3] ptest-pgxs.bbclass: add class for PGXS extension tests
Date: Wed, 2 Dec 2026 01:25:56 +0000 [thread overview]
Message-ID: <20261202012557.7-3-bbnpreetsingh@gmail.com> (raw)
In-Reply-To: <20261202012557.7-1-bbnpreetsingh@gmail.com>
Run a PGXS extension's own pg_regress tests as its ptest, with the
tests and options taken from the extension's Makefile.
AI-Generated: Uses Claude (claude-opus-5-5)
Signed-off-by: Babanpreet Singh <bbnpreetsingh@gmail.com>
---
v2:
- write the scratch makefile to ${T}
- install a --schedule file under its basename and pass that name to
pg_regress, so a schedule in a subdirectory is found
- document the fixed database and PTEST_PGXS_CONF in the class header,
and the whitespace split of REGRESS_OPTS
- pg_regress path kept as ${libdir}/postgresql: in this class ${BPN}
is the extension's name, not postgresql
meta-oe/classes/ptest-pgxs.bbclass | 108 +++++++++++++++++++++++++++++
1 file changed, 108 insertions(+)
create mode 100644 meta-oe/classes/ptest-pgxs.bbclass
diff --git a/meta-oe/classes/ptest-pgxs.bbclass b/meta-oe/classes/ptest-pgxs.bbclass
new file mode 100644
index 0000000000..8e1eda3602
--- /dev/null
+++ b/meta-oe/classes/ptest-pgxs.bbclass
@@ -0,0 +1,108 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+# Class for running the pg_regress tests of PostgreSQL extensions built
+# with PGXS as ptest
+#
+# The tests run against a temporary server, always in the database
+# contrib_regression: --temp-instance, --temp-config and --dbname in the
+# extension's REGRESS_OPTS are replaced. An extension whose expected
+# output names its own database, or needs other server settings, sets
+# them in PTEST_PGXS_CONF (pg-cron sets cron.database_name this way).
+
+inherit pgxs ptest
+
+PTEST_PGXS_CONF ?= ""
+PTEST_PGXS_CONF[doc] = "Extra postgresql.conf lines for the test server, separated by \\n."
+
+do_install_ptest() {
+ cat > ${T}/ptest-pgxs.mk << 'EOF'
+ptest-pgxs-vars:
+ @echo "REGRESS=$(REGRESS)"
+ @echo "REGRESS_OPTS=$(REGRESS_OPTS)"
+EOF
+ vars=$(oe_runmake -s -C ${B} -f Makefile -f ${T}/ptest-pgxs.mk ptest-pgxs-vars)
+ regress=$(echo "$vars" | sed -n 's/^REGRESS=//p')
+ conf=""
+ opts=""
+ inputdir=.
+ schedules=""
+ # REGRESS_OPTS is split on whitespace, so an option whose value
+ # contains spaces or quotes is not supported
+ for o in $(echo "$vars" | sed -n 's/^REGRESS_OPTS=//p'); do
+ case "$o" in
+ --temp-config=*) conf=$(basename "${o#--temp-config=}") ;;
+ --temp-instance=*|--dbname=*) ;;
+ --inputdir=*) inputdir="${o#--inputdir=}"; opts="$opts $o" ;;
+ --schedule=*)
+ schedules="$schedules ${o#--schedule=}"
+ opts="$opts --schedule=$(basename "${o#--schedule=}")"
+ ;;
+ *) opts="$opts $o" ;;
+ esac
+ done
+
+ install -d ${D}${PTEST_PATH}/tests/$inputdir
+ for d in sql expected input output data; do
+ if [ -d ${S}/$inputdir/$d ]; then
+ cp -r ${S}/$inputdir/$d ${D}${PTEST_PATH}/tests/$inputdir/
+ fi
+ done
+ for s in $schedules; do
+ install -m 0644 ${S}/$s ${D}${PTEST_PATH}/tests/
+ done
+
+ : > ${D}${PTEST_PATH}/tests/ptest.conf
+ if [ -n "$conf" ] && [ -f ${S}/$conf ]; then
+ cat ${S}/$conf >> ${D}${PTEST_PATH}/tests/ptest.conf
+ fi
+ if [ -n "${PTEST_PGXS_CONF}" ]; then
+ printf '%b\n' "${PTEST_PGXS_CONF}" >> ${D}${PTEST_PATH}/tests/ptest.conf
+ fi
+
+ printf 'REGRESS="%s"\nREGRESS_OPTS="%s"\nPGBIN="%s"\nPG_REGRESS="%s"\n' \
+ "$regress" "$opts" "${bindir}" \
+ "${libdir}/postgresql/pgxs/src/test/regress/pg_regress" \
+ > ${D}${PTEST_PATH}/ptest-pgxs.vars
+
+ if [ ! -f "${UNPACKDIR}/run-ptest" ]; then
+ cat > ${D}${PTEST_PATH}/run-ptest << 'EOF'
+#!/bin/sh
+
+PTEST_PATH=$(dirname "$(readlink -f "$0")")
+. "$PTEST_PATH/ptest-pgxs.vars"
+NAME=$(basename "$(dirname "$PTEST_PATH")")
+
+WORK=$(mktemp -d /tmp/ptest-pgxs.XXXXXX)
+cp -r "$PTEST_PATH/tests/." "$WORK/"
+chown -R postgres:postgres "$WORK"
+
+LOG="$WORK/pg_regress.log"
+{ su postgres -c "cd $WORK && $PG_REGRESS \
+ --temp-instance=$WORK/tmp_check --temp-config=$WORK/ptest.conf \
+ --bindir=$PGBIN --dbname=contrib_regression \
+ $REGRESS_OPTS $REGRESS" 2>&1; echo $? > "$WORK/rc"; } |
+ tee "$LOG" |
+ sed -n -e 's/^ok [0-9]* *[-+] *\([^ ]*\).*/PASS: \1/p' \
+ -e 's/^not ok [0-9]* *[-+] *\([^ ]*\).*/FAIL: \1/p'
+RC=$(cat "$WORK/rc" 2>/dev/null || echo 2)
+
+if [ "$RC" -ne 0 ]; then
+ if [ "$RC" -ne 1 ] || ! grep -q '^\(not \)\{0,1\}ok [0-9]' "$LOG"; then
+ echo "FAIL: $NAME"
+ cat "$LOG"
+ echo
+ fi
+ [ -f "$WORK/regression.diffs" ] && cat "$WORK/regression.diffs"
+fi
+rm -rf "$WORK"
+[ "$RC" -eq 0 ]
+EOF
+ chmod 0755 ${D}${PTEST_PATH}/run-ptest
+ fi
+}
+
+RDEPENDS:${PN}-ptest += "postgresql postgresql-client postgresql-regress"
--
2.43.0
next prev parent reply other threads:[~2026-12-02 1:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 1:25 [meta-oe][PATCH v2 0/3] ptest for PGXS extensions Babanpreet Singh
2026-12-02 1:25 ` [meta-oe][PATCH v2 1/3] postgresql: package pg_regress in postgresql-regress Babanpreet Singh
2026-12-02 1:25 ` Babanpreet Singh [this message]
2026-12-02 1:25 ` [meta-oe][PATCH v2 3/3] pg-cron: add ptest support Babanpreet Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202012557.7-3-bbnpreetsingh@gmail.com \
--to=bbnpreetsingh@gmail.com \
--cc=openembedded-devel@lists.openembedded.org \
--cc=raj.khem@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.