Skip to content

Commit 54d15f0

Browse files
committed
test(thread): add gtests for ProfiledThread park state
1 parent 74a498a commit 54d15f0

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2026 Datadog, Inc.
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+
17+
#include <gtest/gtest.h>
18+
#include "thread.h"
19+
20+
TEST(ProfiledThreadParkStateTest, ParkFlagLifecycle) {
21+
ProfiledThread* thread = ProfiledThread::forTid(12345);
22+
23+
EXPECT_FALSE(thread->isParkedForWallclock());
24+
25+
thread->parkEnter(101, 202, 777);
26+
EXPECT_TRUE(thread->isParkedForWallclock());
27+
28+
u64 start_ticks = 0;
29+
Context park_context = {};
30+
EXPECT_TRUE(thread->parkExit(start_ticks, park_context));
31+
EXPECT_EQ(777ULL, start_ticks);
32+
EXPECT_EQ(101ULL, park_context.spanId);
33+
EXPECT_EQ(202ULL, park_context.rootSpanId);
34+
EXPECT_FALSE(thread->isParkedForWallclock());
35+
36+
// Second exit is a no-op once the parked bit is cleared.
37+
EXPECT_FALSE(thread->parkExit(start_ticks, park_context));
38+
}
39+
40+
TEST(ProfiledThreadParkStateTest, ParkEnterSnapshotsTagEncodings) {
41+
ProfiledThread* thread = ProfiledThread::forTid(12346);
42+
u32* tags = thread->getOtelTagEncodingsPtr();
43+
tags[0] = 11;
44+
tags[1] = 22;
45+
tags[2] = 33;
46+
47+
thread->parkEnter(303, 404, 888);
48+
49+
// Mutate live encodings after enter: park context must keep the enter snapshot.
50+
tags[0] = 111;
51+
tags[1] = 222;
52+
tags[2] = 333;
53+
54+
u64 start_ticks = 0;
55+
Context park_context = {};
56+
ASSERT_TRUE(thread->parkExit(start_ticks, park_context));
57+
EXPECT_EQ(888ULL, start_ticks);
58+
EXPECT_EQ(303ULL, park_context.spanId);
59+
EXPECT_EQ(404ULL, park_context.rootSpanId);
60+
EXPECT_EQ(11U, park_context.tags[0].value);
61+
EXPECT_EQ(22U, park_context.tags[1].value);
62+
EXPECT_EQ(33U, park_context.tags[2].value);
63+
}

0 commit comments

Comments
 (0)