1 //===-- Implementation of libc death test executors -----------------------===//
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-exception
7 //===----------------------------------------------------------------------===//
11 #include "test/UnitTest/ExecuteFunction.h"
12 #include "test/UnitTest/TestLogger.h"
16 namespace __llvm_libc
{
19 bool Test::testProcessKilled(testutils::FunctionCaller
*Func
, int Signal
,
20 const char *LHSStr
, const char *RHSStr
,
21 internal::Location Loc
) {
22 testutils::ProcessStatus Result
= testutils::invoke_in_subprocess(Func
, 500);
24 if (const char *error
= Result
.get_error()) {
27 tlog
<< error
<< '\n';
31 if (Result
.timed_out()) {
34 tlog
<< "Process timed out after " << 500 << " milliseconds.\n";
38 if (Result
.exited_normally()) {
41 tlog
<< "Expected " << LHSStr
42 << " to be killed by a signal\nBut it exited normally!\n";
46 int KilledBy
= Result
.get_fatal_signal();
47 assert(KilledBy
!= 0 && "Not killed by any signal");
48 if (Signal
== -1 || KilledBy
== Signal
)
51 using testutils::signal_as_string
;
54 tlog
<< " Expected: " << LHSStr
<< '\n'
55 << "To be killed by signal: " << Signal
<< '\n'
56 << " Which is: " << signal_as_string(Signal
) << '\n'
57 << " But it was killed by: " << KilledBy
<< '\n'
58 << " Which is: " << signal_as_string(KilledBy
) << '\n';
62 bool Test::testProcessExits(testutils::FunctionCaller
*Func
, int ExitCode
,
63 const char *LHSStr
, const char *RHSStr
,
64 internal::Location Loc
) {
65 testutils::ProcessStatus Result
= testutils::invoke_in_subprocess(Func
, 500);
67 if (const char *error
= Result
.get_error()) {
70 tlog
<< error
<< '\n';
74 if (Result
.timed_out()) {
77 tlog
<< "Process timed out after " << 500 << " milliseconds.\n";
81 if (!Result
.exited_normally()) {
84 tlog
<< "Expected " << LHSStr
<< '\n'
85 << "to exit with exit code " << ExitCode
<< '\n'
86 << "But it exited abnormally!\n";
90 int ActualExit
= Result
.get_exit_code();
91 if (ActualExit
== ExitCode
)
96 tlog
<< "Expected exit code of: " << LHSStr
<< '\n'
97 << " Which is: " << ActualExit
<< '\n'
98 << " To be equal to: " << RHSStr
<< '\n'
99 << " Which is: " << ExitCode
<< '\n';
103 } // namespace testing
104 } // namespace __llvm_libc