2009-09-24 06:23:57 +00:00
|
|
|
//===- not.cpp - The 'not' testing tool -----------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include "llvm/Support/Program.h"
|
2010-10-29 20:20:29 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-09-24 06:23:57 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
int main(int argc, const char **argv) {
|
2013-07-05 02:50:03 +00:00
|
|
|
bool ExpectCrash = false;
|
|
|
|
|
|
|
|
++argv;
|
|
|
|
--argc;
|
|
|
|
|
|
|
|
if (argc > 0 && StringRef(argv[0]) == "--crash") {
|
|
|
|
++argv;
|
|
|
|
--argc;
|
|
|
|
ExpectCrash = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
std::string Program = sys::FindProgramByName(argv[0]);
|
2010-10-29 20:20:29 +00:00
|
|
|
|
|
|
|
std::string ErrMsg;
|
2014-06-08 22:29:17 +00:00
|
|
|
int Result = sys::ExecuteAndWait(Program, argv, nullptr, nullptr, 0, 0,
|
|
|
|
&ErrMsg);
|
2014-06-13 12:23:56 +00:00
|
|
|
#ifdef _WIN32
|
2014-06-23 22:54:33 +00:00
|
|
|
// Handle abort() in msvcrt -- It has exit code as 3. abort(), aka
|
|
|
|
// unreachable, should be recognized as a crash. However, some binaries use
|
|
|
|
// exit code 3 on non-crash failure paths, so only do this if we expect a
|
|
|
|
// crash.
|
|
|
|
if (ExpectCrash && Result == 3)
|
2014-06-13 12:23:56 +00:00
|
|
|
Result = -3;
|
|
|
|
#endif
|
2010-10-29 20:20:29 +00:00
|
|
|
if (Result < 0) {
|
|
|
|
errs() << "Error: " << ErrMsg << "\n";
|
2013-07-05 02:50:03 +00:00
|
|
|
if (ExpectCrash)
|
|
|
|
return 0;
|
2010-10-29 20:20:29 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-07-05 02:50:03 +00:00
|
|
|
if (ExpectCrash)
|
|
|
|
return 1;
|
|
|
|
|
2010-10-29 20:20:29 +00:00
|
|
|
return Result == 0;
|
2009-09-24 06:23:57 +00:00
|
|
|
}
|