1 //===- OProfileJITEventListenerTest.cpp - Unit tests for OProfileJITEventsListener --------===//
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 "llvm/ExecutionEngine/OProfileWrapper.h"
11 #include "JITEventListenerTestCommon.h"
12 #include "llvm/ExecutionEngine/JITEventListener.h"
20 struct OprofileNativeFunction {
24 unsigned int CodeSize;
26 OprofileNativeFunction(const char* name,
37 typedef std::list<OprofileNativeFunction> NativeFunctionList;
38 typedef std::list<debug_line_info> NativeDebugList;
39 NativeFunctionList NativeFunctions;
41 NativeCodeMap ReportedDebugFuncs;
45 /// Mock implementaion of opagent library
46 namespace test_opagent {
48 op_agent_t globalAgent = reinterpret_cast<op_agent_t>(42);
50 op_agent_t open_agent()
52 // return non-null op_agent_t
56 int close_agent(op_agent_t agent)
58 EXPECT_EQ(globalAgent, agent);
62 int write_native_code(op_agent_t agent,
68 EXPECT_EQ(globalAgent, agent);
69 OprofileNativeFunction func(name, addr, code, size);
70 NativeFunctions.push_back(func);
72 // Verify no other registration has take place for the same address
73 EXPECT_TRUE(ReportedDebugFuncs.find(addr) == ReportedDebugFuncs.end());
75 ReportedDebugFuncs[addr];
79 int write_debug_line_info(op_agent_t agent,
82 struct debug_line_info const* info)
84 EXPECT_EQ(globalAgent, agent);
86 //verify code has been loaded first
87 uint64_t addr = reinterpret_cast<uint64_t>(code);
88 NativeCodeMap::iterator i = ReportedDebugFuncs.find(addr);
89 EXPECT_TRUE(i != ReportedDebugFuncs.end());
91 NativeDebugList NativeInfo(info, info + num_entries);
94 for(NativeDebugList::iterator i = NativeInfo.begin();
95 i != NativeInfo.end();
97 locs.push_back(std::make_pair(std::string(i->filename), i->lineno));
99 ReportedDebugFuncs[addr] = locs;
104 int unload_native_code(op_agent_t agent, uint64_t addr) {
105 EXPECT_EQ(globalAgent, agent);
107 //verify that something for the given JIT addr has been loaded first
108 NativeCodeMap::iterator i = ReportedDebugFuncs.find(addr);
109 EXPECT_TRUE(i != ReportedDebugFuncs.end());
110 ReportedDebugFuncs.erase(i);
118 bool is_oprofile_running() {
122 } //namespace test_opagent
124 class OProfileJITEventListenerTest
125 : public JITEventListenerTestBase<OProfileWrapper>
128 OProfileJITEventListenerTest()
129 : JITEventListenerTestBase<OProfileWrapper>(
130 new OProfileWrapper(test_opagent::open_agent,
131 test_opagent::close_agent,
132 test_opagent::write_native_code,
133 test_opagent::write_debug_line_info,
134 test_opagent::unload_native_code,
135 test_opagent::version,
136 test_opagent::version,
137 test_opagent::is_oprofile_running))
139 EXPECT_TRUE(0 != MockWrapper);
141 Listener.reset(JITEventListener::createOProfileJITEventListener(
143 EXPECT_TRUE(0 != Listener);
144 EE->RegisterJITEventListener(Listener.get());
148 TEST_F(OProfileJITEventListenerTest, NoDebugInfo) {
149 TestNoDebugInfo(ReportedDebugFuncs);
152 TEST_F(OProfileJITEventListenerTest, SingleLine) {
153 TestSingleLine(ReportedDebugFuncs);
156 TEST_F(OProfileJITEventListenerTest, MultipleLines) {
157 TestMultipleLines(ReportedDebugFuncs);
160 TEST_F(OProfileJITEventListenerTest, MultipleFiles) {
161 TestMultipleFiles(ReportedDebugFuncs);
164 testing::Environment* const jit_env =
165 testing::AddGlobalTestEnvironment(new JITEnvironment);