diff options
| author | Guocai He <guocai.he.cn@windriver.com> | 2026-03-24 18:50:21 +0800 |
|---|---|---|
| committer | Khem Raj <khem.raj@oss.qualcomm.com> | 2026-03-24 09:13:49 -0700 |
| commit | 4fe575d155a02e8d286d1caaa14286d23ea74a84 (patch) | |
| tree | 43768c1f0d25fb55a9559afe36eb464938e4d894 | |
| parent | c4c6915cba39bf510d53ceb11778314665b510f6 (diff) | |
| download | meta-openembedded-4fe575d155a02e8d286d1caaa14286d23ea74a84.tar.gz | |
postgresql: add ptest support
Add ptest infrastructure to run the PostgreSQL standard regression test
suite (pg_regress) on the target system.
Test logs:
root@qemux86-64:~# ptest-runner postgresql
START: ptest-runner
2026-03-24T02:42
BEGIN: /usr/lib64/postgresql/ptest
.....
**if all pass **
PASS: - event_trigger_login 1901 ms
PASS: - fast_default 9459 ms
PASS: - tablespace 16542 ms
PASS: all tests passed
**if have fail**
FAIL: create_type 1763 ms
PASS: create_schema 2123 ms
PASS: - tablespace 23226 ms
FAIL: some tests failed
waiting for server to shut down.... done
server stopped
DURATION: 853
END: /usr/lib64/postgresql/ptest
2026-03-24T02:56
STOP: ptest-runner
TOTAL: 1 FAIL: 0
Signed-off-by: Guocai He <guocai.he.cn@windriver.com>
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
| -rw-r--r-- | meta-oe/conf/include/ptest-packagelists-meta-oe.inc | 1 | ||||
| -rw-r--r-- | meta-oe/recipes-dbs/postgresql/files/run-ptest | 65 | ||||
| -rw-r--r-- | meta-oe/recipes-dbs/postgresql/postgresql.inc | 42 |
3 files changed, 107 insertions, 1 deletions
diff --git a/meta-oe/conf/include/ptest-packagelists-meta-oe.inc b/meta-oe/conf/include/ptest-packagelists-meta-oe.inc index e88e50b59c..a4398dd7e4 100644 --- a/meta-oe/conf/include/ptest-packagelists-meta-oe.inc +++ b/meta-oe/conf/include/ptest-packagelists-meta-oe.inc | |||
| @@ -77,6 +77,7 @@ PTESTS_SLOW_META_OE = "\ | |||
| 77 | fftw \ | 77 | fftw \ |
| 78 | libusb-compat \ | 78 | libusb-compat \ |
| 79 | mariadb \ | 79 | mariadb \ |
| 80 | postgresql \ | ||
| 80 | re2 \ | 81 | re2 \ |
| 81 | rocksdb \ | 82 | rocksdb \ |
| 82 | " | 83 | " |
diff --git a/meta-oe/recipes-dbs/postgresql/files/run-ptest b/meta-oe/recipes-dbs/postgresql/files/run-ptest new file mode 100644 index 0000000000..4cb8e5c7e1 --- /dev/null +++ b/meta-oe/recipes-dbs/postgresql/files/run-ptest | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # | ||
| 3 | # PostgreSQL regression test runner for ptest | ||
| 4 | # | ||
| 5 | # This script initializes a temporary PostgreSQL database cluster, | ||
| 6 | # starts a server instance, and executes the standard regression test | ||
| 7 | # suite via pg_regress against the installed PostgreSQL binaries. | ||
| 8 | # | ||
| 9 | |||
| 10 | set -e | ||
| 11 | |||
| 12 | PGDATA=/tmp/ptest_pgdata | ||
| 13 | PTEST_PATH=$(dirname "$(readlink -f "$0")") | ||
| 14 | TESTDIR="${PTEST_PATH}/test" | ||
| 15 | PGBIN=$(pg_config --bindir) | ||
| 16 | PKGLIBDIR=$(pg_config --pkglibdir) | ||
| 17 | |||
| 18 | cleanup() { | ||
| 19 | su - postgres -c "pg_ctl -D ${PGDATA} stop -m immediate" 2>/dev/null || true | ||
| 20 | rm -rf "${PGDATA}" | ||
| 21 | } | ||
| 22 | trap cleanup EXIT | ||
| 23 | |||
| 24 | # Initialize the database cluster | ||
| 25 | rm -rf "${PGDATA}" | ||
| 26 | su - postgres -c "${PGBIN}/initdb -D ${PGDATA} --no-locale" || exit 1 | ||
| 27 | |||
| 28 | # Start the server | ||
| 29 | su - postgres -c "pg_ctl -D ${PGDATA} -l ${PGDATA}/logfile start -w -t 120" || exit 1 | ||
| 30 | |||
| 31 | # Ensure the test directory is writable by the postgres user for | ||
| 32 | # regression output files (regression.out, regression.diffs, results/). | ||
| 33 | chown -R postgres:postgres "${TESTDIR}" | ||
| 34 | |||
| 35 | # Prepare the tablespace test directory | ||
| 36 | mkdir -p "${TESTDIR}/testtablespace" | ||
| 37 | chmod 0700 "${TESTDIR}/testtablespace" | ||
| 38 | chown postgres:postgres "${TESTDIR}/testtablespace" | ||
| 39 | |||
| 40 | # Disable set -e before the pipe so we can capture PIPESTATUS | ||
| 41 | set +e | ||
| 42 | |||
| 43 | # Run the regression tests. | ||
| 44 | # --dlpath points to the standard PostgreSQL package library directory | ||
| 45 | # where regress.so and contrib modules (autoinc.so, refint.so, etc.) | ||
| 46 | # are installed, so that CREATE FUNCTION ... AS tests can locate them. | ||
| 47 | su - postgres -c "cd ${TESTDIR} && \ | ||
| 48 | ${TESTDIR}/pg_regress \ | ||
| 49 | --inputdir=. \ | ||
| 50 | --bindir=${PGBIN} \ | ||
| 51 | --dlpath=${PKGLIBDIR} \ | ||
| 52 | --max-concurrent-tests=20 \ | ||
| 53 | --schedule=parallel_schedule" 2>&1 | \ | ||
| 54 | stdbuf -oL sed -n \ | ||
| 55 | -e 's/^ok [0-9]\+\s\+[+* ]\?\s*/PASS: /p' \ | ||
| 56 | -e 's/^not ok [0-9]\+\s\+[+* ]\?\s*/FAIL: /p' | ||
| 57 | RESULT=${PIPESTATUS[0]} | ||
| 58 | |||
| 59 | if [ "${RESULT}" = "0" ]; then | ||
| 60 | echo "PASS: all tests passed" | ||
| 61 | else | ||
| 62 | echo "FAIL: some tests failed" | ||
| 63 | fi | ||
| 64 | |||
| 65 | exit ${RESULT} | ||
diff --git a/meta-oe/recipes-dbs/postgresql/postgresql.inc b/meta-oe/recipes-dbs/postgresql/postgresql.inc index 040b3d5e34..6858015478 100644 --- a/meta-oe/recipes-dbs/postgresql/postgresql.inc +++ b/meta-oe/recipes-dbs/postgresql/postgresql.inc | |||
| @@ -29,6 +29,7 @@ SRC_URI = "https://ftp.postgresql.org/pub/source/v${PV}/${BP}.tar.bz2 \ | |||
| 29 | file://postgresql.pam \ | 29 | file://postgresql.pam \ |
| 30 | file://postgresql-setup \ | 30 | file://postgresql-setup \ |
| 31 | file://postgresql.service \ | 31 | file://postgresql.service \ |
| 32 | file://run-ptest \ | ||
| 32 | " | 33 | " |
| 33 | 34 | ||
| 34 | LEAD_SONAME = "libpq.so" | 35 | LEAD_SONAME = "libpq.so" |
| @@ -37,7 +38,7 @@ LEAD_SONAME = "libpq.so" | |||
| 37 | export LDFLAGS_SL = "${LDFLAGS}" | 38 | export LDFLAGS_SL = "${LDFLAGS}" |
| 38 | export LDFLAGS_EX_BE = "-Wl,--export-dynamic" | 39 | export LDFLAGS_EX_BE = "-Wl,--export-dynamic" |
| 39 | 40 | ||
| 40 | inherit autotools pkgconfig perlnative python3native python3targetconfig useradd update-rc.d systemd gettext perl-version multilib_header | 41 | inherit autotools pkgconfig perlnative python3native python3targetconfig useradd update-rc.d systemd gettext perl-version multilib_header ptest |
| 41 | 42 | ||
| 42 | CFLAGS += "-I${STAGING_INCDIR}/${PYTHON_DIR}" | 43 | CFLAGS += "-I${STAGING_INCDIR}/${PYTHON_DIR}" |
| 43 | 44 | ||
| @@ -184,6 +185,45 @@ do_compile:append() { | |||
| 184 | done | 185 | done |
| 185 | } | 186 | } |
| 186 | 187 | ||
| 188 | do_compile_ptest() { | ||
| 189 | oe_runmake -C src/test/regress all | ||
| 190 | } | ||
| 191 | |||
| 192 | do_install_ptest() { | ||
| 193 | mkdir -p ${D}${PTEST_PATH}/test | ||
| 194 | |||
| 195 | # Install pg_regress binary | ||
| 196 | install -m 0755 ${B}/src/test/regress/pg_regress ${D}${PTEST_PATH}/test/ | ||
| 197 | |||
| 198 | # Install test schedules and resultmap | ||
| 199 | for f in parallel_schedule serial_schedule resultmap; do | ||
| 200 | [ -f ${S}/src/test/regress/$f ] && install -m 0644 ${S}/src/test/regress/$f ${D}${PTEST_PATH}/test/ | ||
| 201 | done | ||
| 202 | |||
| 203 | # Install SQL, expected, input, output, and data files | ||
| 204 | for d in sql expected input output data; do | ||
| 205 | if [ -d ${S}/src/test/regress/$d ]; then | ||
| 206 | cp -r ${S}/src/test/regress/$d ${D}${PTEST_PATH}/test/ | ||
| 207 | fi | ||
| 208 | done | ||
| 209 | |||
| 210 | # Install the regress test shared library into the standard PostgreSQL | ||
| 211 | # package library directory (PKGLIBDIR) alongside contrib modules such | ||
| 212 | # as autoinc.so and refint.so. This allows pg_regress --dlpath to | ||
| 213 | # resolve all required shared libraries from a single location. | ||
| 214 | install -d ${D}${libdir}/${BPN} | ||
| 215 | install -m 0755 ${B}/src/test/regress/regress.so ${D}${libdir}/${BPN}/ | ||
| 216 | |||
| 217 | # Install run-ptest | ||
| 218 | install -m 0755 ${UNPACKDIR}/run-ptest ${D}${PTEST_PATH}/ | ||
| 219 | |||
| 220 | # Set ownership to postgres user for running tests | ||
| 221 | chown -R postgres:postgres ${D}${PTEST_PATH} | ||
| 222 | } | ||
| 223 | |||
| 224 | RDEPENDS:${PN}-ptest += "${PN}-client ${PN}-contrib perl" | ||
| 225 | FILES:${PN}-ptest += "${libdir}/${BPN}/regress.so" | ||
| 226 | |||
| 187 | # server needs to configure user and group | 227 | # server needs to configure user and group |
| 188 | usernum = "28" | 228 | usernum = "28" |
| 189 | groupnum = "28" | 229 | groupnum = "28" |
