1 //===- JITEventListenerTest.cpp - Tests for Intel JITEventListener --------===//
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 //===----------------------------------------------------------------------===//
10 #include "JITEventListenerTestCommon.h"
14 // Because we want to keep the implementation details of the Intel API used to
15 // communicate with Amplifier out of the public header files, the header below
16 // is included from the source tree instead.
17 #include "../../../lib/ExecutionEngine/IntelJITEvents/IntelJITEventsWrapper.h"
24 // map of function ("method") IDs to source locations
25 NativeCodeMap ReportedDebugFuncs;
29 /// Mock implementaion of Intel JIT API jitprofiling library
30 namespace test_jitprofiling {
32 int NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) {
34 case iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED: {
35 EXPECT_TRUE(0 != EventSpecificData);
36 iJIT_Method_Load* msg = static_cast<iJIT_Method_Load*>(EventSpecificData);
38 ReportedDebugFuncs[msg->method_id];
40 for(unsigned int i = 0; i < msg->line_number_size; ++i) {
41 EXPECT_TRUE(0 != msg->line_number_table);
42 std::pair<std::string, unsigned int> loc(
43 std::string(msg->source_file_name),
44 msg->line_number_table[i].LineNumber);
45 ReportedDebugFuncs[msg->method_id].push_back(loc);
49 case iJVM_EVENT_TYPE_METHOD_UNLOAD_START: {
50 EXPECT_TRUE(0 != EventSpecificData);
52 = *reinterpret_cast<unsigned int*>(EventSpecificData);
53 EXPECT_TRUE(1 == ReportedDebugFuncs.erase(UnloadId));
61 iJIT_IsProfilingActiveFlags IsProfilingActive(void) {
62 // for testing, pretend we have an Intel Parallel Amplifier XE 2011
64 return iJIT_SAMPLING_ON;
67 unsigned int GetNewMethodID(void) {
68 static unsigned int id = 0;
72 } //namespace test_jitprofiling
74 class IntelJITEventListenerTest
75 : public JITEventListenerTestBase<IntelJITEventsWrapper> {
77 IntelJITEventListenerTest()
78 : JITEventListenerTestBase<IntelJITEventsWrapper>(
79 new IntelJITEventsWrapper(test_jitprofiling::NotifyEvent, 0,
80 test_jitprofiling::IsProfilingActive, 0, 0,
81 test_jitprofiling::GetNewMethodID))
83 EXPECT_TRUE(0 != MockWrapper);
85 Listener.reset(JITEventListener::createIntelJITEventListener(
87 EXPECT_TRUE(0 != Listener);
88 EE->RegisterJITEventListener(Listener.get());
92 TEST_F(IntelJITEventListenerTest, NoDebugInfo) {
93 TestNoDebugInfo(ReportedDebugFuncs);
96 TEST_F(IntelJITEventListenerTest, SingleLine) {
97 TestSingleLine(ReportedDebugFuncs);
100 TEST_F(IntelJITEventListenerTest, MultipleLines) {
101 TestMultipleLines(ReportedDebugFuncs);
104 // This testcase is disabled because the Intel JIT API does not support a single
105 // JITted function with source lines associated with multiple files
107 TEST_F(IntelJITEventListenerTest, MultipleFiles) {
108 TestMultipleFiles(ReportedDebugFuncs);
112 testing::Environment* const jit_env =
113 testing::AddGlobalTestEnvironment(new JITEnvironment);