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/JITEventListener.h"
11 #include "llvm/ExecutionEngine/OProfileWrapper.h"
12 #include "JITEventListenerTestCommon.h"
21 struct OprofileNativeFunction {
25 unsigned int CodeSize;
27 OprofileNativeFunction(const char* name,
38 typedef std::list<OprofileNativeFunction> NativeFunctionList;
39 typedef std::list<debug_line_info> NativeDebugList;
40 NativeFunctionList NativeFunctions;
42 NativeCodeMap ReportedDebugFuncs;
46 /// Mock implementaion of opagent library
47 namespace test_opagent {
49 op_agent_t globalAgent = reinterpret_cast<op_agent_t>(42);
51 op_agent_t open_agent()
53 // return non-null op_agent_t
57 int close_agent(op_agent_t agent)
59 EXPECT_EQ(globalAgent, agent);
63 int write_native_code(op_agent_t agent,
69 EXPECT_EQ(globalAgent, agent);
70 OprofileNativeFunction func(name, addr, code, size);
71 NativeFunctions.push_back(func);
73 // Verify no other registration has take place for the same address
74 EXPECT_TRUE(ReportedDebugFuncs.find(addr) == ReportedDebugFuncs.end());
76 ReportedDebugFuncs[addr];
80 int write_debug_line_info(op_agent_t agent,
83 struct debug_line_info const* info)
85 EXPECT_EQ(globalAgent, agent);
87 //verify code has been loaded first
88 uint64_t addr = reinterpret_cast<uint64_t>(code);
89 NativeCodeMap::iterator i = ReportedDebugFuncs.find(addr);
90 EXPECT_TRUE(i != ReportedDebugFuncs.end());
92 NativeDebugList NativeInfo(info, info + num_entries);
95 for(NativeDebugList::iterator i = NativeInfo.begin();
96 i != NativeInfo.end();
98 locs.push_back(std::make_pair(std::string(i->filename), i->lineno));
100 ReportedDebugFuncs[addr] = locs;
105 int unload_native_code(op_agent_t agent, uint64_t addr) {
106 EXPECT_EQ(globalAgent, agent);
108 //verify that something for the given JIT addr has been loaded first
109 NativeCodeMap::iterator i = ReportedDebugFuncs.find(addr);
110 EXPECT_TRUE(i != ReportedDebugFuncs.end());
111 ReportedDebugFuncs.erase(i);
119 bool is_oprofile_running() {
123 } //namespace test_opagent
125 class OProfileJITEventListenerTest
126 : public JITEventListenerTestBase<OProfileWrapper>
129 OProfileJITEventListenerTest()
130 : JITEventListenerTestBase<OProfileWrapper>(
131 new OProfileWrapper(test_opagent::open_agent,
132 test_opagent::close_agent,
133 test_opagent::write_native_code,
134 test_opagent::write_debug_line_info,
135 test_opagent::unload_native_code,
136 test_opagent::version,
137 test_opagent::version,
138 test_opagent::is_oprofile_running))
140 EXPECT_TRUE(0 != MockWrapper);
142 Listener.reset(JITEventListener::createOProfileJITEventListener(
144 EXPECT_TRUE(0 != Listener);
145 EE->RegisterJITEventListener(Listener.get());
149 TEST_F(OProfileJITEventListenerTest, NoDebugInfo) {
150 TestNoDebugInfo(ReportedDebugFuncs);
153 TEST_F(OProfileJITEventListenerTest, SingleLine) {
154 TestSingleLine(ReportedDebugFuncs);
157 TEST_F(OProfileJITEventListenerTest, MultipleLines) {
158 TestMultipleLines(ReportedDebugFuncs);
161 TEST_F(OProfileJITEventListenerTest, MultipleFiles) {
162 TestMultipleFiles(ReportedDebugFuncs);
165 testing::Environment* const jit_env =
166 testing::AddGlobalTestEnvironment(new JITEnvironment);