1 //===- not.cpp - The 'not' testing tool -----------------------------------===//
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 //===----------------------------------------------------------------------===//
10 // Will return true if cmd doesn't crash and returns false.
12 // Will return true if cmd crashes (e.g. for testing crash reporting).
14 #include "llvm/Support/Program.h"
15 #include "llvm/Support/WithColor.h"
16 #include "llvm/Support/raw_ostream.h"
24 int main(int argc
, const char **argv
) {
25 bool ExpectCrash
= false;
30 if (argc
> 0 && StringRef(argv
[0]) == "--crash") {
35 // Crash is expected, so disable crash report and symbolization to reduce
36 // output and avoid potentially slow symbolization.
38 SetEnvironmentVariableA("LLVM_DISABLE_CRASH_REPORT", "1");
39 SetEnvironmentVariableA("LLVM_DISABLE_SYMBOLIZATION", "1");
41 setenv("LLVM_DISABLE_CRASH_REPORT", "1", 0);
42 setenv("LLVM_DISABLE_SYMBOLIZATION", "1", 0);
49 auto Program
= sys::findProgramByName(argv
[0]);
51 WithColor::error() << "unable to find `" << argv
[0]
52 << "' in PATH: " << Program
.getError().message() << "\n";
56 std::vector
<StringRef
> Argv
;
58 for (int i
= 0; i
< argc
; ++i
)
59 Argv
.push_back(argv
[i
]);
61 int Result
= sys::ExecuteAndWait(*Program
, Argv
, None
, {}, 0, 0, &ErrMsg
);
63 // Handle abort() in msvcrt -- It has exit code as 3. abort(), aka
64 // unreachable, should be recognized as a crash. However, some binaries use
65 // exit code 3 on non-crash failure paths, so only do this if we expect a
67 if (ExpectCrash
&& Result
== 3)
71 WithColor::error() << ErrMsg
<< "\n";