summaryrefslogtreecommitdiff
path: root/unittests/ExecutionEngine/JIT/IntelJITEventListenerTest.cpp
blob: db9088777a91fc672aa2304e1a6a58c7fd1da446 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//===- JITEventListenerTest.cpp - Tests for Intel JITEventListener --------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "JITEventListenerTestCommon.h"

using namespace llvm;

// Because we want to keep the implementation details of the Intel API used to
// communicate with Amplifier out of the public header files, the header below
// is included from the source tree instead.
#include "../../../lib/ExecutionEngine/IntelJITEvents/IntelJITEventsWrapper.h"

#include <map>
#include <list>

namespace {

// map of function ("method") IDs to source locations
NativeCodeMap ReportedDebugFuncs;

} // namespace

/// Mock implementaion of Intel JIT API jitprofiling library
namespace test_jitprofiling {

int NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) {
  switch (EventType) {
    case iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED: {
      EXPECT_TRUE(0 != EventSpecificData);
      iJIT_Method_Load* msg = static_cast<iJIT_Method_Load*>(EventSpecificData);

      ReportedDebugFuncs[msg->method_id];

      for(unsigned int i = 0; i < msg->line_number_size; ++i) {
        EXPECT_TRUE(0 != msg->line_number_table);
        std::pair<std::string, unsigned int> loc(
          std::string(msg->source_file_name),
          msg->line_number_table[i].LineNumber);
        ReportedDebugFuncs[msg->method_id].push_back(loc);
      }
    }
    break;
    case iJVM_EVENT_TYPE_METHOD_UNLOAD_START: {
      EXPECT_TRUE(0 != EventSpecificData);
      unsigned int UnloadId
        = *reinterpret_cast<unsigned int*>(EventSpecificData);
      EXPECT_TRUE(1 == ReportedDebugFuncs.erase(UnloadId));
    }
    default:
      break;
  }
  return 0;
}

iJIT_IsProfilingActiveFlags IsProfilingActive(void) {
  // for testing, pretend we have an Intel Parallel Amplifier XE 2011
  // instance attached
  return iJIT_SAMPLING_ON;
}

unsigned int GetNewMethodID(void) {
  static unsigned int id = 0;
  return ++id;
}

} //namespace test_jitprofiling

class IntelJITEventListenerTest
  : public JITEventListenerTestBase<IntelJITEventsWrapper> {
public:
  IntelJITEventListenerTest()
  : JITEventListenerTestBase<IntelJITEventsWrapper>(
      new IntelJITEventsWrapper(test_jitprofiling::NotifyEvent, 0,
        test_jitprofiling::IsProfilingActive, 0, 0,
        test_jitprofiling::GetNewMethodID))
  {
    EXPECT_TRUE(0 != MockWrapper);

    Listener.reset(JITEventListener::createIntelJITEventListener(
      MockWrapper.release()));
    EXPECT_TRUE(0 != Listener);
    EE->RegisterJITEventListener(Listener.get());
  }
};

TEST_F(IntelJITEventListenerTest, NoDebugInfo) {
  TestNoDebugInfo(ReportedDebugFuncs);
}

TEST_F(IntelJITEventListenerTest, SingleLine) {
  TestSingleLine(ReportedDebugFuncs);
}

TEST_F(IntelJITEventListenerTest, MultipleLines) {
  TestMultipleLines(ReportedDebugFuncs);
}

// This testcase is disabled because the Intel JIT API does not support a single
// JITted function with source lines associated with multiple files
/*
TEST_F(IntelJITEventListenerTest, MultipleFiles) {
  TestMultipleFiles(ReportedDebugFuncs);
}
*/

testing::Environment* const jit_env =
  testing::AddGlobalTestEnvironment(new JITEnvironment);