brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 5844fd5 Raw
54 lines · c
1//===-- ExecuteFunction.h ---------------------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_TEST_UNITTEST_EXECUTEFUNCTION_H10#define LLVM_LIBC_TEST_UNITTEST_EXECUTEFUNCTION_H11 12#include "hdr/stdint_proxy.h"13#include "src/__support/CPP/limits.h"14#include "src/__support/macros/config.h"15 16namespace LIBC_NAMESPACE_DECL {17namespace testutils {18 19class FunctionCaller {20public:21  virtual ~FunctionCaller() {}22  virtual void operator()() = 0;23};24 25struct ProcessStatus {26  int platform_defined;27  const char *failure = nullptr;28 29  static constexpr int TIMEOUT = cpp::numeric_limits<int>::max();30 31  static ProcessStatus error(const char *error) { return {0, error}; }32  static ProcessStatus timed_out_ps() {33    return {0, reinterpret_cast<const char *>(TIMEOUT)};34  }35 36  bool timed_out() const {37    return failure == reinterpret_cast<const char *>(TIMEOUT);38  }39  const char *get_error() const { return timed_out() ? nullptr : failure; }40  bool exited_normally();41  int get_exit_code();42  int get_fatal_signal();43};44 45ProcessStatus invoke_in_subprocess(FunctionCaller *func,46                                   int timeout_ms = ProcessStatus::TIMEOUT);47 48const char *signal_as_string(int signum);49 50} // namespace testutils51} // namespace LIBC_NAMESPACE_DECL52 53#endif // LLVM_LIBC_TEST_UNITTEST_EXECUTEFUNCTION_H54