Bug 45060 - Add unit tests for red-black tree and (POD) arena
Summary: Add unit tests for red-black tree and (POD) arena
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Kenneth Russell
URL:
Keywords:
Depends on: 45059
Blocks: 44729 45161
  Show dependency treegraph
 
Reported: 2010-09-01 13:46 PDT by Kenneth Russell
Modified: 2010-09-05 21:45 PDT (History)
9 users (show)

See Also:


Attachments
Patch (13.20 KB, patch)
2010-09-01 14:34 PDT, Kenneth Russell
kbr: commit-queue-
Details | Formatted Diff | Diff
Revised patch (13.20 KB, patch)
2010-09-01 15:21 PDT, Kenneth Russell
kbr: commit-queue-
Details | Formatted Diff | Diff
Revised patch (18.03 KB, patch)
2010-09-02 19:36 PDT, Kenneth Russell
kbr: commit-queue-
Details | Formatted Diff | Diff
Revised patch (18.03 KB, patch)
2010-09-02 19:58 PDT, Kenneth Russell
fishd: review-
kbr: commit-queue-
Details | Formatted Diff | Diff
Revised patch (18.29 KB, patch)
2010-09-03 16:49 PDT, Kenneth Russell
kbr: commit-queue-
Details | Formatted Diff | Diff
Revised patch (19.63 KB, patch)
2010-09-03 17:14 PDT, Kenneth Russell
fishd: review+
kbr: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kenneth Russell 2010-09-01 13:46:31 PDT
The red-black tree being integrated in https://bugs.webkit.org/show_bug.cgi?id=45059 needs unit tests integrated as well.
Comment 1 Kenneth Russell 2010-09-01 14:34:43 PDT
Created attachment 66273 [details]
Patch

Patch incorporating unit tests for PODRedBlackTree. They're currently being incorporated under the Chromium port only because it's this port which has a unit test framework (gtest) available.
Comment 2 Kenneth Russell 2010-09-01 15:21:48 PDT
Created attachment 66288 [details]
Revised patch

