Closed
Bug 1471144
Opened 7 years ago
Closed 7 years ago
Add gtest coverage for CombinedStacks
Categories
(Toolkit :: Telemetry, enhancement, P3)
Toolkit
Telemetry
Tracking
()
RESOLVED
FIXED
mozilla63
Tracking | Status | |
---|---|---|
firefox63 | --- | fixed |
People
(Reporter: Dexter, Assigned: petru.gurita1, Mentored)
References
(Blocks 1 open bug)
Details
(Whiteboard: [lang=c++][good-next-bug])
Attachments
(1 file, 4 obsolete files)
While CombinedStacks [1] is indirectly covered by the xpcshell test coverage for KeyedStackCapturer [2], it might be a good idea to add gtest unit testing for it.
We should at least test adding and removing stacks.
[1] - https://searchfox.org/mozilla-central/rev/39b790b29543a4718d876d8ca3fd179d82fc24f7/toolkit/components/telemetry/CombinedStacks.cpp
[2] - https://searchfox.org/mozilla-central/source/toolkit/components/telemetry/tests/unit/test_TelemetryCaptureStack.js#61
Reporter | ||
Comment 1•7 years ago
|
||
To do this, we should:
- add a new test file (e.g. "TestCombinedStacks.cpp") in https://searchfox.org/mozilla-central/source/toolkit/components/telemetry/tests/gtest
- add a test case |TEST_F(...)| to the file, as done in https://searchfox.org/mozilla-central/rev/d2966246905102b36ef5221b0e3cbccf7ea15a86/toolkit/components/telemetry/tests/gtest/TestCounters.cpp#16
- add the new file to the list in moz.build here: https://searchfox.org/mozilla-central/rev/d2966246905102b36ef5221b0e3cbccf7ea15a86/toolkit/components/telemetry/tests/gtest/moz.build#17
To make sure the tests are working, the following command can be used:
> ./mach gtest Telemetry*
Mentor: alessio.placitelli
Priority: -- → P3
Whiteboard: [lang=c++][good-next-bug]
Comment hidden (mozreview-request) |
Assignee | ||
Comment 3•7 years ago
|
||
I am not sure if I am on the right track.
1. I don't know if I tested the Add operation as intended/ properly.
2. I don't know which method to call in order to test the remove stack method.
3. Should I use an `AutoJSContextWithGlobal` object for different calls (I've seen this in most of the tests from gtest/)? If yes, how do I find which one?
Thanks!
Reporter | ||
Comment 4•7 years ago
|
||
mozreview-review |
Comment on attachment 8990609 [details]
Bug 1471144 - Add gtest coverage for 'CombinedStacks' .
https://reviewboard.mozilla.org/r/255666/#review262422
This looks like a good start, thank you for your contribution! While the current test would work, I think we should test the behaviour of the `AddStack` function a bit deeper, as explained below.
::: toolkit/components/telemetry/tests/gtest/TestCombinedStacks.cpp:1
(Diff revision 1)
> +#include "CombinedStacks.h"
We should add the copyright header before the include, as done [here](https://searchfox.org/mozilla-central/rev/28daa2806c89684b3dfa4f0b551db1d099dda7c2/toolkit/components/telemetry/tests/gtest/TestHistograms.cpp#2-4)
::: toolkit/components/telemetry/tests/gtest/TestCombinedStacks.cpp:3
(Diff revision 1)
> +#include "CombinedStacks.h"
> +
> +namespace mozilla {
Let's not add tests to these namespaces: there's no need to
::: toolkit/components/telemetry/tests/gtest/TestCombinedStacks.cpp:8
(Diff revision 1)
> +namespace mozilla {
> + namespace Telemetry {
> +
> + TEST_F(TelemetryTestFixture, CombinedStacksAdd) {
> +
> + const size_t kMaxChromeStacksKept = 10;
nit: let's call this `kMaxStacksKept`
::: toolkit/components/telemetry/tests/gtest/TestCombinedStacks.cpp:9
(Diff revision 1)
> + namespace Telemetry {
> +
> + TEST_F(TelemetryTestFixture, CombinedStacksAdd) {
> +
> + const size_t kMaxChromeStacksKept = 10;
> + CombinedStacks cStack(kMaxChromeStacksKept);
nit: let's call this simply `stacks`
::: toolkit/components/telemetry/tests/gtest/TestCombinedStacks.cpp:11
(Diff revision 1)
> + TEST_F(TelemetryTestFixture, CombinedStacksAdd) {
> +
> + const size_t kMaxChromeStacksKept = 10;
> + CombinedStacks cStack(kMaxChromeStacksKept);
> +
> + for (size_t i = 0; i < kMaxChromeStacksKept; ++i) {
Since we're making the `CombinedStacks` instance hold 10 elements, we should try to push more than that to it: it's a circular queue, so it should overwrite the oldest elements it contains. Let's make sure of that.
::: toolkit/components/telemetry/tests/gtest/TestCombinedStacks.cpp:12
(Diff revision 1)
> +
> + const size_t kMaxChromeStacksKept = 10;
> + CombinedStacks cStack(kMaxChromeStacksKept);
> +
> + for (size_t i = 0; i < kMaxChromeStacksKept; ++i) {
> + cStack.AddStack(ProcessedStack());
To verify that we're overwriting the right elements when adding more than 10, we could add some data to `ProcessedStack`. We can do something like that (see the interface [here](https://searchfox.org/mozilla-central/source/toolkit/components/telemetry/ProcessedStack.h#26)):
```
ProcessedStack s;
ProcessedStack::Module m = { ... some data here ...};
ProcessedStack::Frame f = {...data..};
s.AddModule(m);
s.AddFrame(f);
stacks.AddStack(s);
```
Of course the data from `m` and `f` would need to change at each iteration.
::: toolkit/components/telemetry/tests/gtest/TestCombinedStacks.cpp:15
(Diff revision 1)
> +
> + for (size_t i = 0; i < kMaxChromeStacksKept; ++i) {
> + cStack.AddStack(ProcessedStack());
> + }
> +
> + const size_t actualValue = cStack.GetStackCount();
We can simply use `stacks.GetStackCount()` and `kMaxStacksKept` in the `ASSERT_EQ` below, without assigning them to constants that are just once.
Attachment #8990609 -
Flags: review?(alessio.placitelli) → review-
Reporter | ||
Comment 5•7 years ago
|
||
(In reply to Petru Gurita from comment #3)
> I am not sure if I am on the right track.
> 1. I don't know if I tested the Add operation as intended/ properly.
You started good! I left a few notes to improve the coverage there.
> 2. I don't know which method to call in order to test the remove stack
> method.
You should call the |RemoveStack| method: https://searchfox.org/mozilla-central/rev/28daa2806c89684b3dfa4f0b551db1d099dda7c2/toolkit/components/telemetry/CombinedStacks.h#35
> 3. Should I use an `AutoJSContextWithGlobal` object for different calls
> (I've seen this in most of the tests from gtest/)? If yes, how do I find
> which one?
> Thanks!
For this test, there's no need to instantiate that object, so you don't need to worry about that. That object is used to provide a JS context when calling other JS-based Telemetry internal functions from the tests.
Assignee | ||
Comment 6•7 years ago
|
||
This is my progress so far. When I try to print the number of stacks, mozilla crashes. I don't know how to solve the issue.
Reporter | ||
Comment 7•7 years ago
|
||
(In reply to Petru Gurita from comment #6)
> Created attachment 8992483 [details]
> TestCombinedStacks.cpp
>
> This is my progress so far. When I try to print the number of stacks,
> mozilla crashes. I don't know how to solve the issue.
Hey! Would you mind updating the ReviewBoard request or attaching a patch? It would make it easier to review and leave comments.
I can't see where you are trying to print the number of stacks in that code. Moreover, can you please give more information about where it's crashing? Do you have a stack?
Assignee: nobody → petru.gurita1
Flags: needinfo?(petru.gurita1)
Assignee | ||
Comment 8•7 years ago
|
||
I'm not at my personal computer right now and so I'm unable to attach a patch (changing the head to this particular commit will not work. If I run `hg log -u "Petru Gurita" ` the patch will not be shown). I tested the code again it crashes without even printing the number of stacks (the printing was done after adding the stacks). It crashes at `stacks.AddStack(s);`. Yes I do
Flags: needinfo?(petru.gurita1)
Assignee | ||
Comment 9•7 years ago
|
||
Ok, I found out that was the problem:
ProcessedStack::Module m = {NS_LITERAL_STRING("test"), moduleName};
If I add this module to the stack the program crushes.
I don't know how to set a nsString value with a particular string value.
I also tried yesterday for few hours to figure it out but couldn't solve the issue.
Assignee | ||
Comment 10•7 years ago
|
||
When I try to add the changes to the path all I get is the message 'nothing changed'. I don't know what to do.
Reporter | ||
Comment 11•7 years ago
|
||
(In reply to Petru Gurita from comment #10)
> When I try to add the changes to the path all I get is the message 'nothing
> changed'. I don't know what to do.
Which commands are you trying to run? Did you add the new file to the current changes using "hg add"?
Assignee | ||
Comment 12•7 years ago
|
||
Yes. I tried with and without `hg add`.
Reporter | ||
Comment 13•7 years ago
|
||
(In reply to Petru Gurita from comment #12)
> Yes. I tried with and without `hg add`.
What's the status of your tree? Check with |hg diff -c .|. You should be seeing the files you changed there. If not, you should probably hop on IRC and get help in #introduction :(
Assignee | ||
Comment 14•7 years ago
|
||
I'll eventually either find a solution or just submit a new patch, but the problem regarding assigning a string to a nsString still remains!
Reporter | ||
Comment 15•7 years ago
|
||
(In reply to Petru Gurita from comment #14)
> I'll eventually either find a solution or just submit a new patch, but the
> problem regarding assigning a string to a nsString still remains!
I'm getting away for some time, Jan-Erik will take over the mentoring for this bug! He'll help you take this to the last line :)
@Petru, are you still having difficulties with mercurial?
Mentor: jrediger
Flags: needinfo?(petru.gurita1)
Assignee | ||
Comment 17•7 years ago
|
||
Assignee | ||
Updated•7 years ago
|
Attachment #8992483 -
Attachment is obsolete: true
Assignee | ||
Comment 18•7 years ago
|
||
Comment on attachment 8994144 [details]
TestCombinedStacks.cpp
>/* Any copyright is dedicated to the Public Domain.
> * http://creativecommons.org/publicdomain/zero/1.0/
> */
>
>#include "CombinedStacks.h"
>#include "ProcessedStack.h"
>
>using namespace mozilla::Telemetry;
>using namespace TelemetryTestHelpers;
>
>TEST_F(TelemetryTestFixture, CombinedStacks) {
>
> const size_t kMaxStacksKept = 10;
> CombinedStacks stacks(kMaxStacksKept);
>
> size_t iterations = kMaxStacksKept * 2;
>
> //TEST ADD
>
> for (size_t i = 0; i < iterations * 2; ++i) {
>
> Telemetry::ProcessedStack s;
> ProcessedStack::Frame f;
> s.AddFrame(f);
> stacks.AddStack(s);
> }
>}
Attachment #8994144 -
Attachment is obsolete: true
Comment hidden (mozreview-request) |
Assignee | ||
Updated•7 years ago
|
Attachment #8990609 -
Attachment is obsolete: true
Comment hidden (mozreview-request) |
Assignee | ||
Updated•7 years ago
|
Attachment #8995262 -
Attachment is obsolete: true
Attachment #8995262 -
Flags: review?(jrediger)
Comment 21•7 years ago
|
||
mozreview-review |
Comment on attachment 8995267 [details]
Bug 1471144 - Add gtest coverage for 'CombinedStacks' .
https://reviewboard.mozilla.org/r/259746/#review266920
Attachment #8995267 -
Flags: review?(jrediger) → review+
Comment 22•7 years ago
|
||
Pushed by jrediger@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/c7c002c926ef
Add gtest coverage for 'CombinedStacks' . r=janerik
Comment 23•7 years ago
|
||
bugherder |
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla63
You need to log in
before you can comment on or make changes to this bug.
Description
•