summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/xray/tests
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2018-07-31 04:16:54 +0000
committerDean Michael Berris <dberris@google.com>2018-07-31 04:16:54 +0000
commit3bd20d460521706269318e81da9f28346bfdb949 (patch)
treef2294e4081d6f7d1faa9b4b9130fd1c242886778 /compiler-rt/lib/xray/tests
parent3587150fcbe36cdaca3df2fa2887059e3aba69eb (diff)
downloadbcm5719-llvm-3bd20d460521706269318e81da9f28346bfdb949.tar.gz
bcm5719-llvm-3bd20d460521706269318e81da9f28346bfdb949.zip
[XRay][compiler-rt] Profiling Mode: Include file header in buffers
Summary: This change provides access to the file header even in the in-memory buffer processing. This allows in-memory processing of the buffers to also check the version, and the format, of the profile data. Reviewers: eizan, kpw Reviewed By: eizan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D50037 llvm-svn: 338347
Diffstat (limited to 'compiler-rt/lib/xray/tests')
-rw-r--r--compiler-rt/lib/xray/tests/unit/profile_collector_test.cc36
1 files changed, 34 insertions, 2 deletions
diff --git a/compiler-rt/lib/xray/tests/unit/profile_collector_test.cc b/compiler-rt/lib/xray/tests/unit/profile_collector_test.cc
index b7dbe567312..00a7d53dc99 100644
--- a/compiler-rt/lib/xray/tests/unit/profile_collector_test.cc
+++ b/compiler-rt/lib/xray/tests/unit/profile_collector_test.cc
@@ -15,6 +15,8 @@
#include "xray_profile_collector.h"
#include "xray_profiling_flags.h"
#include <cstdint>
+#include <cstring>
+#include <memory>
#include <thread>
#include <utility>
#include <vector>
@@ -24,6 +26,29 @@ namespace {
static constexpr auto kHeaderSize = 16u;
+constexpr uptr ExpectedProfilingVersion = 0x20180424;
+
+struct ExpectedProfilingFileHeader {
+ const u64 MagicBytes = 0x7872617970726f66; // Identifier for XRay profiling
+ // files 'xrayprof' in hex.
+ const uptr Version = ExpectedProfilingVersion;
+ uptr Timestamp = 0;
+ uptr PID = 0;
+};
+
+void ValidateFileHeaderBlock(XRayBuffer B) {
+ ASSERT_NE(static_cast<const void *>(B.Data), nullptr);
+ ASSERT_EQ(B.Size, sizeof(ExpectedProfilingFileHeader));
+ typename std::aligned_storage<sizeof(ExpectedProfilingFileHeader)>::type
+ FileHeaderStorage;
+ ExpectedProfilingFileHeader ExpectedHeader;
+ std::memcpy(&FileHeaderStorage, B.Data, B.Size);
+ auto &FileHeader =
+ *reinterpret_cast<ExpectedProfilingFileHeader *>(&FileHeaderStorage);
+ ASSERT_EQ(ExpectedHeader.MagicBytes, FileHeader.MagicBytes);
+ ASSERT_EQ(ExpectedHeader.Version, FileHeader.Version);
+}
+
void ValidateBlock(XRayBuffer B) {
profilingFlags()->setDefaults();
ASSERT_NE(static_cast<const void *>(B.Data), nullptr);
@@ -107,9 +132,13 @@ TEST(profileCollectorServiceTest, PostSerializeCollect) {
// Then we serialize the data.
profileCollectorService::serialize();
- // Then we go through a single buffer to see whether we're getting the data we
- // expect.
+ // Then we go through two buffers to see whether we're getting the data we
+ // expect. The first block must always be as large as a file header, which
+ // will have a fixed size.
auto B = profileCollectorService::nextBuffer({nullptr, 0});
+ ValidateFileHeaderBlock(B);
+
+ B = profileCollectorService::nextBuffer(B);
ValidateBlock(B);
u32 BlockSize;
u32 BlockNum;
@@ -169,6 +198,9 @@ TEST(profileCollectorServiceTest, PostSerializeCollectMultipleThread) {
// Ensure that we see two buffers.
auto B = profileCollectorService::nextBuffer({nullptr, 0});
+ ValidateFileHeaderBlock(B);
+
+ B = profileCollectorService::nextBuffer(B);
ValidateBlock(B);
B = profileCollectorService::nextBuffer(B);
OpenPOWER on IntegriCloud