PG_TEST_EXTRA and meson

Started by Ashutosh Bapatover 1 year ago39 messages
#1Ashutosh Bapat
ashutosh.bapat.oss@gmail.com

Hi All,
Using PG_TEST_EXTRA with make is simple, one just sets that environment variable
$ make check
... snip ...
PG_REGRESS='/home/ashutosh/work/units/pghead_make/coderoot/pg/src/test/modules/xid_wraparound/../../../../src/test/regress/pg_regress'
/usr/bin/prove -I ../../../../src/test/perl/ -I . t/*.pl
# +++ tap check in src/test/modules/xid_wraparound +++
t/001_emergency_vacuum.pl .. skipped: test xid_wraparound not enabled
in PG_TEST_EXTRA
t/002_limits.pl ............ skipped: test xid_wraparound not enabled
in PG_TEST_EXTRA
t/003_wraparounds.pl ....... skipped: test xid_wraparound not enabled
in PG_TEST_EXTRA
Files=3, Tests=0, 1 wallclock secs ( 0.02 usr 0.00 sys + 0.20 cusr
0.03 csys = 0.25 CPU)
Result: NOTESTS

Set PG_TEST_EXTRA
$ PG_TEST_EXTRA=xid_wraparound make check
PG_REGRESS='/home/ashutosh/work/units/pghead_make/coderoot/pg/src/test/modules/xid_wraparound/../../../../src/test/regress/pg_regress'
/usr/bin/prove -I ../../../../src/test/perl/ -I . t/*.pl
# +++ tap check in src/test/modules/xid_wraparound +++
t/001_emergency_vacuum.pl .. ok
t/002_limits.pl ............ ok
t/003_wraparounds.pl ....... ok
All tests successful.
Files=3, Tests=11, 181 wallclock secs ( 0.03 usr 0.00 sys + 2.87
cusr 3.10 csys = 6.00 CPU)
Result: PASS

But this simple trick does not work with meson
$ meson test -C $BuildDir --suite setup --suite xid_wraparound
ninja: Entering directory `/home/ashutosh/work/units/pg_review/build_dev'
ninja: no work to do.
1/6 postgresql:setup / tmp_install
OK 0.85s
2/6 postgresql:setup / install_test_files
OK 0.06s
3/6 postgresql:setup / initdb_cache
OK 1.57s
4/6 postgresql:xid_wraparound / xid_wraparound/001_emergency_vacuum
SKIP 0.24s
5/6 postgresql:xid_wraparound / xid_wraparound/003_wraparounds
SKIP 0.26s
6/6 postgresql:xid_wraparound / xid_wraparound/002_limits
SKIP 0.27s

$ PG_TEST_EXTRA=xid_wraparound meson test -C $BuildDir --suite setup
--suite xid_wraparound
ninja: Entering directory `/home/ashutosh/work/units/pg_review/build_dev'
ninja: no work to do.
1/6 postgresql:setup / tmp_install
OK 0.41s
2/6 postgresql:setup / install_test_files
OK 0.06s
3/6 postgresql:setup / initdb_cache
OK 1.57s
4/6 postgresql:xid_wraparound / xid_wraparound/003_wraparounds
SKIP 0.20s
5/6 postgresql:xid_wraparound / xid_wraparound/001_emergency_vacuum
SKIP 0.24s
6/6 postgresql:xid_wraparound / xid_wraparound/002_limits
SKIP 0.24s

the tests are still skipped.

In order to run these tests, we have to run meson setup again. There
are couple of problems with this
1. It's not clear why the tests were skipped. Also not clear that we
have to run meson setup again - from the output alone
2. Running meson setup again is costly, every time we have to run a
new test from PG_TEST_EXTRA.
3. Always configuring meson with PG_TEST_EXTRA means we will run heavy
tests every time meson test is run. I didn't find a way to not run
these tests as part of meson test once configured this way.

We should either allow make like behaviour or provide a way to not run
these tests even if configured that way.

--
Best Wishes,
Ashutosh Bapat

#2Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Ashutosh Bapat (#1)
2 attachment(s)
Re: PG_TEST_EXTRA and meson

Hi,

On Thu, 11 Jul 2024 at 09:30, Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

In order to run these tests, we have to run meson setup again. There
are couple of problems with this
1. It's not clear why the tests were skipped. Also not clear that we
have to run meson setup again - from the output alone
2. Running meson setup again is costly, every time we have to run a
new test from PG_TEST_EXTRA.
3. Always configuring meson with PG_TEST_EXTRA means we will run heavy
tests every time meson test is run. I didn't find a way to not run
these tests as part of meson test once configured this way.

We should either allow make like behaviour or provide a way to not run
these tests even if configured that way.

I have a two quick solutions to this:

1- More like make behaviour. PG_TEST_EXTRA is able to be set from the
setup command, delete this feature so it could be set only from the
environment. Then use it from the environment.

2- If PG_TEST_EXTRA is set from the setup command, use it from the
setup command and discard the environment variable. If PG_TEST_EXTRA
is not set from the setup command, then use it from the environment.

I hope these patches help.

--
Regards,
Nazir Bilal Yavuz
Microsoft

Attachments:

Solution-2.patchtext/x-patch; charset=US-ASCII; name=Solution-2.patchDownload
From 16170a9e48db00eaedc25a6040cc44ec30fffe63 Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: Tue, 16 Jul 2024 23:56:59 +0300
Subject: [PATCH] Solution 2

---
 meson.build | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 5387bb6d5fd..a3a95372e2c 100644
--- a/meson.build
+++ b/meson.build
@@ -3227,7 +3227,9 @@ test_env.set('INITDB_TEMPLATE', test_initdb_template)
 # Test suites that are not safe by default but can be run if selected
 # by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
 # Export PG_TEST_EXTRA so it can be checked in individual tap tests.
-test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))
+if get_option('PG_TEST_EXTRA') != ''
+  test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))
+endif
 
 # Add the temporary installation to the library search path on platforms where
 # that works (everything but windows, basically). On windows everything
-- 
2.45.2

Solution-1.patchtext/x-patch; charset=US-ASCII; name=Solution-1.patchDownload
From 5eabb10189b635ddf1969a6f85ba80d70fec3a83 Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: Wed, 17 Jul 2024 00:01:48 +0300
Subject: [PATCH] Solution 1

---
 meson.build       | 5 -----
 meson_options.txt | 3 ---
 2 files changed, 8 deletions(-)

diff --git a/meson.build b/meson.build
index 5387bb6d5fd..4fbbac0897f 100644
--- a/meson.build
+++ b/meson.build
@@ -3224,11 +3224,6 @@ test_env.set('PG_REGRESS', pg_regress.full_path())
 test_env.set('REGRESS_SHLIB', regress_module.full_path())
 test_env.set('INITDB_TEMPLATE', test_initdb_template)
 
-# Test suites that are not safe by default but can be run if selected
-# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-# Export PG_TEST_EXTRA so it can be checked in individual tap tests.
-test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))
-
 # Add the temporary installation to the library search path on platforms where
 # that works (everything but windows, basically). On windows everything
 # library-like gets installed into bindir, solving that issue.
diff --git a/meson_options.txt b/meson_options.txt
index 246cecf3827..0eaf7890521 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -46,9 +46,6 @@ option('tap_tests', type: 'feature', value: 'auto',
 option('injection_points', type: 'boolean', value: false,
   description: 'Enable injection points')
 
-option('PG_TEST_EXTRA', type: 'string', value: '',
-  description: 'Enable selected extra tests')
-
 option('atomics', type: 'boolean', value: true,
   description: 'Use atomic operations')
 
-- 
2.45.2

#3Jacob Champion
jacob.champion@enterprisedb.com
In reply to: Nazir Bilal Yavuz (#2)
Re: PG_TEST_EXTRA and meson

On Tue, Jul 16, 2024 at 2:12 PM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

2- If PG_TEST_EXTRA is set from the setup command, use it from the
setup command and discard the environment variable. If PG_TEST_EXTRA
is not set from the setup command, then use it from the environment.

Is there a way for the environment to override the Meson setting
rather than vice-versa? My vote would be to have both available, but
with the implementation in patch 2 I'd still have to reconfigure if I
wanted to change my test setup.

Thanks!
--Jacob

#4Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Jacob Champion (#3)
1 attachment(s)
Re: PG_TEST_EXTRA and meson

Hi,

On Wed, 17 Jul 2024 at 00:27, Jacob Champion
<jacob.champion@enterprisedb.com> wrote:

On Tue, Jul 16, 2024 at 2:12 PM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

2- If PG_TEST_EXTRA is set from the setup command, use it from the
setup command and discard the environment variable. If PG_TEST_EXTRA
is not set from the setup command, then use it from the environment.

Is there a way for the environment to override the Meson setting
rather than vice-versa? My vote would be to have both available, but
with the implementation in patch 2 I'd still have to reconfigure if I
wanted to change my test setup.

I think something like attached does the trick. I did not test it
extensively but it passed the couple of tests I tried.

--
Regards,
Nazir Bilal Yavuz
Microsoft

Attachments:

Solution-3.patchtext/x-patch; charset=US-ASCII; name=Solution-3.patchDownload
From f03878870cbbac661bd6f7b483fd1dcf36d5ea38 Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: Wed, 17 Jul 2024 00:54:29 +0300
Subject: [PATCH] Solution 3

---
 meson.build        | 6 +-----
 meson_options.txt  | 2 +-
 src/tools/testwrap | 5 +++++
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/meson.build b/meson.build
index 5387bb6d5fd..3105b3e6724 100644
--- a/meson.build
+++ b/meson.build
@@ -3224,11 +3224,6 @@ test_env.set('PG_REGRESS', pg_regress.full_path())
 test_env.set('REGRESS_SHLIB', regress_module.full_path())
 test_env.set('INITDB_TEMPLATE', test_initdb_template)
 
-# Test suites that are not safe by default but can be run if selected
-# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-# Export PG_TEST_EXTRA so it can be checked in individual tap tests.
-test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))
-
 # Add the temporary installation to the library search path on platforms where
 # that works (everything but windows, basically). On windows everything
 # library-like gets installed into bindir, solving that issue.
@@ -3292,6 +3287,7 @@ foreach test_dir : tests
     testwrap,
     '--basedir', meson.build_root(),
     '--srcdir', test_dir['sd'],
+    '--pg_test_extra', get_option('PG_TEST_EXTRA'),
   ]
 
   foreach kind, v : test_dir
diff --git a/meson_options.txt b/meson_options.txt
index 246cecf3827..042fd22cebe 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -47,7 +47,7 @@ option('injection_points', type: 'boolean', value: false,
   description: 'Enable injection points')
 
 option('PG_TEST_EXTRA', type: 'string', value: '',
-  description: 'Enable selected extra tests')
+  description: 'Enable selected extra tests, please note that this can be overriden by PG_TEST_EXTRA environment variable')
 
 option('atomics', type: 'boolean', value: true,
   description: 'Use atomic operations')
diff --git a/src/tools/testwrap b/src/tools/testwrap
index 9a270beb72d..389a7f6a113 100755
--- a/src/tools/testwrap
+++ b/src/tools/testwrap
@@ -13,6 +13,7 @@ parser.add_argument('--basedir', help='base directory of test', type=str)
 parser.add_argument('--testgroup', help='test group', type=str)
 parser.add_argument('--testname', help='test name', type=str)
 parser.add_argument('--skip', help='skip test (with reason)', type=str)
+parser.add_argument('--pg_test_extra', help='extra tests', type=str)
 parser.add_argument('test_command', nargs='*')
 
 args = parser.parse_args()
@@ -41,6 +42,10 @@ env_dict = {**os.environ,
             'TESTDATADIR': os.path.join(testdir, 'data'),
             'TESTLOGDIR': os.path.join(testdir, 'log')}
 
+# If PG_TEST_EXTRA is not set in the environment, then use it from meson
+if "PG_TEST_EXTRA" not in os.environ:
+    env_dict["PG_TEST_EXTRA"] = args.pg_test_extra
+
 sp = subprocess.Popen(args.test_command, env=env_dict, stdout=subprocess.PIPE)
 # Meson categorizes a passing TODO test point as bad
 # (https://github.com/mesonbuild/meson/issues/13183).  Remove the TODO
-- 
2.45.2

#5Ashutosh Bapat
ashutosh.bapat.oss@gmail.com
In reply to: Nazir Bilal Yavuz (#4)
Re: PG_TEST_EXTRA and meson

On Wed, Jul 17, 2024 at 3:31 AM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

Hi,

On Wed, 17 Jul 2024 at 00:27, Jacob Champion
<jacob.champion@enterprisedb.com> wrote:

On Tue, Jul 16, 2024 at 2:12 PM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

2- If PG_TEST_EXTRA is set from the setup command, use it from the
setup command and discard the environment variable. If PG_TEST_EXTRA
is not set from the setup command, then use it from the environment.

Is there a way for the environment to override the Meson setting
rather than vice-versa? My vote would be to have both available, but
with the implementation in patch 2 I'd still have to reconfigure if I
wanted to change my test setup.

I think something like attached does the trick. I did not test it
extensively but it passed the couple of tests I tried.

Thanks a lot for working on this.

I tested this patch with xid_wraparound. It seems to be working.
$ mts xid_wraparound
... snip
1/6 postgresql:setup / tmp_install
OK 0.36s
2/6 postgresql:setup / install_test_files
OK 0.10s
3/6 postgresql:setup / initdb_cache
OK 1.14s
4/6 postgresql:xid_wraparound / xid_wraparound/001_emergency_vacuum
SKIP 0.14s
5/6 postgresql:xid_wraparound / xid_wraparound/003_wraparounds
SKIP 0.14s
6/6 postgresql:xid_wraparound / xid_wraparound/002_limits
SKIP 0.14s

... snip

$ PG_TEST_EXTRA=xid_wraparound mts xid_wraparound
... snip
1/6 postgresql:setup / tmp_install
OK 0.38s
2/6 postgresql:setup / install_test_files
OK 0.07s
3/6 postgresql:setup / initdb_cache
OK 1.13s
4/6 postgresql:xid_wraparound / xid_wraparound/001_emergency_vacuum
OK 67.33s 7 subtests passed
5/6 postgresql:xid_wraparound / xid_wraparound/002_limits
OK 70.14s 3 subtests passed
6/6 postgresql:xid_wraparound / xid_wraparound/003_wraparounds
OK 178.01s 1 subtests passed

... snip

$ mts xid_wraparound
... snip
1/6 postgresql:setup / tmp_install
OK 0.36s
2/6 postgresql:setup / install_test_files
OK 0.06s
3/6 postgresql:setup / initdb_cache
OK 1.14s
4/6 postgresql:xid_wraparound / xid_wraparound/001_emergency_vacuum
SKIP 0.18s
5/6 postgresql:xid_wraparound / xid_wraparound/002_limits
SKIP 0.19s
6/6 postgresql:xid_wraparound / xid_wraparound/003_wraparounds
SKIP 0.19s

... snip

Providing PG_TEST_EXTRA as a configuration option works as well. But I
find it confusing
$ mts xid_wraparound
... snip
1/6 postgresql:setup / tmp_install
OK 0.71s
2/6 postgresql:setup / install_test_files
OK 0.06s
3/6 postgresql:setup / initdb_cache
OK 1.08s
4/6 postgresql:xid_wraparound / xid_wraparound/001_emergency_vacuum
OK 52.73s 7 subtests passed
5/6 postgresql:xid_wraparound / xid_wraparound/002_limits
OK 56.36s 3 subtests passed
6/6 postgresql:xid_wraparound / xid_wraparound/003_wraparounds
OK 160.46s 1 subtests passed
... snip

$ PG_TEST_EXTRA=ldap mts xid_wraparound
... snip
1/6 postgresql:setup / tmp_install
OK 0.37s
2/6 postgresql:setup / install_test_files
OK 0.08s
3/6 postgresql:setup / initdb_cache
OK 1.16s
4/6 postgresql:xid_wraparound / xid_wraparound/001_emergency_vacuum
SKIP 0.14s
5/6 postgresql:xid_wraparound / xid_wraparound/003_wraparounds
SKIP 0.15s
6/6 postgresql:xid_wraparound / xid_wraparound/002_limits
SKIP 0.15s
... snip
$ PG_TEST_EXTRA=xid_wraparound mts xid_wraparound
... snip
1/6 postgresql:setup / tmp_install
OK 0.36s
2/6 postgresql:setup / install_test_files
OK 0.06s
3/6 postgresql:setup / initdb_cache
OK 1.12s
4/6 postgresql:xid_wraparound / xid_wraparound/001_emergency_vacuum
OK 62.53s 7 subtests passed
5/6 postgresql:xid_wraparound / xid_wraparound/002_limits
OK 69.78s 3 subtests passed
6/6 postgresql:xid_wraparound / xid_wraparound/003_wraparounds
OK 186.78s 1 subtests passed

xid_wraparound tests are run if PG_TEST_EXTRA contains xid_wraparound
or it is not set. Any other setting will not run xid_wraparound test.
That's how the patch is coded but it isn't intuitive that changing
whether a test is run by default would require configuring the build
again. Probably we should just get rid of config time PG_TEST_EXTRA
altogether.

I am including +Tristan Partin who knows meson better.

If you are willing to work on this further, please add it to the commitfest.

--
Best Wishes,
Ashutosh Bapat

#6Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Ashutosh Bapat (#5)
Re: PG_TEST_EXTRA and meson

Hi,

On Wed, 17 Jul 2024 at 13:13, Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

xid_wraparound tests are run if PG_TEST_EXTRA contains xid_wraparound
or it is not set. Any other setting will not run xid_wraparound test.
That's how the patch is coded but it isn't intuitive that changing
whether a test is run by default would require configuring the build
again. Probably we should just get rid of config time PG_TEST_EXTRA
altogether.

I am including +Tristan Partin who knows meson better.

If you are willing to work on this further, please add it to the commitfest.

I think I know why there is confusion. Could you try to set
PG_TEST_EXTRA with quotes? Like PG_TEST_EXTRA="ldap mts
xid_wraparound".

--
Regards,
Nazir Bilal Yavuz
Microsoft

#7Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Nazir Bilal Yavuz (#6)
Re: PG_TEST_EXTRA and meson

Hi,

On Wed, 17 Jul 2024 at 13:23, Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

Hi,

On Wed, 17 Jul 2024 at 13:13, Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

xid_wraparound tests are run if PG_TEST_EXTRA contains xid_wraparound
or it is not set. Any other setting will not run xid_wraparound test.
That's how the patch is coded but it isn't intuitive that changing
whether a test is run by default would require configuring the build
again. Probably we should just get rid of config time PG_TEST_EXTRA
altogether.

I am including +Tristan Partin who knows meson better.

If you are willing to work on this further, please add it to the commitfest.

I think I know why there is confusion. Could you try to set
PG_TEST_EXTRA with quotes? Like PG_TEST_EXTRA="ldap mts
xid_wraparound".

Sorry, the previous reply was wrong; I misunderstood what you said.
Yes, that is how the patch was coded and I agree that getting rid of
config time PG_TEST_EXTRA could be a better alternative.

--
Regards,
Nazir Bilal Yavuz
Microsoft

#8Jacob Champion
jacob.champion@enterprisedb.com
In reply to: Nazir Bilal Yavuz (#7)
Re: PG_TEST_EXTRA and meson

On Wed, Jul 17, 2024 at 3:34 AM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

Sorry, the previous reply was wrong; I misunderstood what you said.
Yes, that is how the patch was coded and I agree that getting rid of
config time PG_TEST_EXTRA could be a better alternative.

Personally I use the config-time PG_TEST_EXTRA extensively. I'd be sad
to see it go, especially if developers are no longer forced to use it.
(In practice, I don't change that setting much after initial
configure, because I use separate worktrees/build directories for
different patchsets. And the reconfiguration is fast when I do need to
modify it.)

Thanks,
--Jacob

#9Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jacob Champion (#8)
Re: PG_TEST_EXTRA and meson

Jacob Champion <jacob.champion@enterprisedb.com> writes:

On Wed, Jul 17, 2024 at 3:34 AM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

Sorry, the previous reply was wrong; I misunderstood what you said.
Yes, that is how the patch was coded and I agree that getting rid of
config time PG_TEST_EXTRA could be a better alternative.

Personally I use the config-time PG_TEST_EXTRA extensively. I'd be sad
to see it go, especially if developers are no longer forced to use it.

The existing and documented expectation is that PG_TEST_EXTRA is an
environment variable, ie it's a runtime option not a configure option.
Making it be the latter seems like a significant loss of flexibility
to me.

regards, tom lane

#10Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#9)
Re: PG_TEST_EXTRA and meson

On 2024-07-17 We 11:01 AM, Tom Lane wrote:

Jacob Champion<jacob.champion@enterprisedb.com> writes:

On Wed, Jul 17, 2024 at 3:34 AM Nazir Bilal Yavuz<byavuz81@gmail.com> wrote:

Sorry, the previous reply was wrong; I misunderstood what you said.
Yes, that is how the patch was coded and I agree that getting rid of
config time PG_TEST_EXTRA could be a better alternative.

Personally I use the config-time PG_TEST_EXTRA extensively. I'd be sad
to see it go, especially if developers are no longer forced to use it.

The existing and documented expectation is that PG_TEST_EXTRA is an
environment variable, ie it's a runtime option not a configure option.
Making it be the latter seems like a significant loss of flexibility
to me.

AIUI the only reason we have it as a configure option at all is that
meson is *very* dogmatic about not using environment variables. I get
their POV when it comes to building, but that should not extend to
testing. That said, I don't mind if this is a configure option as long
as it can be overridden at run time without having to run "meson
configure".

cheers

andrew

--
Andrew Dunstan
EDB:https://www.enterprisedb.com

#11Jacob Champion
jacob.champion@enterprisedb.com
In reply to: Tom Lane (#9)
Re: PG_TEST_EXTRA and meson

On Wed, Jul 17, 2024 at 8:01 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Jacob Champion <jacob.champion@enterprisedb.com> writes:

Personally I use the config-time PG_TEST_EXTRA extensively. I'd be sad
to see it go, especially if developers are no longer forced to use it.

The existing and documented expectation is that PG_TEST_EXTRA is an
environment variable, ie it's a runtime option not a configure option.
Making it be the latter seems like a significant loss of flexibility
to me.

I think/hope we're saying the same thing -- developers should not be
forced to lock PG_TEST_EXTRA into their configurations; that's
inflexible and unhelpful.

What I'm saying in addition to that is, I really like that I can
currently put a default PG_TEST_EXTRA into my meson config so that I
don't have to keep track of it, and I do that all the time. So I'm in
favor of the "option 3" approach.

Thanks,
--Jacob

#12Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jacob Champion (#11)
Re: PG_TEST_EXTRA and meson

Jacob Champion <jacob.champion@enterprisedb.com> writes:

On Wed, Jul 17, 2024 at 8:01 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:

The existing and documented expectation is that PG_TEST_EXTRA is an
environment variable, ie it's a runtime option not a configure option.
Making it be the latter seems like a significant loss of flexibility
to me.

I think/hope we're saying the same thing -- developers should not be
forced to lock PG_TEST_EXTRA into their configurations; that's
inflexible and unhelpful.

Indeed.

What I'm saying in addition to that is, I really like that I can
currently put a default PG_TEST_EXTRA into my meson config so that I
don't have to keep track of it, and I do that all the time. So I'm in
favor of the "option 3" approach.

Ah. I have no particular objection to that, but I wonder whether
we should make the autoconf/makefile infrastructure do it too.

regards, tom lane

#13Jacob Champion
jacob.champion@enterprisedb.com
In reply to: Tom Lane (#12)
Re: PG_TEST_EXTRA and meson

On Wed, Jul 17, 2024 at 11:11 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Ah. I have no particular objection to that, but I wonder whether
we should make the autoconf/makefile infrastructure do it too.

I don't need it personally, having moved almost entirely to Meson. But
if the asymmetry is a sticking point, I can work on a patch.

Thanks!
--Jacob

#14Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Ashutosh Bapat (#5)
2 attachment(s)
Re: PG_TEST_EXTRA and meson

Hi,

On Wed, 17 Jul 2024 at 13:13, Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

If you are willing to work on this further, please add it to the commitfest.

Since general consensus is more towards having an environment variable
to override Meson configure option, I converted solution-3 to
something more like a patch. I updated the docs, added more comments
and added this to the commitfest [1]https://commitfest.postgresql.org/49/5134/.

The one downside of this approach is that PG_TEXT_EXTRA in user
defined options in meson setup output could be misleading now.

Also, with this change; PG_TEST_EXTRA from configure_scripts in the
.cirrus.tasks.yml file should be removed as they are useless now. I
added that as a second patch.

[1]: https://commitfest.postgresql.org/49/5134/

--
Regards,
Nazir Bilal Yavuz
Microsoft

Attachments:

v1-0001-Make-PG_TEST_EXTRA-env-variable-override-its-Meso.patchtext/x-patch; charset=US-ASCII; name=v1-0001-Make-PG_TEST_EXTRA-env-variable-override-its-Meso.patchDownload
From 7e6c31c73d14f8e50d13ad7ce4aa1aa167193afd Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: Fri, 19 Jul 2024 09:48:47 +0300
Subject: [PATCH v1 1/2] Make PG_TEST_EXTRA env variable override its Meson
 configure option

Since PG_TEST_EXTRA configure option is set while configuring Meson,
each change on PG_TEST_EXTRA needs reconfigure and this is costly. So,
first try to use PG_TEST_EXTRA from environment. If it does not exist,
then try to use it from its configure option in Meson builds.
---
 doc/src/sgml/installation.sgml |  6 ++++--
 meson.build                    | 11 ++++++-----
 meson_options.txt              |  2 +-
 src/tools/testwrap             |  6 ++++++
 4 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index 4784834ab9f..a78ef8cb78b 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -3132,8 +3132,10 @@ ninja install
       <listitem>
        <para>
         Enable test suites which require special software to run.  This option
-        accepts arguments via a whitespace-separated list.  See <xref
-        linkend="regress-additional"/> for details.
+        accepts arguments via a whitespace-separated list.  Please note that
+        this configure option is overridden by PG_TEST_EXTRA environment
+        variable if it exists.  See <xref linkend="regress-additional"/> for
+        details.
        </para>
       </listitem>
      </varlistentry>
diff --git a/meson.build b/meson.build
index 5387bb6d5fd..e0b04b01756 100644
--- a/meson.build
+++ b/meson.build
@@ -3224,11 +3224,6 @@ test_env.set('PG_REGRESS', pg_regress.full_path())
 test_env.set('REGRESS_SHLIB', regress_module.full_path())
 test_env.set('INITDB_TEMPLATE', test_initdb_template)
 
-# Test suites that are not safe by default but can be run if selected
-# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-# Export PG_TEST_EXTRA so it can be checked in individual tap tests.
-test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))
-
 # Add the temporary installation to the library search path on platforms where
 # that works (everything but windows, basically). On windows everything
 # library-like gets installed into bindir, solving that issue.
@@ -3292,6 +3287,12 @@ foreach test_dir : tests
     testwrap,
     '--basedir', meson.build_root(),
     '--srcdir', test_dir['sd'],
+    # Test suites that are not safe by default but can be run if selected
+    # by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
+    # Export PG_TEST_EXTRA so it can be checked in individual tap tests.
+    # This configure option is overridden by PG_TEST_EXTRA environment variable
+    # if it exists.
+    '--pg_test_extra', get_option('PG_TEST_EXTRA'),
   ]
 
   foreach kind, v : test_dir
diff --git a/meson_options.txt b/meson_options.txt
index 246cecf3827..e1d55311702 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -47,7 +47,7 @@ option('injection_points', type: 'boolean', value: false,
   description: 'Enable injection points')
 
 option('PG_TEST_EXTRA', type: 'string', value: '',
-  description: 'Enable selected extra tests')
+  description: 'Enable selected extra tests, please note that this configure option is overridden by PG_TEST_EXTRA environment variable if it exists')
 
 option('atomics', type: 'boolean', value: true,
   description: 'Use atomic operations')
diff --git a/src/tools/testwrap b/src/tools/testwrap
index 9a270beb72d..0dca4c26f2b 100755
--- a/src/tools/testwrap
+++ b/src/tools/testwrap
@@ -13,6 +13,7 @@ parser.add_argument('--basedir', help='base directory of test', type=str)
 parser.add_argument('--testgroup', help='test group', type=str)
 parser.add_argument('--testname', help='test name', type=str)
 parser.add_argument('--skip', help='skip test (with reason)', type=str)
+parser.add_argument('--pg_test_extra', help='extra tests', type=str)
 parser.add_argument('test_command', nargs='*')
 
 args = parser.parse_args()
@@ -41,6 +42,11 @@ env_dict = {**os.environ,
             'TESTDATADIR': os.path.join(testdir, 'data'),
             'TESTLOGDIR': os.path.join(testdir, 'log')}
 
+# If PG_TEST_EXTRA is not set in the environment, then look for its Meson
+# configure option.
+if "PG_TEST_EXTRA" not in os.environ and args.pg_test_extra:
+    env_dict["PG_TEST_EXTRA"] = args.pg_test_extra
+
 sp = subprocess.Popen(args.test_command, env=env_dict, stdout=subprocess.PIPE)
 # Meson categorizes a passing TODO test point as bad
 # (https://github.com/mesonbuild/meson/issues/13183).  Remove the TODO
-- 
2.45.2

v1-0002-Remove-PG_TEST_EXTRA-from-configure_scripts-in-.c.patchtext/x-patch; charset=US-ASCII; name=v1-0002-Remove-PG_TEST_EXTRA-from-configure_scripts-in-.c.patchDownload
From 9e3de3b53943501c0aa60f4f1f84802451519982 Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: Fri, 19 Jul 2024 09:59:40 +0300
Subject: [PATCH v1 2/2] Remove PG_TEST_EXTRA from configure_scripts in
 .cirrus.tasks.yml

Meson builds are able to get PG_TEST_EXTRA from environment now and
this overrides the configure option. PG_TEST_EXTRA environment variable
is set at the top of the .cirrus.tasks.yml file. So, PG_TEXT_EXTRA in
configure scripts became useless and were removed because of that.
---
 .cirrus.tasks.yml | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index 99ca74d5133..8449addbdcf 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -174,7 +174,6 @@ task:
         --buildtype=debug \
         -Dcassert=true -Dinjection_points=true \
         -Duuid=bsd -Dtcl_version=tcl86 -Ddtrace=auto \
-        -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
         -Dextra_lib_dirs=/usr/local/lib -Dextra_include_dirs=/usr/local/include/ \
         build
     EOF
@@ -362,7 +361,6 @@ task:
             --buildtype=debug \
             -Dcassert=true -Dinjection_points=true \
             ${LINUX_MESON_FEATURES} \
-            -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
             build
         EOF
 
@@ -378,7 +376,6 @@ task:
             -Dllvm=disabled \
             --pkg-config-path /usr/lib/i386-linux-gnu/pkgconfig/ \
             -DPERL=perl5.36-i386-linux-gnu \
-            -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
             build-32
         EOF
 
@@ -492,7 +489,6 @@ task:
       -Dextra_lib_dirs=/opt/local/lib \
       -Dcassert=true -Dinjection_points=true \
       -Duuid=e2fs -Ddtrace=auto \
-      -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
       build
 
   build_script: ninja -C build -j${BUILD_JOBS}
@@ -564,7 +560,7 @@ task:
   # Use /DEBUG:FASTLINK to avoid high memory usage during linking
   configure_script: |
     vcvarsall x64
-    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Dinjection_points=true -Db_pch=true -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
+    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Dinjection_points=true -Db_pch=true -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% build
 
   build_script: |
     vcvarsall x64
-- 
2.45.2

#15Ashutosh Bapat
ashutosh.bapat.oss@gmail.com
In reply to: Nazir Bilal Yavuz (#14)
Re: PG_TEST_EXTRA and meson

Hi Nazir,

On Fri, Jul 19, 2024 at 1:37 PM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

If you are willing to work on this further, please add it to the commitfest.

Since general consensus is more towards having an environment variable
to override Meson configure option, I converted solution-3 to
something more like a patch. I updated the docs, added more comments
and added this to the commitfest [1].

Thanks.

The one downside of this approach is that PG_TEXT_EXTRA in user
defined options in meson setup output could be misleading now.

Upthread Tom asked whether we should do a symmetric change to "make".
This set of patches does not do that. Here are my thoughts:
1. Those who use make, are not using configure time PG_TEST_EXTRA
anyway, so they don't need it.
2. Those meson users who use setup time PG_TEST_EXTRA and also want to
use make may find the need for the feature in make.
3. https://www.postgresql.org/docs/devel/install-requirements.html
says that the meson support is currently experimental and only works
when building from a Git checkout. So there's a possibility (even if
theoretical) that make and meson will co-exist. Also that we may
abandon meson?

Considering those, it seems to me that symmetry is required. I don't
know how hard it is to introduce PG_TEST_EXTRA as a configure time
option in "make". If it's simple, we should do that. Otherwise it will
be better to just remove PG_EXTRA_TEST option support from meson
support to keep make and meson symmetrical.

As far as the implementation is concerned the patch seems to be doing
what's expected. If PG_TEST_EXTRA is specified at setup time, it is
not needed to be specified as an environment variable at run time. But
it can also be overridden at runtime. If PG_TEST_EXTRA is not
specified at the time of setup, but specified at run time, it works. I
have tested xid_wraparound and wal_consistency_check.

I wonder whether we really require pg_test_extra argument to testwrap.
Why can't we use the logic in testwrap, to set run time PG_TEST_EXTRA,
in meson.build directly? I.e. set test_env['PG_TEST_EXTRA'] to
os.environ[;PG_TEST_EXTRA'] if the latter is set, otherwise set the
first to get_option('PG_TEST_EXTRA').

Also, with this change; PG_TEST_EXTRA from configure_scripts in the
.cirrus.tasks.yml file should be removed as they are useless now. I
added that as a second patch.

I think this is useful and allows both make and meson to use the same
logic in cirrus.

--
Best Wishes,
Ashutosh Bapat

#16Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Ashutosh Bapat (#15)
Re: PG_TEST_EXTRA and meson

Hi,

On Tue, 23 Jul 2024 at 12:26, Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

Upthread Tom asked whether we should do a symmetric change to "make".
This set of patches does not do that. Here are my thoughts:
1. Those who use make, are not using configure time PG_TEST_EXTRA
anyway, so they don't need it.
2. Those meson users who use setup time PG_TEST_EXTRA and also want to
use make may find the need for the feature in make.
3. https://www.postgresql.org/docs/devel/install-requirements.html
says that the meson support is currently experimental and only works
when building from a Git checkout. So there's a possibility (even if
theoretical) that make and meson will co-exist. Also that we may
abandon meson?

Considering those, it seems to me that symmetry is required. I don't
know how hard it is to introduce PG_TEST_EXTRA as a configure time
option in "make". If it's simple, we should do that. Otherwise it will
be better to just remove PG_EXTRA_TEST option support from meson
support to keep make and meson symmetrical.

I agree that symmetry should be the ultimate goal.

Upthread Jacob said he could work on a patch about introducing the
PG_TEST_EXTRA configure option to make builds. Would you still be
interested in working on this? If not, I would gladly work on it.

As far as the implementation is concerned the patch seems to be doing
what's expected. If PG_TEST_EXTRA is specified at setup time, it is
not needed to be specified as an environment variable at run time. But
it can also be overridden at runtime. If PG_TEST_EXTRA is not
specified at the time of setup, but specified at run time, it works. I
have tested xid_wraparound and wal_consistency_check.

Thanks for testing it!

I wonder whether we really require pg_test_extra argument to testwrap.
Why can't we use the logic in testwrap, to set run time PG_TEST_EXTRA,
in meson.build directly? I.e. set test_env['PG_TEST_EXTRA'] to
os.environ[;PG_TEST_EXTRA'] if the latter is set, otherwise set the
first to get_option('PG_TEST_EXTRA').

When test_env('PG_TEST_EXTRA') is set, it could not be overridden
afterwards. Perhaps there is a way to override test_env() but I do not
know how.

--
Regards,
Nazir Bilal Yavuz
Microsoft

#17Ashutosh Bapat
ashutosh.bapat.oss@gmail.com
In reply to: Nazir Bilal Yavuz (#16)
Re: PG_TEST_EXTRA and meson

On Tue, Jul 23, 2024 at 4:02 PM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

I wonder whether we really require pg_test_extra argument to testwrap.
Why can't we use the logic in testwrap, to set run time PG_TEST_EXTRA,
in meson.build directly? I.e. set test_env['PG_TEST_EXTRA'] to
os.environ[;PG_TEST_EXTRA'] if the latter is set, otherwise set the
first to get_option('PG_TEST_EXTRA').

When test_env('PG_TEST_EXTRA') is set, it could not be overridden
afterwards. Perhaps there is a way to override test_env() but I do not
know how.

I am not suggesting to override test_env['PG_TEST_EXTRA'] but set it
to the value after overriding if required. meson.build file seems to
allow some conditional variable setting. So I thought this would be
possible, haven't tried myself though.

--
Best Wishes,
Ashutosh Bapat

#18Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Ashutosh Bapat (#17)
Re: PG_TEST_EXTRA and meson

Hi,

On Tue, 23 Jul 2024 at 13:40, Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

On Tue, Jul 23, 2024 at 4:02 PM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

I wonder whether we really require pg_test_extra argument to testwrap.
Why can't we use the logic in testwrap, to set run time PG_TEST_EXTRA,
in meson.build directly? I.e. set test_env['PG_TEST_EXTRA'] to
os.environ[;PG_TEST_EXTRA'] if the latter is set, otherwise set the
first to get_option('PG_TEST_EXTRA').

When test_env('PG_TEST_EXTRA') is set, it could not be overridden
afterwards. Perhaps there is a way to override test_env() but I do not
know how.

I am not suggesting to override test_env['PG_TEST_EXTRA'] but set it
to the value after overriding if required. meson.build file seems to
allow some conditional variable setting. So I thought this would be
possible, haven't tried myself though.

Sorry if I caused a misunderstanding. What I meant was, when the
test_env('PG_TEST_EXTRA') is set, Meson will always use PG_TEST_EXTRA
from the setup. So, Meson needs to be built again to change
PG_TEST_EXTRA.

AFAIK Meson does not support accessing environment variables but
run_command() could be used to test this:

-test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))
+pg_test_extra_env = run_command(
+  [python,
+  '-c',
+  'import os; print(os.getenv("PG_TEST_EXTRA", ""))'],
+  check: true).stdout()
+
+test_env.set('PG_TEST_EXTRA', pg_test_extra_env != '' ?
+  pg_test_extra_env :
+  get_option('PG_TEST_EXTRA'))
+

--
Regards,
Nazir Bilal Yavuz
Microsoft

#19Jacob Champion
jacob.champion@enterprisedb.com
In reply to: Nazir Bilal Yavuz (#16)
1 attachment(s)
Re: PG_TEST_EXTRA and meson

On Tue, Jul 23, 2024 at 3:32 AM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

Upthread Jacob said he could work on a patch about introducing the
PG_TEST_EXTRA configure option to make builds. Would you still be
interested in working on this? If not, I would gladly work on it.

Sure! Attached is a minimalist approach using AC_ARG_VAR.

It works for top-level `make check-world`, or `make check -C
src/test`. If you run `make check` directly from a test subdirectory,
the variable doesn't get picked up, because it's only exported from
the src/test level as of your patch c3382a3c3cc -- but if that turns
out to be a problem, we can plumb it all the way down or expand the
scope of the export.

Thanks,
--Jacob

Attachments:

make_test_extra.diffapplication/octet-stream; name=make_test_extra.diffDownload
diff --git a/configure b/configure
index 062d40e1ab..e04ae17ab6 100755
--- a/configure
+++ b/configure
@@ -763,6 +763,7 @@ LDFLAGS
 CFLAGS
 CC
 enable_injection_points
+PG_TEST_EXTRA
 enable_tap_tests
 enable_dtrace
 DTRACEFLAGS
@@ -881,6 +882,7 @@ enable_largefile
       ac_precious_vars='build_alias
 host_alias
 target_alias
+PG_TEST_EXTRA
 CC
 CFLAGS
 LDFLAGS
@@ -1590,6 +1592,8 @@ Optional Packages:
   --with-openssl          obsolete spelling of --with-ssl=openssl
 
 Some influential environment variables:
+  PG_TEST_EXTRA
+              enable selected extra tests
   CC          C compiler command
   CFLAGS      C compiler flags
   LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
@@ -3686,6 +3690,7 @@ fi
 
 
 
+
 #
 # Injection points
 #
diff --git a/configure.ac b/configure.ac
index ef56226156..82401efe74 100644
--- a/configure.ac
+++ b/configure.ac
@@ -248,6 +248,7 @@ AC_SUBST(enable_dtrace)
 PGAC_ARG_BOOL(enable, tap-tests, no,
               [enable TAP tests (requires Perl and IPC::Run)])
 AC_SUBST(enable_tap_tests)
+AC_ARG_VAR(PG_TEST_EXTRA, [enable selected extra tests])
 
 #
 # Injection points
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 83b91fe916..d92b0f19a0 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -641,6 +641,8 @@ submake-libpgfeutils: | submake-generated-headers
 #
 # Testing support
 
+PG_TEST_EXTRA = @PG_TEST_EXTRA@
+
 ifneq ($(USE_MODULE_DB),)
   PL_TESTDB = pl_regression_$(NAME)
   ifneq ($(MODULE_big),)
#20Ashutosh Bapat
ashutosh.bapat.oss@gmail.com
In reply to: Jacob Champion (#19)
Re: PG_TEST_EXTRA and meson

Hi Jacob,

On Tue, Jul 23, 2024 at 7:54 PM Jacob Champion
<jacob.champion@enterprisedb.com> wrote:

On Tue, Jul 23, 2024 at 3:32 AM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

Upthread Jacob said he could work on a patch about introducing the
PG_TEST_EXTRA configure option to make builds. Would you still be
interested in working on this? If not, I would gladly work on it.

Sure! Attached is a minimalist approach using AC_ARG_VAR.

It works for top-level `make check-world`, or `make check -C
src/test`. If you run `make check` directly from a test subdirectory,
the variable doesn't get picked up, because it's only exported from
the src/test level as of your patch c3382a3c3cc -- but if that turns
out to be a problem, we can plumb it all the way down or expand the
scope of the export.

Sorry for the delay in reply.

Here are my observations with the patch applied
1. If I run configure without setting PG_TEST_EXTRA, it won't run the
tests that require PG_TEST_EXTRA to be set. This is expected.
2. But it wont' run tests even if PG_TEST_EXTRA is set while running
make check.- that's unexpected
3. If I run configure with PG_TEST_EXTRA set and run 'make check' in
the test directory, it runs those tests. That's expected from the
final patch but that doesn't seem to be what you described above.
3. After 3, if I run `PG_TEST_EXTRA="something" make check`, it still
runs those tests. So it looks like PG_TEST_EXTRA doesn't get
overridden. If PG_TEST_EXTRA is set to something other than what was
configured, it doesn't take effect when running the corresponding
tests. E.g. PG_TEST_EXTRA is set to xid_wraparound at configure time,
but `PG_TEST_EXTRA=wal_consistency_check make check ` is run, the
tests won't use wal_consistency_check=all. - that's not expected.

I this the patch lacks overriding PG_TEST_EXTRA at run time.

AFAIU, following was expected behaviour from both meson and make.
Please correct if I am wrong.
1. If PG_TEST_EXTRA is set at the setup/configuration time, it is not
required to be set at run time.
2. Runtime PG_TEST_EXTRA always overrides configure time PG_TEST_EXTRA.
--
Best Wishes,
Ashutosh Bapat

#21Andrew Dunstan
andrew@dunslane.net
In reply to: Ashutosh Bapat (#20)
Re: PG_TEST_EXTRA and meson

On 2024-08-09 Fr 5:26 AM, Ashutosh Bapat wrote:

I this the patch lacks overriding PG_TEST_EXTRA at run time.

AFAIU, following was expected behaviour from both meson and make.
Please correct if I am wrong.
1. If PG_TEST_EXTRA is set at the setup/configuration time, it is not
required to be set at run time.
2. Runtime PG_TEST_EXTRA always overrides configure time PG_TEST_EXTRA.

Yes, that's my understanding of the requirement.

cheers

andrew

--
Andrew Dunstan
EDB:https://www.enterprisedb.com

#22Jacob Champion
jacob.champion@enterprisedb.com
In reply to: Ashutosh Bapat (#20)
Re: PG_TEST_EXTRA and meson

On Fri, Aug 9, 2024 at 2:26 AM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

Here are my observations with the patch applied
1. If I run configure without setting PG_TEST_EXTRA, it won't run the
tests that require PG_TEST_EXTRA to be set. This is expected.
2. But it wont' run tests even if PG_TEST_EXTRA is set while running
make check.- that's unexpected

(see below)

3. If I run configure with PG_TEST_EXTRA set and run 'make check' in
the test directory, it runs those tests. That's expected from the
final patch but that doesn't seem to be what you described above.

I'm not entirely sure what you mean? src/test should work fine,
anything lower than that (say src/test/ssl) does not.

3. After 3, if I run `PG_TEST_EXTRA="something" make check`, it still
runs those tests. So it looks like PG_TEST_EXTRA doesn't get
overridden. If PG_TEST_EXTRA is set to something other than what was
configured, it doesn't take effect when running the corresponding
tests. E.g. PG_TEST_EXTRA is set to xid_wraparound at configure time,
but `PG_TEST_EXTRA=wal_consistency_check make check ` is run, the
tests won't use wal_consistency_check=all. - that's not expected.

I think you're running into the GNU Make override order [1]https://www.gnu.org/software/make/manual/html_node/Environment.html. For
instance when I want to override PG_TEST_EXTRA, I write

make check PG_TEST_EXTRA=whatever

If you want the environment variable to work by default instead, you can do

PG_TEST_EXTRA=whatever make check -e

If you don't want devs to have to worry about the difference, I think
we can change the assignment operator to `?=` in Makefile.global.in.

Thanks,
--Jacob

[1]: https://www.gnu.org/software/make/manual/html_node/Environment.html

#23Ashutosh Bapat
ashutosh.bapat.oss@gmail.com
In reply to: Jacob Champion (#22)
Re: PG_TEST_EXTRA and meson

On Wed, Aug 14, 2024 at 2:24 AM Jacob Champion
<jacob.champion@enterprisedb.com> wrote:

On Fri, Aug 9, 2024 at 2:26 AM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

Here are my observations with the patch applied
1. If I run configure without setting PG_TEST_EXTRA, it won't run the
tests that require PG_TEST_EXTRA to be set. This is expected.
2. But it wont' run tests even if PG_TEST_EXTRA is set while running
make check.- that's unexpected

(see below)

3. If I run configure with PG_TEST_EXTRA set and run 'make check' in
the test directory, it runs those tests. That's expected from the
final patch but that doesn't seem to be what you described above.

I'm not entirely sure what you mean? src/test should work fine,
anything lower than that (say src/test/ssl) does not.

I could run them from src/test/modules/xid_wraparound/. That's desirable.

3. After 3, if I run `PG_TEST_EXTRA="something" make check`, it still
runs those tests. So it looks like PG_TEST_EXTRA doesn't get
overridden. If PG_TEST_EXTRA is set to something other than what was
configured, it doesn't take effect when running the corresponding
tests. E.g. PG_TEST_EXTRA is set to xid_wraparound at configure time,
but `PG_TEST_EXTRA=wal_consistency_check make check ` is run, the
tests won't use wal_consistency_check=all. - that's not expected.

I think you're running into the GNU Make override order [1]. For
instance when I want to override PG_TEST_EXTRA, I write

make check PG_TEST_EXTRA=whatever

If you want the environment variable to work by default instead, you can do

PG_TEST_EXTRA=whatever make check -e

If you don't want devs to have to worry about the difference, I think
we can change the assignment operator to `?=` in Makefile.global.in.

What is working now should continue to work even after this change.
PG_TEST_EXTRA="xyz" make check works right now.

--
Best Wishes,
Ashutosh Bapat

#24Jacob Champion
jacob.champion@enterprisedb.com
In reply to: Ashutosh Bapat (#23)
1 attachment(s)
Re: PG_TEST_EXTRA and meson

On Tue, Aug 13, 2024 at 9:07 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

I'm not entirely sure what you mean? src/test should work fine,
anything lower than that (say src/test/ssl) does not.

I could run them from src/test/modules/xid_wraparound/. That's desirable.

On my machine, storing xid_wraparound into PG_TEST_EXTRA at configure
time and running `make check` from the modules/xid_wraparound
directory causes them to be skipped. Setting the environment variable
will continue to work at that directory level, though; my patch
shouldn't change that.

What is working now should continue to work even after this change.
PG_TEST_EXTRA="xyz" make check works right now.

Fair point, see attached.

Thanks,
--Jacob

Attachments:

v2-make_test_extra.diffapplication/octet-stream; name=v2-make_test_extra.diffDownload
diff --git a/configure b/configure
index 4f3aa44756..0a5f4c8912 100755
--- a/configure
+++ b/configure
@@ -764,6 +764,7 @@ LDFLAGS
 CFLAGS
 CC
 enable_injection_points
+PG_TEST_EXTRA
 enable_tap_tests
 enable_dtrace
 DTRACEFLAGS
@@ -880,6 +881,7 @@ enable_largefile
       ac_precious_vars='build_alias
 host_alias
 target_alias
+PG_TEST_EXTRA
 CC
 CFLAGS
 LDFLAGS
@@ -1587,6 +1589,8 @@ Optional Packages:
   --with-openssl          obsolete spelling of --with-ssl=openssl
 
 Some influential environment variables:
+  PG_TEST_EXTRA
+              enable selected extra tests
   CC          C compiler command
   CFLAGS      C compiler flags
   LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
@@ -3629,6 +3633,7 @@ fi
 
 
 
+
 #
 # Injection points
 #
diff --git a/configure.ac b/configure.ac
index 049bc01491..0c76ad0ebf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -236,6 +236,7 @@ AC_SUBST(enable_dtrace)
 PGAC_ARG_BOOL(enable, tap-tests, no,
               [enable TAP tests (requires Perl and IPC::Run)])
 AC_SUBST(enable_tap_tests)
+AC_ARG_VAR(PG_TEST_EXTRA, [enable selected extra tests])
 
 #
 # Injection points
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 42f50b4976..ee5a59f2a1 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -642,6 +642,11 @@ submake-libpgfeutils: | submake-generated-headers
 #
 # Testing support
 
+# Store any configure-time setting for PG_TEST_EXTRA, but let environment
+# variables override it to maintain the historical behavior of the tests.
+# (Standard `=` assignment would require devs to use a commandline option.)
+PG_TEST_EXTRA ?= @PG_TEST_EXTRA@
+
 ifneq ($(USE_MODULE_DB),)
   PL_TESTDB = pl_regression_$(NAME)
   ifneq ($(MODULE_big),)
#25Ashutosh Bapat
ashutosh.bapat.oss@gmail.com
In reply to: Jacob Champion (#24)
1 attachment(s)
Re: PG_TEST_EXTRA and meson

Hi Jacob,

On Wed, Aug 14, 2024 at 6:19 PM Jacob Champion
<jacob.champion@enterprisedb.com> wrote:

On Tue, Aug 13, 2024 at 9:07 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

I'm not entirely sure what you mean? src/test should work fine,
anything lower than that (say src/test/ssl) does not.

I could run them from src/test/modules/xid_wraparound/. That's desirable.

On my machine, storing xid_wraparound into PG_TEST_EXTRA at configure
time and running `make check` from the modules/xid_wraparound
directory causes them to be skipped. Setting the environment variable
will continue to work at that directory level, though; my patch
shouldn't change that.

What is working now should continue to work even after this change.
PG_TEST_EXTRA="xyz" make check works right now.

Fair point, see attached.

If I run
export PG_TEST_EXTRA=xid_wraparound; ./configure --prefix=$BuildDir
--enable-tap-tests && make -j4 && make -j4 install; unset
PG_TEST_EXTRA
followed by
make -C $XID_MODULE_DIR check where
XID_MODULE_DIR=src/test/modules/xid_wraparound - it skips the tests.

I thought this was working before.

Anyway, now I have written a script to test all the scenarios. You may
want to test your patch using the script. It just needs PGDir to set
to root directory of code.

If there's some other way to setting PG_TEST_EXTRA when running
configure, I think it needs to be documented.

--
Best Wishes,
Ashutosh Bapat

Attachments:

test_pg_test_extra.shapplication/x-shellscript; name=test_pg_test_extra.shDownload
#26Jacob Champion
jacob.champion@enterprisedb.com
In reply to: Ashutosh Bapat (#25)
Re: PG_TEST_EXTRA and meson

On Fri, Aug 23, 2024 at 5:59 AM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

If I run
export PG_TEST_EXTRA=xid_wraparound; ./configure --prefix=$BuildDir
--enable-tap-tests && make -j4 && make -j4 install; unset
PG_TEST_EXTRA
followed by
make -C $XID_MODULE_DIR check where
XID_MODULE_DIR=src/test/modules/xid_wraparound - it skips the tests.

Right.

I thought this was working before.

No, that goes back to my note in [1]/messages/by-id/CAOYmi+=8HVgxANzFT_BZrAeDPxAgA5_kbHy-4VowdbGr0chHvQ@mail.gmail.com -- as of c3382a3c3cc, the
variable was exported at only the src/test level, and I wanted to get
input on that so we could decide on the next approach if needed.

Anyway, now I have written a script to test all the scenarios. You may
want to test your patch using the script. It just needs PGDir to set
to root directory of code.

Thanks! I see failures in 110, 120, and 130, as expected. Note that
constructions like

PG_TEST_EXTRA="" cd $XID_MODULE_DIR && make check && cd $PGDir

will not override the environment variable for the make invocation,
just for the `cd`. Also, rather than

export PG_TEST_EXTRA; ./configure ...; unset PG_TEST_EXTRA

it's probably easier to just pass PG_TEST_EXTRA=<setting> as a command
line option to configure.

If there's some other way to setting PG_TEST_EXTRA when running
configure, I think it needs to be documented.

./configure --help shows the new variable, with the same wording as
Meson. Or do you mean that it's significant enough to deserve a spot
in installation.sgml?

--Jacob

[1]: /messages/by-id/CAOYmi+=8HVgxANzFT_BZrAeDPxAgA5_kbHy-4VowdbGr0chHvQ@mail.gmail.com

#27Ashutosh Bapat
ashutosh.bapat.oss@gmail.com
In reply to: Ashutosh Bapat (#1)
Re: PG_TEST_EXTRA and meson

On Wed, Aug 28, 2024 at 5:26 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

On Fri, Aug 23, 2024 at 9:55 PM Jacob Champion
<jacob.champion@enterprisedb.com> wrote:

On Fri, Aug 23, 2024 at 5:59 AM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

If I run
export PG_TEST_EXTRA=xid_wraparound; ./configure --prefix=$BuildDir
--enable-tap-tests && make -j4 && make -j4 install; unset
PG_TEST_EXTRA
followed by
make -C $XID_MODULE_DIR check where
XID_MODULE_DIR=src/test/modules/xid_wraparound - it skips the tests.

Right.

I thought this was working before.

No, that goes back to my note in [1] -- as of c3382a3c3cc, the
variable was exported at only the src/test level, and I wanted to get
input on that so we could decide on the next approach if needed.

I had an offline discussion with Jacob. Because of c3382a3c3cc, `make
-C src/test/modules/xid_wraparound check` will skip xid_wraparound
tests. It should be noted that when that commit was added well before
the xid_wraparound tests were added. But I don't know whether the
tests controlled by PG_TEST_EXTRA could be run using make -C that
time.

Anyway, I think, supporting PG_TEST_EXTRA at configure time without
being able to run tests using `make -C <test directory> ` is not that
useful. It only helps make check-world but not when running individual
tests.

Nazir, since you authored c3382a3c3cc, can you please provide input
that Jacob needs?

Otherwise, we should just go ahead with meson support and drop make
support for now. We may revisit it later.

--
Best Wishes,
Ashutosh Bapat

#28Jacob Champion
jacob.champion@enterprisedb.com
In reply to: Ashutosh Bapat (#27)
Re: PG_TEST_EXTRA and meson

On Wed, Aug 28, 2024 at 6:41 AM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

Nazir, since you authored c3382a3c3cc, can you please provide input
that Jacob needs?

Specifically, why the PG_TEST_EXTRA variable was being exported at the
src/test level only. If there's no longer a use case being targeted,
we can always change it in this patch, but I didn't want to do that
without understanding why it was like that to begin with.

--Jacob

#29Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Ashutosh Bapat (#27)
Re: PG_TEST_EXTRA and meson

Hi,

On Wed, 28 Aug 2024 at 16:41, Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

On Wed, Aug 28, 2024 at 5:26 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

On Fri, Aug 23, 2024 at 9:55 PM Jacob Champion
<jacob.champion@enterprisedb.com> wrote:

On Fri, Aug 23, 2024 at 5:59 AM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

If I run
export PG_TEST_EXTRA=xid_wraparound; ./configure --prefix=$BuildDir
--enable-tap-tests && make -j4 && make -j4 install; unset
PG_TEST_EXTRA
followed by
make -C $XID_MODULE_DIR check where
XID_MODULE_DIR=src/test/modules/xid_wraparound - it skips the tests.

Right.

I thought this was working before.

No, that goes back to my note in [1] -- as of c3382a3c3cc, the
variable was exported at only the src/test level, and I wanted to get
input on that so we could decide on the next approach if needed.

I had an offline discussion with Jacob. Because of c3382a3c3cc, `make
-C src/test/modules/xid_wraparound check` will skip xid_wraparound
tests. It should be noted that when that commit was added well before
the xid_wraparound tests were added. But I don't know whether the
tests controlled by PG_TEST_EXTRA could be run using make -C that
time.

I did not test but I think they could not be run because of the same
reason as below.

Anyway, I think, supporting PG_TEST_EXTRA at configure time without
being able to run tests using `make -C <test directory> ` is not that
useful. It only helps make check-world but not when running individual
tests.

Nazir, since you authored c3382a3c3cc, can you please provide input
that Jacob needs?

I think the problem is that we define PG_TEST_EXTRA in the
Makefile.global file but we do not export it there, instead we export
in the src/test/Makefile. But when you run tests from their Makefiles,
they do not include src/test/Makefile (they include Makefile.global);
so they can not get the PG_TEST_EXTRA env variable. Exporting
PG_TEST_EXTRA in the Makefile.global should solve the problem.

Also, I think TEST 110 and 170 do not look correct to me. In the
current way, we do not pass PG_TEST_EXTRA to the make command.

110 should be:
'cd $XID_MODULE_DIR && PG_TEST_EXTRA=xid_wraparound make check'
instead of 'PG_TEST_EXTRA=xid_wraparound cd $XID_MODULE_DIR && make
check'

170 should be:
'cd $XID_MODULE_DIR && PG_TEST_EXTRA="" make check && cd $PGDir'
instead of 'PG_TEST_EXTRA="" cd $XID_MODULE_DIR && make check && cd
$PGDir'

--
Regards,
Nazir Bilal Yavuz
Microsoft

#30Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Jacob Champion (#28)
Re: PG_TEST_EXTRA and meson

Hi,

On Wed, 28 Aug 2024 at 18:11, Jacob Champion
<jacob.champion@enterprisedb.com> wrote:

On Wed, Aug 28, 2024 at 6:41 AM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

Nazir, since you authored c3382a3c3cc, can you please provide input
that Jacob needs?

Specifically, why the PG_TEST_EXTRA variable was being exported at the
src/test level only. If there's no longer a use case being targeted,
we can always change it in this patch, but I didn't want to do that
without understanding why it was like that to begin with.

I do not exactly remember the reason but I think I copied the same
behavior as before, PG_TEST_EXTRA variable was checked in the
src/test/Makefile so I exported it there.

--
Regards,
Nazir Bilal Yavuz
Microsoft

#31Ashutosh Bapat
ashutosh.bapat.oss@gmail.com
In reply to: Nazir Bilal Yavuz (#29)
1 attachment(s)
Re: PG_TEST_EXTRA and meson

On Wed, Aug 28, 2024 at 8:46 PM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

Also, I think TEST 110 and 170 do not look correct to me. In the
current way, we do not pass PG_TEST_EXTRA to the make command.

110 should be:
'cd $XID_MODULE_DIR && PG_TEST_EXTRA=xid_wraparound make check'
instead of 'PG_TEST_EXTRA=xid_wraparound cd $XID_MODULE_DIR && make
check'

170 should be:
'cd $XID_MODULE_DIR && PG_TEST_EXTRA="" make check && cd $PGDir'
instead of 'PG_TEST_EXTRA="" cd $XID_MODULE_DIR && make check && cd
$PGDir'

You are right. Jacob did point that out, but I didn't fix all the
places back then. Here's updated script.

--
Best Wishes,
Ashutosh Bapat

Attachments:

test_pg_test_extra.shapplication/x-shellscript; name=test_pg_test_extra.shDownload
#32Jacob Champion
jacob.champion@enterprisedb.com
In reply to: Nazir Bilal Yavuz (#30)
1 attachment(s)
Re: PG_TEST_EXTRA and meson

On Wed, Aug 28, 2024 at 8:21 AM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

I do not exactly remember the reason but I think I copied the same
behavior as before, PG_TEST_EXTRA variable was checked in the
src/test/Makefile so I exported it there.

Okay, give v3 a try then. This exports directly from Makefile.global.
Since that gets pulled into a bunch of places, the scope is a lot
wider than it used to be; I've disabled it for PGXS so it doesn't end
up poisoning other extensions.

--Jacob

Attachments:

v3-make_test_extra.diffapplication/octet-stream; name=v3-make_test_extra.diffDownload
commit 64d222d5504ac4099d18a79b4d152c9871df015b
Author: Jacob Champion <jacob.champion@enterprisedb.com>
Date:   Fri Aug 30 10:14:48 2024 -0700

    WIP: add configure-time PG_TEST_EXTRA

diff --git a/configure b/configure
index 537366945c..c74a4aeed6 100755
--- a/configure
+++ b/configure
@@ -764,6 +764,7 @@ LDFLAGS
 CFLAGS
 CC
 enable_injection_points
+PG_TEST_EXTRA
 enable_tap_tests
 enable_dtrace
 DTRACEFLAGS
@@ -880,6 +881,7 @@ enable_largefile
       ac_precious_vars='build_alias
 host_alias
 target_alias
+PG_TEST_EXTRA
 CC
 CFLAGS
 LDFLAGS
@@ -1587,6 +1589,8 @@ Optional Packages:
   --with-openssl          obsolete spelling of --with-ssl=openssl
 
 Some influential environment variables:
+  PG_TEST_EXTRA
+              enable selected extra tests
   CC          C compiler command
   CFLAGS      C compiler flags
   LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
@@ -3629,6 +3633,7 @@ fi
 
 
 
+
 #
 # Injection points
 #
diff --git a/configure.ac b/configure.ac
index 4e279c4bd6..63994405e8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -236,6 +236,7 @@ AC_SUBST(enable_dtrace)
 PGAC_ARG_BOOL(enable, tap-tests, no,
               [enable TAP tests (requires Perl and IPC::Run)])
 AC_SUBST(enable_tap_tests)
+AC_ARG_VAR(PG_TEST_EXTRA, [enable selected extra tests])
 
 #
 # Injection points
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 42f50b4976..4859343153 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -642,6 +642,16 @@ submake-libpgfeutils: | submake-generated-headers
 #
 # Testing support
 
+# Store any configure-time setting for PG_TEST_EXTRA, but let environment
+# variables override it to maintain the historical behavior of the tests.
+# (Standard `=` assignment would require devs to use a commandline option.)
+# This is skipped in PGXS mode to keep the setting from escaping into other
+# projects' builds.
+ifndef PGXS
+PG_TEST_EXTRA ?= @PG_TEST_EXTRA@
+export PG_TEST_EXTRA
+endif
+
 ifneq ($(USE_MODULE_DB),)
   PL_TESTDB = pl_regression_$(NAME)
   ifneq ($(MODULE_big),)
diff --git a/src/test/Makefile b/src/test/Makefile
index dbd3192874..fc42f1db2b 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -27,11 +27,6 @@ ifeq ($(with_ssl),openssl)
 SUBDIRS += ssl
 endif
 
-# Test suites that are not safe by default but can be run if selected
-# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-# Export PG_TEST_EXTRA to check it in individual tap tests.
-export PG_TEST_EXTRA
-
 # We don't build or execute these by default, but we do want "make
 # clean" etc to recurse into them.  (We must filter out those that we
 # have conditionally included into SUBDIRS above, else there will be
#33Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Jacob Champion (#32)
Re: PG_TEST_EXTRA and meson

Hi,

On Fri, 30 Aug 2024 at 21:36, Jacob Champion
<jacob.champion@enterprisedb.com> wrote:

On Wed, Aug 28, 2024 at 8:21 AM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

I do not exactly remember the reason but I think I copied the same
behavior as before, PG_TEST_EXTRA variable was checked in the
src/test/Makefile so I exported it there.

Okay, give v3 a try then. This exports directly from Makefile.global.
Since that gets pulled into a bunch of places, the scope is a lot
wider than it used to be; I've disabled it for PGXS so it doesn't end
up poisoning other extensions.

Patch looks good and it passes all the test cases in Ashutosh's test script.

--
Regards,
Nazir Bilal Yavuz
Microsoft

#34Ashutosh Bapat
ashutosh.bapat.oss@gmail.com
In reply to: Nazir Bilal Yavuz (#33)
Re: PG_TEST_EXTRA and meson

On Mon, Sep 2, 2024 at 8:32 PM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

Hi,

On Fri, 30 Aug 2024 at 21:36, Jacob Champion
<jacob.champion@enterprisedb.com> wrote:

On Wed, Aug 28, 2024 at 8:21 AM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

I do not exactly remember the reason but I think I copied the same
behavior as before, PG_TEST_EXTRA variable was checked in the
src/test/Makefile so I exported it there.

Okay, give v3 a try then. This exports directly from Makefile.global.
Since that gets pulled into a bunch of places, the scope is a lot
wider than it used to be;

This looks similar to what meson does with PG_TEST_EXTRA, it is
available via get_option(). So we are closing the gap between meson
and make. That's the intention.

I've disabled it for PGXS so it doesn't end

up poisoning other extensions.

Patch looks good and it passes all the test cases in Ashutosh's test script.

Thanks Bilal for testing the patch. Can you or Jacob please create one
patchset including both meson and make fixes? Please keep the meson
and make changes in separate patches though. I think the meson patches
come from [1]/messages/by-id/CAN55FZ1Tko2N=X4f6icgFhb7syJYo_APP-9EbFcT-uH6tEi_Xg@mail.gmail.com (they probably need a rebase, git am failed) and make
patch comes from [2]/messages/by-id/CAOYmi+=6HNVhbFOVsV6X2_DVDYcUDL4AMnj7iM15gAfw__beKA@mail.gmail.com.The one fixing make needs a good commit message.

some comments on code

1. comments on changes to meson

+ variable if it exists. See <xref linkend="regress-additional"/> for

s/exists/set/

-# Test suites that are not safe by default but can be run if selected
-# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-# Export PG_TEST_EXTRA so it can be checked in individual tap tests.
-test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))

A naive question. What happens if we add PG_TEST_EXTRA in meson.build
itself rather than passing it via testwrap? E.g. like
if "PG_TEST_EXTRA" not in os.environ
test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))

I am worried that we might have to add an extra argument to testwrap
for every environment variable that influences the tests. Avoiding it
would be better.

option('PG_TEST_EXTRA', type: 'string', value: '',
- description: 'Enable selected extra tests')
+ description: 'Enable selected extra tests, please note that this
configure option is overridden by PG_TEST_EXTRA environment variable
if it exists')

All the descriptions look much shorter than this one. I suggest we
shorten this one too as
"Enable selected extra tests. Overridden by PG_TEST_EXTRA environment variable."
not as short as other descriptions but shorter than before and yet
serves its intended purpose. Or just make it the same as the one in
configure.ac. Either way the descriptions in configure.ac and
meson_options.txt should be in sync.

+# If PG_TEST_EXTRA is not set in the environment, then look for its Meson
+# configure option.
+if "PG_TEST_EXTRA" not in os.environ and args.pg_test_extra:
+ env_dict["PG_TEST_EXTRA"] = args.pg_test_extra
+

If somebody looks at just these lines, it's not clear how
PG_TEST_EXTRA is passed to the test environment if it's available in
os.environ. So one has to understand that env_dict is the test
environment. If that's so, the code and comment rewritten as below
makes more sense to me. What do you think?

# If PG_TEST_EXTRA is not already part of the test environment, check if it's
# passed via program argument --pg_test_extra. Thus we also override
# configuration time value by run time value of PG_TEST_EXTRA.
if "PG_TEST_EXTRA" not in env_dict and args.pg_test_extra:
env_dict["PG_TEST_EXTRA"] = args.pg_test_extra

But in case we decide to fix meson.build as suggested in one of the
commentsabove, this change will be unnecessary.

Note that PG_TEST_EXTRA is used in only TAP tests right now. The way
the value passed to --pg_test_extra is handled in testwrap, it will
available to every test, not just TAP tests. But this looks fine to me
since the documentation of PG_TEST_EXTRA or its name itself does not
show any intention to limit it only to TAP tests.

2. comments on make changes
Since Makefile.global.in is included in src/test/Makefile I was
expecting that the PG_TEST_EXTRA picked from configuration would be
available in src/test/Makefile from which it would be exported. But
that doesn't seem to be the case. In fact, I am getting doubtful about
the role of the current "export PG_TEST_EXTRA" in /src/test/Makefile.
Even if I remove it, it doesn't affect anything. Commands a.
PG_TEST_EXTRA=xid_wraparound make check, b.
PG_TEST_EXTRA=xid_wraparound make -C $XID_MODULE_DIR check run the
tests (and don't skip them).

Anyway with the proposed change PG_TEST_EXTRA passed at configuration
time is used if it's not defined at run time as expected. I think the
patch looks good. Nothing to complain there.

[1]: /messages/by-id/CAN55FZ1Tko2N=X4f6icgFhb7syJYo_APP-9EbFcT-uH6tEi_Xg@mail.gmail.com
[2]: /messages/by-id/CAOYmi+=6HNVhbFOVsV6X2_DVDYcUDL4AMnj7iM15gAfw__beKA@mail.gmail.com

--
Best Wishes,
Ashutosh Bapat

#35Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Ashutosh Bapat (#34)
2 attachment(s)
Re: PG_TEST_EXTRA and meson

Hi,

On Wed, 11 Sept 2024 at 13:04, Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

Thanks Bilal for testing the patch. Can you or Jacob please create one
patchset including both meson and make fixes? Please keep the meson
and make changes in separate patches though. I think the meson patches
come from [1] (they probably need a rebase, git am failed) and make
patch comes from [2].The one fixing make needs a good commit message.

I created and attached a patchset and wrote a commit message to 'make'
fix. Please feel free to edit them.

some comments on code

1. comments on changes to meson

+ variable if it exists. See <xref linkend="regress-additional"/> for

s/exists/set/

Done.

-# Test suites that are not safe by default but can be run if selected
-# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-# Export PG_TEST_EXTRA so it can be checked in individual tap tests.
-test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))

A naive question. What happens if we add PG_TEST_EXTRA in meson.build
itself rather than passing it via testwrap? E.g. like
if "PG_TEST_EXTRA" not in os.environ
test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))

Then this configure time option will be passed to the test environment
and there is no way to change it without reconfiguring if we don't
touch the testwrap file.

I am worried that we might have to add an extra argument to testwrap
for every environment variable that influences the tests. Avoiding it
would be better.

If we want to have both configure time and run time variables, I
believe that this is the only way for now.

option('PG_TEST_EXTRA', type: 'string', value: '',
- description: 'Enable selected extra tests')
+ description: 'Enable selected extra tests, please note that this
configure option is overridden by PG_TEST_EXTRA environment variable
if it exists')

All the descriptions look much shorter than this one. I suggest we
shorten this one too as
"Enable selected extra tests. Overridden by PG_TEST_EXTRA environment variable."
not as short as other descriptions but shorter than before and yet
serves its intended purpose. Or just make it the same as the one in
configure.ac. Either way the descriptions in configure.ac and
meson_options.txt should be in sync.

I liked your suggestion, done in both meson_options.txt and configure.ac.

+# If PG_TEST_EXTRA is not set in the environment, then look for its Meson
+# configure option.
+if "PG_TEST_EXTRA" not in os.environ and args.pg_test_extra:
+ env_dict["PG_TEST_EXTRA"] = args.pg_test_extra
+

If somebody looks at just these lines, it's not clear how
PG_TEST_EXTRA is passed to the test environment if it's available in
os.environ. So one has to understand that env_dict is the test
environment. If that's so, the code and comment rewritten as below
makes more sense to me. What do you think?

# If PG_TEST_EXTRA is not already part of the test environment, check if it's
# passed via program argument --pg_test_extra. Thus we also override
# configuration time value by run time value of PG_TEST_EXTRA.
if "PG_TEST_EXTRA" not in env_dict and args.pg_test_extra:
env_dict["PG_TEST_EXTRA"] = args.pg_test_extra

I think your suggestion is better, done.

But in case we decide to fix meson.build as suggested in one of the
commentsabove, this change will be unnecessary.

Note that PG_TEST_EXTRA is used in only TAP tests right now. The way
the value passed to --pg_test_extra is handled in testwrap, it will
available to every test, not just TAP tests. But this looks fine to me
since the documentation of PG_TEST_EXTRA or its name itself does not
show any intention to limit it only to TAP tests.

I agree, it looks fine to me as well.

2. comments on make changes
Since Makefile.global.in is included in src/test/Makefile I was
expecting that the PG_TEST_EXTRA picked from configuration would be
available in src/test/Makefile from which it would be exported. But
that doesn't seem to be the case. In fact, I am getting doubtful about
the role of the current "export PG_TEST_EXTRA" in /src/test/Makefile.
Even if I remove it, it doesn't affect anything. Commands a.
PG_TEST_EXTRA=xid_wraparound make check, b.
PG_TEST_EXTRA=xid_wraparound make -C $XID_MODULE_DIR check run the
tests (and don't skip them).

Yes, it looks like it is useless. If we export PG_TEST_EXTRA, then it
should be already available on the environment, right?

Anyway with the proposed change PG_TEST_EXTRA passed at configuration
time is used if it's not defined at run time as expected. I think the
patch looks good. Nothing to complain there.

--
Regards,
Nazir Bilal Yavuz
Microsoft

Attachments:

v4-0001-Make-PG_TEST_EXTRA-env-variable-override-its-Meso.patchtext/x-patch; charset=US-ASCII; name=v4-0001-Make-PG_TEST_EXTRA-env-variable-override-its-Meso.patchDownload
From 3a511b2a287b7660a0be1751fda8b52f1f5995cc Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: Wed, 11 Sep 2024 15:41:27 +0300
Subject: [PATCH v4 1/2] Make PG_TEST_EXTRA env variable override its Meson
 configure option

Since PG_TEST_EXTRA configure option is set while configuring Meson,
each change on PG_TEST_EXTRA needs reconfigure and this is costly. So,
first try to use PG_TEST_EXTRA from environment. If it does not exist,
then try to use it from its configure option in Meson builds.

After the above change, Meson builds are able to get PG_TEST_EXTRA from
environment and this overrides the configure option. PG_TEST_EXTRA
environment variable is set at the top of the .cirrus.tasks.yml file. So,
PG_TEXT_EXTRA in configure scripts became useless and were removed
because of that.
---
 doc/src/sgml/installation.sgml |  6 ++++--
 .cirrus.tasks.yml              |  6 +-----
 meson.build                    | 11 ++++++-----
 meson_options.txt              |  2 +-
 src/tools/testwrap             |  8 ++++++++
 5 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index ff9abd4649d..7c481e07e98 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -3073,8 +3073,10 @@ ninja install
       <listitem>
        <para>
         Enable test suites which require special software to run.  This option
-        accepts arguments via a whitespace-separated list.  See <xref
-        linkend="regress-additional"/> for details.
+        accepts arguments via a whitespace-separated list.  Please note that
+        this configure option is overridden by PG_TEST_EXTRA environment
+        variable if it is set.  See <xref linkend="regress-additional"/> for
+        details.
        </para>
       </listitem>
      </varlistentry>
diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index 90cb95c8681..fc413eb11ef 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -175,7 +175,6 @@ task:
         --buildtype=debug \
         -Dcassert=true -Dinjection_points=true \
         -Duuid=bsd -Dtcl_version=tcl86 -Ddtrace=auto \
-        -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
         -Dextra_lib_dirs=/usr/local/lib -Dextra_include_dirs=/usr/local/include/ \
         build
     EOF
@@ -364,7 +363,6 @@ task:
             --buildtype=debug \
             -Dcassert=true -Dinjection_points=true \
             ${LINUX_MESON_FEATURES} \
-            -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
             build
         EOF
 
@@ -380,7 +378,6 @@ task:
             -Dllvm=disabled \
             --pkg-config-path /usr/lib/i386-linux-gnu/pkgconfig/ \
             -DPERL=perl5.36-i386-linux-gnu \
-            -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
             build-32
         EOF
 
@@ -502,7 +499,6 @@ task:
       -Dextra_lib_dirs=/opt/local/lib \
       -Dcassert=true -Dinjection_points=true \
       -Duuid=e2fs -Ddtrace=auto \
-      -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
       build
 
   build_script: ninja -C build -j${BUILD_JOBS}
@@ -574,7 +570,7 @@ task:
   # Use /DEBUG:FASTLINK to avoid high memory usage during linking
   configure_script: |
     vcvarsall x64
-    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Dinjection_points=true -Db_pch=true -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
+    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Dinjection_points=true -Db_pch=true -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% build
 
   build_script: |
     vcvarsall x64
diff --git a/meson.build b/meson.build
index 4764b09266e..c11bc928b93 100644
--- a/meson.build
+++ b/meson.build
@@ -3322,11 +3322,6 @@ test_env.set('PG_REGRESS', pg_regress.full_path())
 test_env.set('REGRESS_SHLIB', regress_module.full_path())
 test_env.set('INITDB_TEMPLATE', test_initdb_template)
 
-# Test suites that are not safe by default but can be run if selected
-# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-# Export PG_TEST_EXTRA so it can be checked in individual tap tests.
-test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))
-
 # Add the temporary installation to the library search path on platforms where
 # that works (everything but windows, basically). On windows everything
 # library-like gets installed into bindir, solving that issue.
@@ -3390,6 +3385,12 @@ foreach test_dir : tests
     testwrap,
     '--basedir', meson.build_root(),
     '--srcdir', test_dir['sd'],
+    # Test suites that are not safe by default but can be run if selected
+    # by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
+    # Export PG_TEST_EXTRA so it can be checked in individual tap tests.
+    # This configure option is overridden by PG_TEST_EXTRA environment variable
+    # if it exists.
+    '--pg_test_extra', get_option('PG_TEST_EXTRA'),
   ]
 
   foreach kind, v : test_dir
diff --git a/meson_options.txt b/meson_options.txt
index b9421557606..38935196394 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -47,7 +47,7 @@ option('injection_points', type: 'boolean', value: false,
   description: 'Enable injection points')
 
 option('PG_TEST_EXTRA', type: 'string', value: '',
-  description: 'Enable selected extra tests')
+  description: 'Enable selected extra tests. Overridden by PG_TEST_EXTRA environment variable.')
 
 option('PG_GIT_REVISION', type: 'string', value: 'HEAD',
   description: 'git revision to be packaged by pgdist target')
diff --git a/src/tools/testwrap b/src/tools/testwrap
index 9a270beb72d..665e3f14ed0 100755
--- a/src/tools/testwrap
+++ b/src/tools/testwrap
@@ -13,6 +13,7 @@ parser.add_argument('--basedir', help='base directory of test', type=str)
 parser.add_argument('--testgroup', help='test group', type=str)
 parser.add_argument('--testname', help='test name', type=str)
 parser.add_argument('--skip', help='skip test (with reason)', type=str)
+parser.add_argument('--pg_test_extra', help='extra tests', type=str)
 parser.add_argument('test_command', nargs='*')
 
 args = parser.parse_args()
@@ -41,6 +42,13 @@ env_dict = {**os.environ,
             'TESTDATADIR': os.path.join(testdir, 'data'),
             'TESTLOGDIR': os.path.join(testdir, 'log')}
 
+
+# If PG_TEST_EXTRA is not already part of the test environment, check if it's
+# passed via program argument --pg_test_extra. Thus we also override
+# configuration time value by run time value of PG_TEST_EXTRA.
+if "PG_TEST_EXTRA" not in os.environ and args.pg_test_extra:
+    env_dict["PG_TEST_EXTRA"] = args.pg_test_extra
+
 sp = subprocess.Popen(args.test_command, env=env_dict, stdout=subprocess.PIPE)
 # Meson categorizes a passing TODO test point as bad
 # (https://github.com/mesonbuild/meson/issues/13183).  Remove the TODO
-- 
2.45.2

v4-0002-Add-PG_TEST_EXTRA-configure-option-to-the-make-bu.patchtext/x-patch; charset=US-ASCII; name=v4-0002-Add-PG_TEST_EXTRA-configure-option-to-the-make-bu.patchDownload
From 81f27b15bf1e03335afbbe0c07187474997d3aa0 Mon Sep 17 00:00:00 2001
From: Jacob Champion <jacob.champion@enterprisedb.com>
Date: Wed, 11 Sep 2024 15:46:33 +0300
Subject: [PATCH v4 2/2] Add PG_TEST_EXTRA configure option to the make builds

The Meson builds have PG_TEST_EXTRA as a configure-time option, which was
not available in the make builds. To ensure both build systems are in
sync, PG_TEST_EXTRA is now added as a configure-time option. It can be
set like this:
./configure PG_TEST_EXTRA="kerberos, ssl, ..."

Note that to preserve the old behavior, this configure-time option is
overridden by the PG_TEST_EXTRA environment variable.
---
 src/test/Makefile      |  5 -----
 configure              |  5 +++++
 configure.ac           |  1 +
 src/Makefile.global.in | 10 ++++++++++
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/test/Makefile b/src/test/Makefile
index dbd3192874d..fc42f1db2b9 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -27,11 +27,6 @@ ifeq ($(with_ssl),openssl)
 SUBDIRS += ssl
 endif
 
-# Test suites that are not safe by default but can be run if selected
-# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-# Export PG_TEST_EXTRA to check it in individual tap tests.
-export PG_TEST_EXTRA
-
 # We don't build or execute these by default, but we do want "make
 # clean" etc to recurse into them.  (We must filter out those that we
 # have conditionally included into SUBDIRS above, else there will be
diff --git a/configure b/configure
index 53c8a1f2bad..d06ded9cd4a 100755
--- a/configure
+++ b/configure
@@ -764,6 +764,7 @@ LDFLAGS
 CFLAGS
 CC
 enable_injection_points
+PG_TEST_EXTRA
 enable_tap_tests
 enable_dtrace
 DTRACEFLAGS
@@ -880,6 +881,7 @@ enable_largefile
       ac_precious_vars='build_alias
 host_alias
 target_alias
+PG_TEST_EXTRA
 CC
 CFLAGS
 LDFLAGS
@@ -1587,6 +1589,8 @@ Optional Packages:
   --with-openssl          obsolete spelling of --with-ssl=openssl
 
 Some influential environment variables:
+  PG_TEST_EXTRA
+              enable selected extra tests
   CC          C compiler command
   CFLAGS      C compiler flags
   LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
@@ -3629,6 +3633,7 @@ fi
 
 
 
+
 #
 # Injection points
 #
diff --git a/configure.ac b/configure.ac
index 6a35b2880bf..c5037f71964 100644
--- a/configure.ac
+++ b/configure.ac
@@ -236,6 +236,7 @@ AC_SUBST(enable_dtrace)
 PGAC_ARG_BOOL(enable, tap-tests, no,
               [enable TAP tests (requires Perl and IPC::Run)])
 AC_SUBST(enable_tap_tests)
+AC_ARG_VAR(PG_TEST_EXTRA, [Enable selected extra tests. Overridden by PG_TEST_EXTRA environment variable.])
 
 #
 # Injection points
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 42f50b49761..4859343153b 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -642,6 +642,16 @@ submake-libpgfeutils: | submake-generated-headers
 #
 # Testing support
 
+# Store any configure-time setting for PG_TEST_EXTRA, but let environment
+# variables override it to maintain the historical behavior of the tests.
+# (Standard `=` assignment would require devs to use a commandline option.)
+# This is skipped in PGXS mode to keep the setting from escaping into other
+# projects' builds.
+ifndef PGXS
+PG_TEST_EXTRA ?= @PG_TEST_EXTRA@
+export PG_TEST_EXTRA
+endif
+
 ifneq ($(USE_MODULE_DB),)
   PL_TESTDB = pl_regression_$(NAME)
   ifneq ($(MODULE_big),)
-- 
2.45.2

#36Ashutosh Bapat
ashutosh.bapat.oss@gmail.com
In reply to: Nazir Bilal Yavuz (#35)
1 attachment(s)
Re: PG_TEST_EXTRA and meson

Thanks Nazir,

-# Test suites that are not safe by default but can be run if selected
-# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-# Export PG_TEST_EXTRA so it can be checked in individual tap tests.
-test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))

A naive question. What happens if we add PG_TEST_EXTRA in meson.build
itself rather than passing it via testwrap? E.g. like
if "PG_TEST_EXTRA" not in os.environ
test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))

Then this configure time option will be passed to the test environment
and there is no way to change it without reconfiguring if we don't
touch the testwrap file.

I am worried that we might have to add an extra argument to testwrap
for every environment variable that influences the tests. Avoiding it
would be better.

If we want to have both configure time and run time variables, I
believe that this is the only way for now.

Here's what I understand, please correct me: The code in meson.build
is only called at the time of setup; not during meson test. Hence we
can not check the existence of a runtime environment variable in that
file. The things in test_env override those set at run time. So we
save it as an argument to --pg_test_extra and then use it if
PG_TEST_EXTRA is not set at run time. I tried to find if there's some
other place to store "environment variables that can be overriden at
runtime" but I can not find it. So it looks like this is the best we
can do for now.

If it comes to a point where there are more such environment variables
that need to be passed, probably we will pass a key-value string of
those to testwrap. For now, for a single variable, this looks ok.

+# If PG_TEST_EXTRA is not set in the environment, then look for its Meson
+# configure option.
+if "PG_TEST_EXTRA" not in os.environ and args.pg_test_extra:
+ env_dict["PG_TEST_EXTRA"] = args.pg_test_extra
+

If somebody looks at just these lines, it's not clear how
PG_TEST_EXTRA is passed to the test environment if it's available in
os.environ. So one has to understand that env_dict is the test
environment. If that's so, the code and comment rewritten as below
makes more sense to me. What do you think?

# If PG_TEST_EXTRA is not already part of the test environment, check if it's
# passed via program argument --pg_test_extra. Thus we also override
# configuration time value by run time value of PG_TEST_EXTRA.
if "PG_TEST_EXTRA" not in env_dict and args.pg_test_extra:
env_dict["PG_TEST_EXTRA"] = args.pg_test_extra

I think your suggestion is better, done.

I didn't see the expected change. I was talking about something like attached.

Also
1. I have also made changes to the comment,
2. renamed the argument --pg_test_extra to --pg-test-extra using
convention similar to other arguments.
3. few other cosmetic changes.

Please review and incorporate those in the respective patches and
tests. Sorry for a single diff.

Once this is done, I think we can mark this CF entry as RFC.

--
Best Wishes,
Ashutosh Bapat

Attachments:

pg_test_extra.diffsapplication/octet-stream; name=pg_test_extra.diffsDownload
diff --git a/configure b/configure
index d06ded9cd4a..31e547816f3 100755
--- a/configure
+++ b/configure
@@ -3633,7 +3633,6 @@ fi
 
 
 
-
 #
 # Injection points
 #
diff --git a/configure.ac b/configure.ac
index c5037f71964..cd63ed803af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -236,7 +236,8 @@ AC_SUBST(enable_dtrace)
 PGAC_ARG_BOOL(enable, tap-tests, no,
               [enable TAP tests (requires Perl and IPC::Run)])
 AC_SUBST(enable_tap_tests)
-AC_ARG_VAR(PG_TEST_EXTRA, [Enable selected extra tests. Overridden by PG_TEST_EXTRA environment variable.])
+AC_ARG_VAR(PG_TEST_EXTRA,
+           [Enable selected extra tests. Overridden by PG_TEST_EXTRA environment variable.])
 
 #
 # Injection points
diff --git a/meson.build b/meson.build
index c11bc928b93..9d1d8847af3 100644
--- a/meson.build
+++ b/meson.build
@@ -3390,7 +3390,7 @@ foreach test_dir : tests
     # Export PG_TEST_EXTRA so it can be checked in individual tap tests.
     # This configure option is overridden by PG_TEST_EXTRA environment variable
     # if it exists.
-    '--pg_test_extra', get_option('PG_TEST_EXTRA'),
+    '--pg-test-extra', get_option('PG_TEST_EXTRA'),
   ]
 
   foreach kind, v : test_dir
diff --git a/src/tools/testwrap b/src/tools/testwrap
index 665e3f14ed0..8ae8fb79ba7 100755
--- a/src/tools/testwrap
+++ b/src/tools/testwrap
@@ -13,7 +13,7 @@ parser.add_argument('--basedir', help='base directory of test', type=str)
 parser.add_argument('--testgroup', help='test group', type=str)
 parser.add_argument('--testname', help='test name', type=str)
 parser.add_argument('--skip', help='skip test (with reason)', type=str)
-parser.add_argument('--pg_test_extra', help='extra tests', type=str)
+parser.add_argument('--pg-test-extra', help='extra tests', type=str)
 parser.add_argument('test_command', nargs='*')
 
 args = parser.parse_args()
@@ -43,10 +43,12 @@ env_dict = {**os.environ,
             'TESTLOGDIR': os.path.join(testdir, 'log')}
 
 
-# If PG_TEST_EXTRA is not already part of the test environment, check if it's
-# passed via program argument --pg_test_extra. Thus we also override
-# configuration time value by run time value of PG_TEST_EXTRA.
-if "PG_TEST_EXTRA" not in os.environ and args.pg_test_extra:
+# The configuration time value of PG_TEST_EXTRA is supplied via arguement
+# --pg-test-extra. But it can be overridden by environment variable
+# PG_TEST_EXTRA at the time of running a test. Hence use value from arguments
+# only if PG_TEST_EXTRA is not set in the test environment, which already
+# contains all the environment variables at the time of running the test.
+if "PG_TEST_EXTRA" not in env_dict and args.pg_test_extra:
     env_dict["PG_TEST_EXTRA"] = args.pg_test_extra
 
 sp = subprocess.Popen(args.test_command, env=env_dict, stdout=subprocess.PIPE)
#37Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Ashutosh Bapat (#36)
2 attachment(s)
Re: PG_TEST_EXTRA and meson

Hi,

On Thu, 12 Sept 2024 at 12:35, Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:

Here's what I understand, please correct me: The code in meson.build
is only called at the time of setup; not during meson test. Hence we
can not check the existence of a runtime environment variable in that
file. The things in test_env override those set at run time. So we
save it as an argument to --pg_test_extra and then use it if
PG_TEST_EXTRA is not set at run time. I tried to find if there's some
other place to store "environment variables that can be overriden at
runtime" but I can not find it. So it looks like this is the best we
can do for now.

Yes, that is exactly what is happening.

If it comes to a point where there are more such environment variables
that need to be passed, probably we will pass a key-value string of
those to testwrap. For now, for a single variable, this looks ok.

Yes, that would be better.

+# If PG_TEST_EXTRA is not set in the environment, then look for its Meson
+# configure option.
+if "PG_TEST_EXTRA" not in os.environ and args.pg_test_extra:
+ env_dict["PG_TEST_EXTRA"] = args.pg_test_extra
+

If somebody looks at just these lines, it's not clear how
PG_TEST_EXTRA is passed to the test environment if it's available in
os.environ. So one has to understand that env_dict is the test
environment. If that's so, the code and comment rewritten as below
makes more sense to me. What do you think?

# If PG_TEST_EXTRA is not already part of the test environment, check if it's
# passed via program argument --pg_test_extra. Thus we also override
# configuration time value by run time value of PG_TEST_EXTRA.
if "PG_TEST_EXTRA" not in env_dict and args.pg_test_extra:
env_dict["PG_TEST_EXTRA"] = args.pg_test_extra

I think your suggestion is better, done.

I didn't see the expected change. I was talking about something like attached.

Also
1. I have also made changes to the comment,
2. renamed the argument --pg_test_extra to --pg-test-extra using
convention similar to other arguments.
3. few other cosmetic changes.

Please review and incorporate those in the respective patches and
tests. Sorry for a single diff.

Once this is done, I think we can mark this CF entry as RFC.

Thanks for the changes. I applied all of them in respective patches.

--
Regards,
Nazir Bilal Yavuz
Microsoft

Attachments:

v5-0001-Make-PG_TEST_EXTRA-env-variable-override-its-Meso.patchtext/x-patch; charset=US-ASCII; name=v5-0001-Make-PG_TEST_EXTRA-env-variable-override-its-Meso.patchDownload
From 035fe94107fe2c03647a4bb3ec4f0b3d1673e004 Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: Wed, 11 Sep 2024 15:41:27 +0300
Subject: [PATCH v5 1/2] Make PG_TEST_EXTRA env variable override its Meson
 configure option

Since PG_TEST_EXTRA configure option is set while configuring Meson,
each change on PG_TEST_EXTRA needs reconfigure and this is costly. So,
first try to use PG_TEST_EXTRA from environment. If it does not exist,
then try to use it from its configure option in Meson builds.

After the above change, Meson builds are able to get PG_TEST_EXTRA from
environment and this overrides the configure option. PG_TEST_EXTRA
environment variable is set at the top of the .cirrus.tasks.yml file. So,
PG_TEXT_EXTRA in configure scripts became useless and were removed
because of that.
---
 doc/src/sgml/installation.sgml |  6 ++++--
 .cirrus.tasks.yml              |  6 +-----
 meson.build                    | 11 ++++++-----
 meson_options.txt              |  2 +-
 src/tools/testwrap             | 10 ++++++++++
 5 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index ff9abd4649d..7c481e07e98 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -3073,8 +3073,10 @@ ninja install
       <listitem>
        <para>
         Enable test suites which require special software to run.  This option
-        accepts arguments via a whitespace-separated list.  See <xref
-        linkend="regress-additional"/> for details.
+        accepts arguments via a whitespace-separated list.  Please note that
+        this configure option is overridden by PG_TEST_EXTRA environment
+        variable if it is set.  See <xref linkend="regress-additional"/> for
+        details.
        </para>
       </listitem>
      </varlistentry>
diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index 90cb95c8681..fc413eb11ef 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -175,7 +175,6 @@ task:
         --buildtype=debug \
         -Dcassert=true -Dinjection_points=true \
         -Duuid=bsd -Dtcl_version=tcl86 -Ddtrace=auto \
-        -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
         -Dextra_lib_dirs=/usr/local/lib -Dextra_include_dirs=/usr/local/include/ \
         build
     EOF
@@ -364,7 +363,6 @@ task:
             --buildtype=debug \
             -Dcassert=true -Dinjection_points=true \
             ${LINUX_MESON_FEATURES} \
-            -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
             build
         EOF
 
@@ -380,7 +378,6 @@ task:
             -Dllvm=disabled \
             --pkg-config-path /usr/lib/i386-linux-gnu/pkgconfig/ \
             -DPERL=perl5.36-i386-linux-gnu \
-            -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
             build-32
         EOF
 
@@ -502,7 +499,6 @@ task:
       -Dextra_lib_dirs=/opt/local/lib \
       -Dcassert=true -Dinjection_points=true \
       -Duuid=e2fs -Ddtrace=auto \
-      -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
       build
 
   build_script: ninja -C build -j${BUILD_JOBS}
@@ -574,7 +570,7 @@ task:
   # Use /DEBUG:FASTLINK to avoid high memory usage during linking
   configure_script: |
     vcvarsall x64
-    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Dinjection_points=true -Db_pch=true -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
+    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Dinjection_points=true -Db_pch=true -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% build
 
   build_script: |
     vcvarsall x64
diff --git a/meson.build b/meson.build
index 4764b09266e..9d1d8847af3 100644
--- a/meson.build
+++ b/meson.build
@@ -3322,11 +3322,6 @@ test_env.set('PG_REGRESS', pg_regress.full_path())
 test_env.set('REGRESS_SHLIB', regress_module.full_path())
 test_env.set('INITDB_TEMPLATE', test_initdb_template)
 
-# Test suites that are not safe by default but can be run if selected
-# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-# Export PG_TEST_EXTRA so it can be checked in individual tap tests.
-test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))
-
 # Add the temporary installation to the library search path on platforms where
 # that works (everything but windows, basically). On windows everything
 # library-like gets installed into bindir, solving that issue.
@@ -3390,6 +3385,12 @@ foreach test_dir : tests
     testwrap,
     '--basedir', meson.build_root(),
     '--srcdir', test_dir['sd'],
+    # Test suites that are not safe by default but can be run if selected
+    # by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
+    # Export PG_TEST_EXTRA so it can be checked in individual tap tests.
+    # This configure option is overridden by PG_TEST_EXTRA environment variable
+    # if it exists.
+    '--pg-test-extra', get_option('PG_TEST_EXTRA'),
   ]
 
   foreach kind, v : test_dir
diff --git a/meson_options.txt b/meson_options.txt
index b9421557606..38935196394 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -47,7 +47,7 @@ option('injection_points', type: 'boolean', value: false,
   description: 'Enable injection points')
 
 option('PG_TEST_EXTRA', type: 'string', value: '',
-  description: 'Enable selected extra tests')
+  description: 'Enable selected extra tests. Overridden by PG_TEST_EXTRA environment variable.')
 
 option('PG_GIT_REVISION', type: 'string', value: 'HEAD',
   description: 'git revision to be packaged by pgdist target')
diff --git a/src/tools/testwrap b/src/tools/testwrap
index 9a270beb72d..8ae8fb79ba7 100755
--- a/src/tools/testwrap
+++ b/src/tools/testwrap
@@ -13,6 +13,7 @@ parser.add_argument('--basedir', help='base directory of test', type=str)
 parser.add_argument('--testgroup', help='test group', type=str)
 parser.add_argument('--testname', help='test name', type=str)
 parser.add_argument('--skip', help='skip test (with reason)', type=str)
+parser.add_argument('--pg-test-extra', help='extra tests', type=str)
 parser.add_argument('test_command', nargs='*')
 
 args = parser.parse_args()
@@ -41,6 +42,15 @@ env_dict = {**os.environ,
             'TESTDATADIR': os.path.join(testdir, 'data'),
             'TESTLOGDIR': os.path.join(testdir, 'log')}
 
+
+# The configuration time value of PG_TEST_EXTRA is supplied via arguement
+# --pg-test-extra. But it can be overridden by environment variable
+# PG_TEST_EXTRA at the time of running a test. Hence use value from arguments
+# only if PG_TEST_EXTRA is not set in the test environment, which already
+# contains all the environment variables at the time of running the test.
+if "PG_TEST_EXTRA" not in env_dict and args.pg_test_extra:
+    env_dict["PG_TEST_EXTRA"] = args.pg_test_extra
+
 sp = subprocess.Popen(args.test_command, env=env_dict, stdout=subprocess.PIPE)
 # Meson categorizes a passing TODO test point as bad
 # (https://github.com/mesonbuild/meson/issues/13183).  Remove the TODO
-- 
2.45.2

v5-0002-Add-PG_TEST_EXTRA-configure-option-to-the-make-bu.patchtext/x-patch; charset=US-ASCII; name=v5-0002-Add-PG_TEST_EXTRA-configure-option-to-the-make-bu.patchDownload
From 8326585575b7571e227392269afae272fdb3eb28 Mon Sep 17 00:00:00 2001
From: Jacob Champion <jacob.champion@enterprisedb.com>
Date: Wed, 11 Sep 2024 15:46:33 +0300
Subject: [PATCH v5 2/2] Add PG_TEST_EXTRA configure option to the make builds

The Meson builds have PG_TEST_EXTRA as a configure-time option, which was
not available in the make builds. To ensure both build systems are in
sync, PG_TEST_EXTRA is now added as a configure-time option. It can be
set like this:
./configure PG_TEST_EXTRA="kerberos, ssl, ..."

Note that to preserve the old behavior, this configure-time option is
overridden by the PG_TEST_EXTRA environment variable.
---
 src/test/Makefile      |  5 -----
 configure              |  4 ++++
 configure.ac           |  2 ++
 src/Makefile.global.in | 10 ++++++++++
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/test/Makefile b/src/test/Makefile
index dbd3192874d..fc42f1db2b9 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -27,11 +27,6 @@ ifeq ($(with_ssl),openssl)
 SUBDIRS += ssl
 endif
 
-# Test suites that are not safe by default but can be run if selected
-# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-# Export PG_TEST_EXTRA to check it in individual tap tests.
-export PG_TEST_EXTRA
-
 # We don't build or execute these by default, but we do want "make
 # clean" etc to recurse into them.  (We must filter out those that we
 # have conditionally included into SUBDIRS above, else there will be
diff --git a/configure b/configure
index 53c8a1f2bad..31e547816f3 100755
--- a/configure
+++ b/configure
@@ -764,6 +764,7 @@ LDFLAGS
 CFLAGS
 CC
 enable_injection_points
+PG_TEST_EXTRA
 enable_tap_tests
 enable_dtrace
 DTRACEFLAGS
@@ -880,6 +881,7 @@ enable_largefile
       ac_precious_vars='build_alias
 host_alias
 target_alias
+PG_TEST_EXTRA
 CC
 CFLAGS
 LDFLAGS
@@ -1587,6 +1589,8 @@ Optional Packages:
   --with-openssl          obsolete spelling of --with-ssl=openssl
 
 Some influential environment variables:
+  PG_TEST_EXTRA
+              enable selected extra tests
   CC          C compiler command
   CFLAGS      C compiler flags
   LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
diff --git a/configure.ac b/configure.ac
index 6a35b2880bf..cd63ed803af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -236,6 +236,8 @@ AC_SUBST(enable_dtrace)
 PGAC_ARG_BOOL(enable, tap-tests, no,
               [enable TAP tests (requires Perl and IPC::Run)])
 AC_SUBST(enable_tap_tests)
+AC_ARG_VAR(PG_TEST_EXTRA,
+           [Enable selected extra tests. Overridden by PG_TEST_EXTRA environment variable.])
 
 #
 # Injection points
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 42f50b49761..4859343153b 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -642,6 +642,16 @@ submake-libpgfeutils: | submake-generated-headers
 #
 # Testing support
 
+# Store any configure-time setting for PG_TEST_EXTRA, but let environment
+# variables override it to maintain the historical behavior of the tests.
+# (Standard `=` assignment would require devs to use a commandline option.)
+# This is skipped in PGXS mode to keep the setting from escaping into other
+# projects' builds.
+ifndef PGXS
+PG_TEST_EXTRA ?= @PG_TEST_EXTRA@
+export PG_TEST_EXTRA
+endif
+
 ifneq ($(USE_MODULE_DB),)
   PL_TESTDB = pl_regression_$(NAME)
   ifneq ($(MODULE_big),)
-- 
2.45.2

#38Ashutosh Bapat
ashutosh.bapat.oss@gmail.com
In reply to: Nazir Bilal Yavuz (#37)
3 attachment(s)
Re: PG_TEST_EXTRA and meson

On Thu, Sep 12, 2024 at 4:28 PM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

Once this is done, I think we can mark this CF entry as RFC.

Thanks for the changes. I applied all of them in respective patches.

Thanks a lot. PFA the patchset with

1. Improved comment related to PG_TEST_EXTRA in meson.build. More on
the improvement in the commit message of patch 0002, which should be
merged into 0001.
2. You have written comprehensive commit messages. I elaborated on
them a bit. I have left your version in the commit message for
committer to pick up appropriate one.

Marking the entry as RFC.

--
Best Wishes,
Ashutosh Bapat

Attachments:

0002-Improve-comment-about-configuration-time-PG-20240913.patchtext/x-patch; charset=US-ASCII; name=0002-Improve-comment-about-configuration-time-PG-20240913.patchDownload
From f345f5dbbd0324a1b7389e046caefecab4c357fc Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 13 Sep 2024 10:58:40 +0530
Subject: [PATCH 3/4] Improve comment about configuration time PG_TEST_EXTRA

The comment mentioned "not safe" and "while-space separate list" which are not
relevant to the code in meson.build file. The purpose mentioned in the comment
has already gone stale; the variable is used for tests which take longer but are
otherwise safe. And the content may change in the future. This code should just
make the value of the variable available to the tests irrespective of its
purpose and content. Improved the comment to mention how the PG_TEST_EXTRA is
passed to tests instead of the variable's content and purpose.

Ashutosh Bapat
---
 meson.build | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/meson.build b/meson.build
index 9d1d8847af3..24a25a72bd1 100644
--- a/meson.build
+++ b/meson.build
@@ -3385,11 +3385,10 @@ foreach test_dir : tests
     testwrap,
     '--basedir', meson.build_root(),
     '--srcdir', test_dir['sd'],
-    # Test suites that are not safe by default but can be run if selected
-    # by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-    # Export PG_TEST_EXTRA so it can be checked in individual tap tests.
-    # This configure option is overridden by PG_TEST_EXTRA environment variable
-    # if it exists.
+    # Some test suites are not run by default but can be run if selected by the
+    # user via variable PG_TEST_EXTRA. Pass configuration time value of
+    # PG_TEST_EXTRA as an argument to testwrap so that it can be overridden by
+    # run time value, if any.
     '--pg-test-extra', get_option('PG_TEST_EXTRA'),
   ]
 
-- 
2.34.1

0001-Runtime-value-of-PG_TEST_EXTRA-in-Meson-20240913.patchtext/x-patch; charset=US-ASCII; name=0001-Runtime-value-of-PG_TEST_EXTRA-in-Meson-20240913.patchDownload
From 8c518478ed1457ce227914009183b88ad56738c9 Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: Wed, 11 Sep 2024 15:41:27 +0300
Subject: [PATCH 2/4] Runtime value of PG_TEST_EXTRA in Meson

Tests run using Meson ignore the value of environment variable
PG_TEST_EXTRA at the time of running tests and use the configuration
time value. In order to run the tests not specified in configuration
time PG_TEST_EXTRA, one needs to reconfigure which is costly. Allow
runtime value of PG_TEST_EXTRA to override the configuration time value.
In order to do this the configuration time value is passed as argument
"--pg-test-extra" to testwrap instead of adding it to the test
environment. If the environment variable is set at the time of running
test, its value is used. Otherwise value passed as the argument is used.

Meson builds use the same value of PG_TEST_EXTRA at the configuration
time and at the time of running the tests. Hence remove it from meson
setup command so as to treat both Meson and Make builds the same way in
CI.

--- original commit message by Nazir Bilal Yavuz
Make PG_TEST_EXTRA env variable override its Meson configure option

Since PG_TEST_EXTRA configure option is set while configuring Meson,
each change on PG_TEST_EXTRA needs reconfigure and this is costly. So,
first try to use PG_TEST_EXTRA from environment. If it does not exist,
then try to use it from its configure option in Meson builds.

After the above change, Meson builds are able to get PG_TEST_EXTRA from
environment and this overrides the configure option. PG_TEST_EXTRA
environment variable is set at the top of the .cirrus.tasks.yml file. So,
PG_TEXT_EXTRA in configure scripts became useless and were removed
because of that.
---- original commit message by Nazir Bilal Yavuz ends

Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reviewed by: Ashutosh Bapat with inputs from Tom Lane and Andrew Dunstan
---
 .cirrus.tasks.yml              |  6 +-----
 doc/src/sgml/installation.sgml |  6 ++++--
 meson.build                    | 11 ++++++-----
 meson_options.txt              |  2 +-
 src/tools/testwrap             | 10 ++++++++++
 5 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index 90cb95c8681..fc413eb11ef 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -175,7 +175,6 @@ task:
         --buildtype=debug \
         -Dcassert=true -Dinjection_points=true \
         -Duuid=bsd -Dtcl_version=tcl86 -Ddtrace=auto \
-        -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
         -Dextra_lib_dirs=/usr/local/lib -Dextra_include_dirs=/usr/local/include/ \
         build
     EOF
@@ -364,7 +363,6 @@ task:
             --buildtype=debug \
             -Dcassert=true -Dinjection_points=true \
             ${LINUX_MESON_FEATURES} \
-            -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
             build
         EOF
 
@@ -380,7 +378,6 @@ task:
             -Dllvm=disabled \
             --pkg-config-path /usr/lib/i386-linux-gnu/pkgconfig/ \
             -DPERL=perl5.36-i386-linux-gnu \
-            -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
             build-32
         EOF
 
@@ -502,7 +499,6 @@ task:
       -Dextra_lib_dirs=/opt/local/lib \
       -Dcassert=true -Dinjection_points=true \
       -Duuid=e2fs -Ddtrace=auto \
-      -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
       build
 
   build_script: ninja -C build -j${BUILD_JOBS}
@@ -574,7 +570,7 @@ task:
   # Use /DEBUG:FASTLINK to avoid high memory usage during linking
   configure_script: |
     vcvarsall x64
-    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Dinjection_points=true -Db_pch=true -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build
+    meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Dinjection_points=true -Db_pch=true -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% build
 
   build_script: |
     vcvarsall x64
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index ff9abd4649d..7c481e07e98 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -3073,8 +3073,10 @@ ninja install
       <listitem>
        <para>
         Enable test suites which require special software to run.  This option
-        accepts arguments via a whitespace-separated list.  See <xref
-        linkend="regress-additional"/> for details.
+        accepts arguments via a whitespace-separated list.  Please note that
+        this configure option is overridden by PG_TEST_EXTRA environment
+        variable if it is set.  See <xref linkend="regress-additional"/> for
+        details.
        </para>
       </listitem>
      </varlistentry>
diff --git a/meson.build b/meson.build
index 4764b09266e..9d1d8847af3 100644
--- a/meson.build
+++ b/meson.build
@@ -3322,11 +3322,6 @@ test_env.set('PG_REGRESS', pg_regress.full_path())
 test_env.set('REGRESS_SHLIB', regress_module.full_path())
 test_env.set('INITDB_TEMPLATE', test_initdb_template)
 
-# Test suites that are not safe by default but can be run if selected
-# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-# Export PG_TEST_EXTRA so it can be checked in individual tap tests.
-test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))
-
 # Add the temporary installation to the library search path on platforms where
 # that works (everything but windows, basically). On windows everything
 # library-like gets installed into bindir, solving that issue.
@@ -3390,6 +3385,12 @@ foreach test_dir : tests
     testwrap,
     '--basedir', meson.build_root(),
     '--srcdir', test_dir['sd'],
+    # Test suites that are not safe by default but can be run if selected
+    # by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
+    # Export PG_TEST_EXTRA so it can be checked in individual tap tests.
+    # This configure option is overridden by PG_TEST_EXTRA environment variable
+    # if it exists.
+    '--pg-test-extra', get_option('PG_TEST_EXTRA'),
   ]
 
   foreach kind, v : test_dir
diff --git a/meson_options.txt b/meson_options.txt
index b9421557606..38935196394 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -47,7 +47,7 @@ option('injection_points', type: 'boolean', value: false,
   description: 'Enable injection points')
 
 option('PG_TEST_EXTRA', type: 'string', value: '',
-  description: 'Enable selected extra tests')
+  description: 'Enable selected extra tests. Overridden by PG_TEST_EXTRA environment variable.')
 
 option('PG_GIT_REVISION', type: 'string', value: 'HEAD',
   description: 'git revision to be packaged by pgdist target')
diff --git a/src/tools/testwrap b/src/tools/testwrap
index 9a270beb72d..8ae8fb79ba7 100755
--- a/src/tools/testwrap
+++ b/src/tools/testwrap
@@ -13,6 +13,7 @@ parser.add_argument('--basedir', help='base directory of test', type=str)
 parser.add_argument('--testgroup', help='test group', type=str)
 parser.add_argument('--testname', help='test name', type=str)
 parser.add_argument('--skip', help='skip test (with reason)', type=str)
+parser.add_argument('--pg-test-extra', help='extra tests', type=str)
 parser.add_argument('test_command', nargs='*')
 
 args = parser.parse_args()
@@ -41,6 +42,15 @@ env_dict = {**os.environ,
             'TESTDATADIR': os.path.join(testdir, 'data'),
             'TESTLOGDIR': os.path.join(testdir, 'log')}
 
+
+# The configuration time value of PG_TEST_EXTRA is supplied via arguement
+# --pg-test-extra. But it can be overridden by environment variable
+# PG_TEST_EXTRA at the time of running a test. Hence use value from arguments
+# only if PG_TEST_EXTRA is not set in the test environment, which already
+# contains all the environment variables at the time of running the test.
+if "PG_TEST_EXTRA" not in env_dict and args.pg_test_extra:
+    env_dict["PG_TEST_EXTRA"] = args.pg_test_extra
+
 sp = subprocess.Popen(args.test_command, env=env_dict, stdout=subprocess.PIPE)
 # Meson categorizes a passing TODO test point as bad
 # (https://github.com/mesonbuild/meson/issues/13183).  Remove the TODO
-- 
2.34.1

0003-Add-PG_TEST_EXTRA-configure-option-to-the-M-20240913.patchtext/x-patch; charset=US-ASCII; name=0003-Add-PG_TEST_EXTRA-configure-option-to-the-M-20240913.patchDownload
From e1aba24cdd01da33169d7e7769b91a98a1f6a125 Mon Sep 17 00:00:00 2001
From: Jacob Champion <jacob.champion@enterprisedb.com>
Date: Wed, 11 Sep 2024 15:46:33 +0300
Subject: [PATCH 4/4] Add PG_TEST_EXTRA configure option to the Make builds

The Meson builds have PG_TEST_EXTRA as a configure-time variable, which
was not available in the Make builds. To ensure both build systems are
in sync, PG_TEST_EXTRA is now added as a configure-time variable. It can
be set like this:
./configure PG_TEST_EXTRA="kerberos, ssl, ..."

Note that to preserve the old behavior, this configure-time variable is
overridden by the PG_TEST_EXTRA environment variable.

Author: Jacob Champion <jacob.champion@enterprisedb.com>
Reviewed by: Ashutosh Bapat, Nazir Bilal Yavuz with inputs from Tom Lane
and Andrew Dunstan
---
 configure              |  4 ++++
 configure.ac           |  2 ++
 src/Makefile.global.in | 10 ++++++++++
 src/test/Makefile      |  5 -----
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/configure b/configure
index 53c8a1f2bad..31e547816f3 100755
--- a/configure
+++ b/configure
@@ -764,6 +764,7 @@ LDFLAGS
 CFLAGS
 CC
 enable_injection_points
+PG_TEST_EXTRA
 enable_tap_tests
 enable_dtrace
 DTRACEFLAGS
@@ -880,6 +881,7 @@ enable_largefile
       ac_precious_vars='build_alias
 host_alias
 target_alias
+PG_TEST_EXTRA
 CC
 CFLAGS
 LDFLAGS
@@ -1587,6 +1589,8 @@ Optional Packages:
   --with-openssl          obsolete spelling of --with-ssl=openssl
 
 Some influential environment variables:
+  PG_TEST_EXTRA
+              enable selected extra tests
   CC          C compiler command
   CFLAGS      C compiler flags
   LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
diff --git a/configure.ac b/configure.ac
index 6a35b2880bf..cd63ed803af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -236,6 +236,8 @@ AC_SUBST(enable_dtrace)
 PGAC_ARG_BOOL(enable, tap-tests, no,
               [enable TAP tests (requires Perl and IPC::Run)])
 AC_SUBST(enable_tap_tests)
+AC_ARG_VAR(PG_TEST_EXTRA,
+           [Enable selected extra tests. Overridden by PG_TEST_EXTRA environment variable.])
 
 #
 # Injection points
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 42f50b49761..4859343153b 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -642,6 +642,16 @@ submake-libpgfeutils: | submake-generated-headers
 #
 # Testing support
 
+# Store any configure-time setting for PG_TEST_EXTRA, but let environment
+# variables override it to maintain the historical behavior of the tests.
+# (Standard `=` assignment would require devs to use a commandline option.)
+# This is skipped in PGXS mode to keep the setting from escaping into other
+# projects' builds.
+ifndef PGXS
+PG_TEST_EXTRA ?= @PG_TEST_EXTRA@
+export PG_TEST_EXTRA
+endif
+
 ifneq ($(USE_MODULE_DB),)
   PL_TESTDB = pl_regression_$(NAME)
   ifneq ($(MODULE_big),)
diff --git a/src/test/Makefile b/src/test/Makefile
index dbd3192874d..fc42f1db2b9 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -27,11 +27,6 @@ ifeq ($(with_ssl),openssl)
 SUBDIRS += ssl
 endif
 
-# Test suites that are not safe by default but can be run if selected
-# by the user via the whitespace-separated list in variable PG_TEST_EXTRA.
-# Export PG_TEST_EXTRA to check it in individual tap tests.
-export PG_TEST_EXTRA
-
 # We don't build or execute these by default, but we do want "make
 # clean" etc to recurse into them.  (We must filter out those that we
 # have conditionally included into SUBDIRS above, else there will be
-- 
2.34.1

#39Heikki Linnakangas
hlinnaka@iki.fi
In reply to: Ashutosh Bapat (#38)
Re: PG_TEST_EXTRA and meson

On 13/09/2024 13:41, Ashutosh Bapat wrote:

On Thu, Sep 12, 2024 at 4:28 PM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote:

Once this is done, I think we can mark this CF entry as RFC.

Thanks for the changes. I applied all of them in respective patches.

Thanks a lot. PFA the patchset with

1. Improved comment related to PG_TEST_EXTRA in meson.build. More on
the improvement in the commit message of patch 0002, which should be
merged into 0001.
2. You have written comprehensive commit messages. I elaborated on
them a bit. I have left your version in the commit message for
committer to pick up appropriate one.

Marking the entry as RFC.

Committed with minor changes. I squashed the first two patches, and
rephrased the docs and some comments a little.

Thanks!

--
Heikki Linnakangas
Neon (https://neon.tech)