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 #include "llvm/ExecutionEngine/IntelJITEventsWrapper.h"
21 // map of function ("method") IDs to source locations
22 NativeCodeMap ReportedDebugFuncs;
26 /// Mock implementaion of Intel JIT API jitprofiling library
27 namespace test_jitprofiling {
29 int NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) {
31 case iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED: {
32 EXPECT_TRUE(0 != EventSpecificData);
33 iJIT_Method_Load* msg = static_cast<iJIT_Method_Load*>(EventSpecificData);
35 ReportedDebugFuncs[msg->method_id];
37 for(unsigned int i = 0; i < msg->line_number_size; ++i) {
38 EXPECT_TRUE(0 != msg->line_number_table);
39 std::pair<std::string, unsigned int> loc(
40 std::string(msg->source_file_name),
41 msg->line_number_table[i].LineNumber);
42 ReportedDebugFuncs[msg->method_id].push_back(loc);
46 case iJVM_EVENT_TYPE_METHOD_UNLOAD_START: {
47 EXPECT_TRUE(0 != EventSpecificData);
49 = *reinterpret_cast<unsigned int*>(EventSpecificData);
50 EXPECT_TRUE(1 == ReportedDebugFuncs.erase(UnloadId));
58 iJIT_IsProfilingActiveFlags IsProfilingActive(void) {
59 // for testing, pretend we have an Intel Parallel Amplifier XE 2011
61 return iJIT_SAMPLING_ON;
64 unsigned int GetNewMethodID(void) {
65 static unsigned int id = 0;
69 } //namespace test_jitprofiling
71 class IntelJITEventListenerTest
72 : public JITEventListenerTestBase<IntelJITEventsWrapper> {
74 IntelJITEventListenerTest()
75 : JITEventListenerTestBase<IntelJITEventsWrapper>(
76 new IntelJITEventsWrapper(test_jitprofiling::NotifyEvent, 0,
77 test_jitprofiling::IsProfilingActive, 0, 0,
78 test_jitprofiling::GetNewMethodID))
80 EXPECT_TRUE(0 != MockWrapper);
82 Listener.reset(JITEventListener::createIntelJITEventListener(
84 EXPECT_TRUE(0 != Listener);
85 EE->RegisterJITEventListener(Listener.get());
89 TEST_F(IntelJITEventListenerTest, NoDebugInfo) {
90 TestNoDebugInfo(ReportedDebugFuncs);
93 TEST_F(IntelJITEventListenerTest, SingleLine) {
94 TestSingleLine(ReportedDebugFuncs);
97 TEST_F(IntelJITEventListenerTest, MultipleLines) {
98 TestMultipleLines(ReportedDebugFuncs);
101 // This testcase is disabled because the Intel JIT API does not support a single
102 // JITted function with source lines associated with multiple files
104 TEST_F(IntelJITEventListenerTest, MultipleFiles) {
105 TestMultipleFiles(ReportedDebugFuncs);
109 testing::Environment* const jit_env =
110 testing::AddGlobalTestEnvironment(new JITEnvironment);