| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
import argparse |
| 4 |
import shutil |
| 5 |
import subprocess |
| 6 |
import os |
| 7 |
import sys |
| 8 |
|
| 9 |
parser = argparse.ArgumentParser() |
| 10 |
|
| 11 |
parser.add_argument('--srcdir', help='source directory of test', type=str) |
| 12 |
parser.add_argument('--basedir', help='base directory of test', type=str) |
| 13 |
parser.add_argument('--testgroup', help='test group', type=str) |
| 14 |
parser.add_argument('--testname', help='test name', type=str) |
| 15 |
parser.add_argument('--skip', help='skip test (with reason)', type=str) |
| 16 |
parser.add_argument('--pg-test-extra', help='extra tests', type=str) |
| 17 |
parser.add_argument('test_command', nargs='*') |
| 18 |
|
| 19 |
args = parser.parse_args() |
| 20 |
|
| 21 |
testdir = '{}/testrun/{}/{}'.format( |
| 22 |
args.basedir, args.testgroup, args.testname) |
| 23 |
|
| 24 |
print('# executing test in {} group {} test {}'.format( |
| 25 |
testdir, args.testgroup, args.testname)) |
| 26 |
sys.stdout.flush() |
| 27 |
|
| 28 |
if args.skip is not None: |
| 29 |
print('1..0 # Skipped: ' + args.skip) |
| 30 |
sys.exit(0) |
| 31 |
|
| 32 |
if os.path.exists(testdir) and os.path.isdir(testdir): |
| 33 |
shutil.rmtree(testdir) |
| 34 |
os.makedirs(testdir) |
| 35 |
|
| 36 |
os.chdir(args.srcdir) |
| 37 |
|
| 38 |
# mark test as having started |
| 39 |
open(os.path.join(testdir, 'test.start'), 'x') |
| 40 |
|
| 41 |
env_dict = {**os.environ, |
| 42 |
'TESTDATADIR': os.path.join(testdir, 'data'), |
| 43 |
'TESTLOGDIR': os.path.join(testdir, 'log')} |
| 44 |
|
| 45 |
|
| 46 |
# The configuration time value of PG_TEST_EXTRA is supplied via argument |
| 47 |
# --pg-test-extra. But it can be overridden by environment variable |
| 48 |
# PG_TEST_EXTRA at the time of running a test. Hence use value from arguments |
| 49 |
# only if PG_TEST_EXTRA is not set in the test environment, which already |
| 50 |
# contains all the environment variables at the time of running the test. |
| 51 |
if "PG_TEST_EXTRA" not in env_dict and args.pg_test_extra: |
| 52 |
env_dict["PG_TEST_EXTRA"] = args.pg_test_extra |
| 53 |
|
| 54 |
sp = subprocess.Popen(args.test_command, env=env_dict, stdout=subprocess.PIPE) |
| 55 |
# Meson categorizes a passing TODO test point as bad |
| 56 |
# (https://github.com/mesonbuild/meson/issues/13183). Remove the TODO |
| 57 |
# directive, so Meson computes the file result like Perl does. This could |
| 58 |
# have the side effect of delaying stdout lines relative to stderr. That |
| 59 |
# doesn't affect the log file, and the TAP protocol uses stdout only. |
| 60 |
for line in sp.stdout: |
| 61 |
if line.startswith(b'ok '): |
| 62 |
line = line.replace(b' # TODO ', b' # testwrap-overridden-TODO ', 1) |
| 63 |
sys.stdout.buffer.write(line) |
| 64 |
sys.stdout.flush() |
| 65 |
returncode = sp.wait() |
| 66 |
|
| 67 |
if returncode == 0: |
| 68 |
print('# test succeeded') |
| 69 |
open(os.path.join(testdir, 'test.success'), 'x') |
| 70 |
else: |
| 71 |
print('# test failed') |
| 72 |
open(os.path.join(testdir, 'test.fail'), 'x') |
| 73 |
sys.exit(returncode) |