IntelJITEventListenerTest.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #include "JITEventListenerTestCommon.h"
  10. using namespace llvm;
  11. #include "llvm/ExecutionEngine/IntelJITEventsWrapper.h"
  12. #include <map>
  13. #include <list>
  14. namespace {
  15. // map of function ("method") IDs to source locations
  16. NativeCodeMap ReportedDebugFuncs;
  17. } // namespace
  18. /// Mock implementaion of Intel JIT API jitprofiling library
  19. namespace test_jitprofiling {
  20. int NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) {
  21. switch (EventType) {
  22. case iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED: {
  23. EXPECT_TRUE(0 != EventSpecificData);
  24. iJIT_Method_Load* msg = static_cast<iJIT_Method_Load*>(EventSpecificData);
  25. ReportedDebugFuncs[msg->method_id];
  26. for(unsigned int i = 0; i < msg->line_number_size; ++i) {
  27. EXPECT_TRUE(0 != msg->line_number_table);
  28. std::pair<std::string, unsigned int> loc(
  29. std::string(msg->source_file_name),
  30. msg->line_number_table[i].LineNumber);
  31. ReportedDebugFuncs[msg->method_id].push_back(loc);
  32. }
  33. }
  34. break;
  35. case iJVM_EVENT_TYPE_METHOD_UNLOAD_START: {
  36. EXPECT_TRUE(0 != EventSpecificData);
  37. unsigned int UnloadId
  38. = *reinterpret_cast<unsigned int*>(EventSpecificData);
  39. EXPECT_TRUE(1 == ReportedDebugFuncs.erase(UnloadId));
  40. }
  41. default:
  42. break;
  43. }
  44. return 0;
  45. }
  46. iJIT_IsProfilingActiveFlags IsProfilingActive(void) {
  47. // for testing, pretend we have an Intel Parallel Amplifier XE 2011
  48. // instance attached
  49. return iJIT_SAMPLING_ON;
  50. }
  51. unsigned int GetNewMethodID(void) {
  52. static unsigned int id = 0;
  53. return ++id;
  54. }
  55. } //namespace test_jitprofiling
  56. class IntelJITEventListenerTest
  57. : public JITEventListenerTestBase<IntelJITEventsWrapper> {
  58. public:
  59. IntelJITEventListenerTest()
  60. : JITEventListenerTestBase<IntelJITEventsWrapper>(
  61. new IntelJITEventsWrapper(test_jitprofiling::NotifyEvent, 0,
  62. test_jitprofiling::IsProfilingActive, 0, 0,
  63. test_jitprofiling::GetNewMethodID))
  64. {
  65. EXPECT_TRUE(0 != MockWrapper);
  66. Listener.reset(JITEventListener::createIntelJITEventListener(
  67. MockWrapper.get()));
  68. EXPECT_TRUE(0 != Listener);
  69. EE->RegisterJITEventListener(Listener.get());
  70. }
  71. };
  72. TEST_F(IntelJITEventListenerTest, NoDebugInfo) {
  73. TestNoDebugInfo(ReportedDebugFuncs);
  74. }
  75. TEST_F(IntelJITEventListenerTest, SingleLine) {
  76. TestSingleLine(ReportedDebugFuncs);
  77. }
  78. TEST_F(IntelJITEventListenerTest, MultipleLines) {
  79. TestMultipleLines(ReportedDebugFuncs);
  80. }
  81. // This testcase is disabled because the Intel JIT API does not support a single
  82. // JITted function with source lines associated with multiple files
  83. /*
  84. TEST_F(IntelJITEventListenerTest, MultipleFiles) {
  85. TestMultipleFiles(ReportedDebugFuncs);
  86. }
  87. */
  88. testing::Environment* const jit_env =
  89. testing::AddGlobalTestEnvironment(new JITEnvironment);