blob: af942500186474bb390347ef053c1ed6d5b49e23 [file] [log] [blame]
Daniel Dunbar00dd4482009-09-24 06:23:57 +00001//===- not.cpp - The 'not' testing tool -----------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Michael J. Spencer447762d2010-11-29 18:16:10 +000010#include "llvm/Support/Path.h"
11#include "llvm/Support/Program.h"
Dan Gohmanb75ce4f2010-10-29 20:20:29 +000012#include "llvm/Support/raw_ostream.h"
Daniel Dunbar00dd4482009-09-24 06:23:57 +000013using namespace llvm;
14
15int main(int argc, const char **argv) {
Rafael Espindola91487582013-07-05 02:50:03 +000016 bool ExpectCrash = false;
17
18 ++argv;
19 --argc;
20
21 if (argc > 0 && StringRef(argv[0]) == "--crash") {
22 ++argv;
23 --argc;
24 ExpectCrash = true;
25 }
26
27 if (argc == 0)
28 return 1;
29
30 std::string Program = sys::FindProgramByName(argv[0]);
Dan Gohmanb75ce4f2010-10-29 20:20:29 +000031
32 std::string ErrMsg;
Craig Topper66f09ad2014-06-08 22:29:17 +000033 int Result = sys::ExecuteAndWait(Program, argv, nullptr, nullptr, 0, 0,
34 &ErrMsg);
NAKAMURA Takumia2e405c2014-06-13 12:23:56 +000035#ifdef _WIN32
36 // Handle abort() in msvcrt -- It has exit code as 3.
37 // abort(), aka unreachable, may be handled as crash.
38 // FIXME: Could we move this into Win32/Program.inc?
39 if (Result == 3)
40 Result = -3;
41#endif
Dan Gohmanb75ce4f2010-10-29 20:20:29 +000042 if (Result < 0) {
43 errs() << "Error: " << ErrMsg << "\n";
Rafael Espindola91487582013-07-05 02:50:03 +000044 if (ExpectCrash)
45 return 0;
Dan Gohmanb75ce4f2010-10-29 20:20:29 +000046 return 1;
47 }
48
Rafael Espindola91487582013-07-05 02:50:03 +000049 if (ExpectCrash)
50 return 1;
51
Dan Gohmanb75ce4f2010-10-29 20:20:29 +000052 return Result == 0;
Daniel Dunbar00dd4482009-09-24 06:23:57 +000053}