# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
-from functools import partial
import filecmp
import os
from pathlib import Path
import subprocess
import tempfile
import time
-from typing import Any, List, Optional
+from typing import Any
import pytest
return isctest.template.TemplateEngine(system_test_dir)
-def _run_script(
- system_test_dir: Path,
- interpreter: str,
- script: str,
- args: Optional[List[str]] = None,
-):
- """Helper function for the shell / perl script invocations (through fixtures below)."""
- if args is None:
- args = []
- path = Path(script)
- if not path.is_absolute():
- # make sure relative paths are always relative to system_dir
- path = system_test_dir.parent / path
- script = str(path)
- cwd = os.getcwd()
- if not path.exists():
- raise FileNotFoundError(f"script {script} not found in {cwd}")
- isctest.log.debug("running script: %s %s %s", interpreter, script, " ".join(args))
- isctest.log.debug(" workdir: %s", cwd)
- returncode = 1
-
- cmd = [interpreter, script] + args
- with subprocess.Popen(
- cmd,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- bufsize=1,
- universal_newlines=True,
- errors="backslashreplace",
- ) as proc:
- if proc.stdout:
- for line in proc.stdout:
- isctest.log.info(" %s", line.rstrip("\n"))
- proc.communicate()
- returncode = proc.returncode
- if returncode:
- raise subprocess.CalledProcessError(returncode, cmd)
- isctest.log.debug(" exited with %d", returncode)
-
-
def _get_node_path(node) -> Path:
if isinstance(node.parent, pytest.Session):
if _pytest_major_ver >= 8:
@pytest.fixture(scope="module")
-def shell(system_test_dir):
- """Function to call a shell script with arguments."""
- return partial(_run_script, system_test_dir, os.environ["SHELL"])
-
-
-@pytest.fixture(scope="module")
-def perl(system_test_dir):
- """Function to call a perl script with arguments."""
- return partial(_run_script, system_test_dir, os.environ["PERL"])
-
-
-@pytest.fixture(scope="module")
-def run_tests_sh(system_test_dir, shell):
+def run_tests_sh(system_test_dir):
"""Utility function to execute tests.sh as a python test."""
def run_tests():
- shell(f"{system_test_dir}/tests.sh")
+ isctest.run.shell(f"{system_test_dir}/tests.sh")
return run_tests
request,
system_test_dir,
templates,
- shell,
- perl,
):
"""
Driver of the test setup/teardown process. Used automatically for every test module.
def check_net_interfaces():
try:
- perl("testsock.pl", ["-p", os.environ["PORT"]])
+ isctest.run.perl(
+ f"{os.environ['srcdir']}/testsock.pl", ["-p", os.environ["PORT"]]
+ )
except subprocess.CalledProcessError as exc:
isctest.log.error("testsock.pl: exited with code %d", exc.returncode)
pytest.skip("Network interface aliases not set up.")
def check_prerequisites():
try:
- shell(f"{system_test_dir}/prereq.sh")
+ isctest.run.shell(f"{system_test_dir}/prereq.sh")
except FileNotFoundError:
pass # prereq.sh is optional
except subprocess.CalledProcessError:
def setup_test():
templates.render_auto()
try:
- shell(f"{system_test_dir}/setup.sh")
+ isctest.run.shell(f"{system_test_dir}/setup.sh")
except FileNotFoundError:
pass # setup.sh is optional
except subprocess.CalledProcessError as exc:
def start_servers():
try:
- perl("start.pl", ["--port", os.environ["PORT"], system_test_dir.name])
+ isctest.run.perl(
+ f"{os.environ['srcdir']}/start.pl",
+ ["--port", os.environ["PORT"], system_test_dir.name],
+ )
except subprocess.CalledProcessError as exc:
isctest.log.error("Failed to start servers")
pytest.fail(f"start.pl exited with {exc.returncode}")
def stop_servers():
try:
- perl("stop.pl", [system_test_dir.name])
+ isctest.run.perl(f"{os.environ['srcdir']}/stop.pl", [system_test_dir.name])
except subprocess.CalledProcessError as exc:
isctest.log.error("Failed to stop servers")
get_core_dumps()
def get_core_dumps():
try:
- shell("get_core_dumps.sh", [system_test_dir.name])
+ isctest.run.shell(
+ f"{os.environ['srcdir']}/get_core_dumps.sh", [system_test_dir.name]
+ )
except subprocess.CalledProcessError as exc:
isctest.log.error("Found core dumps or sanitizer reports")
pytest.fail(f"get_core_dumps.sh exited with {exc.returncode}")
# information regarding copyright ownership.
import os
+from pathlib import Path
import subprocess
import time
-from typing import Optional
+from typing import List, Optional
import isctest.log
from isctest.compat import dns_rcode
return exc
+def _run_script(
+ interpreter: str,
+ script: str,
+ args: Optional[List[str]] = None,
+):
+ if args is None:
+ args = []
+ path = Path(script)
+ script = str(path)
+ cwd = os.getcwd()
+ if not path.exists():
+ raise FileNotFoundError(f"script {script} not found in {cwd}")
+ isctest.log.debug("running script: %s %s %s", interpreter, script, " ".join(args))
+ isctest.log.debug(" workdir: %s", cwd)
+ returncode = 1
+
+ command = [interpreter, script] + args
+ with subprocess.Popen(
+ command,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ bufsize=1,
+ universal_newlines=True,
+ errors="backslashreplace",
+ ) as proc:
+ if proc.stdout:
+ for line in proc.stdout:
+ isctest.log.info(" %s", line.rstrip("\n"))
+ proc.communicate()
+ returncode = proc.returncode
+ if returncode:
+ raise subprocess.CalledProcessError(returncode, command)
+ isctest.log.debug(" exited with %d", returncode)
+
+
+def shell(script: str, args: Optional[List[str]] = None) -> None:
+ """Run a given script with system's shell interpreter."""
+ _run_script(os.environ["SHELL"], script, args)
+
+
+def perl(script: str, args: Optional[List[str]] = None) -> None:
+ """Run a given script with system's perl interpreter."""
+ _run_script(os.environ["PERL"], script, args)
+
+
def retry_with_timeout(func, timeout, delay=1, msg=None):
start_time = time.time()
while time.time() < start_time + timeout: