Files
Library/include/Void/Testing/Subprocess.hpp
T

57 lines
1.4 KiB
C++

#pragma once
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <optional>
#include <span>
#include <string>
#include <string_view>
namespace Void::Testing
{
/// Per-child resource limits applied before exec. Unset values are left at
/// the parent's limits.
struct ProcessResourceLimits {
std::optional<std::uint64_t> cpu_seconds{};
std::optional<std::uint64_t> address_space_bytes{};
std::optional<std::uint64_t> file_size_bytes{};
std::optional<std::uint64_t> open_files{};
/// Prevent a crashing child from writing a core file.
bool disable_core_dumps{true};
};
struct ProcessTestOptions {
std::chrono::milliseconds timeout{60000};
std::size_t max_output_bytes{1024ULL * 1024ULL};
ProcessResourceLimits resources{};
};
enum class ProcessOutcome {
passed,
failed,
crashed,
timed_out,
infrastructure_error
};
struct ProcessTestResult {
ProcessOutcome outcome{ProcessOutcome::infrastructure_error};
int exit_code{-1};
int term_signal{0};
std::string stdout_captured{};
std::string stderr_captured{};
bool stdout_truncated{false};
bool stderr_truncated{false};
std::string diagnostic{};
};
[[nodiscard]] std::string current_executable_path();
[[nodiscard]] ProcessTestResult run_isolated_subprocess(
std::string_view executable,
std::span<const std::string> args = {},
ProcessTestOptions options = {});
} // namespace Void::Testing