1//===- JITEventListenerTest.cpp - Tests for Intel JITEventListener --------===// 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#include "JITEventListenerTestCommon.h" 11 12using namespace llvm; 13 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" 18 19#include <map> 20#include <list> 21 22namespace { 23 24// map of function ("method") IDs to source locations 25NativeCodeMap ReportedDebugFuncs; 26 27} // namespace 28 29/// Mock implementaion of Intel JIT API jitprofiling library 30namespace test_jitprofiling { 31 32int NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) { 33 switch (EventType) { 34 case iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED: { 35 EXPECT_TRUE(0 != EventSpecificData); 36 iJIT_Method_Load* msg = static_cast<iJIT_Method_Load*>(EventSpecificData); 37 38 ReportedDebugFuncs[msg->method_id]; 39 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); 46 } 47 } 48 break; 49 case iJVM_EVENT_TYPE_METHOD_UNLOAD_START: { 50 EXPECT_TRUE(0 != EventSpecificData); 51 unsigned int UnloadId 52 = *reinterpret_cast<unsigned int*>(EventSpecificData); 53 EXPECT_TRUE(1 == ReportedDebugFuncs.erase(UnloadId)); 54 } 55 default: 56 break; 57 } 58 return 0; 59} 60 61iJIT_IsProfilingActiveFlags IsProfilingActive(void) { 62 // for testing, pretend we have an Intel Parallel Amplifier XE 2011 63 // instance attached 64 return iJIT_SAMPLING_ON; 65} 66 67unsigned int GetNewMethodID(void) { 68 static unsigned int id = 0; 69 return ++id; 70} 71 72} //namespace test_jitprofiling 73 74class IntelJITEventListenerTest 75 : public JITEventListenerTestBase<IntelJITEventsWrapper> { 76public: 77 IntelJITEventListenerTest() 78 : JITEventListenerTestBase<IntelJITEventsWrapper>( 79 new IntelJITEventsWrapper(test_jitprofiling::NotifyEvent, 0, 80 test_jitprofiling::IsProfilingActive, 0, 0, 81 test_jitprofiling::GetNewMethodID)) 82 { 83 EXPECT_TRUE(0 != MockWrapper); 84 85 Listener.reset(JITEventListener::createIntelJITEventListener( 86 MockWrapper.take())); 87 EXPECT_TRUE(0 != Listener); 88 EE->RegisterJITEventListener(Listener.get()); 89 } 90}; 91 92TEST_F(IntelJITEventListenerTest, NoDebugInfo) { 93 TestNoDebugInfo(ReportedDebugFuncs); 94} 95 96TEST_F(IntelJITEventListenerTest, SingleLine) { 97 TestSingleLine(ReportedDebugFuncs); 98} 99 100TEST_F(IntelJITEventListenerTest, MultipleLines) { 101 TestMultipleLines(ReportedDebugFuncs); 102} 103 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 106/* 107TEST_F(IntelJITEventListenerTest, MultipleFiles) { 108 TestMultipleFiles(ReportedDebugFuncs); 109} 110*/ 111 112testing::Environment* const jit_env = 113 testing::AddGlobalTestEnvironment(new JITEnvironment); 114