blob: 8160a186f413be40f90c413e087013f59307ac14 [file] [log] [blame]
Andrew Kaylord2755af2013-04-29 17:49:40 +00001//===- MCJITTestBase.h - Common base class for MCJIT Unit tests ----------===//
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//
10// This class implements functionality shared by both MCJIT C API tests, and
11// the C++ API tests.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef MCJIT_TEST_API_COMMON_H
16#define MCJIT_TEST_API_COMMON_H
17
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/ADT/Triple.h"
20#include "llvm/Support/Host.h"
21#include "llvm/Support/TargetSelect.h"
22
23// Used to skip tests on unsupported architectures and operating systems.
24// To skip a test, add this macro at the top of a test-case in a suite that
25// inherits from MCJITTestBase. See MCJITTest.cpp for examples.
26#define SKIP_UNSUPPORTED_PLATFORM \
27 do \
28 if (!ArchSupportsMCJIT() || !OSSupportsMCJIT()) \
29 return; \
30 while(0)
31
32namespace llvm {
33
34class MCJITTestAPICommon {
35protected:
36 MCJITTestAPICommon()
37 : HostTriple(sys::getProcessTriple())
38 {
39 InitializeNativeTarget();
40 InitializeNativeTargetAsmPrinter();
41
42#ifdef LLVM_ON_WIN32
43 // On Windows, generate ELF objects by specifying "-elf" in triple
44 HostTriple += "-elf";
45#endif // LLVM_ON_WIN32
46 HostTriple = Triple::normalize(HostTriple);
47 }
48
49 /// Returns true if the host architecture is known to support MCJIT
50 bool ArchSupportsMCJIT() {
51 Triple Host(HostTriple);
52 if (std::find(SupportedArchs.begin(), SupportedArchs.end(), Host.getArch())
53 == SupportedArchs.end()) {
54 return false;
55 }
56 return true;
57 }
58
59 /// Returns true if the host OS is known to support MCJIT
60 bool OSSupportsMCJIT() {
61 Triple Host(HostTriple);
62 if (std::find(UnsupportedOSs.begin(), UnsupportedOSs.end(), Host.getOS())
63 == UnsupportedOSs.end()) {
64 return true;
65 }
66 return false;
67 }
68
69 std::string HostTriple;
70 SmallVector<Triple::ArchType, 4> SupportedArchs;
71 SmallVector<Triple::OSType, 4> UnsupportedOSs;
72};
73
74} // namespace llvm
75
76#endif // MCJIT_TEST_API_COMMON_H
77