record_equal_test.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2015 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. static void CheckMmapRecordDataEqual(const MmapRecord& r1, const MmapRecord& r2) {
  17. ASSERT_EQ(0, memcmp(r1.data, r2.data, sizeof(*r1.data)));
  18. ASSERT_STREQ(r1.filename, r2.filename);
  19. }
  20. static void CheckCommRecordDataEqual(const CommRecord& r1, const CommRecord& r2) {
  21. ASSERT_EQ(0, memcmp(r1.data, r2.data, sizeof(*r1.data)));
  22. ASSERT_STREQ(r1.comm, r2.comm);
  23. }
  24. static void CheckBuildIdRecordDataEqual(const BuildIdRecord& r1, const BuildIdRecord& r2) {
  25. ASSERT_EQ(r1.pid, r2.pid);
  26. ASSERT_EQ(r1.build_id, r2.build_id);
  27. ASSERT_STREQ(r1.filename, r2.filename);
  28. }
  29. static void CheckSampleRecordDataEqual(const SampleRecord& r1, const SampleRecord& r2) {
  30. ASSERT_EQ(r1.sample_type, r2.sample_type);
  31. if (r1.sample_type & PERF_SAMPLE_IP) {
  32. EXPECT_EQ(r1.ip_data.ip, r2.ip_data.ip);
  33. }
  34. if (r1.sample_type & PERF_SAMPLE_TID) {
  35. EXPECT_EQ(r1.tid_data.pid, r2.tid_data.pid);
  36. EXPECT_EQ(r1.tid_data.tid, r2.tid_data.tid);
  37. }
  38. if (r1.sample_type & PERF_SAMPLE_TIME) {
  39. EXPECT_EQ(r1.time_data.time, r2.time_data.time);
  40. }
  41. if (r1.sample_type & PERF_SAMPLE_ID) {
  42. EXPECT_EQ(r1.id_data.id, r2.id_data.id);
  43. }
  44. if (r1.sample_type & PERF_SAMPLE_CPU) {
  45. EXPECT_EQ(r1.cpu_data.cpu, r2.cpu_data.cpu);
  46. }
  47. if (r1.sample_type & PERF_SAMPLE_PERIOD) {
  48. EXPECT_EQ(r1.period_data.period, r2.period_data.period);
  49. }
  50. if (r1.sample_type & PERF_SAMPLE_CALLCHAIN) {
  51. ASSERT_EQ(r1.callchain_data.ip_nr, r2.callchain_data.ip_nr);
  52. for (size_t i = 0; i < r1.callchain_data.ip_nr; ++i) {
  53. EXPECT_EQ(r1.callchain_data.ips[i], r2.callchain_data.ips[i]);
  54. }
  55. }
  56. if (r1.sample_type & PERF_SAMPLE_REGS_USER) {
  57. ASSERT_EQ(r1.regs_user_data.abi, r2.regs_user_data.abi);
  58. if (r1.regs_user_data.abi != 0) {
  59. ASSERT_EQ(r1.regs_user_data.reg_mask, r2.regs_user_data.reg_mask);
  60. ASSERT_EQ(0, memcmp(r1.regs_user_data.regs, r2.regs_user_data.regs,
  61. r1.regs_user_data.reg_nr * sizeof(uint64_t)));
  62. }
  63. }
  64. if (r1.sample_type & PERF_SAMPLE_STACK_USER) {
  65. ASSERT_EQ(r1.stack_user_data.size, r2.stack_user_data.size);
  66. if (r1.stack_user_data.size > 0) {
  67. ASSERT_EQ(r1.stack_user_data.dyn_size, r2.stack_user_data.dyn_size);
  68. ASSERT_EQ(0, memcmp(r1.stack_user_data.data, r2.stack_user_data.data,
  69. r1.stack_user_data.size));
  70. }
  71. }
  72. }
  73. static void CheckRecordEqual(const Record& r1, const Record& r2) {
  74. ASSERT_EQ(r1.type(), r2.type());
  75. ASSERT_EQ(r1.misc(), r2.misc());
  76. ASSERT_EQ(r1.size(), r2.size());
  77. if (r1.type() == PERF_RECORD_SAMPLE) {
  78. CheckSampleRecordDataEqual(static_cast<const SampleRecord&>(r1),
  79. static_cast<const SampleRecord&>(r2));
  80. return;
  81. }
  82. ASSERT_EQ(0, memcmp(&r1.sample_id, &r2.sample_id, sizeof(r1.sample_id)));
  83. if (r1.type() == PERF_RECORD_MMAP) {
  84. CheckMmapRecordDataEqual(static_cast<const MmapRecord&>(r1), static_cast<const MmapRecord&>(r2));
  85. } else if (r1.type() == PERF_RECORD_COMM) {
  86. CheckCommRecordDataEqual(static_cast<const CommRecord&>(r1), static_cast<const CommRecord&>(r2));
  87. } else if (r1.type() == PERF_RECORD_BUILD_ID) {
  88. CheckBuildIdRecordDataEqual(static_cast<const BuildIdRecord&>(r1),
  89. static_cast<const BuildIdRecord&>(r2));
  90. }
  91. }