tests: Run test.py with full logging in the presence of TEST_LOGS environment variable

This commit is contained in:
Gabriel Ferreira
2024-09-11 10:47:23 +02:00
parent 9f3232ce6e
commit 9281078dd2
2 changed files with 31 additions and 2 deletions

16
test.py
View File

@@ -846,6 +846,11 @@ def make_paths():
VALGRIND_SUPPRESSIONS_FILE = ".ns3.supp"
# VALGRIND_SUPPRESSIONS_FILE = None
# When the TEST_LOGS environment variable is set to 1 or true,
# NS_LOG is set to NS_LOG=*, and stdout/stderr
# from tests are discarded to prevent running out of memory.
TEST_LOGS = bool(os.getenv("TEST_LOGS", False))
def run_job_synchronously(shell_command, directory, valgrind, is_python, build_path=""):
if VALGRIND_SUPPRESSIONS_FILE is not None:
@@ -878,9 +883,16 @@ def run_job_synchronously(shell_command, directory, valgrind, is_python, build_p
start_time = time.time()
proc = subprocess.Popen(
cmd, shell=True, cwd=directory, stdout=subprocess.PIPE, stderr=subprocess.PIPE
cmd,
shell=True,
cwd=directory,
stdout=subprocess.PIPE if not TEST_LOGS else subprocess.DEVNULL,
stderr=subprocess.PIPE if not TEST_LOGS else subprocess.STDOUT,
)
stdout_results, stderr_results = proc.communicate()
stdout_results = b"" if stdout_results is None else stdout_results
stderr_results = b"" if stderr_results is None else stderr_results
elapsed_time = time.time() - start_time
retval = proc.returncode
@@ -1343,7 +1355,7 @@ def run_tests():
# test.py runs. If you want to see logging output from your tests, you
# have to run them using the test-runner directly.
#
os.environ["NS_LOG"] = ""
os.environ["NS_LOG"] = "*" if TEST_LOGS else ""
#
# There are a couple of options that imply we can to exit before starting