24 #include <boost/filesystem.hpp> 41 std::stringstream converter(hex);
43 converter >> std::hex >>
value;
59 const std::vector<uint8_t>&
v,
62 auto pos = std::find(v.begin() + curPos, v.begin() + limit, 0);
63 if (pos == v.begin() + limit) {
66 return std::distance(v.begin(), pos);
69 static intptr_t
getAddr(
const std::vector<uint8_t>&
v,
size_t& pos) {
72 folly::loadUnaligned<intptr_t>(v.data() + pos -
kAddrWidth));
76 getStr(
const std::vector<uint8_t>&
v,
size_t& pos,
const size_t len) {
80 for (
size_t i = 0;
i < len - 1;
i++) {
81 CHECK_NE(v[pos +
i], 0);
82 res[
i] = char(v[pos +
i]);
84 CHECK_EQ(0, v[pos + len - 1]);
91 return boost::filesystem::read_symlink(path).string();
96 std::vector<std::string>{
103 auto output = subProc.communicate();
104 auto retCode = subProc.wait();
105 CHECK(retCode.exited());
106 CHECK(output.second.empty());
111 std::vector<uint8_t> res;
113 CHECK(!rawContent.empty());
117 auto pos = rawContent.find(contentStart);
118 CHECK_NE(pos, std::string::npos);
119 pos = rawContent.find(
"\n", pos + 1);
120 CHECK_NE(pos, std::string::npos);
121 rawContent = rawContent.substr(pos + 1);
122 std::vector<std::string>
lines;
124 CHECK_GT(lines.size(), 0);
126 for (
auto line : lines) {
128 auto endPos = line.find(
" ");
129 CHECK_NE(endPos, std::string::npos);
130 line = line.substr(0, endPos);
131 std::vector<std::string> segments;
133 CHECK_GE(segments.size(), 2);
135 for (
size_t i = 1;
i < segments.size();
i++) {
136 CHECK_EQ(8, segments[
i].
size());
137 for (
size_t j = 0; j < 8; j += 2) {
143 CHECK_EQ(0, res.size() % 4);
147 template <std::
size_t SIZE>
150 std::array<int, SIZE>& expectedSize) {
151 std::vector<std::string> args;
153 EXPECT_EQ(expectedSize.size(), args.size());
154 for (
size_t i = 0;
i < args.size();
i++) {
156 auto pos = args[
i].find(
"@");
160 EXPECT_EQ(expectedSize[
i], abs(folly::to<int>(argSize)));
173 const uintptr_t expectedSemaphore,
178 auto len = note.size();
184 CHECK_LE(pos + 12, len);
190 size_t remaining = contentSize;
196 CHECK_LE(pos + headerSize + contentSize, len);
204 intptr_t probeAddr =
getAddr(note, pos);
205 CHECK_GT(probeAddr, 0);
208 intptr_t baseAddr =
getAddr(note, pos);
209 CHECK_EQ(0, baseAddr);
212 intptr_t semaphoreAddr =
getAddr(note, pos);
216 int providerEnd =
getNextZero(note, pos, pos + remaining - 1);
217 CHECK_GE(providerEnd, 0);
218 size_t providerLen = providerEnd - pos + 1;
220 remaining -= providerLen;
222 int probeEnd =
getNextZero(note, pos, pos + remaining - 1);
223 CHECK_GE(probeEnd, 0);
224 size_t probeLen = probeEnd - pos + 1;
226 remaining -= probeLen;
228 arguments =
getStr(note, pos, remaining);
231 if (provider == expectedProvider && probe == expectedProbe) {
232 CHECK_EQ(expectedSemaphore, semaphoreAddr);
248 TEST(StaticTracepoint, TestArray) {
253 "folly",
"test_static_tracepoint_array", 0, arguments));
254 std::array<int, 3> expected{{
sizeof(
void*),
sizeof(
int),
sizeof(
int64_t)}};
262 const char*
a = str.c_str();
267 TEST(StaticTracepoint, TestPointer) {
272 "folly",
"test_static_tracepoint_array", 0, arguments));
273 std::array<int, 3> expected{{
sizeof(
void*),
sizeof(
int),
sizeof(
void*)}};
281 TEST(StaticTracepoint, TestEmpty) {
286 "folly",
"test_static_tracepoint_empty", 0, arguments));
295 bool bool_ = (
a % 2) == (
b % 2);
296 char char_ =
a & 255;
297 short short_ =
b & 32767;
299 float float_ = float(
a) / float(
b);
300 double double_ = double(
a) / double(
b);
303 test_static_tracepoint_many_arg_types,
316 TEST(StaticTracepoint, TestManyArgTypes) {
321 "folly",
"test_static_tracepoint_many_arg_types", 0, arguments));
322 std::array<int, 8> expected{{
342 TEST(StaticTracepoint, TestAlwaysInline) {
347 "folly",
"test_static_tracepoint_always_inline", 0, arguments));
358 FOLLY_SDT(
folly, test_static_tracepoint_branch_2,
double(a) /
double(b));
362 TEST(StaticTracepoint, TestBranch) {
367 "folly",
"test_static_tracepoint_branch_1", 0, arguments1));
368 std::array<int, 1> expected1{{
sizeof(
uint32_t)}};
373 "folly",
"test_static_tracepoint_branch_2", 0, arguments2));
374 std::array<int, 1> expected2{{
sizeof(double)}};
393 TEST(StaticTracepoint, TestStruct) {
398 "folly",
"test_static_tracepoint_struct", 0, arguments));
403 TEST(StaticTracepoint, TestSemaphoreLocal) {
409 "test_semaphore_local",
412 std::array<int, 2> expected{{
sizeof(long),
sizeof(
short)}};
419 TEST(StaticTracepoint, TestSemaphoreExtern) {
#define FOLLY_SDT_NOTE_NAME
constexpr size_t headerSize()
#define FOLLY_SDT_SEMAPHORE(provider, name)
#define FOLLY_SDT(provider, name,...)
static FOLLY_ALWAYS_INLINE uint32_t alwaysInlineTestFunc()
static std::string getExe()
static uint32_t pointerTestFunc()
#define FOLLY_SDT_NOTE_TYPE
#define FOLLY_ALWAYS_INLINE
FOLLY_SDT_DECLARE_SEMAPHORE(folly, test_semaphore_extern)
static int getNextZero(const std::vector< uint8_t > &v, const size_t curPos, const size_t limit)
std::string sformat(StringPiece fmt, Args &&...args)
#define EXPECT_EQ(val1, val2)
static std::string getStr(const std::vector< uint8_t > &v, size_t &pos, const size_t len)
—— Concurrent Priority Queue Implementation ——
static std::string getNoteRawContent(const std::string &fileName)
unsigned staticTracepointTestFunc(unsigned v)
void split(const Delim &delimiter, const String &input, std::vector< OutputType > &out, bool ignoreEmpty)
static void emptyTestFunc()
static void branchTestFunc()
static void structTestFunc()
constexpr auto size(C const &c) -> decltype(c.size())
static void align4Bytes(size_t &pos)
constexpr auto empty(C const &c) -> decltype(c.empty())
double expectedProbe(std::vector< std::size_t > const &probeLengths)
#define FOLLY_SDT_WITH_SEMAPHORE(provider, name,...)
static bool getTracepointArguments(const std::string &expectedProvider, const std::string &expectedProbe, const uintptr_t expectedSemaphore, std::string &arguments)
#define FOLLY_SDT_IS_ENABLED(provider, name)
static const size_t kAddrWidth
S lines(StringPiece source)
static uint32_t arrayTestFunc()
static const char *const value
static const std::string kUSDTSubsectionName
TEST(StaticTracepoint, TestArray)
static intptr_t getAddr(const std::vector< uint8_t > &v, size_t &pos)
std::integral_constant< bool, B > bool_
static void checkTracepointArguments(const std::string &arguments, std::array< int, SIZE > &expectedSize)
#define EXPECT_TRUE(condition)
static uint8_t hexToInt(const std::string &hex)
#define FOLLY_SDT_DEFINE_SEMAPHORE(provider, name)
static int get4BytesValue(const std::vector< uint8_t > &v, size_t &pos)
#define EXPECT_NE(val1, val2)
static const int kUSDTNoteType
#define EXPECT_FALSE(condition)
#define EXPECT_LT(val1, val2)
static uint32_t manyArgTypesTestFunc()
static std::vector< uint8_t > readNote(const std::string &fileName)
#define ASSERT_TRUE(condition)