1 //===- not.cpp - The 'not' testing tool -----------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 // Will return true if cmd doesn't crash and returns false.
13 // Will return true if cmd crashes (e.g. for testing crash reporting).
15 #include "llvm/Support/Program.h"
16 #include "llvm/Support/raw_ostream.h"
19 int main(int argc
, const char **argv
) {
20 bool ExpectCrash
= false;
25 if (argc
> 0 && StringRef(argv
[0]) == "--crash") {
34 auto Program
= sys::findProgramByName(argv
[0]);
36 errs() << "Error: Unable to find `" << argv
[0]
37 << "' in PATH: " << Program
.getError().message() << "\n";
41 std::vector
<StringRef
> Argv
;
43 for (int i
= 0; i
< argc
; ++i
)
44 Argv
.push_back(argv
[i
]);
46 int Result
= sys::ExecuteAndWait(*Program
, Argv
, None
, {}, 0, 0, &ErrMsg
);
48 // Handle abort() in msvcrt -- It has exit code as 3. abort(), aka
49 // unreachable, should be recognized as a crash. However, some binaries use
50 // exit code 3 on non-crash failure paths, so only do this if we expect a
52 if (ExpectCrash
&& Result
== 3)
56 errs() << "Error: " << ErrMsg
<< "\n";