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 2/3] ptest-pgxs.bbclass: add class for PGXS extension tests
Date: Tue, 1 Dec 2026 20:16:59 +0000 [thread overview]
Message-ID: <20261201201700.7-3-bbnpreetsingh@gmail.com> (raw)
In-Reply-To: <20261201201700.7-1-bbnpreetsingh@gmail.com>
Run the regression tests of a PostgreSQL extension built with PGXS as
its ptest. The tests and their options come from the extension's own
Makefile.
AI-Generated: Uses Claude (claude-opus-5-5)
Signed-off-by: Babanpreet Singh <bbnpreetsingh@gmail.com>
---
meta-oe/classes/ptest-pgxs.bbclass | 97 ++++++++++++++++++++++++++++++
1 file changed, 97 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..95ca4be08c
--- /dev/null
+++ b/meta-oe/classes/ptest-pgxs.bbclass
@@ -0,0 +1,97 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+# Class for running the pg_regress tests of PostgreSQL extensions built
+# with PGXS as ptest
+
+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 > ${WORKDIR}/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 ${WORKDIR}/ptest-pgxs.mk ptest-pgxs-vars)
+ regress=$(echo "$vars" | sed -n 's/^REGRESS=//p')
+ conf=""
+ opts=""
+ inputdir=.
+ 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" ;;
+ *) 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 o in $opts; do
+ case "$o" in
+ --schedule=*) install -m 0644 ${S}/${o#--schedule=} ${D}${PTEST_PATH}/tests/ ;;
+ esac
+ 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-01 20:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 20:16 [meta-oe][PATCH 0/3] ptest for PGXS extensions Babanpreet Singh
2026-12-01 20:16 ` [meta-oe][PATCH 1/3] postgresql: package pg_regress in postgresql-regress Babanpreet Singh
2026-12-02 0:53 ` [PATCH " Khem Raj
2026-12-01 20:16 ` Babanpreet Singh [this message]
2026-12-02 0:53 ` [PATCH 2/3] ptest-pgxs.bbclass: add class for PGXS extension tests Khem Raj
2026-12-02 1:26 ` [meta-oe][PATCH " Babanpreet Singh
2026-12-01 20:17 ` [meta-oe][PATCH 3/3] pg-cron: add ptest support Babanpreet Singh
2026-12-02 0:53 ` [PATCH " Khem Raj
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=20261201201700.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox