Skip to content

Commit

Permalink
Adjust unit test to an allowed sample size
Browse files Browse the repository at this point in the history
  • Loading branch information
r1viollet committed Jul 6, 2023
1 parent e7249b6 commit f136a1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
11 changes: 7 additions & 4 deletions test/ddprof_context-ut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ TEST(DDProfContext, env_variable_with_extra_semicolons) {
TEST(DDProfContext, stack_size) {
LogHandle handle;
// Set environment variable
setenv(k_events_env_variable, "sCPU sample_stack_user=65536;", 1);
setenv(k_events_env_variable, "sCPU sample_stack_user=65528;", 1);
defer { unsetenv(k_events_env_variable); };

// Init CLI and parse inputs
Expand All @@ -405,22 +405,25 @@ TEST(DDProfContext, stack_size) {

ASSERT_EQ(ctx.watchers.size(), 1);
EXPECT_EQ(ctx.watchers[0].ddprof_event_type, DDPROF_PWE_sCPU);
EXPECT_EQ(ctx.watchers[0].options.sample_stack_user, 65536);
EXPECT_EQ(ctx.watchers[0].options.sample_stack_user, 65528);
}

TEST(DDProfContext, default_stack_size) {
LogHandle handle;
// Init CLI and parse inputs
DDProfCLI ddprof_cli;
const char *input_values[] = {MYNAME, "--sample_stack_user", "65536",
uint32_t big_sample_size = 65528;
std::string big_sample_size_str = std::to_string(big_sample_size);
const char *input_values[] = {MYNAME, "--sample_stack_user",
big_sample_size_str.c_str(),
"--show_config", "my_program"};
int res = ddprof_cli.parse(std::size(input_values), input_values);
ASSERT_EQ(res, 0);
DDProfContext ctx;
DDRes ddres = context_set(ddprof_cli, ctx);
EXPECT_TRUE(IsDDResOK(ddres));
EXPECT_EQ(ctx.watchers[0].ddprof_event_type, DDPROF_PWE_sCPU);
EXPECT_EQ(ctx.watchers[0].options.sample_stack_user, 65536);
EXPECT_EQ(ctx.watchers[0].options.sample_stack_user, big_sample_size);
}

} // namespace ddprof
7 changes: 3 additions & 4 deletions test/deep_stacks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ CONFIG_DEEP_STACK="../test/configs/deep_stacks.toml"

# Check for truncated stack traces
truncated_input=$(awk -F': ' '/datadog.profiling.native.unwind.stack.truncated_input/ { print $NF }' ./log_ddprof.txt)
truncated_output=$(awk -F': ' '/datadog.profiling.native.unwind.stack.truncated_output/ { print $NF }' ./log_ddprof.txt)

# If we fail to run ddprof we should also be missing the metric (so this test should fail)
if [ "$truncated_input" != "0" ] || [ "$truncated_output" != "0" ]; then
# If we fail to run ddprof we should also be missing the metric
if [ "$truncated_input" != "0" ]; then
echo "Found truncated stack traces!"
echo "Truncated input: $truncated_input, Truncated output: $truncated_output"
echo "Truncated input: $truncated_input"
exit 1
else
echo "No truncated stack traces found."
Expand Down

0 comments on commit f136a1c

Please sign in to comment.