Changed EXPECT_TRUE to ASSERT_TRUE in InsertionAndDeletionTest to abort execution upon first failure.
Comment 3 WebKit Review Bot 2010-09-01 19:11:31 PDT
Attachment 66288 [details] did not build on chromium:
Build output: http://queues.webkit.org/results/3933043
Comment 4 Kenneth Russell 2010-09-01 19:21:25 PDT
(In reply to comment #3)
> Attachment 66288 [details] did not build on chromium:
> Build output: http://queues.webkit.org/results/3933043

That's expected, since this can't land before https://bugs.webkit.org/show_bug.cgi?id=45059 .
Comment 5 Kenneth Russell 2010-09-02 19:19:06 PDT
Changing synopsis to indicate that tests for both PODRedBlackTree and PODArena will be added.
Comment 6 Kenneth Russell 2010-09-02 19:36:35 PDT
Created attachment 66460 [details]
Revised patch

Added tests for PODArena, and revised PODRedBlackTreeTests for updated tree API in bug 45059.
Comment 7 WebKit Review Bot 2010-09-02 19:37:31 PDT
Attachment 66460 [details] did not pass style-queue:

Failed to run "['WebKitTools/Scripts/check-webkit-style']" exit_code: 1
WebKit/chromium/tests/PODArenaTest.cpp:57:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
WebKit/chromium/tests/PODArenaTest.cpp:63:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
WebKit/chromium/tests/PODArenaTest.cpp:65:  Consider using ASSERT_GE instead of ASSERT_TRUE(a >= b)  [readability/check] [2]
WebKit/chromium/tests/PODArenaTest.cpp:70:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
WebKit/chromium/tests/PODArenaTest.cpp:71:  Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.  [readability/comparison_to_zero] [5]
WebKit/chromium/tests/PODArenaTest.cpp:74:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
WebKit/chromium/tests/PODArenaTest.cpp:107:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
WebKit/chromium/tests/PODArenaTest.cpp:116:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
WebKit/chromium/tests/PODArenaTest.cpp:122:  One line control clauses should not use braces.  [whitespace/braces] [4]
WebKit/chromium/tests/PODArenaTest.cpp:129:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
Total errors found: 10 in 6 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 8 Kenneth Russell 2010-09-02 19:58:13 PDT
Created attachment 66464 [details]
Revised patch

Fixed style errors in last patch.
Comment 9 Darin Adler 2010-09-03 10:03:19 PDT
Can we please leave this POD prefix off of most of these class names? I don’t think the POD prefix adds anything in almsot every case.

The classes in WTF such as HashMap also have limitations for what objects they work with, but trying to encode those limitations into the class names seems awkward and unpleasant. Unless we have imminent plans to have a second red-black tree.
Comment 10 Darin Adler 2010-09-03 10:04:08 PDT
Chromium-only unit tests seem wrong. We’ve added quite a few unit tests cross-platform by making them triggerable from DumpRenderTree.

It’s not a good direction for the WebKit project to add major new functionality with tests only on a single platform.
Comment 11 Kenneth Russell 2010-09-03 10:15:28 PDT
(In reply to comment #9)
> Can we please leave this POD prefix off of most of these class names? I don’t think the POD prefix adds anything in almsot every case.
> 
> The classes in WTF such as HashMap also have limitations for what objects they work with, but trying to encode those limitations into the class names seems awkward and unpleasant. Unless we have imminent plans to have a second red-black tree.

Darin, I will do my best to eliminate the restrictions on these classes and then remove the POD prefix -- after I have checkpointed the code. Right now I've landed two of the three classes and none of the using code, and to keep my bookkeeping sane I do not want to rename them until I've gotten an initial version of the code checked in, which hopefully should be within a week.
Comment 12 Kenneth Russell 2010-09-03 10:18:16 PDT
(In reply to comment #10)
> Chromium-only unit tests seem wrong. We’ve added quite a few unit tests cross-platform by making them triggerable from DumpRenderTree.
> 
> It’s not a good direction for the WebKit project to add major new functionality with tests only on a single platform.

Could you point me to an example of a unit test that is hooked up in DRT and how it is invoked? I would definitely like to make these tests run on all ports.
Comment 13 Darin Adler 2010-09-03 14:37:24 PDT
(In reply to comment #11)
> Darin, I will do my best to eliminate the restrictions on these classes and then remove the POD prefix

That’s nice to hear. But I think you’re missing my point. Even with the restrictions, the POD prefix is not helpful.
Comment 14 Kenneth Russell 2010-09-03 14:58:04 PDT
(In reply to comment #13)
> (In reply to comment #11)
> > Darin, I will do my best to eliminate the restrictions on these classes and then remove the POD prefix
> 
> That’s nice to hear. But I think you’re missing my point. Even with the restrictions, the POD prefix is not helpful.

I understand your point. I am not prepared to rename these classes until I've checkpointed an initial version of this code so I can use svn and do-webcore-rename to do the work. I'd appreciate your help reviewing these patches modulo the naming convention.
Comment 15 Darin Adler 2010-09-03 15:21:33 PDT
(In reply to comment #14)
> I'd appreciate your help reviewing these patches modulo the naming convention.

I can’t review these classes at all. I don’t understand the big picture. It seems like there is a lot of already working code that you want to get into WebKit as quickly as possible.
Comment 16 Darin Fisher (:fishd, Google) 2010-09-03 15:45:37 PDT
(In reply to comment #15)
> (In reply to comment #14)
> > I'd appreciate your help reviewing these patches modulo the naming convention.
> 
> I can’t review these classes at all. I don’t understand the big picture. It seems like there is a lot of already working code that you want to get into WebKit as quickly as possible.

Hi Darin, yes... Ken is working to contribute his GPU based path renderer, which we discussed with cmarrin, hyatt, smfr, and others in person about a week ago.  These are preliminary patches.  The code will live in graphics/gpu/.

The plan is for Ken to land his code as a check point and then make incremental improvements.

There has been a healthy debate about naming conventions.  We have chosen a naming convention that has issues (the POD prefix), and we are committed to fixing that.  It is easier to rename using the tools in WebKit (that depend on code already being committed), so please bear with us as we take these incremental steps.

The unit test issue is another example.  In the Chromium port we have a well established way of writing unit tests using the Gtest framework.  WebCore seems to lack a good way to unit test basic data structures, but we'd like to find a way to share these unit tests with all ports so that this code will be sure to run properly on all ports.  The existing layout test framework does not seem to be a good fit, or at least it is not obvious how to make it fit.  Regardless, it is useful to check point these unit tests since they are already written and of value to Ken (who is developing this code).  We will figure out how best to make these tests available more universally.  We are taking an incremental path.
Comment 17 Darin Fisher (:fishd, Google) 2010-09-03 16:06:54 PDT
Comment on attachment 66464 [details]
Revised patch

View in context: https://bugs.webkit.org/attachment.cgi?id=66464&action=prettypatch

> WebKit/chromium/tests/PODArenaTest.cpp:32
> +// Tests for the PODArena.
nit: I'd nuke this comment since it is redundant with the file name.

> WebKit/chromium/tests/PODArenaTest.cpp:82
> +protected:
nit: looks like this constructor can just be in the private section

> WebKit/chromium/tests/PODArenaTest.cpp:115
> +    for (int i = 0; i < 10000; ++i)
this choice of 10000 seems to depend on the value of DefaultChunkSize.
maybe you should parameterize this using that value?  this test could
fail if DefaultChunkSize were increased significantly.

> WebKit/chromium/tests/PODRedBlackTreeTest.cpp:44
> +using namespace TreeTestHelpers;
instead of a namespace, I think a class with static methods would be 
better.  it is just uncommon in webkit to use a namespace like this.

> WebKit/chromium/tests/PODRedBlackTreeTest.cpp:147
> +    tree.add(5113);
is there something special about the choice of numbers here?
maybe a comment would be good if so?  elsewhere, you use
smaller numbers :)

> WebKit/chromium/tests/PODRedBlackTreeTest.cpp:168
> +        int val = nextRandom(maximumValue);
nit: spell out "value"

> WebKit/chromium/tests/PODRedBlackTreeTest.cpp:176
> +        int idx = nextRandom(treeSize);
nit: spell out "index" and "value"
Comment 18 Kenneth Russell 2010-09-03 16:49:55 PDT
Created attachment 66565 [details]
Revised patch

Addressed most review feedback; made TrackedAllocator constructor private, added FIXME about DefaultChunkSize, added comment about origin of values in one regression test, and avoided abbreviations in variable names.
Comment 19 Kenneth Russell 2010-09-03 16:59:28 PDT
(In reply to comment #17)
> (From update of attachment 66464 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=66464&action=prettypatch
> 
> > WebKit/chromium/tests/PODArenaTest.cpp:32
> > +// Tests for the PODArena.
> nit: I'd nuke this comment since it is redundant with the file name.

Done.

> > WebKit/chromium/tests/PODArenaTest.cpp:82
> > +protected:
> nit: looks like this constructor can just be in the private section

Done.

> > WebKit/chromium/tests/PODArenaTest.cpp:115
> > +    for (int i = 0; i < 10000; ++i)
> this choice of 10000 seems to depend on the value of DefaultChunkSize.
> maybe you should parameterize this using that value?  this test could
> fail if DefaultChunkSize were increased significantly.

Right now DefaultChunkSize is private, and making this test a friend is really ugly due to gtest's name mangling. I added a FIXME. I hope this will be sufficient for now.

> > WebKit/chromium/tests/PODRedBlackTreeTest.cpp:44
> > +using namespace TreeTestHelpers;
> instead of a namespace, I think a class with static methods would be 
> better.  it is just uncommon in webkit to use a namespace like this.

The std namespace is used in many places in WebKit. The ability to use the TreeTestHelpers namespace rather than prefixing every method call with the class name really cleans up the code, and I'm using this technique elsewhere in forthcoming patches. I'd really rather leave this as is.

> > WebKit/chromium/tests/PODRedBlackTreeTest.cpp:147
> > +    tree.add(5113);
> is there something special about the choice of numbers here?
> maybe a comment would be good if so?  elsewhere, you use
> smaller numbers :)

Added a comment.

> > WebKit/chromium/tests/PODRedBlackTreeTest.cpp:168
> > +        int val = nextRandom(maximumValue);
> nit: spell out "value"

Done.

> > WebKit/chromium/tests/PODRedBlackTreeTest.cpp:176
> > +        int idx = nextRandom(treeSize);
> nit: spell out "index" and "value"

Done.
Comment 20 Darin Fisher (:fishd, Google) 2010-09-03 17:04:46 PDT
(In reply to comment #19)
...
> > > WebKit/chromium/tests/PODArenaTest.cpp:115
> > > +    for (int i = 0; i < 10000; ++i)
> > this choice of 10000 seems to depend on the value of DefaultChunkSize.
> > maybe you should parameterize this using that value?  this test could
> > fail if DefaultChunkSize were increased significantly.
> 
> Right now DefaultChunkSize is private, and making this test a friend is really ugly due to gtest's name mangling. I added a FIXME. I hope this will be sufficient for now.

I was proposing that you make that public so it could be used here.
A FIXME is fine, but please consider making the change now since it
would be pretty trivial.


> > > WebKit/chromium/tests/PODRedBlackTreeTest.cpp:44
> > > +using namespace TreeTestHelpers;
> > instead of a namespace, I think a class with static methods would be 
> > better.  it is just uncommon in webkit to use a namespace like this.
> 
> The std namespace is used in many places in WebKit. The ability to use the TreeTestHelpers namespace rather than prefixing every method call with the class name really cleans up the code, and I'm using this technique elsewhere in forthcoming patches. I'd really rather leave this as is.

This is quite different from the std:: namespace.  The problem I had
when reading this code is that it wasn't obvious where some of these
functions are defined, so I had to go "grepping" for them, which led
me to the namespace.  That is not a problem for very commonly used
classes and functions like what you find in the WTF namespace.

Anyways, I don't feel strongly enough about this.  It was just something
I observed that might not be obvious when one already has all of this
code loaded in one's head.
Comment 21 Kenneth Russell 2010-09-03 17:09:28 PDT
(In reply to comment #20)
> (In reply to comment #19)
> ...
> > > > WebKit/chromium/tests/PODArenaTest.cpp:115
> > > > +    for (int i = 0; i < 10000; ++i)
> > > this choice of 10000 seems to depend on the value of DefaultChunkSize.
> > > maybe you should parameterize this using that value?  this test could
> > > fail if DefaultChunkSize were increased significantly.
> > 
> > Right now DefaultChunkSize is private, and making this test a friend is really ugly due to gtest's name mangling. I added a FIXME. I hope this will be sufficient for now.
> 
> I was proposing that you make that public so it could be used here.
> A FIXME is fine, but please consider making the change now since it
> would be pretty trivial.

OK, I'll make it public and update the tests. Revised patch coming.

> > > > WebKit/chromium/tests/PODRedBlackTreeTest.cpp:44
> > > > +using namespace TreeTestHelpers;
> > > instead of a namespace, I think a class with static methods would be 
> > > better.  it is just uncommon in webkit to use a namespace like this.
> > 
> > The std namespace is used in many places in WebKit. The ability to use the TreeTestHelpers namespace rather than prefixing every method call with the class name really cleans up the code, and I'm using this technique elsewhere in forthcoming patches. I'd really rather leave this as is.
> 
> This is quite different from the std:: namespace.  The problem I had
> when reading this code is that it wasn't obvious where some of these
> functions are defined, so I had to go "grepping" for them, which led
> me to the namespace.  That is not a problem for very commonly used
> classes and functions like what you find in the WTF namespace.
> 
> Anyways, I don't feel strongly enough about this.  It was just something
> I observed that might not be obvious when one already has all of this
> code loaded in one's head.

I see your point. I could add explicit using directives for each of the imported functions so it would be more obvious. I'd really like to keep it as a namespace though.
Comment 22 Kenneth Russell 2010-09-03 17:14:46 PDT
Created attachment 66567 [details]
Revised patch

Made DefaultChunkSize public in arena and use it in unit test rather than magic constant.
Comment 23 Darin Fisher (:fishd, Google) 2010-09-04 20:29:34 PDT
Comment on attachment 66567 [details]
Revised patch

The explicit 'using TestTreeHelpers::nextRandom' and so on would be nice assuming
that works for functions?

R=me
Comment 24 Kenneth Russell 2010-09-05 20:53:29 PDT
(In reply to comment #23)
> (From update of attachment 66567 [details])
> The explicit 'using TestTreeHelpers::nextRandom' and so on would be nice assuming
> that works for functions?

It does; see "using std::max" elsewhere in the source tree, for example. Changed in version to be committed; also fixed incorrect license at top of these files and the other recently checked in ones.
Comment 25 Kenneth Russell 2010-09-05 21:45:57 PDT
Committed r66808: <http://trac.webkit.org/changeset/66808>