Skip to content

Commit eabd91f

Browse files
committed
Fix make distcheck for Python test suite
Python tests assumed the build and source directories were identical, which holds for an in-tree build but not for `make distcheck`, where automake builds in a separate _build/sub directory. Under distcheck the wolfssl binary was searched for under the source tree (where it did not exist), fixture files were opened via cwd-relative paths, and the certs/ tree was not distributed at all. As a result every Python test either failed to find the wolfssl binary or skipped because certs/ was missing. - Add certs/ to EXTRA_DIST so it ships in the distribution tarball. - Teach wolfclu_test.py to locate the wolfssl binary and certs/ via the build/source directories exported through AM_TESTS_ENVIRONMENT, with sensible fallbacks for direct script invocation. - Replace cwd-relative "./tests/<dir>" paths in dgst, hash, and x509-process tests with paths derived from each test file's location, so they resolve correctly regardless of where the test is run from.
1 parent 14cae20 commit eabd91f

5 files changed

Lines changed: 32 additions & 5 deletions

File tree

Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ dist_noinst_SCRIPTS=
2121

2222
TEST_EXTENSIONS = .sh .py
2323
PY_LOG_COMPILER = $(PYTHON)
24+
AM_TESTS_ENVIRONMENT = \
25+
WOLFCLU_BUILDDIR='$(abs_top_builddir)'; export WOLFCLU_BUILDDIR; \
26+
WOLFCLU_SRCDIR='$(abs_top_srcdir)'; export WOLFCLU_SRCDIR;
2427

2528
#includes additional rules from aminclude.am
2629
@INC_AMINCLUDE@
@@ -32,6 +35,7 @@ DISTCLEANFILES+= aminclude.am
3235
ACLOCAL_AMFLAGS= -I m4
3336

3437
EXTRA_DIST+= tests
38+
EXTRA_DIST+= certs
3539
EXTRA_DIST+= manpages
3640
EXTRA_DIST+= README.md
3741
EXTRA_DIST+= LICENSE

tests/dgst/dgst-test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
1010
from wolfclu_test import CERTS_DIR, run_wolfssl, test_main
1111

12-
DGST_DIR = os.path.join(".", "tests", "dgst")
12+
DGST_DIR = os.path.dirname(os.path.abspath(__file__))
1313

1414

1515
class DgstVerifyTest(unittest.TestCase):

tests/hash/hash-test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
99
from wolfclu_test import CERTS_DIR, run_wolfssl, test_main
1010

11-
HASH_DIR = os.path.join(".", "tests", "hash")
11+
HASH_DIR = os.path.dirname(os.path.abspath(__file__))
1212
CERT_FILE = os.path.join(CERTS_DIR, "ca-cert.pem")
1313

1414

tests/wolfclu_test.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@
1212

1313

1414
def _find_wolfssl_bin():
15-
"""Locate the wolfssl binary, searching common build output paths."""
15+
"""Locate the wolfssl binary, searching common build output paths.
16+
17+
Under `make distcheck`, the build directory differs from the source
18+
directory, so the binary is produced next to where tests are invoked
19+
(the current working directory) rather than under the source tree.
20+
Honour WOLFCLU_BUILDDIR if set by the test harness, then fall back to
21+
the current working directory, and finally the source tree.
22+
"""
23+
builddir = os.environ.get("WOLFCLU_BUILDDIR") or os.getcwd()
1624
if platform.system() == "Windows":
1725
candidates = [
26+
os.path.join(builddir, "wolfssl.exe"),
1827
os.path.join(_PROJECT_ROOT, "x64", "Debug", "wolfssl.exe"),
1928
os.path.join(_PROJECT_ROOT, "x64", "Release", "wolfssl.exe"),
2029
os.path.join(_PROJECT_ROOT, "Debug", "wolfssl.exe"),
@@ -23,6 +32,7 @@ def _find_wolfssl_bin():
2332
]
2433
else:
2534
candidates = [
35+
os.path.join(builddir, "wolfssl"),
2636
os.path.join(_PROJECT_ROOT, "wolfssl"),
2737
]
2838

@@ -34,8 +44,21 @@ def _find_wolfssl_bin():
3444
return candidates[0]
3545

3646

47+
def _find_certs_dir():
48+
"""Locate the certs directory (source tree or extracted tarball)."""
49+
srcdir = os.environ.get("WOLFCLU_SRCDIR")
50+
candidates = []
51+
if srcdir:
52+
candidates.append(os.path.join(srcdir, "certs"))
53+
candidates.append(os.path.join(_PROJECT_ROOT, "certs"))
54+
for path in candidates:
55+
if os.path.isdir(path):
56+
return path
57+
return candidates[-1]
58+
59+
3760
WOLFSSL_BIN = _find_wolfssl_bin()
38-
CERTS_DIR = os.path.join(_PROJECT_ROOT, "certs")
61+
CERTS_DIR = _find_certs_dir()
3962

4063

4164
def run_wolfssl(*args, stdin_data=None, timeout=60):

tests/x509/x509-process-test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
1111
from wolfclu_test import WOLFSSL_BIN, CERTS_DIR, run_wolfssl, test_main
1212

13-
TESTS_X509_DIR = os.path.join(".", "tests", "x509")
13+
TESTS_X509_DIR = os.path.dirname(os.path.abspath(__file__))
1414
HAS_OPENSSL = shutil.which("openssl") is not None
1515

1616

0 commit comments

Comments
 (0)