Checks the return code and output of a completed process.
(proc, test_dir: str, release_mode: bool, logs: list)
| 95 | raise ValueError(f"{arguments_path} must contain a JSON array of strings") |
| 96 | arguments = parsed |
| 97 | stdin_path = test.directory / "java-stdin.txt" |
| 98 | stdin = read(stdin_path) if stdin_path.exists() else None |
| 99 | return arguments, stdin |
| 100 | |
| 101 | |
| 102 | def jvm_timeout_diagnostics(pid: int) -> str: |
| 103 | def decoded(value: str | bytes | None) -> str: |
| 104 | if value is None: |
| 105 | return "" |
| 106 | return value.decode("utf-8", errors="replace") if isinstance(value, bytes) else value |
| 107 | |
| 108 | sections: list[str] = [] |
| 109 | for command in (["Thread.print", "-l"], ["VM.command_line"], ["GC.heap_info"]): |
| 110 | label = " ".join(command) |
| 111 | try: |
| 112 | result = subprocess.run( |
| 113 | ["jcmd", str(pid), *command], |
| 114 | stdout=subprocess.PIPE, |
| 115 | stderr=subprocess.STDOUT, |
| 116 | text=True, |
| 117 | encoding="utf-8", |
| 118 | errors="replace", |
| 119 | timeout=15, |
| 120 | ) |
| 121 | sections.append(f"===== jcmd {label} =====\n{result.stdout}") |
| 122 | except FileNotFoundError: |
| 123 | sections.append("jcmd is unavailable; no JVM diagnostic could be captured.") |
| 124 | break |
| 125 | except subprocess.TimeoutExpired as error: |
| 126 | partial = decoded(error.stdout) |
| 127 | sections.append(f"===== jcmd {label} timed out =====\n{partial}") |
| 128 | except OSError as error: |
| 129 | sections.append(f"===== jcmd {label} failed =====\n{error}") |
| 130 | return "\n".join(sections) |
| 131 | |
| 132 | |
| 133 | def terminate_process_tree(process: subprocess.Popen[bytes]) -> None: |
| 134 | if os.name == "nt": |
| 135 | subprocess.run( |
| 136 | ["taskkill", "/PID", str(process.pid), "/T", "/F"], |
| 137 | stdout=subprocess.DEVNULL, |
| 138 | stderr=subprocess.DEVNULL, |
| 139 | check=False, |
| 140 | ) |
| 141 | else: |
| 142 | try: |
no test coverage detected