Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PR #1416: unsigned int overflow bug and unstable tests #1436

Merged
merged 1 commit into from
Jul 28, 2020

Conversation

suyuee
Copy link
Contributor

@suyuee suyuee commented Jul 23, 2020

Related to #1416.The merged PR which enables top and div args of print for avg maps has
two issues that need addressing:

  1. It came with subtractions of unsigned integers which can easily cause
    negative overflows.
  2. The runtime tests it came with are somehow unstable and fails randomly. This
    patch brings more straightforward tests.
Checklist
  • Language changes are updated in docs/reference_guide.md
  • User-visible and non-trivial changes updated in CHANGELOG.md

@suyuee suyuee changed the title Fix PR #1416 Fix PR #1416: negative overflow bug and unstable tests Jul 24, 2020
@suyuee suyuee changed the title Fix PR #1416: negative overflow bug and unstable tests Fix PR #1416: unsigned int overflow bug and unstable tests Jul 24, 2020
@suyuee
Copy link
Contributor Author

suyuee commented Jul 24, 2020

Update the CHANGELOG.md

Copy link
Member

@danobi danobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. I think *Output::map and *Output::map_hist suffer from the same issue, right? Can you fix those too?

EXPECT ^4$
NAME print_avg_map_args
RUN bpftrace -e 'BEGIN { @["a"] = avg(10); @["b"] = avg(20); @["c"] = avg(30); @["d"] = avg(40); print(@, 2, 10); print("END"); clear(@); exit(); }'
EXPECT Attaching 1 probe\.\.\.\n@\[c\]: 3\n@\[d\]: 4\n\nEND
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the regex does a line-by-line match which means I think you can do this

Suggested change
EXPECT Attaching 1 probe\.\.\.\n@\[c\]: 3\n@\[d\]: 4\n\nEND
EXPECT @\[c\]: 3\n@\[d\]: 4\n\nEND

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm actually, I do this on purpose. I think the 'EXPECT' actually means 'CONTAINS' in runtime test framework, in other words EXPECT @\[c\]: 3\n@\[d\]: 4\n\nEND would allow something like:

Attaching 1 probe...
@[a]: 1
@[b]: 2
@[c]: 3
@[d]: 4

END

because it contains specified pattern. Prefix the pattern with the line 'Attaching 1 probe...' can prevent it from ignoring the wrong output.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what "wrong output" would it avoid? Isn't it enough to match only

@[a]: 1
@[b]: 2
@[c]: 3
@[d]: 4

END

Why would we need to match the entirety of the output?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I got it right here, but here is what I think. Since we have top = 2, the script below should only print the top 2 entries:

# bpftrace -e 'BEGIN { @["a"] = avg(10); @["b"] = avg(20); @["c"] = avg(30); @["d"] = avg(40); print(@, 2, 10); print("END"); clear(@); exit(); }'

Attaching 1 probe...
@[c]: 3
@[d]: 4

END

And since we want top to be effective, we do not actually want to see all four entries being printed out. If the output contains four entries, top is not functioning properly; but in this case, the four-entry output can still pass the test with EXPECT @\[c\]: 3\n@\[d\]: 4\n\nEND because the output contains this pattern.

If I'm not getting it wrong, the output with all four entries should be the wrong output we may want to avoid here. The expected output should contains exactly @[c]: 3 and @[d]: 4.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah that makes sense. Thanks for the explanation

EXPECT ^@\[[0-9]+\]: 1$
NAME print_avg_map_with_large_top
RUN bpftrace -e 'BEGIN { @["a"] = avg(10); @["b"] = avg(20); @["c"] = avg(30); @["d"] = avg(40); print(@, 10, 10); print("END"); clear(@); exit(); }'
EXPECT Attaching 1 probe\.\.\.\n@\[a\]: 1\n@\[b\]: 2\n@\[c\]: 3\n@\[d\]: 4\n\nEND
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@danobi
Copy link
Member

danobi commented Jul 25, 2020

Ah, just saw #1437 .

Copy link
Member

@danobi danobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but please rebase and resolve merge conflicts

The merged PR which enables `top` and `div` args of `print` for `avg` maps has
two issues that need addressing:

1. It came with subtractions of unsigned integers which can easily cause
negative overflows.
2. The runtime tests it came with are somehow unstable and fails randomly. This
patch brings more straightforward tests.
@suyuee
Copy link
Contributor Author

suyuee commented Jul 28, 2020

Rebased.

@danobi danobi merged commit b6fa141 into bpftrace:master Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants